← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21940: more object bundle validation tests

 

------------------------------------------------------------
revno: 21940
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2016-02-11 12:40:52 +0700
message:
  more object bundle validation tests
removed:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/metadata_preheat1.json
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate1.json
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/InvalidReference.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java
  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-api/src/main/java/org/hisp/dhis/preheat/InvalidReference.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/InvalidReference.java	2016-02-10 08:26:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/InvalidReference.java	2016-02-11 05:40:52 +0000
@@ -32,7 +32,9 @@
 import com.google.common.base.MoreObjects;
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.schema.Property;
+import org.springframework.util.Assert;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -44,16 +46,24 @@
 
     private PreheatIdentifier identifier;
 
+    private Object object;
+
     private IdentifiableObject refObject;
 
     private Property property;
 
-    public InvalidReference( String name, PreheatIdentifier identifier, IdentifiableObject refObject, Property property )
+    public InvalidReference( Object object, PreheatIdentifier identifier, IdentifiableObject refObject, Property property )
     {
-        this.name = name;
+        Assert.notNull( object );
+        Assert.notNull( identifier );
+        Assert.notNull( refObject );
+        Assert.notNull( property );
+
+        this.object = object;
         this.identifier = identifier;
         this.refObject = refObject;
         this.property = property;
+        this.name = IdentifiableObjectUtils.getDisplayName( object );
     }
 
     public String getName()
@@ -76,6 +86,16 @@
         this.identifier = identifier;
     }
 
+    public Object getObject()
+    {
+        return object;
+    }
+
+    public void setObject( Object object )
+    {
+        this.object = object;
+    }
+
     public IdentifiableObject getRefObject()
     {
         return refObject;
@@ -100,6 +120,7 @@
     public String toString()
     {
         return MoreObjects.toStringHelper( this )
+            .add( "name", name )
             .add( "identifier", identifier )
             .add( "refObject", refObject )
             .toString();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java	2016-02-10 08:26:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/PreheatValidation.java	2016-02-11 05:40:52 +0000
@@ -30,7 +30,6 @@
 
 import com.google.common.base.MoreObjects;
 import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.schema.Property;
 
 import java.util.ArrayList;
@@ -49,7 +48,7 @@
 
     public void addInvalidReference( Object object, PreheatIdentifier identifier, IdentifiableObject refObject, Property property )
     {
-        invalidReferences.add( new InvalidReference( IdentifiableObjectUtils.getDisplayName( object ), identifier, refObject, property ) );
+        invalidReferences.add( new InvalidReference( object, identifier, refObject, property ) );
     }
 
     public List<InvalidReference> getInvalidReferences()

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java	2016-02-10 08:22:47 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleValidation.java	2016-02-11 05:40:52 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.base.MoreObjects;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.preheat.PreheatValidation;
 
@@ -55,4 +56,12 @@
     {
         return preheatValidations;
     }
+
+    @Override
+    public String toString()
+    {
+        return MoreObjects.toStringHelper( this )
+            .add( "preheatValidations", preheatValidations )
+            .toString();
+    }
 }

=== 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-02-10 07:45:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-02-11 05:40:52 +0000
@@ -32,9 +32,13 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.option.OptionSet;
+import org.hisp.dhis.preheat.InvalidReference;
 import org.hisp.dhis.preheat.PreheatIdentifier;
 import org.hisp.dhis.preheat.PreheatMode;
+import org.hisp.dhis.preheat.PreheatValidation;
 import org.hisp.dhis.render.RenderFormat;
 import org.hisp.dhis.render.RenderService;
 import org.hisp.dhis.user.User;
@@ -119,7 +123,7 @@
     public void testPreheatValidations() throws IOException
     {
         Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
-            new ClassPathResource( "dxf2/metadata_preheat1.json" ).getInputStream(), RenderFormat.JSON );
+            new ClassPathResource( "dxf2/de_validate1.json" ).getInputStream(), RenderFormat.JSON );
 
         ObjectBundleParams params = new ObjectBundleParams();
         params.setObjectBundleMode( ObjectBundleMode.VALIDATE );
@@ -128,6 +132,31 @@
         ObjectBundle bundle = objectBundleService.create( params );
         ObjectBundleValidation validate = objectBundleService.validate( bundle );
         assertFalse( validate.getPreheatValidations().isEmpty() );
