← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21842: made preheat tests more realistic, now loads json files, scans using ref mode, and then connects ...

 

------------------------------------------------------------
revno: 21842
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-02-01 15:08:59 +0700
message:
  made preheat tests more realistic, now loads json files, scans using ref mode, and then connects ref for preheat cache
added:
  dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/
  dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degACodeRef.json
  dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAUidRef.json
modified:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/MetadataImportServiceTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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 07:10:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/preheat/PreheatServiceTest.java	2016-02-01 08:08:59 +0000
@@ -477,8 +477,7 @@
     @SuppressWarnings( "unchecked" )
     public void testPreheatReferenceConnectUID()
     {
-        DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );
-        dataElementGroup.setAutoFields();
+        DataElementGroup dataElementGroup = fromJson( "preheat/degAUidRef.json", DataElementGroup.class );
 
         DataElement de1 = createDataElement( 'A' );
         DataElement de2 = createDataElement( 'B' );
@@ -491,23 +490,6 @@
         User user = createUser( 'A' );
         manager.save( user );
 
-        dataElementGroup.addDataElement( de1 );
-        dataElementGroup.addDataElement( de2 );
-        dataElementGroup.addDataElement( de3 );
-
-        dataElementGroup.setUser( user );
-
-        manager.save( dataElementGroup );
-        manager.evict( 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.setUser( createUserIdentifier( user.getUid(), PreheatIdentifier.UID ) );
-
         Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.UID );
 
         PreheatParams params = new PreheatParams();
@@ -518,9 +500,7 @@
         Preheat preheat = preheatService.preheat( params );
         preheatService.connectReferences( dataElementGroup, preheat, PreheatIdentifier.UID );
 
-        manager.update( dataElementGroup );
-
-        members = new ArrayList<>( dataElementGroup.getMembers() );
+        List<DataElement> members = new ArrayList<>( dataElementGroup.getMembers() );
 
         assertEquals( "DataElementA", members.get( 0 ).getName() );
         assertEquals( "DataElementCodeA", members.get( 0 ).getCode() );
@@ -538,8 +518,7 @@
     @SuppressWarnings( "unchecked" )
     public void testPreheatReferenceConnectCODE()
     {
-        DataElementGroup dataElementGroup = new DataElementGroup( "DataElementGroupA" );
-        dataElementGroup.setAutoFields();
+        DataElementGroup dataElementGroup = fromJson( "preheat/degACodeRef.json", DataElementGroup.class );
 
         DataElement de1 = createDataElement( 'A' );
         DataElement de2 = createDataElement( 'B' );
@@ -552,23 +531,6 @@
         User user = createUser( 'A' );
         manager.save( user );
 
-        dataElementGroup.addDataElement( de1 );
-        dataElementGroup.addDataElement( de2 );
-        dataElementGroup.addDataElement( de3 );
-
-        dataElementGroup.setUser( user );
-
-        manager.save( dataElementGroup );
-        manager.evict( dataElementGroup );
-
-        List<DataElement> members = new ArrayList<>( dataElementGroup.getMembers() );
-        members.set( 0, createDataElementIdentifier( de1.getCode(), PreheatIdentifier.CODE ) );
-        members.set( 1, createDataElementIdentifier( de2.getCode(), PreheatIdentifier.CODE ) );
-        members.set( 2, createDataElementIdentifier( de3.getCode(), PreheatIdentifier.CODE ) );
-
-        dataElementGroup.setMembers( new HashSet<>( members ) );
-        dataElementGroup.setUser( createUserIdentifier( user.getCode(), PreheatIdentifier.CODE ) );
-
         Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences( dataElementGroup, PreheatIdentifier.CODE );
 
         PreheatParams params = new PreheatParams();
@@ -582,7 +544,7 @@
 
         manager.update( dataElementGroup );
 
-        members = new ArrayList<>( dataElementGroup.getMembers() );
+        List<DataElement> members = new ArrayList<>( dataElementGroup.getMembers() );
 
         assertEquals( "DataElementA", members.get( 0 ).getName() );
         assertEquals( "DataElementCodeA", members.get( 0 ).getCode() );

=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degACodeRef.json'
--- dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degACodeRef.json	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degACodeRef.json	2016-02-01 08:08:59 +0000
@@ -0,0 +1,17 @@
+{
+  "name": "DataElementGroupA",
+  "user": {
+    "code": "UserCodeA"
+  },
+  "dataElements": [
+    {
+      "code": "DataElementCodeA"
+    },
+    {
+      "code": "DataElementCodeB"
+    },
+    {
+      "code": "DataElementCodeC"
+    }
+  ]
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAUidRef.json'
--- dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAUidRef.json	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/resources/preheat/degAUidRef.json	2016-02-01 08:08:59 +0000
@@ -0,0 +1,17 @@
+{
+  "name": "DataElementGroupA",
+  "user": {
+    "id": "userabcdefA"
+  },
+  "dataElements": [
+    {
+      "id": "deabcdefghA"
+    },
+    {
+      "id": "deabcdefghB"
+    },
+    {
+      "id": "deabcdefghC"
+    }
+  ]
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/MetadataImportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/MetadataImportServiceTest.java	2016-02-01 07:47:31 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/MetadataImportServiceTest.java	2016-02-01 08:08:59 +0000
@@ -34,8 +34,6 @@
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.io.IOException;
-
 import static org.junit.Assert.assertNotNull;
 
 /**
@@ -51,7 +49,7 @@
     private IdentifiableObjectManager manager;
 
     @Test
-    public void testConstantImport() throws IOException
+    public void testConstantImport()
     {
         Constant constant1 = fromJson( "dxf2/constant1.json", Constant.class );
         Constant constant2 = fromJson( "dxf2/constant2.json", Constant.class );

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2016-02-01 07:47:31 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2016-02-01 08:08:59 +0000
@@ -147,6 +147,8 @@
 
     protected static final String BASE_OU_UID = "ouabcdefgh";
 
+    protected static final String BASE_USER_UID = "userabcdef";
+
     private static final String EXT_TEST_DIR = System.getProperty( "user.home" ) + File.separator + "dhis2_test_dir";
 
     private static Date date;
@@ -1079,7 +1081,7 @@
     {
         UserCredentials credentials = new UserCredentials();
         User user = new User();
-        user.setAutoFields();
+        user.setUid( BASE_USER_UID + uniqueCharacter );
 
         credentials.setUserInfo( user );
         user.setUserCredentials( credentials );
@@ -1444,9 +1446,18 @@
     // Supportive methods
     // -------------------------------------------------------------------------
 
-    protected <T extends IdentifiableObject> T fromJson( String path, Class<T> klass ) throws IOException
+    protected <T extends IdentifiableObject> T fromJson( String path, Class<T> klass )
     {
-        return renderService.fromJson( new ClassPathResource( path ).getInputStream(), klass );
+        try
+        {
+            return renderService.fromJson( new ClassPathResource( path ).getInputStream(), klass );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+        }
+
+        return null;
     }
 
     /**