Search in sources :

Example 1 with ValidationResults

use of org.openforis.idm.metamodel.validation.ValidationResults in project collect by openforis.

the class DistanceCheckTest method testWarnMaxDistance.

@Test
public void testWarnMaxDistance() {
    String coordStr = "SRID=EPSG:21035;POINT(885750 9333820)";
    Coordinate coord = Coordinate.parseCoordinate(coordStr);
    EntityBuilder.addValue(cluster, "id", new Code("001"));
    CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
    ValidationResults results = validate(vehicleLocation);
    Assert.assertFalse(containsDistanceCheck(results.getErrors()));
    Assert.assertTrue(containsDistanceCheck(results.getWarnings()));
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 2 with ValidationResults

use of org.openforis.idm.metamodel.validation.ValidationResults in project collect by openforis.

the class DistanceCheckTest method testErrorMaxDistance.

@Test
public void testErrorMaxDistance() {
    String coordStr = "SRID=EPSG:21035;POINT(915750 9333820)";
    Coordinate coord = Coordinate.parseCoordinate(coordStr);
    EntityBuilder.addValue(cluster, "id", new Code("001"));
    CoordinateAttribute vehicleLocation = EntityBuilder.addValue(cluster, "vehicle_location", coord);
    ValidationResults results = validate(vehicleLocation);
    Assert.assertTrue(containsDistanceCheck(results.getErrors()));
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) Coordinate(org.openforis.idm.model.Coordinate) CoordinateAttribute(org.openforis.idm.model.CoordinateAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Example 3 with ValidationResults

use of org.openforis.idm.metamodel.validation.ValidationResults in project collect by openforis.

the class CollectRecordIntegrationTest method testConfirmError.

@Test
public void testConfirmError() throws Exception {
    CollectSurvey survey = loadSurvey();
    CollectRecord record = createTestRecord(survey);
    Entity cluster = record.getRootEntity();
    CodeAttribute region = (CodeAttribute) cluster.getChild("region", 0);
    // add wrong value
    {
        NodeChangeSet changeSet = recordUpdater.updateAttribute(region, new Code("ZZZ"));
        assertFalse(changeSet.isEmpty());
        NodeChange<?> regionChange = changeSet.getChange(region);
        assertTrue(regionChange instanceof AttributeChange);
        ValidationResults validationResults = ((AttributeChange) regionChange).getValidationResults();
        List<ValidationResult> errors = validationResults.getErrors();
        assertFalse(errors.isEmpty());
        List<ValidationResult> warnings = validationResults.getWarnings();
        assertTrue(warnings.isEmpty());
    }
    {
        NodeChangeSet changeSet = recordUpdater.confirmError(region);
        assertFalse(changeSet.isEmpty());
        NodeChange<?> regionChange = changeSet.getChange(region);
        assertTrue(regionChange instanceof AttributeChange);
        ValidationResults validationResults = ((AttributeChange) regionChange).getValidationResults();
        List<ValidationResult> errors = validationResults.getErrors();
        assertTrue(errors.isEmpty());
        List<ValidationResult> warnings = validationResults.getWarnings();
        assertFalse(warnings.isEmpty());
    }
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) CodeAttribute(org.openforis.idm.model.CodeAttribute) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) Code(org.openforis.idm.model.Code) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 4 with ValidationResults

use of org.openforis.idm.metamodel.validation.ValidationResults in project collect by openforis.

the class CollectRecordIntegrationTest method checkHasError.

private void checkHasError(CollectRecord record, int attributeId, Class<?> checkType) {
    ValidationResults validationResults = record.getValidationCache().getAttributeValidationResults(attributeId);
    List<ValidationResult> errors = validationResults.getErrors();
    for (ValidationResult validationResult : errors) {
        if (checkType.isAssignableFrom(validationResult.getValidator().getClass())) {
            return;
        }
    }
    Assert.fail("Error of class " + checkType + " not found in validation results");
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Example 5 with ValidationResults

use of org.openforis.idm.metamodel.validation.ValidationResults in project collect by openforis.

the class CollectRecordIntegrationTest method checkHasWarning.

private void checkHasWarning(CollectRecord record, int attributeId, Class<?> checkType) {
    ValidationResults validationResults = record.getValidationCache().getAttributeValidationResults(attributeId);
    List<ValidationResult> warnings = validationResults.getWarnings();
    for (ValidationResult validationResult : warnings) {
        if (checkType.isAssignableFrom(validationResult.getValidator().getClass())) {
            return;
        }
    }
    Assert.fail();
}
Also used : ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Aggregations

ValidationResults (org.openforis.idm.metamodel.validation.ValidationResults)10 Test (org.junit.Test)4 ValidationResult (org.openforis.idm.metamodel.validation.ValidationResult)4 Code (org.openforis.idm.model.Code)4 Coordinate (org.openforis.idm.model.Coordinate)3 CoordinateAttribute (org.openforis.idm.model.CoordinateAttribute)3 ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CodeList (org.openforis.idm.metamodel.CodeList)1 Validator (org.openforis.idm.metamodel.validation.Validator)1 Attribute (org.openforis.idm.model.Attribute)1 CodeAttribute (org.openforis.idm.model.CodeAttribute)1 Entity (org.openforis.idm.model.Entity)1