// @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());
  }
  @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());
  }