Search in sources :

Example 1 with DocumentRoot

use of org.jboss.drools.DocumentRoot in project jbpm by kiegroup.

the class BPMN2EmfExtTest method testOnEntryScriptElement.

public void testOnEntryScriptElement() throws Exception {
    // write
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
    OnEntryScriptType root = DroolsFactory.eINSTANCE.createOnEntryScriptType();
    root.setScript("script");
    root.setScriptFormat("format");
    documentRoot.setOnEntryScript(root);
    inResource.getContents().add(documentRoot);
    StringWriter stringWriter = new StringWriter();
    inResource.save(stringWriter, null);
    assertNotNull(stringWriter.getBuffer().toString());
    if (stringWriter.getBuffer().toString().length() < 1) {
        fail("generated xml is empty");
    }
    // read
    XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.setEncoding("UTF-8");
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
    outResource.load(is, options);
    DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
    assertNotNull(outRoot.getOnEntryScript());
    OnEntryScriptType scriptType = outRoot.getOnEntryScript();
    assertEquals("script", scriptType.getScript());
    assertEquals("format", scriptType.getScriptFormat());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.jboss.drools.DocumentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OnEntryScriptType(org.jboss.drools.OnEntryScriptType) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 2 with DocumentRoot

use of org.jboss.drools.DocumentRoot in project jbpm by kiegroup.

the class BPMN2EmfExtTest method testImportElement.

public void testImportElement() throws Exception {
    // write
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
    ImportType root = DroolsFactory.eINSTANCE.createImportType();
    root.setName("import");
    documentRoot.setImport(root);
    inResource.getContents().add(documentRoot);
    StringWriter stringWriter = new StringWriter();
    inResource.save(stringWriter, null);
    assertNotNull(stringWriter.getBuffer().toString());
    if (stringWriter.getBuffer().toString().length() < 1) {
        fail("generated xml is empty");
    }
    // read
    XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.setEncoding("UTF-8");
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
    outResource.load(is, options);
    DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
    assertNotNull(outRoot.getImport());
    ImportType importType = outRoot.getImport();
    assertEquals("import", importType.getName());
}
Also used : ImportType(org.jboss.drools.ImportType) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.jboss.drools.DocumentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 3 with DocumentRoot

use of org.jboss.drools.DocumentRoot in project jbpm by kiegroup.

the class BPMN2EmfExtTest method testMetadataElement.

@SuppressWarnings("unchecked")
public void testMetadataElement() throws Exception {
    // write
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
    MetaDataType metadataType = DroolsFactory.eINSTANCE.createMetaDataType();
    metadataType.setName("testvalue");
    metadataType.setMetaValue("testentry");
    documentRoot.setMetaData(metadataType);
    inResource.getContents().add(documentRoot);
    StringWriter stringWriter = new StringWriter();
    inResource.save(stringWriter, null);
    assertNotNull(stringWriter.getBuffer().toString());
    if (stringWriter.getBuffer().toString().length() < 1) {
        fail("generated xml is empty");
    }
    // read
    XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.setEncoding("UTF-8");
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
    outResource.load(is, options);
    DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
    assertNotNull(outRoot.getMetaData());
    MetaDataType outMetadataType = outRoot.getMetaData();
    assertEquals(outMetadataType.getName(), "testvalue");
    assertEquals(outMetadataType.getMetaValue(), "testentry");
}
Also used : StringWriter(java.io.StringWriter) MetaDataType(org.jboss.drools.MetaDataType) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.jboss.drools.DocumentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 4 with DocumentRoot

use of org.jboss.drools.DocumentRoot in project jbpm by kiegroup.

the class BPMN2EmfExtTest method testGlobalElement.

public void testGlobalElement() throws Exception {
    // write
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
    GlobalType root = DroolsFactory.eINSTANCE.createGlobalType();
    root.setIdentifier("identifier");
    root.setType("type");
    documentRoot.setGlobal(root);
    inResource.getContents().add(documentRoot);
    StringWriter stringWriter = new StringWriter();
    inResource.save(stringWriter, null);
    assertNotNull(stringWriter.getBuffer().toString());
    if (stringWriter.getBuffer().toString().length() < 1) {
        fail("generated xml is empty");
    }
    // read
    XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.setEncoding("UTF-8");
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
    outResource.load(is, options);
    DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
    assertNotNull(outRoot.getGlobal());
    GlobalType globalType = outRoot.getGlobal();
    assertEquals("identifier", globalType.getIdentifier());
    assertEquals("type", globalType.getType());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.jboss.drools.DocumentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) GlobalType(org.jboss.drools.GlobalType)

Example 5 with DocumentRoot

use of org.jboss.drools.DocumentRoot in project jbpm by kiegroup.

the class BPMN2EmfExtTest method testOnExitScriptElement.

public void testOnExitScriptElement() throws Exception {
    // write
    XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    inResource.setEncoding("UTF-8");
    DocumentRoot documentRoot = DroolsFactory.eINSTANCE.createDocumentRoot();
    OnExitScriptType root = DroolsFactory.eINSTANCE.createOnExitScriptType();
    root.setScript("script");
    root.setScriptFormat("format");
    documentRoot.setOnExitScript(root);
    inResource.getContents().add(documentRoot);
    StringWriter stringWriter = new StringWriter();
    inResource.save(stringWriter, null);
    assertNotNull(stringWriter.getBuffer().toString());
    if (stringWriter.getBuffer().toString().length() < 1) {
        fail("generated xml is empty");
    }
    // read
    XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml"));
    outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    outResource.setEncoding("UTF-8");
    Map<String, Object> options = new HashMap<String, Object>();
    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
    InputStream is = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes("UTF-8"));
    outResource.load(is, options);
    DocumentRoot outRoot = (DocumentRoot) outResource.getContents().get(0);
    assertNotNull(outRoot.getOnExitScript());
    OnExitScriptType scriptType = outRoot.getOnExitScript();
    assertEquals("script", scriptType.getScript());
    assertEquals("format", scriptType.getScriptFormat());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentRoot(org.jboss.drools.DocumentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OnExitScriptType(org.jboss.drools.OnExitScriptType) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)5 DocumentRoot (org.jboss.drools.DocumentRoot)5 GlobalType (org.jboss.drools.GlobalType)1 ImportType (org.jboss.drools.ImportType)1 MetaDataType (org.jboss.drools.MetaDataType)1 OnEntryScriptType (org.jboss.drools.OnEntryScriptType)1 OnExitScriptType (org.jboss.drools.OnExitScriptType)1