Search in sources :

Example 1 with DMNOASResult

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DMNOASResult(org.kie.dmn.openapi.model.DMNOASResult) JsonSchema(com.networknt.schema.JsonSchema) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 2 with DMNOASResult

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DMNOASResult(org.kie.dmn.openapi.model.DMNOASResult) JsonSchema(com.networknt.schema.JsonSchema) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMNDecisionServicesTest(org.kie.dmn.core.decisionservices.DMNDecisionServicesTest) Test(org.junit.Test)

Example 3 with DMNOASResult

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DMNOASResult(org.kie.dmn.openapi.model.DMNOASResult) JsonSchema(com.networknt.schema.JsonSchema) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMN13specificTest(org.kie.dmn.core.v1_3.DMN13specificTest) Test(org.junit.Test) DMNRuntimeTypesTest(org.kie.dmn.core.stronglytyped.DMNRuntimeTypesTest)

Example 4 with DMNOASResult

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DMNOASResult(org.kie.dmn.openapi.model.DMNOASResult) JsonSchema(com.networknt.schema.JsonSchema) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMN13specificTest(org.kie.dmn.core.v1_3.DMN13specificTest) Test(org.junit.Test) DMNRuntimeTypesTest(org.kie.dmn.core.stronglytyped.DMNRuntimeTypesTest)

Example 5 with DMNOASResult

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");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DMNOASResult(org.kie.dmn.openapi.model.DMNOASResult) JsonSchema(com.networknt.schema.JsonSchema) JsonNode(com.fasterxml.jackson.databind.JsonNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

DMNOASResult (org.kie.dmn.openapi.model.DMNOASResult)28 DMNModel (org.kie.dmn.api.core.DMNModel)24 Test (org.junit.Test)22 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)22 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)18 JsonSchema (com.networknt.schema.JsonSchema)18 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Produces (javax.ws.rs.Produces)4 DMNRuntimeTypesTest (org.kie.dmn.core.stronglytyped.DMNRuntimeTypesTest)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 DMN13specificTest (org.kie.dmn.core.v1_3.DMN13specificTest)3 Path (javax.ws.rs.Path)2 DMNDecisionServicesTest (org.kie.dmn.core.decisionservices.DMNDecisionServicesTest)2 DMNEvaluator (org.kie.kogito.jitexecutor.dmn.DMNEvaluator)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)1 Paths (org.eclipse.microprofile.openapi.models.Paths)1 Info (org.eclipse.microprofile.openapi.models.info.Info)1