Search in sources :

Example 16 with ValidationDiagnostic

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

the class NamesValidatorTest method invalidModelDescription.

@Test
public void invalidModelDescription() {
    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");
    Generic vg2 = new Generic();
    vg2.setName("not-unique");
    modelDescription.getGenerics().add(vg1);
    modelDescription.getGenerics().add(vg2);
    NamesValidator namesValidator = new NamesValidator();
    List<ValidationDiagnostic<Name>> diagnostics = namesValidator.validate(modelDescription);
    assertEquals(2, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Test(org.junit.Test)

Example 17 with ValidationDiagnostic

use of com.opensimulationplatform.core.validation.ValidationDiagnostic 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 18 with ValidationDiagnostic

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

the class NamesValidatorTest method validModelDescription.

@Test
public void validModelDescription() {
    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("v3");
    Generic vg2 = new Generic();
    vg2.setName("v4");
    modelDescription.getGenerics().add(vg1);
    modelDescription.getGenerics().add(vg2);
    NamesValidator namesValidator = new NamesValidator();
    List<ValidationDiagnostic<Name>> diagnostics = namesValidator.validate(modelDescription);
    assertEquals(0, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Test(org.junit.Test)

Example 19 with ValidationDiagnostic

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

the class AngularMechanicalPortValidatorTest method valid.

@Test
public void valid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    Torque torque = new Torque();
    torque.setVariables(Arrays.asList(v1));
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.INPUT);
    AngularVelocity angularVelocity = new AngularVelocity();
    angularVelocity.setVariables(Arrays.asList(v2));
    AngularMechanicalPort angularMechanicalPort = new AngularMechanicalPort();
    angularMechanicalPort.setTorque(torque);
    angularMechanicalPort.setAngularVelocity(angularVelocity);
    modelDescription.getAngularMechanicalPorts().add(angularMechanicalPort);
    AngularMechanicalPortValidator angularMechanicalPortValidator = new AngularMechanicalPortValidator();
    List<ValidationDiagnostic<AngularMechanicalPort>> diagnostics = angularMechanicalPortValidator.validate(modelDescription);
    assertTrue(diagnostics.isEmpty());
}
Also used : Torque(com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) AngularVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity) AngularMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.angularmechanicalport.AngularMechanicalPort) Test(org.junit.Test)

Example 20 with ValidationDiagnostic

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

the class VE_AngularMechanicalPort_1_Test method invalid.

@Test
public void invalid() {
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    v1.setUnit(new Unit());
    v1.setType(Variable.Type.REAL);
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.OUTPUT);
    v2.setUnit(new Unit());
    v2.setType(Variable.Type.REAL);
    Variable v3 = new Variable();
    v3.setCausality(Variable.Causality.OUTPUT);
    v3.setUnit(new Unit());
    v3.setType(Variable.Type.REAL);
    Variable v4 = new Variable();
    v4.setCausality(Variable.Causality.OUTPUT);
    v4.setUnit(new Unit());
    v4.setType(Variable.Type.REAL);
    Torque torque = new Torque();
    torque.setVariables(Arrays.asList(v1, v2));
    AngularVelocity angularVelocity = new AngularVelocity();
    angularVelocity.setVariables(Arrays.asList(v3, v4));
    AngularMechanicalPort angularMechanicalPort = new AngularMechanicalPort();
    angularMechanicalPort.setTorque(torque);
    angularMechanicalPort.setAngularVelocity(angularVelocity);
    builder.build(angularMechanicalPort);
    builder.complete();
    List<ValidationDiagnostic<AngularMechanicalPort>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    AngularMechanicalPort invalidAngularMechanicalPort = diagnostics.get(0).getValidatedObject();
    assertEquals(angularMechanicalPort, invalidAngularMechanicalPort);
}
Also used : Torque(com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) AngularVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) AngularMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.angularmechanicalport.AngularMechanicalPort) Test(org.junit.Test)

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