dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42835
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21843: more test fixes
------------------------------------------------------------
revno: 21843
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-02-01 15:40:20 +0700
message:
more test fixes
added:
dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAAutoRef.json
modified:
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.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/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java 2016-02-01 08:08:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java 2016-02-01 08:40:20 +0000
@@ -44,7 +44,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -424,32 +423,8 @@
@SuppressWarnings( "unchecked" )
public void testPreheatReferenceWithScanUID()
{
- DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );
- dataElementGroup.setAutoFields();
-
- DataElement de1 = createDataElement( 'A' );
- DataElement de2 = createDataElement( 'B' );
- DataElement de3 = createDataElement( 'C' );
-
- manager.save( de1 );
- manager.save( de2 );
- manager.save( de3 );
-
- User user = createUser( 'A' );
- manager.save( user );
-
- dataElementGroup.addDataElement( de1 );
- dataElementGroup.addDataElement( de2 );
- dataElementGroup.addDataElement( de3 );
-
- dataElementGroup.setUser( user );
- manager.save( dataElementGroup );
-
- List<DataElement> members = new ArrayList<>( dataElementGroup.getMembers() );
- members.set( 0, createDataElementIdentifier( de1.getUid(), PreheatIdentifier.UID ) );
- members.set( 1, createDataElementIdentifier( de2.getUid(), PreheatIdentifier.UID ) );
- members.set( 2, createDataElementIdentifier( de3.getUid(), PreheatIdentifier.UID ) );
- dataElementGroup.setMembers( new HashSet<>( members ) );
+ DataElementGroup dataElementGroup = fromJson( "preheat/degAUidRef.json", DataElementGroup.class );
+ defaultSetup();
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.UID );
@@ -466,11 +441,39 @@
assertTrue( preheat.isEmpty( PreheatIdentifier.UID, DataElementGroup.class ) );
assertFalse( preheat.isEmpty( PreheatIdentifier.UID, User.class ) );
- assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, de1.getUid() ) );
- assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, de2.getUid() ) );
- assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, de3.getUid() ) );
- assertFalse( preheat.containsKey( PreheatIdentifier.UID, DataElementGroup.class, dataElementGroup.getUid() ) );
- assertTrue( preheat.containsKey( PreheatIdentifier.UID, User.class, user.getUid() ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, "deabcdefghA" ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, "deabcdefghB" ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, DataElement.class, "deabcdefghC" ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.UID, User.class, "userabcdefA" ) );
+ }
+
+ @Test
+ @SuppressWarnings( "unchecked" )
+ public void testPreheatReferenceWithScanCODE()
+ {
+ DataElementGroup dataElementGroup = fromJson( "preheat/degACodeRef.json", DataElementGroup.class );
+ defaultSetup();
+
+ Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.CODE );
+
+ PreheatParams params = new PreheatParams();
+ params.setPreheatIdentifier( PreheatIdentifier.CODE );
+ params.setPreheatMode( PreheatMode.REFERENCE );
+ params.setReferences( references );
+
+ preheatService.validate( params );
+ Preheat preheat = preheatService.preheat( params );
+
+ assertFalse( preheat.isEmpty() );
+ assertFalse( preheat.isEmpty( PreheatIdentifier.CODE ) );
+ assertFalse( preheat.isEmpty( PreheatIdentifier.CODE, DataElement.class ) );
+ assertTrue( preheat.isEmpty( PreheatIdentifier.CODE, DataElementGroup.class ) );
+ assertFalse( preheat.isEmpty( PreheatIdentifier.CODE, User.class ) );
+
+ assertTrue( preheat.containsKey( PreheatIdentifier.CODE, DataElement.class, "DataElementCodeA" ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.CODE, DataElement.class, "DataElementCodeB" ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.CODE, DataElement.class, "DataElementCodeC" ) );
+ assertTrue( preheat.containsKey( PreheatIdentifier.CODE, User.class, "UserCodeA" ) );
}
@Test
@@ -478,17 +481,7 @@
public void testPreheatReferenceConnectUID()
{
DataElementGroup dataElementGroup = fromJson( "preheat/degAUidRef.json", DataElementGroup.class );
-
- DataElement de1 = createDataElement( 'A' );
- DataElement de2 = createDataElement( 'B' );
- DataElement de3 = createDataElement( 'C' );
-
- manager.save( de1 );
- manager.save( de2 );
- manager.save( de3 );
-
- User user = createUser( 'A' );
- manager.save( user );
+ defaultSetup();
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.UID );
@@ -519,7 +512,72 @@
public void testPreheatReferenceConnectCODE()
{
DataElementGroup dataElementGroup = fromJson( "preheat/degACodeRef.json", DataElementGroup.class );
-
+ defaultSetup();
+
+ Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.CODE );
+
+ PreheatParams params = new PreheatParams();
+ params.setPreheatIdentifier( PreheatIdentifier.CODE );
+ params.setPreheatMode( PreheatMode.REFERENCE );
+ params.setReferences( references );
+
+ preheatService.validate( params );
+ Preheat preheat = preheatService.preheat( params );
+ preheatService.connectReferences( dataElementGroup, preheat, PreheatIdentifier.CODE );
+
+ manager.update( dataElementGroup );
+
+ List<DataElement> members = new ArrayList<>( dataElementGroup.getMembers() );
+
+ assertEquals( "DataElementA", members.get( 0 ).getName() );
+ assertEquals( "DataElementCodeA", members.get( 0 ).getCode() );
+ assertEquals( "DataElementB", members.get( 1 ).getName() );
+ assertEquals( "DataElementCodeB", members.get( 1 ).getCode() );
+ assertEquals( "DataElementC", members.get( 2 ).getName() );
+ assertEquals( "DataElementCodeC", members.get( 2 ).getCode() );
+
+ assertEquals( "FirstNameA", dataElementGroup.getUser().getFirstName() );
+ assertEquals( "SurnameA", dataElementGroup.getUser().getSurname() );
+ assertEquals( "UserCodeA", dataElementGroup.getUser().getCode() );
+ }
+
+ @Test
+ @SuppressWarnings( "unchecked" )
+ @Ignore
+ public void testPreheatReferenceConnectAUTO()
+ {
+ DataElementGroup dataElementGroup = fromJson( "preheat/degAAutoRef.json", DataElementGroup.class );
+ defaultSetup();
+
+ Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.UID );
+
+ PreheatParams params = new PreheatParams();
+ params.setPreheatIdentifier( PreheatIdentifier.CODE );
+ params.setPreheatMode( PreheatMode.REFERENCE );
+ params.setReferences( references );
+
+ preheatService.validate( params );
+ Preheat preheat = preheatService.preheat( params );
+ preheatService.connectReferences( dataElementGroup, preheat, PreheatIdentifier.CODE );
+
+ manager.update( dataElementGroup );
+
+ List<DataElement> members = new ArrayList<>( dataElementGroup.getMembers() );
+
+ assertEquals( "DataElementA", members.get( 0 ).getName() );
+ assertEquals( "DataElementCodeA", members.get( 0 ).getCode() );
+ assertEquals( "DataElementB", members.get( 1 ).getName() );
+ assertEquals( "DataElementCodeB", members.get( 1 ).getCode() );
+ assertEquals( "DataElementC", members.get( 2 ).getName() );
+ assertEquals( "DataElementCodeC", members.get( 2 ).getCode() );
+
+ assertEquals( "FirstNameA", dataElementGroup.getUser().getFirstName() );
+ assertEquals( "SurnameA", dataElementGroup.getUser().getSurname() );
+ assertEquals( "UserCodeA", dataElementGroup.getUser().getCode() );
+ }
+
+ private void defaultSetup()
+ {
DataElement de1 = createDataElement( 'A' );
DataElement de2 = createDataElement( 'B' );
DataElement de3 = createDataElement( 'C' );
@@ -530,63 +588,5 @@
User user = createUser( 'A' );
manager.save( user );
-
- Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.CODE );
-
- PreheatParams params = new PreheatParams();
- params.setPreheatIdentifier( PreheatIdentifier.CODE );
- params.setPreheatMode( PreheatMode.REFERENCE );
- params.setReferences( references );
-
- preheatService.validate( params );
- Preheat preheat = preheatService.preheat( params );
- preheatService.connectReferences( dataElementGroup, preheat, PreheatIdentifier.CODE );
-
- manager.update( dataElementGroup );
-
- List<DataElement> members = new ArrayList<>( dataElementGroup.getMembers() );
-
- assertEquals( "DataElementA", members.get( 0 ).getName() );
- assertEquals( "DataElementCodeA", members.get( 0 ).getCode() );
- assertEquals( "DataElementB", members.get( 1 ).getName() );
- assertEquals( "DataElementCodeB", members.get( 1 ).getCode() );
- assertEquals( "DataElementC", members.get( 2 ).getName() );
- assertEquals( "DataElementCodeC", members.get( 2 ).getCode() );
-
- assertEquals( "FirstNameA", dataElementGroup.getUser().getFirstName() );
- assertEquals( "SurnameA", dataElementGroup.getUser().getSurname() );
- assertEquals( "UserCodeA", dataElementGroup.getUser().getCode() );
- }
-
- private DataElement createDataElementIdentifier( String identifier, PreheatIdentifier preheatIdentifier )
- {
- DataElement dataElement = new DataElement();
-
- if ( PreheatIdentifier.UID == preheatIdentifier )
- {
- dataElement.setUid( identifier );
- }
- else if ( PreheatIdentifier.CODE == preheatIdentifier )
- {
- dataElement.setCode( identifier );
- }
-
- return dataElement;
- }
-
- private User createUserIdentifier( String identifier, PreheatIdentifier preheatIdentifier )
- {
- User user = new User();
-
- if ( PreheatIdentifier.UID == preheatIdentifier )
- {
- user.setUid( identifier );
- }
- else if ( PreheatIdentifier.CODE == preheatIdentifier )
- {
- user.setCode( identifier );
- }
-
- return user;
}
}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAAutoRef.json'
--- dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAAutoRef.json 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAAutoRef.json 2016-02-01 08:40:20 +0000
@@ -0,0 +1,17 @@
+{
+ "name": "DataElementGroupA",
+ "user": {
+ "code": "UserCodeA"
+ },
+ "dataElements": [
+ {
+ "id": "deabcdefghA"
+ },
+ {
+ "id": "deabcdefghB"
+ },
+ {
+ "code": "DataElementCodeC"
+ }
+ ]
+}
\ No newline at end of file