private Collection<KnowledgePackage> readContent() throws IOException, ClassNotFoundException {
    Object streamedInObject = DroolsStreamUtils.streamIn(inputStream, classLoader, true);
    assertThat(streamedInObject)
        .as("object read from stream")
        .isNotNull()
        .isInstanceOf(Collection.class);

    Collection loadedObjects = Collection.class.cast(streamedInObject);
    ensureLoadedObjectsAreKnowledgePackages(loadedObjects);
    Collection<KnowledgePackage> knowledgePackages =
        convertCollectionItemsToKnowledgePackages(loadedObjects);
    return knowledgePackages;
  }
Exemplo n.º 2
0
  @Test
  public void testRules() throws IOException, ClassNotFoundException {
    try {
      executeTarget("rules");
    } catch (Exception e) {
      e.printStackTrace();
      fail("Should not throw any exception: " + e.getMessage());
    }

    RuleBase r1 = (RuleBase) DroolsStreamUtils.streamIn(new FileInputStream("target/cheese.rules"));

    assertNotNull(r1);
    assertEquals(1, r1.getPackages().length);
  }
Exemplo n.º 3
0
  @Test
  public void testRuleFlowKnowledge() throws IOException, ClassNotFoundException {
    try {
      executeTarget("ruleFlowKnowledge");
    } catch (Exception e) {
      e.printStackTrace();
      fail("Should not throw any exception: " + e.getMessage());
    }

    KnowledgeBase kbase =
        (KnowledgeBase) DroolsStreamUtils.streamIn(new FileInputStream("target/ruleFlow.rules"));

    assertNotNull(kbase);
    assertEquals(1, kbase.getKnowledgePackages().size());
  }
Exemplo n.º 4
0
  @Test
  public void testDslRulesKnowledge() throws IOException, ClassNotFoundException {
    try {
      executeTarget("dslRulesKnowledge");
    } catch (Exception e) {
      e.printStackTrace();
      fail("Should not throw any exception: " + e.getMessage());
    }

    KnowledgePackage kpackage1 =
        (KnowledgePackage)
            DroolsStreamUtils.streamIn(new FileInputStream("target/cheese.rules.pkg"));

    assertNotNull(kpackage1);
    assertEquals(1, kpackage1.getRules().size());
  }
 public static void writePackage(KnowledgePackage pkg, File dest) {
   dest.deleteOnExit();
   OutputStream out = null;
   try {
     out = new BufferedOutputStream(new FileOutputStream(dest));
     DroolsStreamUtils.streamOut(out, pkg);
   } catch (Exception e) {
     throw new RuntimeException(e);
   } finally {
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
       }
     }
   }
 }
Exemplo n.º 6
0
 @SuppressWarnings("unchecked")
 public static <T> T serializeObject(T obj, ClassLoader classLoader)
     throws IOException, ClassNotFoundException {
   return (T) DroolsStreamUtils.streamIn(DroolsStreamUtils.streamOut(obj), classLoader);
 }