← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21313: test attribute schemes in DataValueServiceTest

 

------------------------------------------------------------
revno: 21313
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-12-04 13:35:23 +0700
message:
  test attribute schemes in DataValueServiceTest
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBattribute.xml
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBcode.xml


--
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/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2015-12-04 05:41:43 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2015-12-04 06:35:23 +0000
@@ -30,8 +30,14 @@
 
 import com.google.common.collect.Sets;
 import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.attribute.AttributeValue;
+import org.hisp.dhis.attribute.exception.NonUniqueAttributeValueException;
 import org.hisp.dhis.common.IdSchemes;
+import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
@@ -101,6 +107,11 @@
     @Autowired
     private IdentifiableObjectManager idObjectManager;
 
+    @Autowired
+    private AttributeService attributeService;
+
+    private Attribute attribute;
+
     private DataElementCategoryOptionCombo ocDef;
     private DataElementCategoryOption categoryOptionA;
     private DataElementCategoryOption categoryOptionB;
@@ -130,6 +141,21 @@
     private MockBatchHandler<DataValue> mockDataValueBatchHandler = null;
     private MockBatchHandlerFactory mockBatchHandlerFactory = null;
 
+    private AttributeValue addAttributeValue( IdentifiableObject identifiableObject, Attribute attribute, String value )
+    {
+        AttributeValue attributeValue = new AttributeValue( value, attribute );
+
+        try
+        {
+            attributeService.addAttributeValue( identifiableObject, attributeValue );
+        }
+        catch ( NonUniqueAttributeValueException ignored )
+        {
+        }
+
+        return attributeValue;
+    }
+
     @Override
     public void setUpTest()
     {
@@ -138,6 +164,12 @@
         mockBatchHandlerFactory.registerBatchHandler( DataValueBatchHandler.class, mockDataValueBatchHandler );
         setDependency( dataValueSetService, "batchHandlerFactory", mockBatchHandlerFactory );
 
+        attribute = new Attribute( "CUSTOM_ID", ValueType.TEXT );
+        attribute.setUnique( true );
+        attribute.setOrganisationUnitAttribute( true );
+        attribute.setDataElementAttribute( true );
+        idObjectManager.save( attribute );
+
         categoryOptionA = createCategoryOption( 'A' );
         categoryOptionB = createCategoryOption( 'B' );
         categoryA = createDataElementCategory( 'A', categoryOptionA, categoryOptionB );
@@ -195,9 +227,13 @@
         categoryService.addDataElementCategoryOptionCombo( ocA );
         categoryService.addDataElementCategoryOptionCombo( ocB );
 
+        addAttributeValue( deA, attribute, "DE1" );
         dataElementService.addDataElement( deA );
+        addAttributeValue( deB, attribute, "DE2" );
         dataElementService.addDataElement( deB );
+        addAttributeValue( deC, attribute, "DE3" );
         dataElementService.addDataElement( deC );
+        addAttributeValue( deD, attribute, "DE4" );
         dataElementService.addDataElement( deD );
 
         idObjectManager.save( osA );
@@ -207,8 +243,11 @@
         dsA.addDataElement( deC );
         dsA.addDataElement( deD );
 
+        addAttributeValue( ouA, attribute, "OU1" );
         organisationUnitService.addOrganisationUnit( ouA );
+        addAttributeValue( ouB, attribute, "OU2" );
         organisationUnitService.addOrganisationUnit( ouB );
+        addAttributeValue( ouC, attribute, "OU3" );
         organisationUnitService.addOrganisationUnit( ouC );
 
         dsA.addOrganisationUnit( ouA );
@@ -330,6 +369,29 @@
     }
 
     @Test
+    public void testImportDataValuesXmlWithAttributeB()
+        throws Exception
+    {
+        in = new ClassPathResource( "datavalueset/dataValueSetBattribute.xml" ).getInputStream();
+
+        ImportOptions importOptions = new ImportOptions()
+            .setIdScheme( "ATTRIBUTE:" + attribute.getUid() )
+            .setDataElementIdScheme( "ATTRIBUTE:" + attribute.getUid() )
+            .setOrgUnitIdScheme( "ATTRIBUTE:" + attribute.getUid() );
+
+        ImportSummary summary = dataValueSetService.saveDataValueSet( in, importOptions );
+
+        assertEquals( summary.getConflicts().toString(), 0, summary.getConflicts().size() );
+        assertEquals( 12, summary.getImportCount().getImported() );
+        assertEquals( 0, summary.getImportCount().getUpdated() );
+        assertEquals( 0, summary.getImportCount().getDeleted() );
+        assertEquals( 0, summary.getImportCount().getIgnored() );
+        assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+
+        assertImportDataValues( summary );
+    }
+
+    @Test
     public void testImportDataValuesXmlWithCodePreheatCacheFalse()
         throws Exception
     {

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBattribute.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBattribute.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBattribute.xml	2015-12-04 06:35:23 +0000
@@ -0,0 +1,14 @@
+<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0";>
+  <dataValue dataElement="DE1" period="201201" orgUnit="OU1" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE1" period="201201" orgUnit="OU2" value="10002" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE1" period="201202" orgUnit="OU1" value="10003" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE1" period="201202" orgUnit="OU2" value="10004" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE2" period="201201" orgUnit="OU1" value="10005" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE2" period="201201" orgUnit="OU2" value="10006" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE2" period="201202" orgUnit="OU1" value="10007" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE2" period="201202" orgUnit="OU2" value="10008" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE3" period="201201" orgUnit="OU1" value="10009" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE3" period="201201" orgUnit="OU2" value="10010" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE3" period="201202" orgUnit="OU1" value="10011" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE3" period="201202" orgUnit="OU2" value="10012" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+</dataValueSet>

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBcode.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBcode.xml	2012-05-30 11:13:07 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetBcode.xml	2015-12-04 06:35:23 +0000
@@ -1,14 +1,14 @@
 <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0";>
-    <dataValue dataElement="DE_A" period="201201" orgUnit="OU_A" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_A" period="201201" orgUnit="OU_B" value="10002" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_A" period="201202" orgUnit="OU_A" value="10003" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_A" period="201202" orgUnit="OU_B" value="10004" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_B" period="201201" orgUnit="OU_A" value="10005" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_B" period="201201" orgUnit="OU_B" value="10006" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_B" period="201202" orgUnit="OU_A" value="10007" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_B" period="201202" orgUnit="OU_B" value="10008" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_C" period="201201" orgUnit="OU_A" value="10009" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_C" period="201201" orgUnit="OU_B" value="10010" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_C" period="201202" orgUnit="OU_A" value="10011" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
-    <dataValue dataElement="DE_C" period="201202" orgUnit="OU_B" value="10012" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+  <dataValue dataElement="DE_A" period="201201" orgUnit="OU_A" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_A" period="201201" orgUnit="OU_B" value="10002" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_A" period="201202" orgUnit="OU_A" value="10003" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_A" period="201202" orgUnit="OU_B" value="10004" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_B" period="201201" orgUnit="OU_A" value="10005" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_B" period="201201" orgUnit="OU_B" value="10006" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_B" period="201202" orgUnit="OU_A" value="10007" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_B" period="201202" orgUnit="OU_B" value="10008" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_C" period="201201" orgUnit="OU_A" value="10009" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_C" period="201201" orgUnit="OU_B" value="10010" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_C" period="201202" orgUnit="OU_A" value="10011" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
+  <dataValue dataElement="DE_C" period="201202" orgUnit="OU_B" value="10012" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false" />
 </dataValueSet>