Search in sources :

Example 21 with SystemStructure

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

the class VariableGroupConnectionsValidatorTest method invalid.

@Test
public void invalid() {
    SystemStructure systemStructure = new SystemStructure();
    VariableGroupConnection variableGroupConnection = new VariableGroupConnection();
    Simulator simulatorA = new Simulator();
    Force force = new Force();
    force.setName("force");
    Variable variableA = new Variable();
    Unit unitA = new Unit();
    unitA.setExponent(Unit.Exponent.KILOGRAM, 1);
    variableA.setName("variableA");
    variableA.setUnit(unitA);
    variableA.setType(Variable.Type.REAL);
    variableA.setCausality(Variable.Causality.OUTPUT);
    force.setVariables(Arrays.asList(variableA));
    simulatorA.getModelDescription().getVariables().add(variableA);
    simulatorA.getModelDescription().getForces().add(force);
    variableGroupConnection.setSimulatorA(simulatorA);
    variableGroupConnection.setVariableGroupA(force);
    Simulator simulatorB = new Simulator();
    LinearVelocity linearVelocity = new LinearVelocity();
    linearVelocity.setName("linearVelocity");
    Variable variableB = new Variable();
    Unit unitB = new Unit();
    unitB.setExponent(Unit.Exponent.KILOGRAM, 1);
    variableB.setName("variableB");
    variableB.setUnit(unitB);
    variableB.setType(Variable.Type.REAL);
    variableB.setCausality(Variable.Causality.INPUT);
    linearVelocity.setVariables(Arrays.asList(variableB));
    simulatorB.getModelDescription().getVariables().add(variableB);
    simulatorB.getModelDescription().getLinearVelocities().add(linearVelocity);
    variableGroupConnection.setSimulatorB(simulatorB);
    variableGroupConnection.setVariableGroupB(linearVelocity);
    systemStructure.getSimulators().add(simulatorA);
    systemStructure.getSimulators().add(simulatorB);
    systemStructure.getVariableGroupConnections().add(variableGroupConnection);
    VariableGroupConnectionsValidator validator = new VariableGroupConnectionsValidator();
    List<ValidationDiagnostic<VariableGroupConnection>> diagnostics = validator.validate(systemStructure);
    assertEquals(1, diagnostics.size());
}
Also used : LinearVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) 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