← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21817: tests for metadataexport with custom queries

 

------------------------------------------------------------
revno: 21817
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-01-27 10:37:57 +0700
message:
  tests for metadataexport with custom queries
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/MetadataExportServiceTest.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/MetadataExportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/MetadataExportServiceTest.java	2016-01-27 03:17:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/MetadataExportServiceTest.java	2016-01-27 03:37:57 +0000
@@ -33,6 +33,10 @@
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.query.Disjunction;
+import org.hisp.dhis.query.Query;
+import org.hisp.dhis.query.Restrictions;
+import org.hisp.dhis.schema.SchemaService;
 import org.hisp.dhis.user.User;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -54,6 +58,9 @@
     @Autowired
     private IdentifiableObjectManager manager;
 
+    @Autowired
+    private SchemaService schemaService;
+
     @Test
     public void testValidate()
     {
@@ -126,4 +133,52 @@
 
         assertEquals( 3, metadata.get( DataElement.class ).size() );
     }
+
+    @Test
+    @SuppressWarnings( "unchecked" )
+    public void testMetadataExportWithCustomQueries()
+    {
+        DataElementGroup deg1 = createDataElementGroup( 'A' );
+        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 );
+
+        deg1.addDataElement( de1 );
+        deg1.addDataElement( de2 );
+        deg1.addDataElement( de3 );
+
+        deg1.setUser( user );
+        manager.save( deg1 );
+
+        Query deQuery = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
+
+        Disjunction disjunction = deQuery.disjunction();
+        disjunction.add( Restrictions.eq( "id", de1.getUid() ) );
+        disjunction.add( Restrictions.eq( "id", de2.getUid() ) );
+
+        deQuery.add( disjunction );
+
+        Query degQuery = Query.from( schemaService.getDynamicSchema( DataElementGroup.class ) );
+        degQuery.add( Restrictions.eq( "id", "INVALID UID" ) );
+
+        MetadataExportParams params = new MetadataExportParams();
+        params.addQuery( deQuery );
+        params.addQuery( degQuery );
+
+        Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata( params );
+
+        assertFalse( metadata.containsKey( User.class ) );
+        assertTrue( metadata.containsKey( DataElementGroup.class ) );
+        assertTrue( metadata.containsKey( DataElement.class ) );
+
+        assertEquals( 2, metadata.get( DataElement.class ).size() );
+        assertEquals( 0, metadata.get( DataElementGroup.class ).size() );
+    }
 }