← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22265: more tests for CREATE_AND_UPDATE mode for dxf2 importer

 

------------------------------------------------------------
revno: 22265
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2016-03-13 11:39:47 +0700
message:
  more tests for CREATE_AND_UPDATE mode for dxf2 importer
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update1.json
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update2.json
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update3.json
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.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-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-13 04:20:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-13 04:39:47 +0000
@@ -1229,7 +1229,7 @@
         assertNotNull( userGroup );
 
         Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
-            new ClassPathResource( "dxf2/de_update1.json" ).getInputStream(), RenderFormat.JSON );
+            new ClassPathResource( "dxf2/de_create_and_update1.json" ).getInputStream(), RenderFormat.JSON );
 
         ObjectBundleParams params = new ObjectBundleParams();
         params.setObjectBundleMode( ObjectBundleMode.COMMIT );
@@ -1276,6 +1276,94 @@
         assertEquals( 0, dataElementD.getUserGroupAccesses().size() );
     }
 
+    @Test
+    public void testCreateAndUpdateMetadata2() throws IOException
+    {
+        defaultSetup();
+
+        Map<String, DataElement> dataElementMap = manager.getIdMap( DataElement.class, IdScheme.UID );
+        UserGroup userGroup = manager.get( UserGroup.class, "ugabcdefghA" );
+        assertEquals( 4, dataElementMap.size() );
+        assertNotNull( userGroup );
+
+        Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
+            new ClassPathResource( "dxf2/de_create_and_update2.json" ).getInputStream(), RenderFormat.JSON );
+
+        ObjectBundleParams params = new ObjectBundleParams();
+        params.setObjectBundleMode( ObjectBundleMode.COMMIT );
+        params.setImportMode( ImportStrategy.CREATE_AND_UPDATE );
+        params.setObjects( metadata );
+
+        ObjectBundle bundle = objectBundleService.create( params );
+        assertTrue( objectBundleService.validate( bundle ).getObjectErrorReports().isEmpty() );
+        objectBundleService.commit( bundle );
+
+        DataElement dataElementA = manager.get( DataElement.class, "deabcdefghA" );
+        DataElement dataElementB = manager.get( DataElement.class, "deabcdefghB" );
+        DataElement dataElementC = manager.get( DataElement.class, "deabcdefghC" );
+        DataElement dataElementD = manager.get( DataElement.class, "deabcdefghD" );
+        DataElement dataElementE = manager.get( DataElement.class, "deabcdefghE" );
+
+        assertNotNull( dataElementA );
+        assertNotNull( dataElementB );
+        assertNotNull( dataElementC );
+        assertNotNull( dataElementD );
+        assertNotNull( dataElementE );
+
+        assertEquals( "DEA", dataElementA.getName() );
+        assertEquals( "DEB", dataElementB.getName() );
+        assertEquals( "DEC", dataElementC.getName() );
+        assertEquals( "DED", dataElementD.getName() );
+        assertEquals( "DEE", dataElementE.getName() );
+
+        assertEquals( "DECA", dataElementA.getCode() );
+        assertEquals( "DECB", dataElementB.getCode() );
+        assertEquals( "DECC", dataElementC.getCode() );
+        assertEquals( "DECD", dataElementD.getCode() );
+        assertEquals( "DECE", dataElementE.getCode() );
+
+        assertEquals( "DESA", dataElementA.getShortName() );
+        assertEquals( "DESB", dataElementB.getShortName() );
+        assertEquals( "DESC", dataElementC.getShortName() );
+        assertEquals( "DESD", dataElementD.getShortName() );
+        assertEquals( "DESE", dataElementE.getShortName() );
+
+        assertEquals( "DEDA", dataElementA.getDescription() );
+        assertEquals( "DEDB", dataElementB.getDescription() );
+        assertEquals( "DEDC", dataElementC.getDescription() );
+        assertEquals( "DEDD", dataElementD.getDescription() );
+        assertEquals( "DEDE", dataElementE.getDescription() );
+
+        assertEquals( 1, dataElementA.getUserGroupAccesses().size() );
+        assertEquals( 0, dataElementB.getUserGroupAccesses().size() );
+        assertEquals( 1, dataElementC.getUserGroupAccesses().size() );
+        assertEquals( 0, dataElementD.getUserGroupAccesses().size() );
+    }
+
+    @Test
+    public void testCreateAndUpdateMetadata3() throws IOException
+    {
+        Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
+            new ClassPathResource( "dxf2/de_create_and_update3.json" ).getInputStream(), RenderFormat.JSON );
+
+        ObjectBundleParams params = new ObjectBundleParams();
+        params.setObjectBundleMode( ObjectBundleMode.COMMIT );
+        params.setImportMode( ImportStrategy.CREATE_AND_UPDATE );
+        params.setObjects( metadata );
+
+        ObjectBundle bundle = objectBundleService.create( params );
+        assertTrue( objectBundleService.validate( bundle ).getObjectErrorReports().isEmpty() );
+        objectBundleService.commit( bundle );
+
+        DataElement dataElementE = manager.get( DataElement.class, "deabcdefghE" );
+
+        assertNotNull( dataElementE );
+        assertEquals( "DEE", dataElementE.getName() );
+        assertEquals( "DECE", dataElementE.getCode() );
+        assertEquals( "DESE", dataElementE.getShortName() );
+        assertEquals( "DEDE", dataElementE.getDescription() );
+    }
+
     private void defaultSetup()
     {
         DataElement de1 = createDataElement( 'A' );

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update1.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update1.json	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update1.json	2016-03-13 04:39:47 +0000
@@ -0,0 +1,100 @@
+{
+  "dataElements": [
+    {
+      "code": "DECA",
+      "created": "2016-03-04T03:37:12.714+0000",
+      "lastUpdated": "2016-03-04T03:37:12.733+0000",
+      "name": "DEA",
+      "id": "deabcdefghA",
+      "shortName": "DESA",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDA",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
+      "attributeValues": [],
+      "aggregationLevels": []
+    },
+    {
+      "code": "DECB",
+      "created": "2016-03-04T03:37:12.720+0000",
+      "lastUpdated": "2016-03-04T03:37:12.741+0000",
+      "name": "DEB",
+      "id": "deabcdefghB",
+      "shortName": "DESB",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDB",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [],
+      "attributeValues": [],
+      "aggregationLevels": []
+    },
+    {
+      "code": "DECC",
+      "created": "2016-03-04T03:37:12.725+0000",
+      "lastUpdated": "2016-03-04T03:37:12.743+0000",
+      "name": "DEC",
+      "id": "deabcdefghC",
+      "shortName": "DESC",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDC",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
+      "attributeValues": [],
+      "aggregationLevels": []
+    },
+    {
+      "code": "DECD",
+      "created": "2016-03-04T03:37:12.729+0000",
+      "lastUpdated": "2016-03-04T03:37:12.745+0000",
+      "name": "DED",
+      "id": "deabcdefghD",
+      "shortName": "DESD",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDD",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [],
+      "attributeValues": [],
+      "aggregationLevels": []
+    }
+  ]
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update2.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update2.json	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update2.json	2016-03-13 04:39:47 +0000
@@ -0,0 +1,120 @@
+{
+  "dataElements": [
+    {
+      "code": "DECA",
+      "created": "2016-03-04T03:37:12.714+0000",
+      "lastUpdated": "2016-03-04T03:37:12.733+0000",
+      "name": "DEA",
+      "id": "deabcdefghA",
+      "shortName": "DESA",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDA",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
+      "attributeValues": [ ],
+      "aggregationLevels": [ ]
+    },
+    {
+      "code": "DECB",
+      "created": "2016-03-04T03:37:12.720+0000",
+      "lastUpdated": "2016-03-04T03:37:12.741+0000",
+      "name": "DEB",
+      "id": "deabcdefghB",
+      "shortName": "DESB",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDB",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [ ],
+      "attributeValues": [ ],
+      "aggregationLevels": [ ]
+    },
+    {
+      "code": "DECC",
+      "created": "2016-03-04T03:37:12.725+0000",
+      "lastUpdated": "2016-03-04T03:37:12.743+0000",
+      "name": "DEC",
+      "id": "deabcdefghC",
+      "shortName": "DESC",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDC",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
+      "attributeValues": [ ],
+      "aggregationLevels": [ ]
+    },
+    {
+      "code": "DECD",
+      "created": "2016-03-04T03:37:12.729+0000",
+      "lastUpdated": "2016-03-04T03:37:12.745+0000",
+      "name": "DED",
+      "id": "deabcdefghD",
+      "shortName": "DESD",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDD",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [ ],
+      "attributeValues": [ ],
+      "aggregationLevels": [ ]
+    },
+    {
+      "code": "DECE",
+      "created": "2016-03-04T03:37:12.729+0000",
+      "lastUpdated": "2016-03-04T03:37:12.745+0000",
+      "name": "DEE",
+      "id": "deabcdefghE",
+      "shortName": "DESE",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDE",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [ ],
+      "attributeValues": [ ],
+      "aggregationLevels": [ ]
+    }
+  ]
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update3.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update3.json	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_create_and_update3.json	2016-03-13 04:39:47 +0000
@@ -0,0 +1,24 @@
+{
+  "dataElements": [
+    {
+      "code": "DECE",
+      "created": "2016-03-04T03:37:12.729+0000",
+      "lastUpdated": "2016-03-04T03:37:12.745+0000",
+      "name": "DEE",
+      "id": "deabcdefghE",
+      "shortName": "DESE",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDE",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [ ],
+      "attributeValues": [ ],
+      "aggregationLevels": [ ]
+    }
+  ]
+}
\ No newline at end of file