Search in sources :

Example 6 with RealAttribute

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

the class CheckConditionExpressionTest method testFalse.

@Test
public void testFalse() throws InvalidExpressionException {
    RealAttribute plotDirection = EntityBuilder.addValue(cluster, "plot_direction", 385.45);
    String expr = "$this >= 0 and $this <= 359";
    boolean b = evaluateExpression(expr, plotDirection);
    Assert.assertFalse(b);
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 7 with RealAttribute

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

the class CheckExpressionTest method testFalse.

@Test
public void testFalse() throws InvalidExpressionException {
    RealAttribute plotDirection = EntityBuilder.addValue(cluster, "plot_direction", 385.45);
    String expr = "$this >= 0 and $this <= 359";
    boolean b = evaluateExpression(expr, plotDirection);
    Assert.assertFalse(b);
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 8 with RealAttribute

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

the class CheckExpressionTest method testTrue.

@Test
public void testTrue() throws InvalidExpressionException {
    RealAttribute plotDirection = EntityBuilder.addValue(cluster, "plot_direction", 345.45);
    String expr = "$this >= 0 and $this <= 359";
    boolean b = evaluateExpression(expr, plotDirection);
    Assert.assertTrue(b);
}
Also used : RealAttribute(org.openforis.idm.model.RealAttribute) AbstractTest(org.openforis.idm.AbstractTest) Test(org.junit.Test)

Example 9 with RealAttribute

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

the class CSVDataImportJobIntegrationTest method newRecordsTest.

@Test
public void newRecordsTest() throws Exception {
    EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
    CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId(), true, true, "2.0");
    assertTrue(process.isCompleted());
    assertTrue(process.getParsingErrors().isEmpty());
    {
        CollectRecord reloadedRecord = loadRecord("10_111");
        Entity cluster = reloadedRecord.getRootEntity();
        RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
        RealValue plotDistanceVal = plotDistance.getValue();
        assertEquals(Double.valueOf(200d), 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(0.3d), plotDistanceVal.getValue());
        assertEquals(kilometerUnit, plotDistanceVal.getUnit());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) RealAttribute(org.openforis.idm.model.RealAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 10 with RealAttribute

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

the class CSVDataImportProcessIntegrationTest 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");
    CSVDataImportProcess process = importCSVFile(MISSING_RECORD_TEST_CSV, clusterDefn.getId());
    ReferenceDataImportStatus<ParsingError> status = process.getStatus();
    assertTrue(status.isError());
    assertEquals(1, status.getSkippedRows().size());
    assertEquals(1, status.getRowsInError().size());
    assertEquals(3, status.getProcessed());
    {
        ParsingError error = status.getErrors().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) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute)

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