Search in sources :

Example 16 with RealAttribute

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

the class ComparisonCheckTest method testRealPassRange.

@Test
public void testRealPassRange() {
    RealAttribute plotDir = EntityBuilder.addValue(cluster, "plot_direction", 256d);
    ValidationResults results = validate(plotDir);
    assertFalse(containsComparisonCheck(results.getErrors()));
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) Test(org.junit.Test)

Example 17 with RealAttribute

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

the class ComparisonCheckTest method testLteWithNormalizedValuesPassOnLt.

@Test
public void testLteWithNormalizedValuesPassOnLt() {
    RealAttribute plotDistance = EntityBuilder.addValue(cluster, "plot_distance", 25000d);
    Unit unit = survey.getUnit("cm");
    plotDistance.setUnit(unit);
    ValidationResults results = validate(plotDistance);
    assertFalse(containsComparisonCheck(results.getErrors()));
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) Unit(org.openforis.idm.metamodel.Unit) Test(org.junit.Test)

Example 18 with RealAttribute

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

the class CustomCheckTest method testCustomMessageWithExpressions.

@Test
public void testCustomMessageWithExpressions() {
    Entity plot = EntityBuilder.addEntity(cluster, "plot");
    Entity tree = EntityBuilder.addEntity(plot, "tree");
    RealAttribute totalHeight = EntityBuilder.addValue(tree, "total_height", 2.0);
    EntityBuilder.addValue(tree, "dbh", 16.5);
    EntityBuilder.addValue(tree, "health", new Code("1"));
    ValidationResults results = validate(totalHeight);
    CustomCheck check = (CustomCheck) results.getWarnings().get(0).getValidator();
    String message = check.getMessageWithEvaluatedExpressions(totalHeight, Locale.ENGLISH.getLanguage());
    Assert.assertEquals("Unusual relationship between dbh (16.5) and total height (2.0).", message);
}
Also used : Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 19 with RealAttribute

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

the class CSVDataImportJobIntegrationTest 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");
    CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId());
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        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) RealAttribute(org.openforis.idm.model.RealAttribute) TextAttribute(org.openforis.idm.model.TextAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 20 with RealAttribute

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

the class CSVDataImportJobIntegrationTest method createMissingParentEntityTest.

@Test
public void createMissingParentEntityTest() throws Exception {
    {
        CollectRecord record = createTestRecord(survey, "10_111");
        recordDao.insert(record);
    }
    {
        CollectRecord record = createTestRecord(survey, "10_114");
        recordDao.insert(record);
    }
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
    EntityDefinition treeDefn = (EntityDefinition) plotDefn.getChildDefinition("tree");
    CSVDataImportJob process = importCSVFile(MISSING_PARENT_ENTITY_TEST_CSV, treeDefn.getId(), true, false, null, true);
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        Entity cluster = reloadedRecord.getRootEntity();
        Entity plot = (Entity) cluster.getChild("plot", 0);
        assertEquals(3, plot.getCount("tree"));
        Entity tree = (Entity) plot.getChild("tree", 2);
        IntegerAttribute treeNo = (IntegerAttribute) tree.getChild("tree_no");
        assertEquals(Integer.valueOf(2), treeNo.getValue().getValue());
        IntegerAttribute stemNo = (IntegerAttribute) tree.getChild("stem_no");
        assertEquals(Integer.valueOf(2), stemNo.getValue().getValue());
        RealAttribute dbh = (RealAttribute) tree.getChild("dbh");
        assertEquals(Double.valueOf(200), dbh.getValue().getValue());
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) IntegerAttribute(org.openforis.idm.model.IntegerAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

RealAttribute (org.openforis.idm.model.RealAttribute)39 Test (org.junit.Test)33 Entity (org.openforis.idm.model.Entity)25 AbstractTest (org.openforis.idm.AbstractTest)14 CollectRecord (org.openforis.collect.model.CollectRecord)9 Code (org.openforis.idm.model.Code)9 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 Node (org.openforis.idm.model.Node)6 RealValue (org.openforis.idm.model.RealValue)6 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)5 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 Coordinate (org.openforis.idm.model.Coordinate)4 Date (org.openforis.idm.model.Date)4 Time (org.openforis.idm.model.Time)4 Unit (org.openforis.idm.metamodel.Unit)2 IntegerAttribute (org.openforis.idm.model.IntegerAttribute)2 TextAttribute (org.openforis.idm.model.TextAttribute)2 GregorianCalendar (java.util.GregorianCalendar)1 Ignore (org.junit.Ignore)1