Search in sources :

Example 11 with RealValue

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

the class CSVDataImportJobIntegrationTest method missingRecordTest.

// @Test
// TODO transactional process not working only in test spring context
public void missingRecordTest() 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");
    CSVDataImportJob process = importCSVFile(MISSING_RECORD_TEST_CSV, clusterDefn.getId());
    assertTrue(process.isFailed());
    assertEquals(1, process.getParsingErrors().size());
    {
        ParsingError error = process.getParsingErrors().get(0);
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertEquals(4, error.getRow());
        assertTrue(Arrays.equals(new String[] { "id" }, error.getColumns()));
    }
    // verify that the transaction is rolled back properly
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(100d), plotDistanceVal.getValue());
        assertEquals(meterUnit, plotDistanceVal.getUnit());
    }
    {
        CollectRecord reloadedRecord = loadRecord("10_114");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(100d), plotDistanceVal.getValue());
        assertEquals(meterUnit, plotDistanceVal.getUnit());
    }
}
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) DataParsingError(org.openforis.collect.io.data.CSVDataImportJob.DataParsingError) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute)

Example 12 with RealValue

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

the class ComparisonExpressionTest method testGtEqOnNumber.

@Test
public void testGtEqOnNumber() throws InvalidExpressionException {
    distanceToForest.setValue(new RealValue(10.0));
    distanceToForest.updateSummaryInfo();
    Assert.assertTrue(evaluateExpression(household, "distance_to_forest >= 10"));
}
Also used : RealValue(org.openforis.idm.model.RealValue) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 13 with RealValue

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

the class ComparisonExpressionTest method testLtOnNumber.

@Test
public void testLtOnNumber() throws InvalidExpressionException {
    distanceToForest.setValue(new RealValue(23.5));
    distanceToForest.updateSummaryInfo();
    Assert.assertFalse(evaluateExpression(household, "distance_to_forest < 10"));
}
Also used : RealValue(org.openforis.idm.model.RealValue) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 14 with RealValue

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

the class ComparisonExpressionTest method testEqOnNumber2.

@Test
public void testEqOnNumber2() throws InvalidExpressionException {
    distanceToForest.setValue(new RealValue(8.0));
    distanceToForest.updateSummaryInfo();
    Assert.assertFalse(evaluateExpression(household, "distance_to_forest = 10"));
}
Also used : RealValue(org.openforis.idm.model.RealValue) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Aggregations

RealValue (org.openforis.idm.model.RealValue)14 Test (org.junit.Test)11 CollectRecord (org.openforis.collect.model.CollectRecord)7 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)7 AbstractTest (org.openforis.idm.AbstractTest)6 Entity (org.openforis.idm.model.Entity)6 RealAttribute (org.openforis.idm.model.RealAttribute)6 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)4 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)4 TextAttribute (org.openforis.idm.model.TextAttribute)2 DataParsingError (org.openforis.collect.io.data.CSVDataImportJob.DataParsingError)1 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)1 Unit (org.openforis.idm.metamodel.Unit)1