Search in sources :

Example 16 with SystemStructure

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

the class NamesValidatorTest method validSystemStructure.

@Test
public void validSystemStructure() {
    SystemStructure systemStructure = new SystemStructure();
    Simulator s1 = new Simulator();
    s1.setName("s1");
    Simulator s2 = new Simulator();
    s2.setName("s2");
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setName("v1");
    Variable v2 = new Variable();
    v2.setName("v2");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    Generic vg1 = new Generic();
    vg1.setName("vg1");
    Generic vg2 = new Generic();
    vg2.setName("vg2");
    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(0, 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 17 with SystemStructure

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

the class ValidateOspSystemStructureFile method main.

public static void main(String[] args) {
    File ospSystemStructureFile = new File("/path/to/OspSystemStructure.xml");
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure modelDescription = factory.create(ospSystemStructureFile);
    SystemStructureValidator validator = new SystemStructureValidator();
    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 : 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) File(java.io.File)

Example 18 with SystemStructure

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

the class ValidateSystemStructureDataModel method main.

public static void main(String[] args) {
    SystemStructure systemStructure = new SystemStructure();
    Simulator s1 = new Simulator();
    s1.setName("s1");
    s1.setModelDescription(getModelDescription(Variable.Causality.INPUT, Variable.Causality.OUTPUT));
    Simulator s2 = new Simulator();
    s2.setName("s2");
    s2.setModelDescription(getModelDescription(Variable.Causality.OUTPUT, Variable.Causality.INPUT));
    VariableConnection vc = new VariableConnection();
    vc.setSimulatorA(s1);
    vc.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v5"));
    vc.setSimulatorB(s2);
    vc.setVariableB(ModelDescriptionUtil.getVariableByName(s2.getModelDescription(), "v5"));
    VariableGroupConnection vgc = new VariableGroupConnection();
    vgc.setSimulatorA(s1);
    vgc.setVariableGroupA(ModelDescriptionUtil.getVariableGroupByName(s1.getModelDescription(), "linearMechanicalPort"));
    vgc.setSimulatorB(s2);
    vgc.setVariableGroupB(ModelDescriptionUtil.getVariableGroupByName(s2.getModelDescription(), "linearMechanicalPort"));
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    systemStructure.getVariableConnections().add(vc);
    systemStructure.getVariableGroupConnections().add(vgc);
    SystemStructureValidator validator = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println("Message: " + diagnostic.getErrorMessage());
        System.out.println("Object: " + diagnostic.getValidatedObject());
    }
}
Also used : SystemStructureValidator(com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator) 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)

Example 19 with SystemStructure

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

the class UseCase2Test method works.

@Test
public void works() {
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure systemStructure = factory.create(TestResources.OSP_SYSTEM_STRUCTURE_USE_CASE_2);
    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 20 with SystemStructure

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

the class SystemStructureFactoryTest method canCreate.

@Test
public void canCreate() {
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure systemStructure = factory.create(TestResources.OSP_SYSTEM_STRUCTURE_CRANE);
    List<Simulator> simulators = systemStructure.getSimulators();
    List<VariableConnection> variableConnections = systemStructure.getVariableConnections();
    List<VariableGroupConnection> variableGroupConnections = systemStructure.getVariableGroupConnections();
    assertEquals(2, simulators.size());
    Simulator s1 = simulators.get(0);
    assertEquals("crane_controller", s1.getName().get());
    Simulator s2 = simulators.get(1);
    assertEquals("knuckle_boom_crane", s2.getName().get());
    assertEquals(1, variableConnections.size());
    VariableConnection variableConnection = variableConnections.get(0);
    Simulator simulatorA = variableConnection.getSimulatorA();
    Variable variableA = variableConnection.getVariableA();
    Simulator simulatorB = variableConnection.getSimulatorB();
    Variable variableB = variableConnection.getVariableB();
    assertEquals("crane_controller", simulatorA.getName().get());
    assertEquals("Act_Limits[1]", variableA.getName().get());
    assertEquals("knuckle_boom_crane", simulatorB.getName().get());
    assertEquals("Act_Limits[1]", variableB.getName().get());
    assertEquals(1, variableGroupConnections.size());
    VariableGroupConnection variableGroupConnection = variableGroupConnections.get(0);
    Simulator simulatorA1 = variableGroupConnection.getSimulatorA();
    VariableGroup variableGroupA = variableGroupConnection.getVariableGroupA();
    Simulator simulatorB1 = variableGroupConnection.getSimulatorB();
    VariableGroup variableGroupB = variableGroupConnection.getVariableGroupB();
    assertEquals("crane_controller", simulatorA1.getName().get());
    assertEquals("linear_mechanical_port", variableGroupA.getName().get());
    assertEquals("knuckle_boom_crane", simulatorB1.getName().get());
    assertEquals("linear_mechanical_port", variableGroupB.getName().get());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) VariableGroup(com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup) 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