コード例 #1
0
  @Test
  public void testDefaultCompiler() throws Exception {

    JarInputStream jis = new JarInputStream(this.getClass().getResourceAsStream("/billasurf.jar"));
    List<JarInputStream> l = new ArrayList<JarInputStream>();
    l.add(jis);
    Properties properties = new Properties();
    properties.setProperty(
        "drools.accumulate.function.groupCount",
        "org.drools.base.accumulators.MaxAccumulateFunction");
    BRMSPackageBuilder builder =
        new BRMSPackageBuilder(properties, new ClassLoaderBuilder(l).buildClassLoader());
    assertEquals(
        "org.drools.base.accumulators.MaxAccumulateFunction",
        builder
            .getPackageBuilderConfiguration()
            .getAccumulateFunction("groupCount")
            .getClass()
            .getName());

    PackageDescr pc = new PackageDescr("foo.bar");
    builder.addPackage(pc);

    String header = "import com.billasurf.Person\n import com.billasurf.Board";
    builder.addPackageFromDrl(new StringReader(header));
    assertFalse(builder.hasErrors());

    JavaDialectConfiguration javaConf =
        (JavaDialectConfiguration)
            builder.getPackageBuilderConfiguration().getDialectConfiguration("java");
    assertEquals(JavaDialectConfiguration.ECLIPSE, javaConf.getCompiler());
  }
コード例 #2
0
  // @FIXME rule "abc" is null and the Packge has no namespace
  @Test
  public void testPartialPackage() throws Exception {

    JarInputStream jis = new JarInputStream(this.getClass().getResourceAsStream("/billasurf.jar"));
    List<JarInputStream> jarInputStreams = new ArrayList<JarInputStream>();
    jarInputStreams.add(jis);

    Properties ps = new Properties();
    ps.setProperty(DefaultPackageNameOption.PROPERTY_NAME, "foo.bar");

    BRMSPackageBuilder builder =
        new BRMSPackageBuilder(ps, new ClassLoaderBuilder(jarInputStreams).buildClassLoader());

    // PackageDescr pc = new PackageDescr("foo.bar");
    // builder.addPackage( pc );

    String header = "import com.billasurf.Person\n import com.billasurf.Board";
    builder.addPackageFromDrl(new StringReader(header));
    assertFalse(builder.hasErrors());

    JavaDialectConfiguration javaConf =
        (JavaDialectConfiguration)
            builder.getPackageBuilderConfiguration().getDialectConfiguration("java");
    assertEquals(JavaDialectConfiguration.ECLIPSE, javaConf.getCompiler());

    String ruleAtom = "rule foo \n when \n Person() \n then \n System.out.println(42); end";
    builder.addPackageFromDrl(new StringReader(ruleAtom));
    if (builder.hasErrors()) {
      System.err.println(builder.getErrors().getErrors()[0].getMessage());
    }
    assertFalse(builder.hasErrors());

    ruleAtom = "rule foo2 \n when \n Person() \n then \n System.out.println(42); end";
    builder.addPackageFromDrl(new StringReader(ruleAtom));
    if (builder.hasErrors()) {
      System.err.println(builder.getErrors().getErrors()[0].getMessage());
    }
    assertFalse(builder.hasErrors());

    assertEquals("foo.bar", builder.getPackage().getName());

    String functionAtom = "function int fooBar(String x) { return 42; }";
    builder.addPackageFromDrl(new StringReader(functionAtom));
    if (builder.hasErrors()) {
      System.err.println(builder.getErrors().getErrors()[0].getMessage());
    }
    assertFalse(builder.hasErrors());

    Package p = builder.getPackage();
    assertEquals(2, p.getRules().length);
    assertEquals(1, p.getFunctions().size());
    assertNotNull(p.getRule("foo2"));

    functionAtom = "xxx";
    builder.addPackageFromDrl(new StringReader(functionAtom));
    assertTrue(builder.hasErrors());
    builder.clearErrors();
    assertFalse(builder.hasErrors());
  }
コード例 #3
0
  @Test
  public void testNamespaceSingle() throws Exception {

    System.setProperty("drools.dialect.java.compiler", "ECLIPSE");
    JarInputStream jis = new JarInputStream(this.getClass().getResourceAsStream("/billasurf.jar"));
    List<JarInputStream> l = new ArrayList<JarInputStream>();
    l.add(jis);
    BRMSPackageBuilder builder =
        new BRMSPackageBuilder(new Properties(), new ClassLoaderBuilder(l).buildClassLoader());

    assertFalse(builder.getPackageBuilderConfiguration().isAllowMultipleNamespaces());
  }
コード例 #4
0
  @Test
  public void testGeneratedBeans() throws Exception {

    JarInputStream jis = new JarInputStream(this.getClass().getResourceAsStream("/billasurf.jar"));
    List<JarInputStream> jarInputStreams = new ArrayList<JarInputStream>();
    jarInputStreams.add(jis);
    BRMSPackageBuilder builder =
        new BRMSPackageBuilder(
            new Properties(), new ClassLoaderBuilder(jarInputStreams).buildClassLoader());

    PackageDescr pc = new PackageDescr("foo.bar");
    builder.addPackage(pc);

    String header =
        "import com.billasurf.Person\n import com.billasurf.Board\n declare GenBean \n name: String \n end";
    builder.addPackageFromDrl(new StringReader(header));
    assertFalse(builder.hasErrors());

    JavaDialectConfiguration javaConf =
        (JavaDialectConfiguration)
            builder.getPackageBuilderConfiguration().getDialectConfiguration("java");
    assertEquals(JavaDialectConfiguration.ECLIPSE, javaConf.getCompiler());

    String ruleAtom =
        "rule foo \n when \n Person() \n GenBean(name=='mike')\n then \n System.out.println(42); end";
    builder.addPackageFromDrl(new StringReader(ruleAtom));
    if (builder.hasErrors()) {
      System.err.println(builder.getErrors().getErrors()[0].getMessage());
    }
    assertFalse(builder.hasErrors());

    ruleAtom = "rule foo2 \n when \n Person() \n then \n System.out.println(42); end";
    builder.addPackageFromDrl(new StringReader(ruleAtom));
    if (builder.hasErrors()) {
      System.err.println(builder.getErrors().getErrors()[0].getMessage());
    }
    assertFalse(builder.hasErrors());

    assertEquals("foo.bar", builder.getPackage().getName());
  }
コード例 #5
0
  @Test
  public void testEclipseCompiler() throws Exception {

    System.setProperty("drools.dialect.java.compiler", "ECLIPSE");
    JarInputStream jis = new JarInputStream(this.getClass().getResourceAsStream("/billasurf.jar"));
    List<JarInputStream> l = new ArrayList<JarInputStream>();
    l.add(jis);
    BRMSPackageBuilder builder =
        new BRMSPackageBuilder(new Properties(), new ClassLoaderBuilder(l).buildClassLoader());

    PackageDescr pc = new PackageDescr("foo.bar");
    builder.addPackage(pc);

    String header = "import com.billasurf.Person\n import com.billasurf.Board";
    builder.addPackageFromDrl(new StringReader(header));
    assertFalse(builder.hasErrors());

    JavaDialectConfiguration javaConf =
        (JavaDialectConfiguration)
            builder.getPackageBuilderConfiguration().getDialectConfiguration("java");
    assertEquals(JavaDialectConfiguration.ECLIPSE, javaConf.getCompiler());
  }