------------------------------------------------------------ revno: 16430 committer: Morten Olav Hansen <morte...@gmail.com> branch nick: dhis2 timestamp: Sun 2014-08-17 20:37:34 +0700 message: tests and bugfixes for node collection fields added: dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.java modified: dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldComplexNodePropertyIntrospectorServiceTest.java dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldSimpleNodePropertyIntrospectorServiceTest.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java 2014-08-17 07:26:09 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java 2014-08-17 13:37:34 +0000 @@ -130,7 +130,15 @@ handleNodeCollection( nodeCollection, property ); } - propertyMap.put( property.getName(), property ); + if ( property.isCollection() ) + { + propertyMap.put( property.getCollectionName(), property ); + } + else + { + propertyMap.put( property.getName(), property ); + } + } return propertyMap; @@ -188,6 +196,8 @@ private void handleNodeCollection( NodeCollection nodeCollection, Property property ) { property.setCollectionWrapping( nodeCollection.useWrapping() ); + property.setNamespace( nodeCollection.namespace() ); + property.setPersisted( nodeCollection.isPersisted() ); property.setWritable( nodeCollection.isWritable() ); property.setReadable( nodeCollection.isReadable() ); @@ -205,6 +215,10 @@ { property.setCollectionName( nodeCollection.value() ); } + else + { + property.setCollectionName( property.getName() ); + } if ( !StringUtils.isEmpty( nodeCollection.itemName() ) ) { === added file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.java 2014-08-17 13:37:34 +0000 @@ -0,0 +1,169 @@ +package org.hisp.dhis.schema; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ + +import org.hisp.dhis.node.annotation.NodeCollection; +import org.hisp.dhis.node.annotation.NodeSimple; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.*; + +class Item +{ + @NodeSimple + private String value; +} + +class CollectionFields +{ + @NodeCollection + private List<String> property = new ArrayList<>(); + + @NodeCollection( value = "renamedProperty" ) + private List<String> propertyToBeRenamed = new ArrayList<>(); + + @NodeCollection( isReadable = true, isWritable = false ) + private List<String> readOnly = new ArrayList<>(); + + @NodeCollection( isReadable = false, isWritable = true ) + private List<String> writeOnly = new ArrayList<>(); + + @NodeCollection( isPersisted = false ) + private List<String> notPersistedProperty = new ArrayList<>(); + + @NodeCollection( namespace = "http://ns.example.org" ) + private List<String> propertyWithNamespace = new ArrayList<>(); + + public List<String> getProperty() + { + return property; + } + + public void setProperty( List<String> property ) + { + this.property = property; + } + + @NodeCollection + private List<Item> items1 = new ArrayList<>(); + + @NodeCollection( value = "items", itemName = "item" ) + private List<Item> items2 = new ArrayList<>(); +} + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +public class FieldCollectionNodePropertyIntrospectorServiceTest +{ + private Map<String, Property> propertyMap; + + @Before + public void setup() + { + propertyMap = new NodePropertyIntrospectorService().scanClass( CollectionFields.class ); + } + + @Test + public void testContainsKey() + { + assertTrue( propertyMap.containsKey( "property" ) ); + assertFalse( propertyMap.containsKey( "propertyToBeRenamed" ) ); + assertTrue( propertyMap.containsKey( "renamedProperty" ) ); + assertTrue( propertyMap.containsKey( "readOnly" ) ); + assertTrue( propertyMap.containsKey( "writeOnly" ) ); + assertTrue( propertyMap.containsKey( "notPersistedProperty" ) ); + assertTrue( propertyMap.containsKey( "propertyWithNamespace" ) ); + assertTrue( propertyMap.containsKey( "items1" ) ); + assertTrue( propertyMap.containsKey( "items" ) ); + } + + @Test + public void testPersisted() + { + assertTrue( propertyMap.get( "property" ).isPersisted() ); + assertFalse( propertyMap.get( "notPersistedProperty" ).isPersisted() ); + } + + @Test + public void testReadWrite() + { + assertTrue( propertyMap.get( "readOnly" ).isReadable() ); + assertFalse( propertyMap.get( "readOnly" ).isWritable() ); + + assertFalse( propertyMap.get( "writeOnly" ).isReadable() ); + assertTrue( propertyMap.get( "writeOnly" ).isWritable() ); + + assertNull( propertyMap.get( "readOnly" ).getSetterMethod() ); + assertNull( propertyMap.get( "writeOnly" ).getGetterMethod() ); + } + + @Test + public void testFieldName() + { + assertEquals( "property", propertyMap.get( "property" ).getFieldName() ); + assertEquals( "propertyToBeRenamed", propertyMap.get( "renamedProperty" ).getFieldName() ); + assertEquals( "items2", propertyMap.get( "items" ).getFieldName() ); + } + + @Test + public void testNamespace() + { + assertEquals( "http://ns.example.org", propertyMap.get( "propertyWithNamespace" ).getNamespace() ); + } + + @Test + public void testGetter() + { + assertNotNull( propertyMap.get( "property" ).getGetterMethod() ); + assertNull( propertyMap.get( "renamedProperty" ).getGetterMethod() ); + } + + @Test + public void testSetter() + { + assertNotNull( propertyMap.get( "property" ).getSetterMethod() ); + assertNull( propertyMap.get( "renamedProperty" ).getSetterMethod() ); + } + + @Test + public void testItemName() + { + assertEquals( "items1", propertyMap.get( "items1" ).getName() ); + assertEquals( "items1", propertyMap.get( "items1" ).getCollectionName() ); + + assertEquals( "item", propertyMap.get( "items" ).getName() ); + assertEquals( "items", propertyMap.get( "items" ).getCollectionName() ); + } +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldComplexNodePropertyIntrospectorServiceTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldComplexNodePropertyIntrospectorServiceTest.java 2014-08-17 07:26:09 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldComplexNodePropertyIntrospectorServiceTest.java 2014-08-17 13:37:34 +0000 @@ -48,7 +48,7 @@ @NodeComplex private Value property; - @NodeComplex( value = "propertyRenamed" ) + @NodeComplex( value = "renamedProperty" ) private Value propertyToBeRenamed; @NodeComplex( isReadable = true, isWritable = false ) @@ -62,6 +62,16 @@ @NodeComplex( namespace = "http://ns.example.org" ) private Value propertyWithNamespace; + + public Value getProperty() + { + return property; + } + + public void setProperty( Value property ) + { + this.property = property; + } } /** @@ -82,10 +92,10 @@ { assertTrue( propertyMap.containsKey( "property" ) ); assertFalse( propertyMap.containsKey( "propertyToBeRenamed" ) ); - assertTrue( propertyMap.containsKey( "propertyRenamed" ) ); + assertTrue( propertyMap.containsKey( "renamedProperty" ) ); assertTrue( propertyMap.containsKey( "readOnly" ) ); assertTrue( propertyMap.containsKey( "writeOnly" ) ); - assertTrue( propertyMap.containsKey( "propertyRenamed" ) ); + assertTrue( propertyMap.containsKey( "notPersistedProperty" ) ); assertTrue( propertyMap.containsKey( "propertyWithNamespace" ) ); } @@ -113,7 +123,7 @@ public void testFieldName() { assertEquals( "property", propertyMap.get( "property" ).getFieldName() ); - assertEquals( "propertyToBeRenamed", propertyMap.get( "propertyRenamed" ).getFieldName() ); + assertEquals( "propertyToBeRenamed", propertyMap.get( "renamedProperty" ).getFieldName() ); } @Test @@ -125,10 +135,14 @@ @Test public void testGetter() { + assertNotNull( propertyMap.get( "property" ).getGetterMethod() ); + assertNull( propertyMap.get( "renamedProperty" ).getGetterMethod() ); } @Test public void testSetter() { + assertNotNull( propertyMap.get( "property" ).getSetterMethod() ); + assertNull( propertyMap.get( "renamedProperty" ).getSetterMethod() ); } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldSimpleNodePropertyIntrospectorServiceTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldSimpleNodePropertyIntrospectorServiceTest.java 2014-08-17 07:26:09 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldSimpleNodePropertyIntrospectorServiceTest.java 2014-08-17 13:37:34 +0000 @@ -39,10 +39,10 @@ class SimpleFields { @NodeSimple( isAttribute = false ) - private String simpleProperty; + private String property; @NodeSimple( value = "renamedProperty", isAttribute = true ) - private String simplePropertyRenamed; + private String propertyToBeRenamed; @NodeSimple( isPersisted = false ) private String notPersistedProperty; @@ -56,14 +56,14 @@ @NodeSimple( namespace = "http://ns.example.org" ) private String propertyWithNamespace; - public void setSimpleProperty( String simpleProperty ) + public String getProperty() { - this.simpleProperty = simpleProperty; + return property; } - public String getSimpleProperty() + public void setProperty( String property ) { - return simpleProperty; + this.property = property; } } @@ -83,8 +83,8 @@ @Test public void testContainsKey() { - assertTrue( propertyMap.containsKey( "simpleProperty" ) ); - assertFalse( propertyMap.containsKey( "simplePropertyRenamed" ) ); + assertTrue( propertyMap.containsKey( "property" ) ); + assertFalse( propertyMap.containsKey( "propertyToBeRenamed" ) ); assertTrue( propertyMap.containsKey( "renamedProperty" ) ); assertTrue( propertyMap.containsKey( "readOnly" ) ); assertTrue( propertyMap.containsKey( "writeOnly" ) ); @@ -93,14 +93,14 @@ @Test public void testAttribute() { - assertFalse( propertyMap.get( "simpleProperty" ).isAttribute() ); + assertFalse( propertyMap.get( "property" ).isAttribute() ); assertTrue( propertyMap.get( "renamedProperty" ).isAttribute() ); } @Test public void testPersisted() { - assertTrue( propertyMap.get( "simpleProperty" ).isPersisted() ); + assertTrue( propertyMap.get( "property" ).isPersisted() ); assertFalse( propertyMap.get( "notPersistedProperty" ).isPersisted() ); } @@ -120,8 +120,8 @@ @Test public void testFieldName() { - assertEquals( "simpleProperty", propertyMap.get( "simpleProperty" ).getFieldName() ); - assertEquals( "simplePropertyRenamed", propertyMap.get( "renamedProperty" ).getFieldName() ); + assertEquals( "property", propertyMap.get( "property" ).getFieldName() ); + assertEquals( "propertyToBeRenamed", propertyMap.get( "renamedProperty" ).getFieldName() ); } @Test @@ -133,14 +133,14 @@ @Test public void testGetter() { - assertNotNull( propertyMap.get( "simpleProperty" ).getGetterMethod() ); + assertNotNull( propertyMap.get( "property" ).getGetterMethod() ); assertNull( propertyMap.get( "renamedProperty" ).getGetterMethod() ); } @Test public void testSetter() { - assertNotNull( propertyMap.get( "simpleProperty" ).getSetterMethod() ); + assertNotNull( propertyMap.get( "property" ).getSetterMethod() ); assertNull( propertyMap.get( "renamedProperty" ).getSetterMethod() ); } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp