@Test(timeout=10000) public void testTimerStartDateISO() throws Exception { NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1); byte[] content = IoUtils.readBytesFromInputStream(this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2")); String processContent = new String(content, "UTF-8"); OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2); processContent = processContent.replaceFirst("#\\{date\\}", plusTwoSeconds.toString()); Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent)); resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2"); resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2"); KieBase kbase = createKnowledgeBaseFromResources(resource); ksession = createKnowledgeSession(kbase); ksession.addEventListener(countDownListener); final List<Long> list = new ArrayList<Long>(); ksession.addEventListener(new DefaultProcessEventListener() { public void beforeProcessStarted(ProcessStartedEvent event) { list.add(event.getProcessInstance().getId()); } }); assertThat(list.size()).isEqualTo(0); countDownListener.waitTillCompleted(); assertThat(list.size()).isEqualTo(1); }
assertThat(dtdFile).exists(); String dtdContent = IoUtils.readFileAsString(dtdFile); dtdContent = dtdContent.replaceAll("@@PATH@@", dtdFile.getParentFile().getAbsolutePath()); IoUtils.write(dtdFile, dtdContent.getBytes("UTF-8")); byte[] data = IoUtils.readBytesFromInputStream(processResource.getInputStream()); String processAsString = new String(data, "UTF-8");
public void writeFs(MemoryFileSystem mfs, Folder f, java.io.File file1) { for ( Resource rs : f.getMembers() ) { if ( rs instanceof Folder ) { java.io.File file2 = new java.io.File( file1, ((Folder) rs).getName()); file2.mkdir(); writeFs( mfs, (Folder) rs, file2 ); } else { byte[] bytes = mfs.getFileContents( (MemoryFile) rs ); try { IoUtils.write(new java.io.File(file1, ((File) rs).getName()), bytes); } catch ( IOException e ) { fail( "Unable to write project to file system\n" + e.getMessage() ); } } } } }
@Test public void testAsSystemSpecificPath() { String urlPath = "c:\\workdir\\server-local\\instance\\tmp\\vfs\\deployment\\deploymentf7b5abe7c4c1cb56\\rules-with-kjar-1.0.jar-57cc270a5729d6b2\\rules-with-kjar-1.0.jar"; String specificPath = IoUtils.asSystemSpecificPath(urlPath, 1); // Check that windows drive (even in lower case) is not removed assertEquals(urlPath, specificPath); } }
@Test public void testProcessWithBrokenItemDefinitionUri() throws Exception { InputStream inputBpmn = getClass().getResourceAsStream("/BPMN2-BrokenStructureRef.bpmn2"); XmlProcessDumper dumper = XmlProcessDumperFactory.getXmlProcessDumperFactoryService().newXmlProcessDumper(); Assert.assertNotNull(dumper); String processXml = new String(IoUtils.readBytesFromInputStream(inputBpmn), "UTF-8"); Assert.assertNotNull(processXml); org.kie.api.definition.process.Process proc = dumper.readProcess(processXml); Assert.assertNotNull(proc); Assert.assertEquals("BrokenStructureRef", proc.getId()); } }
assertThat(dtdFile).exists(); String dtdContent = IoUtils.readFileAsString(dtdFile); dtdContent = dtdContent.replaceAll("@@PATH@@", dtdFile.getParentFile().getAbsolutePath()); IoUtils.write(dtdFile, dtdContent.getBytes("UTF-8")); byte[] data = IoUtils.readBytesFromInputStream(processResource.getInputStream()); String processAsString = new String(data, "UTF-8");
@Test public void testReadEmptyStream() throws IOException { // DROOLS-971 byte[] bytes = IoUtils.readBytesFromInputStream( new ReaderInputStream( new StringReader( "" ) ) ); assertEquals(0, bytes.length); }
@Test public void testSequentialWithRulebaseUpdate() throws Exception { InternalKnowledgeBase kbase = (InternalKnowledgeBase) loadKnowledgeBase(kconf, "simpleSalience.drl"); StatelessKieSession ksession = createStatelessKnowledgeSession( kbase ); final List list = new ArrayList(); ksession.setGlobal( "list", list ); ksession.execute(new Person("pob")); kbase.addPackages(loadKnowledgePackagesFromString( new String( IoUtils.readBytesFromInputStream( DynamicRulesTest.class.getResource("test_Dynamic3.drl").openStream() ) ) ) ); ksession = kbase.newStatelessKieSession(); ksession.setGlobal( "list", list ); Person person = new Person("bop"); ksession.execute(person); assertEquals( 7, list.size() ); assertEquals( "rule 3", list.get( 0 )); assertEquals( "rule 2", list.get( 1 )); assertEquals( "rule 1", list.get( 2 )); assertEquals( "rule 3", list.get( 3 ) ); assertEquals( "rule 2", list.get( 4 ) ); assertEquals( "rule 1", list.get( 5 ) ); assertEquals( person, list.get( 6 )); }
private static byte[] getBytes(String pResourceName) { try { File resource = new File(pResourceName); return resource.exists() ? IoUtils.readBytesFromInputStream(new FileInputStream(pResourceName)) : null; } catch (IOException e) { throw new RuntimeException("Unable to get bytes for: " + new File(pResourceName) + " " + e.getMessage()); } }
private static byte[] readUrlAsBytes(URL url) { InputStream is = null; try { is = url.openStream(); return readBytesFromInputStream(is); } catch (IOException e) { throw new RuntimeException(e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } } }
private static byte[] readUrlAsBytes(URL url) { InputStream is = null; try { is = url.openStream(); return readBytesFromInputStream(is); } catch (IOException e) { throw new RuntimeException(e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } } }
private static byte[] readUrlAsBytes(URL url) { InputStream is = null; try { is = url.openStream(); return readBytesFromInputStream(is); } catch (IOException e) { throw new RuntimeException(e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } } }
@Override public byte[] read(String pResourceName) { FileInputStream fis = null; try { fis = new FileInputStream(getFilePath(pResourceName)); return readBytesFromInputStream(fis); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } }
@Override public byte[] read(String pResourceName) { FileInputStream fis = null; try { fis = new FileInputStream(getFilePath(pResourceName)); return readBytesFromInputStream(fis); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } }
@Override public String loadFromInputStream(InputStream is) throws IOException { String xml = new String(IoUtils.readBytesFromInputStream(is), IoUtils.UTF8_CHARSET); ScoreCardModel model = GuidedScoreCardXMLPersistence.getInstance().unmarshall(xml); return GuidedScoreCardDRLPersistence.marshal(model); }
@Override public String getPMMLStringFromInputStream(InputStream is) throws IOException { String xml = new String(IoUtils.readBytesFromInputStream(is), IoUtils.UTF8_CHARSET); ScoreCardModel model = GuidedScoreCardXMLPersistence.getInstance().unmarshall(xml); PMML pmml = GuidedScoreCardDRLPersistence.createPMMLDocument(model); checkCharacteristics(pmml); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PMML4Compiler compiler = new PMML4Compiler(); compiler.dumpModel(pmml, baos); return new String(baos.toByteArray()); }
@Override public ResourceConversionResult loadFromInputStream(InputStream is) throws IOException { String xml = new String(IoUtils.readBytesFromInputStream(is), IoUtils.UTF8_CHARSET); TemplateModel model = RuleTemplateModelXMLPersistenceImpl.getInstance().unmarshal(xml); String content = RuleTemplateModelDRLPersistenceImpl.getInstance().marshal(model); if (model.hasDSLSentences()) { return new ResourceConversionResult(content, ResourceType.DSLR); } else { return new ResourceConversionResult(content, ResourceType.DRL); } }
@Override public ResourceConversionResult loadFromInputStream(InputStream is) throws IOException { String xml = new String(IoUtils.readBytesFromInputStream(is), IoUtils.UTF8_CHARSET); GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal(xml); String content = GuidedDTDRLPersistence.getInstance().marshal(model); if (hasDSLSentences(model)) { return new ResourceConversionResult(content, ResourceType.DSLR); } else { return new ResourceConversionResult(content, ResourceType.DRL); } }
@Test(timeout=10000) public void testTimerStartDateISO() throws Exception { NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1); byte[] content = IoUtils.readBytesFromInputStream(this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2")); String processContent = new String(content, "UTF-8"); OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2); processContent = processContent.replaceFirst("#\\{date\\}", plusTwoSeconds.toString()); Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent)); resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2"); resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2"); KieBase kbase = createKnowledgeBaseFromResources(resource); ksession = createKnowledgeSession(kbase); ksession.addEventListener(countDownListener); final List<Long> list = new ArrayList<Long>(); ksession.addEventListener(new DefaultProcessEventListener() { public void beforeProcessStarted(ProcessStartedEvent event) { list.add(event.getProcessInstance().getId()); } }); assertThat(list.size()).isEqualTo(0); countDownListener.waitTillCompleted(); assertThat(list.size()).isEqualTo(1); }
@Test public void testProcessWithBrokenItemDefinitionUri() throws Exception { InputStream inputBpmn = getClass().getResourceAsStream("/BPMN2-BrokenStructureRef.bpmn2"); XmlProcessDumper dumper = XmlProcessDumperFactory.getXmlProcessDumperFactoryService().newXmlProcessDumper(); Assert.assertNotNull(dumper); String processXml = new String(IoUtils.readBytesFromInputStream(inputBpmn), "UTF-8"); Assert.assertNotNull(processXml); org.kie.api.definition.process.Process proc = dumper.readProcess(processXml); Assert.assertNotNull(proc); Assert.assertEquals("BrokenStructureRef", proc.getId()); } }