Author: fdesbois Date: 2010-05-10 19:21:46 +0200 (Mon, 10 May 2010) New Revision: 1952 Url: http://nuiton.org/repositories/revision/topia/1952 Log: Continue testing TopiaContextImpl Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 16:40:22 UTC (rev 1951) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2010-05-10 17:21:46 UTC (rev 1952) @@ -320,7 +320,7 @@ @Override public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException { - E result = null; + E result; try { String name = getServiceName(interfaceService); result = (E) getService(name); Modified: trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java =================================================================== --- trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 16:40:22 UTC (rev 1951) +++ trunk/topia-persistence/src/test/java/org/nuiton/topia/framework/TopiaContextImplTest.java 2010-05-10 17:21:46 UTC (rev 1952) @@ -86,7 +86,7 @@ @Test public void testGetServices() throws Exception { - log.info("## testGetServices"); + log.info("## testGetServices"); /** PREPARE DATA **/ properties.setProperty("topia.service.test", @@ -142,32 +142,47 @@ Assert.assertEquals(TopiaNotFoundException.class, eee.getClass()); } } + + @Test + public void testContextHierarchy() throws Exception { + log.info("## testContextHierarchy"); + + /** PREPARE DATA **/ + TopiaContextImpl context = new TopiaContextImpl(properties); + + /** EXEC METHODS **/ + log.info("test 1 : constructor with parent context"); + TopiaContextImpl test1 = new TopiaContextImpl(context); + Assert.assertEquals(context, test1.parentContext); + + log.info("test 2 : addChildContext"); + TopiaContextImpl test2 = new TopiaContextImpl(properties); + TopiaContextImpl child2 = new TopiaContextImpl(); + test2.addChildContext(child2); + Assert.assertEquals(1, test2.childContext.size()); + + log.info("test 3 : removeChildContext"); + TopiaContextImpl test3 = new TopiaContextImpl(properties); + TopiaContextImpl child3 = new TopiaContextImpl(test3); + test3.childContext.add(child3); + test3.removeChildContext(child3); + Assert.assertEquals(0, test3.childContext.size()); + + // No remove if context is closed + test3.childContext.add(child3); + test3.closed = true; + test3.removeChildContext(child3); + Assert.assertEquals(1, test3.childContext.size()); + + log.info("test 4 : getRootContext"); + TopiaContextImplementor test4 = child3.getRootContext(); + Assert.assertEquals(test3, test4); + + // Note : existing test is already done for concurrency problem on + // getChildContext(). Go to : http://www.nuiton.org/repositories/browse/sandbox/testTopiaPostgresError/tru... + } // // @Test -// public void testGetAllServices() throws Exception { -// } -// -// @Test -// public void testGetChildContext() throws Exception { -// } -// -// @Test -// public void testRemoveChildContext() throws Exception { -// } -// -// @Test -// public void testGetParentContext() throws Exception { -// } -// -// @Test -// public void testGetRootContext() throws Exception { -// } -// -// @Test -// public void testGetConfig() throws Exception { -// } -// -// @Test // public void testCreateSchema() throws Exception { // } //