use of org.kie.dmn.openapi.model.DMNOASResult in project drools by kiegroup.
the class TypeWithSpaceTest method test.
@Test
public void test() throws Exception {
final DMNRuntime runtime = createRuntime("typeWithSpace.dmn", this.getClass());
DMNOASResult result = DMNOASGeneratorFactory.generator(runtime.getModels()).build();
DMNModel modelUnderTest = runtime.getModel("ns1", "typeWithSpace");
ObjectNode syntheticJSONSchema = synthesizeSchema(result, modelUnderTest);
JsonSchema validator = getJSONSchema(syntheticJSONSchema);
assertThat(validateUsing(validator, "{ \"a Person\":123 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"a Person\": { \"full name\":123 } }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"a Person\": { \"full name\": \"John Doe\" } }")).isEmpty();
}
use of org.kie.dmn.openapi.model.DMNOASResult in project drools by kiegroup.
the class DS004decisionservicesTest method test0004decisionservices_DS2.
@Test
public void test0004decisionservices_DS2() throws Exception {
final DMNRuntime runtime = createRuntime("0004-decision-services.dmn", DMNDecisionServicesTest.class);
DMNOASResult result = DMNOASGeneratorFactory.generator(runtime.getModels()).build();
DMNModel modelUnderTest = runtime.getModel("http://www.trisotech.com/definitions/_686f58d4-4ec3-4c65-8c06-0e4fd8983def", "Decision Services");
ObjectNode syntheticJSONSchema = synthesizeSchemaForDS(result, modelUnderTest, "A Only Knowing B and C");
JsonSchema validator = getJSONSchema(syntheticJSONSchema);
assertThat(validateUsing(validator, "{ \"an order\":123 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"D\":123, \"E\":456 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"D\":\"d\", \"E\":\"e\" }")).isNotEmpty();
// B and C have FEEL:Any type.
assertThat(validateUsing(validator, "{ \"D\":\"d\", \"E\":\"e\", \"B\":123, \"C\":123 }")).isEmpty();
assertThat(validateUsing(validator, "{ \"D\":\"d\", \"E\":\"e\", \"B\":\"b\", \"C\":\"c\" }")).isEmpty();
}
use of org.kie.dmn.openapi.model.DMNOASResult in project drools by kiegroup.
the class MultipleModelsTest method testTF.
@Test
public void testTF() throws Exception {
final DMNRuntime runtime = createRuntimeWithAdditionalResources("NSEW.dmn", DMNRuntimeTypesTest.class, "Traffic Violation.dmn");
DMNOASResult result = DMNOASGeneratorFactory.generator(runtime.getModels()).build();
DMNModel modelUnderTest = runtime.getModel("https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF", "Traffic Violation");
ObjectNode syntheticJSONSchema = synthesizeSchema(result, modelUnderTest);
JsonSchema validator = getJSONSchema(syntheticJSONSchema);
assertThat(validateUsing(validator, "{ \"asd\":123 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"Driver\":123 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"Driver\": {}, \"Violation\" : {} }")).isEmpty();
assertThat(validateUsing(validator, "{ \"Driver\": { \"Points\": false}, \"Violation\" : {} }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"Driver\": { \"Points\": 10 }, \"Violation\" : {} }")).isEmpty();
assertThat(validateUsing(validator, "{ \"Driver\": { \"Points\": 10 }, \"Violation\" : {\"Type\": 123} }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"Driver\": { \"Points\": 10 }, \"Violation\" : {\"Type\": \"string\"} }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"Driver\": { \"Points\": 10 }, \"Violation\" : {\"Type\": \"speed\",\"Actual Speed\":140, \"Speed Limit\":100} }")).isEmpty();
}
use of org.kie.dmn.openapi.model.DMNOASResult in project drools by kiegroup.
the class MultipleModelsTest method testNSEW.
@Test
public void testNSEW() throws Exception {
final DMNRuntime runtime = createRuntimeWithAdditionalResources("NSEW.dmn", DMNRuntimeTypesTest.class, "Traffic Violation.dmn");
DMNOASResult result = DMNOASGeneratorFactory.generator(runtime.getModels()).build();
DMNModel modelUnderTest = runtime.getModel("https://kiegroup.org/dmn/_FBA17BF4-BC04-4C16-9305-40E8B4B2FECB", "NSEW");
ObjectNode syntheticJSONSchema = synthesizeSchema(result, modelUnderTest);
JsonSchema validator = getJSONSchema(syntheticJSONSchema);
assertThat(validateUsing(validator, "{ \"asd\":123 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"direction\":123 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"direction\":\"Nord\" }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"direction\":\"North\" }")).isEmpty();
assertThat(validateUsing(validator, "{ \"direction\":\"North\", \"asd\":123 }")).isEmpty();
}
use of org.kie.dmn.openapi.model.DMNOASResult in project drools by kiegroup.
the class NumberAllowedValuesTest method testGT.
@Test
public void testGT() throws Exception {
final DMNRuntime runtime = createRuntime("numberGT.dmn", this.getClass());
DMNOASResult result = DMNOASGeneratorFactory.generator(runtime.getModels()).build();
DMNModel modelUnderTest = runtime.getModel("ns1", "numberGT");
ObjectNode syntheticJSONSchema = synthesizeSchema(result, modelUnderTest);
JsonSchema validator = getJSONSchema(syntheticJSONSchema);
assertThat(validateUsing(validator, "{ \"age\": 47, \"negative\" : -47 }")).isEmpty();
JsonNode tAge = syntheticJSONSchema.get("definitions").get("tAge");
assertThat(tAge.fieldNames()).toIterable().doesNotContain("exclusiveMaximum", "maximum");
JsonNode tNegative = syntheticJSONSchema.get("definitions").get("tNegative");
assertThat(tNegative.fieldNames()).toIterable().doesNotContain("exclusiveMinumum", "minumum");
}
Aggregations