コード例 #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
  @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());
  }
コード例 #3
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());
  }