Search in sources :

Example 1 with ValidationDiagnostic

use of com.opensimulationplatform.core.validation.ValidationDiagnostic in project osp-validator by open-simulation-platform.

the class UseCase1Test method works.

@Test
public void works() {
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure systemStructure = factory.create(TestResources.OSP_SYSTEM_STRUCTURE_USE_CASE_1);
    SystemStructureValidator validator = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println(diagnostic.getValidatedObject());
        System.out.println(diagnostic.getErrorMessage());
    }
    assertTrue(diagnostics.isEmpty());
}
Also used : SystemStructureFactory(com.opensimulationplatform.systemstructure.xml.factory.SystemStructureFactory) SystemStructureValidator(com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Test(org.junit.Test)

Example 2 with ValidationDiagnostic

use of com.opensimulationplatform.core.validation.ValidationDiagnostic in project osp-validator by open-simulation-platform.

the class UseCase3Test method works.

@Test
public void works() {
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure systemStructure = factory.create(TestResources.OSP_SYSTEM_STRUCTURE_USE_CASE_3);
    SystemStructureValidator validator = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println(diagnostic.getValidatedObject());
        System.out.println(diagnostic.getErrorMessage());
    }
    assertTrue(diagnostics.isEmpty());
}
Also used : SystemStructureFactory(com.opensimulationplatform.systemstructure.xml.factory.SystemStructureFactory) SystemStructureValidator(com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Test(org.junit.Test)

Example 3 with ValidationDiagnostic

use of com.opensimulationplatform.core.validation.ValidationDiagnostic in project osp-validator by open-simulation-platform.

the class UseCase4Test method works.

@Test
public void works() {
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure systemStructure = factory.create(TestResources.OSP_SYSTEM_STRUCTURE_USE_CASE_4);
    SystemStructureValidator validator = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println(diagnostic.getValidatedObject());
        System.out.println(diagnostic.getErrorMessage());
    }
    assertTrue(diagnostics.isEmpty());
}
Also used : SystemStructureFactory(com.opensimulationplatform.systemstructure.xml.factory.SystemStructureFactory) SystemStructureValidator(com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Test(org.junit.Test)

Example 4 with ValidationDiagnostic

use of com.opensimulationplatform.core.validation.ValidationDiagnostic in project osp-validator by open-simulation-platform.

the class ValidateModelDescriptionDataModel method main.

public static void main(String[] args) {
    ModelDescription modelDescription = new ModelDescription();
    Unit unit = new Unit();
    unit.setExponent(Unit.Exponent.KILOGRAM, 1);
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    v1.setType(Variable.Type.REAL);
    v1.setName("v1");
    v1.setUnit(unit);
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.OUTPUT);
    v2.setType(Variable.Type.REAL);
    v2.setName("v2");
    v2.setUnit(unit);
    Variable v3 = new Variable();
    v3.setCausality(Variable.Causality.INPUT);
    v3.setType(Variable.Type.REAL);
    v3.setName("v3");
    v3.setUnit(unit);
    Variable v4 = new Variable();
    v4.setCausality(Variable.Causality.INPUT);
    v4.setType(Variable.Type.REAL);
    v4.setName("v4");
    v4.setUnit(unit);
    Force force = new Force();
    force.setName("force");
    force.setVariables(Arrays.asList(v1, v2));
    LinearVelocity linearVelocity = new LinearVelocity();
    linearVelocity.setName("linearVelocity");
    linearVelocity.setVariables(Arrays.asList(v3, v4));
    LinearMechanicalPort linearMechanicalPort = new LinearMechanicalPort();
    linearMechanicalPort.setName("linearMechanicalPort");
    linearMechanicalPort.setForce(force);
    linearMechanicalPort.setLinearVelocity(linearVelocity);
    modelDescription.getUnits().add(unit);
    modelDescription.getVariables().addAll(Arrays.asList(v1, v2, v3, v4));
    modelDescription.getForces().add(force);
    modelDescription.getLinearVelocities().add(linearVelocity);
    modelDescription.getLinearMechanicalPorts().add(linearMechanicalPort);
    ModelDescriptionValidator validator = new ModelDescriptionValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(modelDescription);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println("Message: " + diagnostic.getErrorMessage());
        System.out.println("Object: " + diagnostic.getValidatedObject());
    }
}
Also used : LinearVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) ModelDescriptionValidator(com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Unit(com.opensimulationplatform.core.model.modeldescription.Unit)

Example 5 with ValidationDiagnostic

use of com.opensimulationplatform.core.validation.ValidationDiagnostic in project osp-validator by open-simulation-platform.

the class Validator method getModelDescriptionErrorMessages.

private List<String> getModelDescriptionErrorMessages(File ospSystemStructureFile, OspSystemStructure ospSystemStructureElement) {
    List<String> errorMessages = new ArrayList<>();
    for (Simulators.Simulator simulator : ospSystemStructureElement.getSimulators().getSimulator()) {
        FmuLocator fmuLocator = new DefaultFmuLocator(ospSystemStructureFile);
        URI fmu = fmuLocator.get(simulator);
        OspModelDescriptionLocator ospModelDescriptionLocator = new DefaultOspModelDescriptionLocator(ospSystemStructureFile, fmuLocator);
        Optional<File> ospModelDescriptionXml = ospModelDescriptionLocator.get(simulator);
        if (ospModelDescriptionXml.isPresent()) {
            OspModelDescriptionParser parser = new OspModelDescriptionParser();
            OspModelDescriptionType ospModelDescriptionElement = parser.parse(ospModelDescriptionXml.get());
            Map<Object, Location> locations = parser.getLocations();
            ModelDescriptionFactory factory = new ModelDescriptionFactory();
            ModelDescription modelDescription = factory.create(ospModelDescriptionXml.get(), fmu);
            Simulator s = new Simulator();
            s.setName(simulator.getName());
            s.setModelDescription(modelDescription);
            SystemStructure systemStructure = new SystemStructure();
            systemStructure.getSimulators().add(s);
            ModelDescriptionValidator validator = new ModelDescriptionValidator();
            List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
            Map<Object, Object> coreToJaxb = createModelDescriptionMap(ospModelDescriptionElement, modelDescription);
            errorMessages.addAll(getErrorMessages(ospModelDescriptionXml.get(), locations, diagnostics, coreToJaxb));
        }
    }
    return errorMessages;
}
Also used : ModelDescriptionFactory(com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory) OspSystemStructure(com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) URI(java.net.URI) OspModelDescriptionParser(com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser) DefaultFmuLocator(com.opensimulationplatform.systemstructure.util.DefaultFmuLocator) FmuLocator(com.opensimulationplatform.systemstructure.util.FmuLocator) ModelDescriptionValidator(com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulators(com.opensimulationplatform.systemstructure.xml.model.Simulators) DefaultOspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator) OspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.OspModelDescriptionLocator) DefaultOspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator) DefaultFmuLocator(com.opensimulationplatform.systemstructure.util.DefaultFmuLocator) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) File(java.io.File) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Location(javax.xml.stream.Location)

Aggregations

ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)206 Test (org.junit.Test)200 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)183 Unit (com.opensimulationplatform.core.model.modeldescription.Unit)137 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)60 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)31 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)30 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)23 SystemStructure (com.opensimulationplatform.core.model.systemstructure.SystemStructure)19 Pressure (com.opensimulationplatform.core.model.modeldescription.variablegroup.pressure.Pressure)16 Torque (com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque)16 Voltage (com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage)16 Generic (com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic)14 VariableConnection (com.opensimulationplatform.core.model.systemstructure.VariableConnection)13 AngularDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.angulardisplacement.AngularDisplacement)12 AngularVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity)12 Charge (com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge)12 Current (com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current)12 LinearDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.lineardisplacement.LinearDisplacement)12 Volume (com.opensimulationplatform.core.model.modeldescription.variablegroup.volume.Volume)12