r557 - in trunk: wikitty-dto/src/test/java/org/nuiton/wikitty/dto wikitty-generators/src/main/java/org/nuiton/wikitty/generator
Author: jcouteau Date: 2010-12-03 16:52:09 +0100 (Fri, 03 Dec 2010) New Revision: 557 Url: http://nuiton.org/repositories/revision/wikitty/557 Log: Improve version management in DTO. Unit test not passing. Modified: trunk/wikitty-dto/src/test/java/org/nuiton/wikitty/dto/WikittyDTOTest.java trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java Modified: trunk/wikitty-dto/src/test/java/org/nuiton/wikitty/dto/WikittyDTOTest.java =================================================================== --- trunk/wikitty-dto/src/test/java/org/nuiton/wikitty/dto/WikittyDTOTest.java 2010-12-03 14:42:18 UTC (rev 556) +++ trunk/wikitty-dto/src/test/java/org/nuiton/wikitty/dto/WikittyDTOTest.java 2010-12-03 15:52:09 UTC (rev 557) @@ -24,29 +24,38 @@ */ package org.nuiton.wikitty.dto; +import org.junit.Before; import org.junit.Test; -import org.nuiton.util.ApplicationConfig; import org.nuiton.wikitty.WikittyConfig; import org.nuiton.wikitty.WikittyProxy; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; +import org.nuiton.wikitty.WikittyService; +import org.nuiton.wikitty.WikittyServiceFactory; +import org.nuiton.wikitty.WikittyUtil; import org.nuiton.wikitty.entities.WikittyLabel; import org.nuiton.wikitty.entities.WikittyLabelImpl; -import org.nuiton.wikitty.services.WikittyServiceInMemory; public class WikittyDTOTest { static private Log log = LogFactory.getLog(WikittyDTOTest.class); + WikittyProxy proxy; + + @Before + public void clear() throws Exception { + + WikittyConfig config = new WikittyConfig("refcomp-test.properties"); + + WikittyService ws = WikittyServiceFactory.buildWikittyService(config); + ws.clear(null); + proxy = new WikittyProxy(ws); + } + @Test public void testConversions() { - //create proxy as we can only use proxy when dealing with dtos - ApplicationConfig config = new WikittyConfig(); - WikittyServiceInMemory ws = new WikittyServiceInMemory(config); - WikittyProxy proxy = new WikittyProxy(ws); - //create business entity with wikitty WikittyLabel label = new WikittyLabelImpl(); label.addLabels("Test"); @@ -57,24 +66,41 @@ //make conversion WikittyLabel dto = DTOHelper.toDto(label); + //entity=>dto conversion test //check that dto fields are the same than the wikitty ones Assert.assertNotNull(dto); Assert.assertEquals(label.getWikittyId(),dto.getWikittyId()); - Assert.assertEquals(label.getWikittyVersion(),dto.getWikittyVersion()); + Assert.assertTrue(WikittyUtil.versionEquals(label.getWikittyVersion(),dto.getWikittyVersion())); Assert.assertEquals(label.getLabels(), dto.getLabels()); + //First dto=>entity conversion test, no modification + //make conversion to wikitty + WikittyLabel secondLabel = DTOHelper.fromDto(proxy, WikittyLabel.class, dto); + + //check that dto fields are the same than the wikitty ones + Assert.assertNotNull(secondLabel); + Assert.assertEquals(dto.getWikittyId(), secondLabel.getWikittyId()); + Assert.assertEquals(dto.getLabels(), secondLabel.getLabels()); + Assert.assertTrue( + WikittyUtil.versionEquals(secondLabel.getWikittyVersion(), + dto.getWikittyVersion())); + + //Second entity=>dto conversion test, modifications on dto //modify dto dto.addLabels("toto"); - dto.setWikittyVersion("2.0"); //make conversion to wikitty - WikittyLabel secondLabel = DTOHelper.fromDto(proxy,WikittyLabel.class,dto); + WikittyLabel thirdLabel = DTOHelper.fromDto(proxy,WikittyLabel.class,dto); //check that dto fields are the same than the wikitty ones - Assert.assertNotNull(secondLabel); - Assert.assertEquals(dto.getWikittyId(),secondLabel.getWikittyId()); - Assert.assertEquals(dto.getWikittyVersion(), secondLabel.getWikittyVersion()); - Assert.assertEquals(dto.getLabels(), secondLabel.getLabels()); + Assert.assertNotNull(thirdLabel); + Assert.assertEquals(dto.getWikittyId(),thirdLabel.getWikittyId()); + Assert.assertEquals(dto.getLabels(), thirdLabel.getLabels()); + //Check that version have been updated (for storing) + Assert.assertTrue( + WikittyUtil.versionGreaterThan(thirdLabel.getWikittyVersion(), + dto.getWikittyVersion())); + } } \ No newline at end of file Modified: trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java =================================================================== --- trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java 2010-12-03 14:42:18 UTC (rev 556) +++ trunk/wikitty-generators/src/main/java/org/nuiton/wikitty/generator/WikittyDTOGenerator.java 2010-12-03 15:52:09 UTC (rev 557) @@ -234,6 +234,7 @@ } else { this.<%=attributeName%>=<%=attributeName%>; } + modificationCount++; }*/; setOperationBody(setter, setterBody); @@ -248,6 +249,7 @@ this.<%=attributeName%> = new <%=attributeTypeInSetImpl%>(); } <%=attributeName%>.add(element); + modificationCount++; }*/; setOperationBody(adder, adderBody); @@ -259,6 +261,7 @@ String removerBody = "" /*{ <%=attributeName%>.remove(element); + modificationCount++; }*/; setOperationBody(remover, removerBody); @@ -269,6 +272,7 @@ String clearBody = "" /*{ <%=attributeName%>.clear(); + modificationCount++; }*/; setOperationBody(clear, clearBody); @@ -301,6 +305,7 @@ setOperationBody(setter, "" /*{ this.<%=attributeName%>=<%=attributeName%>; + modificationCount++; }*/); } @@ -430,6 +435,9 @@ //adding wikittyId attribute addAttribute(dtoClass, "wikittyId", "String"); + //adding modificationCount attribute. Used to change version. + addAttribute(dtoClass, "modificationCount = 0", "int"); + //adding getWikittyId method ObjectModelOperation getter = addOperation(dtoClass, "getWikittyId", "String"); addAnnotation(dtoClass, getter, "Override"); @@ -457,7 +465,8 @@ addAnnotation(dtoClass, getWikittyVersion, "Override"); setOperationBody(getWikittyVersion, "" /*{ - return wikittyVersion; + String result = wikittyVersion + "." + modificationCount; + return result; }*/); //adding setWikittyVersion method @@ -467,6 +476,7 @@ setOperationBody(setWikittyVersion, "" /*{ this.wikittyVersion=wikittyVersion; + modificationCount=0; }*/); //adding necessary imports @@ -567,12 +577,15 @@ } <%=entityName%> sourceCopy = (<%=entityName%>)source; +}*/; + copyFromBody = addCopyFromAttributes(entity, copyFromBody); + + copyFromBody +="" +/*{ setWikittyVersion(sourceCopy.getWikittyVersion()); }*/; - copyFromBody = addCopyFromAttributes(entity, copyFromBody); - addImport(dtoClass, "org.nuiton.wikitty.WikittyException"); addImport(dtoClass, "org.nuiton.wikitty.entities.BusinessEntity");
participants (1)
-
jcouteau@users.nuiton.org