Search in sources :

Example 6 with SystemStructure

use of com.opensimulationplatform.core.model.systemstructure.SystemStructure in project osp-validator by open-simulation-platform.

the class Validator method getSystemStructureErrorMessages.

private List<String> getSystemStructureErrorMessages(File ospSystemStructureFile, OspSystemStructure ospSystemStructureElement, Map<Object, Location> locations) {
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure systemStructure = factory.create(ospSystemStructureFile);
    SystemStructureValidator validator = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
    Map<Object, Object> coreToJaxb = createSystemStructureMap(systemStructure, ospSystemStructureElement);
    return getErrorMessages(ospSystemStructureFile, locations, diagnostics, coreToJaxb);
}
Also used : SystemStructureFactory(com.opensimulationplatform.systemstructure.xml.factory.SystemStructureFactory) SystemStructureValidator(com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator) OspSystemStructure(com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic)

Example 7 with SystemStructure

use of com.opensimulationplatform.core.model.systemstructure.SystemStructure in project osp-validator by open-simulation-platform.

the class SimulatorsValidatorTest method invalid.

@Test
public void invalid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.UNDEFINED);
    v1.setType(Variable.Type.REAL);
    v1.setName("not-unique");
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.INPUT);
    v2.setType(Variable.Type.INTEGER);
    v2.setName("not-unique");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    Generic g = new Generic();
    g.setName("variable-container");
    g.setVariables(Arrays.asList(v1, v2));
    modelDescription.getGenerics().add(g);
    Force f1 = new Force();
    f1.setName("not-unique");
    Variable v3 = new Variable();
    v3.setName("v3");
    v3.setType(Variable.Type.REAL);
    v3.setCausality(Variable.Causality.OUTPUT);
    f1.setVariables(Arrays.asList(v3));
    Force f2 = new Force();
    f2.setName("not-unique");
    Variable v4 = new Variable();
    v4.setName("v4");
    v4.setType(Variable.Type.INTEGER);
    v4.setCausality(Variable.Causality.INPUT);
    f2.setVariables(Arrays.asList(v4));
    modelDescription.getForces().add(f1);
    modelDescription.getForces().add(f2);
    Variable v5 = new Variable();
    v5.setName("v5");
    v5.setCausality(Variable.Causality.OUTPUT);
    v5.setType(Variable.Type.REAL);
    Variable v6 = new Variable();
    v6.setName("v6");
    v6.setCausality(Variable.Causality.INPUT);
    v6.setType(Variable.Type.REAL);
    Force f3 = new Force();
    f3.setName("f3");
    f3.setVariables(Arrays.asList(v5, v6));
    modelDescription.getForces().add(f3);
    Variable v7 = new Variable();
    v7.setName("v7");
    v7.setCausality(Variable.Causality.OUTPUT);
    v7.setType(Variable.Type.REAL);
    Variable v8 = new Variable();
    v8.setName("v8");
    v8.setCausality(Variable.Causality.OUTPUT);
    v8.setType(Variable.Type.REAL);
    Force f4 = new Force();
    f4.setName("f4");
    f4.setVariables(Arrays.asList(v7, v8));
    Variable v9 = new Variable();
    v9.setName("v9");
    v9.setCausality(Variable.Causality.OUTPUT);
    v9.setType(Variable.Type.REAL);
    Variable v10 = new Variable();
    v10.setName("v10");
    v10.setCausality(Variable.Causality.OUTPUT);
    v10.setType(Variable.Type.REAL);
    LinearVelocity lv1 = new LinearVelocity();
    lv1.setName("lv1");
    lv1.setVariables(Arrays.asList(v9, v10));
    LinearMechanicalPort lmp1 = new LinearMechanicalPort();
    lmp1.setName("lmp1");
    lmp1.setForce(f4);
    lmp1.setLinearVelocity(lv1);
    modelDescription.getLinearMechanicalPorts().add(lmp1);
    Simulator s1 = new Simulator();
    s1.setName("not-unique");
    s1.setModelDescription(modelDescription);
    Simulator s2 = new Simulator();
    s2.setName("not-unique");
    s2.setModelDescription(modelDescription);
    SystemStructure systemStructure = new SystemStructure();
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    SimulatorsValidator v = new SimulatorsValidator();
    List<ValidationDiagnostic<Object>> diagnostics = v.validate(systemStructure);
    assertEquals(13, diagnostics.size());
}
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) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 8 with SystemStructure

