@Test
  public void testImportDataValuesXmlWithCodeA() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetACode.xml").getInputStream();

    ImportSummary summary = dataValueSetService.saveDataValueSet(in);

    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());

    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();

    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));

    CompleteDataSetRegistration registration =
        registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);

    assertNotNull(registration);
    assertEquals(dsA, registration.getDataSet());
    assertEquals(peA, registration.getPeriod());
    assertEquals(ouA, registration.getSource());
    assertEquals(getDate(2012, 1, 9), registration.getDate());
  }
  @Test
  public void testImportDataValuesWithInvalidAttributeOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetF.xml").getInputStream();

    ImportSummary summary = dataValueSetService.saveDataValueSet(in);

    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(ImportStatus.ERROR, summary.getStatus());

    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();

    assertNotNull(dataValues);
    assertEquals(0, dataValues.size());
  }
  @Test
  public void testImportDataValuesWithOrgUnitOutsideHierarchy() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetE.xml").getInputStream();

    ImportSummary summary = dataValueSetService.saveDataValueSet(in);

    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());

    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();

    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocA)));
  }
  @Test
  public void testImportDataValuesXmlDryRun() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();

    ImportOptions options = new ImportOptions(UID, UID, UID, true, true, NEW_AND_UPDATES, false);

    ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);

    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());

    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();

    assertNotNull(dataValues);
    assertEquals(0, dataValues.size());
  }
  @Test
  public void testImportDataValuesWithNonExistingDataElementOrgUnit() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetG.xml").getInputStream();

    ImportSummary summary = dataValueSetService.saveDataValueSet(in);

    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(3, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());

    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();

    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
  }
  private void assertImportDataValues(ImportSummary summary) {
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());

    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();

    assertNotNull(dataValues);
    assertEquals(12, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouB, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deA, peB, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deA, peB, ouB, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouB, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peB, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peB, ouB, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouB, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peB, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peB, ouB, ocDef, ocDef)));
  }