+        List<PreheatValidation> dataElementValidations = validate.getPreheatValidations().get( DataElement.class );
+        assertFalse( dataElementValidations.isEmpty() );
+
+        for ( PreheatValidation preheatValidation : dataElementValidations )
+        {
+            assertFalse( preheatValidation.getInvalidReferences().isEmpty() );
+
+            for ( InvalidReference invalidReference : preheatValidation.getInvalidReferences() )
+            {
+                assertEquals( PreheatIdentifier.UID, invalidReference.getIdentifier() );
+
+                if ( DataElementCategoryCombo.class.isInstance( invalidReference.getRefObject() ) )
+                {
+                    assertEquals( "p0KPaWEg3cf", invalidReference.getRefObject().getUid() );
+                }
+                else if ( User.class.isInstance( invalidReference.getRefObject() ) )
+                {
+                    assertEquals( "GOLswS44mh8", invalidReference.getRefObject().getUid() );
+                }
+                else if ( OptionSet.class.isInstance( invalidReference.getRefObject() ) )
+                {
+                    assertEquals( "pQYCiuosBnZ", invalidReference.getRefObject().getUid() );
+                }
+            }
+        }
     }
 
     private void defaultSetup()

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate1.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate1.json	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_validate1.json	2016-02-11 05:40:52 +0000
@@ -0,0 +1,82 @@
+{
+  "dataElements": [
+    {
+      "lastUpdated": "2016-01-15T15:44:11.475+0000",
+      "aggregationLevels": [],
+      "name": "Birth certificate",
+      "created": "2016-01-15T11:13:32.416+0000",
+      "shortName": "Birth certificate",
+      "domainType": "TRACKER",
+      "aggregationType": "SUM",
+      "id": "uf3svrmp8Oj",
+      "valueType": "FILE_RESOURCE",
+      "userGroupAccesses": [],
+      "publicAccess": "rw------",
+      "user": {
+        "id": "GOLswS44mh8"
+      },
+      "zeroIsSignificant": false,
+      "categoryCombo": {
+        "id": "p0KPaWEg3cf"
+      },
+      "attributeValues": []
+    },
+    {
+      "aggregationType": "SUM",
+      "publicAccess": "rw------",
+      "userGroupAccesses": [],
+      "valueType": "FILE_RESOURCE",
+      "id": "ulD2zW0TIy2",
+      "attributeValues": [],
+      "categoryCombo": {
+        "id": "p0KPaWEg3cf"
+      },
+      "user": {
+        "id": "GOLswS44mh8"
+      },
+      "zeroIsSignificant": false,
+      "name": "Documentation",
+      "lastUpdated": "2016-01-15T15:44:11.475+0000",
+      "aggregationLevels": [],
+      "created": "2016-01-15T11:13:00.541+0000",
+      "shortName": "Documentation",
+      "domainType": "TRACKER"
+    },
+    {
+      "id": "cNkTt6mJQyO",
+      "userGroupAccesses": [],
+      "user": {
+        "id": "GOLswS44mh8"
+      },
+      "description": "Yebo",
+      "zeroIsSignificant": false,
+      "attributeValues": [
+        {
+          "lastUpdated": "2016-01-12T04:53:21.853+0000",
+          "attribute": {
+            "id": "Z4X3J7jMLYV"
+          },
+          "created": "2016-01-12T04:53:21.454+0000",
+          "value": "ACTIVITY"
+        }
+      ],
+      "shortName": "Yebo",
+      "lastUpdated": "2016-01-12T04:53:21.840+0000",
+      "created": "2016-01-12T04:53:21.826+0000",
+      "optionSet": {
+        "id": "pQYCiuosBnZ"
+      },
+      "valueType": "NUMBER",
+      "publicAccess": "rw------",
+      "formName": "Yebo",
+      "categoryCombo": {
+        "id": "p0KPaWEg3cf"
+      },
+      "code": "Yebo",
+      "aggregationType": "SUM",
+      "domainType": "TRACKER",
+      "aggregationLevels": [],
+      "name": "Yebo"
+    }
+  ]
+}

=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/metadata_preheat1.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/metadata_preheat1.json	2016-02-10 06:31:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/metadata_preheat1.json	1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-{
-  "dataElementGroups": [
-    {
-      "name": "DataElementGroupA",
-      "user": {
-        "id": "userabcdefA"
-      },
-      "dataElements": [
-        {
-          "id": "deabcdefghA"
-        },
-        {
-          "id": "deabcdefghB"
-        },
-        {
-          "id": "deabcdefghC"
-        }
-      ]
-    },
-    {
-      "name": "DataElementGroupB",
-      "user": {
-        "id": "userabcdefA"
-      },
-      "dataElements": [
-        {
-          "id": "deabcdefghA"
-        },
-        {
-          "id": "deabcdefghB"
-        },
-        {
-          "id": "deabcdefghC"
-        }
-      ]
-    }
-  ],
-  "dataElements": [
-    {
-      "id": "deabcdefghA",
-      "name": "DataElementA"
-    },
-    {
-      "id": "deabcdefghB",
-      "name": "DataElementB"
-    },
-    {
-      "id": "deabcdefghC",
-      "name": "DataElementC"
-    }
-  ]
-}
\ No newline at end of file