@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()); } }
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()); } }
byte[] bytesFromStream = readBytesFromInputStream(is); byte[] bytesFromURL = readBytesFromInputStream(resourceUrl.openStream()); assertTrue(Arrays.equals(bytesFromStream, bytesFromURL));
byte[] data = IoUtils.readBytesFromInputStream(processResource.getInputStream()); String processAsString = new String(data, "UTF-8");
@Test public void createModuleAndFindResources() throws IOException, ClassNotFoundException, InterruptedException { createKieModule( "fol4", false ); ReleaseId releaseId = KieServices.Factory.get().newReleaseId("fol4", "art1", "1.0-SNAPSHOT"); KieContainer kieContainer = KieServices.Factory.get().newKieContainer(releaseId); assertNotNull(kieContainer); InputStream is = kieContainer.getClassLoader().getResourceAsStream("/META-INF/beans.xml"); assertNotNull(is); byte[] bytesFromStream = readBytesFromInputStream(is); Enumeration<URL> foundResources = kieContainer.getClassLoader().getResources("/META-INF/beans.xml"); assertNotNull(foundResources); List<URL> resourcesAsList = Collections.list(foundResources); assertNotNull(resourcesAsList); assertEquals(1, resourcesAsList.size()); URL resourceUrl = resourcesAsList.get(0); byte[] bytesFromURL = readBytesFromInputStream(resourceUrl.openStream()); assertTrue(Arrays.equals(bytesFromStream, bytesFromURL)); String url = resourceUrl.toString(); assertNotNull(url); assertEquals("mfs:/META-INF/beans.xml", url); String file = resourceUrl.getFile(); assertNotNull(file); assertEquals("/META-INF/beans.xml", file); }