Search in sources :

Example 1 with TextAttribute

use of org.openforis.idm.model.TextAttribute in project collect by openforis.

the class CSVDataImportProcessIntegrationTest method validTest.

@Test
public void validTest() throws Exception {
    {
        CollectRecord record = createTestRecord(survey, "10_111");
        recordDao.insert(record);
        assertEquals(Integer.valueOf(0), record.getErrors());
    }
    {
        CollectRecord record = createTestRecord(survey, "10_114");
        recordDao.insert(record);
    }
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportProcess process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(3, status.getProcessed());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        assertEquals(Integer.valueOf(1), reloadedRecord.getErrors());
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
        RealValue plotDirectionVal = plotDirection.getValue();
        assertEquals(Double.valueOf(50d), plotDirectionVal.getValue());
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
        assertEquals(meterUnit, plotDistanceVal.getUnit());
        TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
        assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
        assertEquals(2, cluster.getCount("map_sheet"));
        {
            TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 0);
            assertEquals("new map sheet 1", mapSheet.getValue().getValue());
        }
        {
            TextAttribute mapSheet = (TextAttribute) cluster.getChild("map_sheet", 1);
            assertEquals("new map sheet 2", mapSheet.getValue().getValue());
        }
    }
    {
        CollectRecord reloadedRecord = loadRecord("10_114");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDirection = (RealAttribute) cluster.getChild("plot_direction");
        RealValue plotDirectionVal = plotDirection.getValue();
        assertEquals(Double.valueOf(40d), plotDirectionVal.getValue());
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
        assertEquals(kilometerUnit, plotDistanceVal.getUnit());
        TextAttribute gpsModel = (TextAttribute) cluster.getChild("gps_model");
        assertEquals("GPS MAP 62S", gpsModel.getValue().getValue());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute) TextAttribute(org.openforis.idm.model.TextAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 2 with TextAttribute

use of org.openforis.idm.model.TextAttribute in project collect by openforis.

the class PatternCheckTest method testValidPattern.

// household id: (X-)?[1-9][0-9]*
@Test
public void testValidPattern() {
    TextAttribute id = EntityBuilder.addValue(household, "id", "X-1");
    ValidationResults results = validate(id);
    assertFalse(containsPatternCheck(results.getErrors()));
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute) Test(org.junit.Test)

Example 3 with TextAttribute

use of org.openforis.idm.model.TextAttribute in project collect by openforis.

the class UniquenessCheckTest method testNotUniqueMapSheet2.

@Test
public void testNotUniqueMapSheet2() {
    TextAttribute mapSheet1 = EntityBuilder.addValue(cluster, MAP_SHEET, "TomTom1");
    EntityBuilder.addValue(cluster, MAP_SHEET, "TomTom1");
    ValidationResults results = validate(mapSheet1);
    Assert.assertTrue(containsUniquenessError(results.getErrors(), MAP_SHEET));
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute) Test(org.junit.Test)

Example 4 with TextAttribute

use of org.openforis.idm.model.TextAttribute in project collect by openforis.

the class UniquenessCheckTest method testUniqueMapSheet2.

@Test
public void testUniqueMapSheet2() {
    TextAttribute mapSheet1 = EntityBuilder.addValue(cluster, MAP_SHEET, "TomTom1");
    EntityBuilder.addValue(cluster, MAP_SHEET, "TomTom2");
    EntityBuilder.addValue(cluster, MAP_SHEET, "TomTom2");
    ValidationResults results = validate(mapSheet1);
    Assert.assertFalse(containsUniquenessError(results.getErrors(), MAP_SHEET));
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute) Test(org.junit.Test)

Example 5 with TextAttribute

use of org.openforis.idm.model.TextAttribute in project collect by openforis.

the class UniquenessCheckTest method testUniqueMapSheet.

@Test
public void testUniqueMapSheet() {
    TextAttribute mapSheet1 = EntityBuilder.addValue(cluster, MAP_SHEET, "TomTom1");
    EntityBuilder.addValue(cluster, MAP_SHEET, "TomTom2");
    ValidationResults results = validate(mapSheet1);
    Assert.assertFalse(containsUniquenessError(results.getErrors(), MAP_SHEET));
}
Also used : TextAttribute(org.openforis.idm.model.TextAttribute) Test(org.junit.Test)

Aggregations

TextAttribute (org.openforis.idm.model.TextAttribute)20 Test (org.junit.Test)19 Entity (org.openforis.idm.model.Entity)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)2 CollectRecord (org.openforis.collect.model.CollectRecord)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 RealAttribute (org.openforis.idm.model.RealAttribute)2 RealValue (org.openforis.idm.model.RealValue)2 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1