Search in sources :

Example 31 with ModelDescription

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

the class VolumeFlowRateValidatorTest method valid.

@Test
public void valid() {
    ModelDescription modelDescription = new ModelDescription();
    VolumeFlowRate volumeFlowRate = new VolumeFlowRate();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.INPUT);
    v1.setType(Variable.Type.REAL);
    v1.setUnit(new Unit());
    Variable v2 = new Variable();
    v2.setCausality(v1.getCausality());
    v2.setType(v1.getType());
    v2.setUnit(v1.getUnit());
    volumeFlowRate.setVariables(Arrays.asList(v1, v2));
    modelDescription.getVolumeFlowRates().add(volumeFlowRate);
    VolumeFlowRateValidator v = new VolumeFlowRateValidator();
    List<ValidationDiagnostic<VolumeFlowRate>> diagnostics = v.validate(modelDescription);
    assertTrue(diagnostics.isEmpty());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) VolumeFlowRate(com.opensimulationplatform.core.model.modeldescription.variablegroup.volumeflowrate.VolumeFlowRate) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Test(org.junit.Test)

Example 32 with ModelDescription

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

the class ModelDescriptionFactoryTest method canCreate.

@Test
public void canCreate() {
    ModelDescriptionFactory factory = new ModelDescriptionFactory();
    ModelDescription converted = factory.create(TestResources.CRANE_CONTROLLER_XML, TestResources.CRANE_CONTROLLER_FMU.toURI());
    List<Variable> variables = converted.getVariables();
    List<LinearMechanicalPort> linearMechanicalPorts = converted.getLinearMechanicalPorts();
    assertEquals(1, linearMechanicalPorts.size());
    linearMechanicalPorts.forEach(linearMechanicalPort -> {
        assertTrue(variables.containsAll(linearMechanicalPort.getForce().getVariables()));
        assertTrue(variables.containsAll(linearMechanicalPort.getLinearVelocity().getVariables()));
    });
    List<Generic> generics = converted.getGenerics();
    assertEquals(1, generics.size());
    generics.forEach(generic -> {
        assertTrue(variables.containsAll(generic.getVariables()));
    });
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Test(org.junit.Test)

Example 33 with ModelDescription

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

the class ModelDescriptionFactoryTest method canCreateWithoutOspModelDescriptionXml.

@Test
public void canCreateWithoutOspModelDescriptionXml() {
    ModelDescriptionFactory factory = new ModelDescriptionFactory();
    ModelDescription converted = factory.create(TestResources.CRANE_CONTROLLER_FMU.toURI());
    assertEquals(12, converted.getVariables().size());
    assertEquals(0, converted.getVariableGroups().size());
}
Also used : ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Test(org.junit.Test)

Example 34 with ModelDescription

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

the class OspModelDescriptionTypeFactoryTest method canCreate.

@Test
public void canCreate() throws Exception {
    ModelDescriptionFactory factory = new ModelDescriptionFactory();
    ModelDescription modelDescription = factory.create(TestResources.CRANE_CONTROLLER_XML, TestResources.CRANE_CONTROLLER_FMU.toURI());
    OspModelDescriptionTypeFactory typeFactory = new OspModelDescriptionTypeFactory();
    OspModelDescriptionType ospModelDescriptionType = typeFactory.create(modelDescription);
    ObjectFactory objectFactory = new ObjectFactory();
    JAXBContext jc = JAXBContext.newInstance(ospModelDescriptionType.getClass());
    JAXBSource source = new JAXBSource(jc, objectFactory.createOspModelDescription(ospModelDescriptionType));
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(OspModelDescriptionParser.class.getResource("/OspModelDescription-1.0.0.xsd"));
    Validator validator = schema.newValidator();
    validator.setErrorHandler(new ErrorHandler() {

        @Override
        public void warning(SAXParseException exception) {
            fail(exception.toString());
        }

        @Override
        public void error(SAXParseException exception) {
            fail(exception.toString());
        }

        @Override
        public void fatalError(SAXParseException exception) {
            fail(exception.toString());
        }
    });
    validator.validate(source);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) ErrorHandler(org.xml.sax.ErrorHandler) OspModelDescriptionType(com.opensimulationplatform.modeldescription.xml.model.OspModelDescriptionType) Schema(javax.xml.validation.Schema) JAXBContext(javax.xml.bind.JAXBContext) OspModelDescriptionParser(com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser) JAXBSource(javax.xml.bind.util.JAXBSource) ObjectFactory(com.opensimulationplatform.modeldescription.xml.model.ObjectFactory) SAXParseException(org.xml.sax.SAXParseException) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Validator(javax.xml.validation.Validator) Test(org.junit.Test)

Example 35 with ModelDescription

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

the class AngularMechanicalPortValidatorTest method invalid.

@Test
public void invalid() {
    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.OUTPUT);
    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);
    assertEquals(1, diagnostics.size());
    assertEquals(angularMechanicalPort, diagnostics.get(0).getValidatedObject());
}
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)

Aggregations

ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)68 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)61 Test (org.junit.Test)61 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)60 Unit (com.opensimulationplatform.core.model.modeldescription.Unit)35 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)17 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)13 LinearMechanicalPort (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort)12 Generic (com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic)9 Pressure (com.opensimulationplatform.core.model.modeldescription.variablegroup.pressure.Pressure)7 Torque (com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque)7 Voltage (com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage)7 AngularDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.angulardisplacement.AngularDisplacement)5 AngularVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity)5 Charge (com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge)5 Current (com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current)5 LinearDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.lineardisplacement.LinearDisplacement)5 Volume (com.opensimulationplatform.core.model.modeldescription.variablegroup.volume.Volume)5 VolumeFlowRate (com.opensimulationplatform.core.model.modeldescription.variablegroup.volumeflowrate.VolumeFlowRate)5 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)4