use of com.opensimulationplatform.core.model.systemstructure.SystemStructure in project osp-validator by open-simulation-platform.

the class SimulatorsValidatorTest method valid.

@Test
public void valid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    v1.setType(Variable.Type.REAL);
    v1.setName("v1");
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.INPUT);
    v2.setType(Variable.Type.INTEGER);
    v2.setName("v2");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    Generic g = new Generic();
    g.setName("variable-container");
    g.setVariables(Arrays.asList(v1, v2));
    modelDescription.getGenerics().add(g);
    Force f1 = new Force();
    f1.setName("f1");
    Variable v3 = new Variable();
    v3.setName("v3");
    v3.setType(Variable.Type.REAL);
    v3.setCausality(Variable.Causality.OUTPUT);
    f1.setVariables(Arrays.asList(v3));
    Force f2 = new Force();
    f2.setName("f2");
    Variable v4 = new Variable();
    v4.setName("v4");
    v4.setType(Variable.Type.INTEGER);
    v4.setCausality(Variable.Causality.INPUT);
    f2.setVariables(Arrays.asList(v4));
    modelDescription.getForces().add(f1);
    modelDescription.getForces().add(f2);
    Variable v5 = new Variable();
    v5.setName("v5");
    v5.setCausality(Variable.Causality.OUTPUT);
    v5.setType(Variable.Type.REAL);
    Variable v6 = new Variable();
    v6.setName("v6");
    v6.setCausality(Variable.Causality.OUTPUT);
    v6.setType(Variable.Type.REAL);
    Force f3 = new Force();
    f3.setName("f3");
    f3.setVariables(Arrays.asList(v5, v6));
    modelDescription.getForces().add(f3);
    Variable v7 = new Variable();
    v7.setName("v7");
    v7.setCausality(Variable.Causality.OUTPUT);
    v7.setType(Variable.Type.REAL);
    Variable v8 = new Variable();
    v8.setName("v8");
    v8.setCausality(Variable.Causality.OUTPUT);
    v8.setType(Variable.Type.REAL);
    Force f4 = new Force();
    f4.setName("f4");
    f4.setVariables(Arrays.asList(v7, v8));
    Variable v9 = new Variable();
    v9.setName("v9");
    v9.setCausality(Variable.Causality.INPUT);
    v9.setType(Variable.Type.REAL);
    Variable v10 = new Variable();
    v10.setName("v10");
    v10.setCausality(Variable.Causality.INPUT);
    v10.setType(Variable.Type.REAL);
    LinearVelocity lv1 = new LinearVelocity();
    lv1.setName("lv1");
    lv1.setVariables(Arrays.asList(v9, v10));
    LinearMechanicalPort lmp1 = new LinearMechanicalPort();
    lmp1.setName("lmp1");
    lmp1.setForce(f4);
    lmp1.setLinearVelocity(lv1);
    modelDescription.getLinearMechanicalPorts().add(lmp1);
    Simulator s1 = new Simulator();
    s1.setName("s1");
    s1.setModelDescription(modelDescription);
    Simulator s2 = new Simulator();
    s2.setName("s2");
    s2.setModelDescription(modelDescription);
    SystemStructure systemStructure = new SystemStructure();
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    SimulatorsValidator v = new SimulatorsValidator();
    List<ValidationDiagnostic<Object>> diagnostics = v.validate(systemStructure);
    assertTrue(diagnostics.isEmpty());
}
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) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 9 with SystemStructure

