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());
}
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()));
});
}
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());
}
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);
}
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());
}
Aggregations