Index: src/test/java/info/magnolia/cms/util/ContentUtilTest.java =================================================================== --- src/test/java/info/magnolia/cms/util/ContentUtilTest.java (revision 39299) +++ src/test/java/info/magnolia/cms/util/ContentUtilTest.java (working copy) @@ -141,11 +141,11 @@ assertTrue(hm.isExist("/gugu")); assertTrue(hm.isExist("/gugu/subnode")); } - + public void testOrderAfter() throws RepositoryException, IOException{ MockHierarchyManager hm = MockUtil.createHierarchyManager( "/node/a\n" + - "/node/b\n" + + "/node/b\n" + "/node/c\n"); Content node = hm.getContent("/node"); Content a = node.getContent("a"); @@ -162,7 +162,7 @@ public void testOrderAfterLastNode() throws RepositoryException, IOException{ MockHierarchyManager hm = MockUtil.createHierarchyManager( "/node/a\n" + - "/node/b\n" + + "/node/b\n" + "/node/c\n"); Content node = hm.getContent("/node"); Content a = node.getContent("a"); @@ -176,17 +176,114 @@ assertEquals(Arrays.asList(new String[]{"b", "c","a"}), result); } + public void testOrderAfterFirstNodeOnlyThree() throws RepositoryException, IOException{ + MockHierarchyManager hm = MockUtil.createHierarchyManager( + "/node/a\n" + + "/node/b\n" + + "/node/c\n"); + Content node = hm.getContent("/node"); + Content c = node.getContent("c"); + ContentUtil.orderAfter(c, "a"); + Collection result = node.getChildren(); + CollectionUtils.transform(result, new Transformer() { + public Object transform(Object childObj) { + return ((Content)childObj).getName(); + } + }); + assertEquals(Arrays.asList(new String[]{"a", "c","b"}), result); + } + + public void testOrderAfterFirstNodeMoreThanThreeVariation1() throws RepositoryException, IOException{ + MockHierarchyManager hm = MockUtil.createHierarchyManager( + "/node/a\n" + + "/node/b\n" + + "/node/c\n" + + "/node/d\n" + + "/node/e\n" + + "/node/f\n"); + Content node = hm.getContent("/node"); + Content c = node.getContent("f"); + ContentUtil.orderAfter(c, "a"); + Collection result = node.getChildren(); + CollectionUtils.transform(result, new Transformer() { + public Object transform(Object childObj) { + return ((Content)childObj).getName(); + } + }); + assertEquals(Arrays.asList(new String[]{"a","f","b","c","d","e"}), result); + } + + public void testOrderAfterFirstNodeMoreThanThreeVariation2() throws RepositoryException, IOException{ + MockHierarchyManager hm = MockUtil.createHierarchyManager( + "/node/a\n" + + "/node/b\n" + + "/node/c\n" + + "/node/d\n" + + "/node/e\n" + + "/node/f\n"); + Content node = hm.getContent("/node"); + Content c = node.getContent("e"); + ContentUtil.orderAfter(c, "a"); + Collection result = node.getChildren(); + CollectionUtils.transform(result, new Transformer() { + public Object transform(Object childObj) { + return ((Content)childObj).getName(); + } + }); + assertEquals(Arrays.asList(new String[]{"a","e","b","c","d","f"}), result); + } + + public void testOrderAfterMidNodeMoreThanThreeVariation1() throws RepositoryException, IOException{ + MockHierarchyManager hm = MockUtil.createHierarchyManager( + "/node/a\n" + + "/node/b\n" + + "/node/c\n" + + "/node/d\n" + + "/node/e\n" + + "/node/f\n"); + Content node = hm.getContent("/node"); + Content c = node.getContent("f"); + ContentUtil.orderAfter(c, "c"); + Collection result = node.getChildren(); + CollectionUtils.transform(result, new Transformer() { + public Object transform(Object childObj) { + return ((Content)childObj).getName(); + } + }); + assertEquals(Arrays.asList(new String[]{"a","b","c","f","d","e"}), result); + } + + public void testOrderAfterMidNodeMoreThanThreeVariation2() throws RepositoryException, IOException{ + MockHierarchyManager hm = MockUtil.createHierarchyManager( + "/node/a\n" + + "/node/b\n" + + "/node/c\n" + + "/node/d\n" + + "/node/e\n" + + "/node/f\n"); + Content node = hm.getContent("/node"); + Content c = node.getContent("e"); + ContentUtil.orderAfter(c, "b"); + Collection result = node.getChildren(); + CollectionUtils.transform(result, new Transformer() { + public Object transform(Object childObj) { + return ((Content)childObj).getName(); + } + }); + assertEquals(Arrays.asList(new String[]{"a","b","e","c","d","f"}), result); + } + public void testChangeNodeTypeReplaceFirstOccurrenceOnly() throws Exception { final HierarchyManager hm = MgnlContext.getHierarchyManager("config"); final Content src = hm.getRoot().createContent("test"); src.createContent("foo"); src.createContent("bar"); final String oldUUID = src.getUUID(); - + assertEquals("wrong initial type", ItemType.CONTENT.getSystemName() , src.getNodeTypeName()); - + ContentUtil.changeNodeType(src, ItemType.CONTENTNODE, false); - + assertTrue(hm.isExist("/test")); assertEquals(oldUUID, hm.getContent("/test").getUUID()); assertEquals(ItemType.CONTENTNODE.getSystemName(), hm.getContent("/test").getNodeTypeName()); @@ -203,9 +300,9 @@ assertEquals("wrong initial type", ItemType.CONTENT.getSystemName(), src.getNodeTypeName()); assertEquals("wrong initial type", ItemType.CONTENT.getSystemName(), hm.getContent("/test/bar").getNodeTypeName()); assertEquals("wrong initial type", ItemType.CONTENT.getSystemName(), hm.getContent("/test/foo").getNodeTypeName()); - + ContentUtil.changeNodeType(src, ItemType.CONTENTNODE, true); - + assertTrue(hm.isExist("/test")); assertEquals(oldUUID, hm.getContent("/test").getUUID()); assertEquals(ItemType.CONTENTNODE.getSystemName(), hm.getContent("/test").getNodeTypeName());