use of com.opensimulationplatform.core.model.systemstructure.SystemStructure in project osp-validator by open-simulation-platform.

the class NamesValidatorTest method invaliSystemStructure.

@Test
public void invaliSystemStructure() {
    SystemStructure systemStructure = new SystemStructure();
    Simulator s1 = new Simulator();
    s1.setName("not-unique");
    Simulator s2 = new Simulator();
    s2.setName("not-unique");
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setName("not-unique");
    Variable v2 = new Variable();
    v2.setName("not-unique");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    Generic vg1 = new Generic();
    vg1.setName("not-unique");
    vg1.setVariables(Arrays.asList(v1));
    Generic vg2 = new Generic();
    vg2.setName("not-unique");
    vg2.setVariables(Arrays.asList(v2));
    modelDescription.getGenerics().add(vg1);
    modelDescription.getGenerics().add(vg2);
    s1.setModelDescription(modelDescription);
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    NamesValidator namesValidator = new NamesValidator();
    List<ValidationDiagnostic<Name>> diagnostics = namesValidator.validate(systemStructure);
    assertEquals(3, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 10 with SystemStructure

use of com.opensimulationplatform.core.model.systemstructure.SystemStructure in project osp-validator by open-simulation-platform.

the class SystemStructureValidatorTest method invalid.

@Test
public void invalid() {
    Simulator s1 = new Simulator();
    s1.setName("s1");
    s1.setModelDescription(createInvalidModelDescription());
    Simulator s2 = new Simulator();
    s2.setName("s2");
    s2.setModelDescription(createInvalidModelDescription());
    SystemStructure systemStructure = new SystemStructure();
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    VariableConnection vc1 = new VariableConnection();
    vc1.setSimulatorA(s1);
    vc1.setSimulatorB(s2);
    vc1.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v3"));
    vc1.setVariableB(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v4"));
    VariableConnection vc2 = new VariableConnection();
    vc2.setSimulatorA(s1);
    vc2.setSimulatorB(s2);
    vc2.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v3"));
    vc2.setVariableB(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v5"));
    VariableConnection vc3 = new VariableConnection();
    vc3.setSimulatorA(s1);
    vc3.setSimulatorB(s2);
    vc3.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v3"));
    vc3.setVariableB(ModelDescriptionUtil.getVariableByName(s2.getModelDescription(), "v6"));
    systemStructure.getVariableConnections().add(vc1);
    systemStructure.getVariableConnections().add(vc2);
    systemStructure.getVariableConnections().add(vc3);
    VariableGroupConnection vgc1 = new VariableGroupConnection();
    vgc1.setSimulatorA(s1);
    vgc1.setSimulatorB(s2);
    vgc1.setVariableGroupA(ModelDescriptionUtil.getVariableGroupByName(s1.getModelDescription(), "f3"));
    vgc1.setVariableGroupB(ModelDescriptionUtil.getVariableGroupByName(s2.getModelDescription(), "lv1"));
    systemStructure.getVariableGroupConnections().add(vgc1);
    SystemStructureValidator v = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = v.validate(systemStructure);
    assertEquals(32, diagnostics.size());
}
Also used : SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Aggregations

SystemStructure (com.opensimulationplatform.core.model.systemstructure.SystemStructure)21 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)19 Test (org.junit.Test)16 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)14 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)9 VariableConnection (com.opensimulationplatform.core.model.systemstructure.VariableConnection)7 VariableGroupConnection (com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection)7 SystemStructureValidator (com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator)7 SystemStructureFactory (com.opensimulationplatform.systemstructure.xml.factory.SystemStructureFactory)6 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)5 Unit (com.opensimulationplatform.core.model.modeldescription.Unit)4 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)4 Generic (com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic)4 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)3 OspSystemStructure (com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure)3 LinearMechanicalPort (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort)2 File (java.io.File)2 VariableGroup (com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup)1 ModelDescriptionValidator (com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator)1 ModelDescriptionFactory (com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory)1