Search in sources :

Example 1 with DMNMarshaller

use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.

the class DMNXMLLoaderTest method testLoadingDefinitions.

@Test
public void testLoadingDefinitions() {
    final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
    final InputStream is = this.getClass().getResourceAsStream("0001-input-data-string.dmn");
    final InputStreamReader isr = new InputStreamReader(is);
    final Definitions def = DMNMarshaller.unmarshal(isr);
    assertThat(def, not(nullValue()));
    assertThat(def.getName(), is("0001-input-data-string"));
    assertThat(def.getId(), is("_0001-input-data-string"));
    assertThat(def.getNamespace(), is("https://github.com/agilepro/dmn-tck"));
    assertThat(def.getDrgElement().size(), is(2));
    assertThat(def.getDrgElement().get(0), is(instanceOf(Decision.class)));
    Decision dec = (Decision) def.getDrgElement().get(0);
    assertThat(dec.getName(), is("Greeting Message"));
    assertThat(dec.getId(), is("d_GreetingMessage"));
    assertThat(dec.getVariable().getName(), is("Greeting Message"));
    assertThat(dec.getVariable().getTypeRef().getPrefix(), is("feel"));
    assertThat(dec.getVariable().getTypeRef().getLocalPart(), is("string"));
    assertThat(dec.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
    assertThat(dec.getInformationRequirement().size(), is(1));
    assertThat(dec.getInformationRequirement().get(0).getRequiredInput().getHref(), is("#i_FullName"));
    assertThat(dec.getExpression(), is(instanceOf(LiteralExpression.class)));
    LiteralExpression le = (LiteralExpression) dec.getExpression();
    assertThat(le.getText(), is("\"Hello \" + Full Name"));
    InputData idata = (InputData) def.getDrgElement().get(1);
    assertThat(idata.getId(), is("i_FullName"));
    assertThat(idata.getName(), is("Full Name"));
    assertThat(idata.getVariable().getName(), is("Full Name"));
    assertThat(idata.getVariable().getTypeRef().getPrefix(), is("feel"));
    assertThat(idata.getVariable().getTypeRef().getLocalPart(), is("string"));
    assertThat(idata.getVariable().getTypeRef().getNamespaceURI(), is(XMLConstants.NULL_NS_URI));
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.api.Definitions) LiteralExpression(org.kie.dmn.model.api.LiteralExpression) InputData(org.kie.dmn.model.api.InputData) Decision(org.kie.dmn.model.api.Decision) Test(org.junit.Test)

Example 2 with DMNMarshaller

use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.

the class UnmarshalMarshalTest method testRoundTrip.

public void testRoundTrip(String subdir, String xmlfile) throws Exception {
    DMNMarshaller marshaller = DMNMarshallerFactory.newDefaultMarshaller();
    testRoundTrip(subdir, xmlfile, marshaller);
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller)

Example 3 with DMNMarshaller

use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.

the class UnmarshalMarshalTest method test0004.

@Test
public void test0004() throws Exception {
    DMNMarshaller marshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DecisionServicesExtensionRegister()));
    testRoundTrip("org/kie/dmn/backend/marshalling/v1_1/", "0004-decision-services.dmn", marshaller);
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) DecisionServicesExtensionRegister(org.kie.dmn.backend.marshalling.v1_1.xstream.extensions.DecisionServicesExtensionRegister) Test(org.junit.Test)

Example 4 with DMNMarshaller

use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.

the class UnmarshalMarshalTest method testHello_World_semantic_namespace_with_extensions.

@Test
public void testHello_World_semantic_namespace_with_extensions() throws Exception {
    DMNMarshaller marshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new MyTestRegister()));
    testRoundTrip("org/kie/dmn/backend/marshalling/v1_1/", "Hello_World_semantic_namespace_with_extensions.dmn", marshaller);
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) MyTestRegister(org.kie.dmn.backend.marshalling.v1_1.extensions.MyTestRegister) Test(org.junit.Test)

Example 5 with DMNMarshaller

use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.

the class UnmarshalMarshalTest method testV12_DMNDIDiagramElementExtension_withContent.

@Test
public void testV12_DMNDIDiagramElementExtension_withContent() throws Exception {
    DMNMarshaller marshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new MyTestRegister()));
    testRoundTrip("org/kie/dmn/backend/marshalling/v1_2/", "DMNDIDiagramElementExtension_withContent.dmn", marshaller, DMN12_SCHEMA_SOURCE);
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) MyTestRegister(org.kie.dmn.backend.marshalling.v1_2.extensions.MyTestRegister) Test(org.junit.Test)

Aggregations

DMNMarshaller (org.kie.dmn.api.marshalling.DMNMarshaller)25 Test (org.junit.Test)19 Definitions (org.kie.dmn.model.api.Definitions)16 InputStreamReader (java.io.InputStreamReader)14 InputStream (java.io.InputStream)6 DecisionServicesExtensionRegister (org.kie.dmn.backend.marshalling.v1_1.xstream.extensions.DecisionServicesExtensionRegister)6 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 FileWriter (java.io.FileWriter)5 Files (java.nio.file.Files)5 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 QName (javax.xml.namespace.QName)5 Source (javax.xml.transform.Source)5 StreamSource (javax.xml.transform.stream.StreamSource)5 Assert.assertFalse (org.junit.Assert.assertFalse)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Logger (org.slf4j.Logger)5