@Test public void testMask() { TypeDeclaration tdeclr = new TypeDeclaration(CImpl.class.getName() ); assertEquals( 0, tdeclr.getSetMask() ); tdeclr.setRole( Role.Type.EVENT ); assertEquals( TypeDeclaration.ROLE_BIT, tdeclr.getSetMask() & TypeDeclaration.ROLE_BIT ); assertFalse( TypeDeclaration.TYPESAFE_BIT == ( tdeclr.getSetMask() & TypeDeclaration.TYPESAFE_BIT ) ); assertFalse( TypeDeclaration.FORMAT_BIT == ( tdeclr.getSetMask() & TypeDeclaration.FORMAT_BIT ) ); tdeclr.setTypesafe( false ); assertEquals( TypeDeclaration.ROLE_BIT, tdeclr.getSetMask() & TypeDeclaration.ROLE_BIT ); assertEquals( TypeDeclaration.TYPESAFE_BIT, tdeclr.getSetMask() & TypeDeclaration.TYPESAFE_BIT ); assertFalse( TypeDeclaration.FORMAT_BIT == ( tdeclr.getSetMask() & TypeDeclaration.FORMAT_BIT ) ); tdeclr = new TypeDeclaration(CImpl.class.getName() ); tdeclr.setTypesafe( true ); assertFalse( TypeDeclaration.ROLE_BIT == ( tdeclr.getSetMask() & TypeDeclaration.ROLE_BIT ) ); assertEquals( TypeDeclaration.TYPESAFE_BIT, tdeclr.getSetMask() & TypeDeclaration.TYPESAFE_BIT ); assertFalse( TypeDeclaration.FORMAT_BIT == ( tdeclr.getSetMask() & TypeDeclaration.FORMAT_BIT ) ); tdeclr.setFormat( Format.POJO ); assertFalse( TypeDeclaration.ROLE_BIT == ( tdeclr.getSetMask() & TypeDeclaration.ROLE_BIT ) ); assertEquals( TypeDeclaration.TYPESAFE_BIT, tdeclr.getSetMask() & TypeDeclaration.TYPESAFE_BIT ); assertEquals( TypeDeclaration.FORMAT_BIT, tdeclr.getSetMask() & TypeDeclaration.FORMAT_BIT ); }
@Test public void testInheritExitenceFromParentClass() { // inherits role and typesafe String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( true, tdecl.isTypesafe() ); assertEquals( Role.Type.EVENT, tdecl.getRole() ); }
compilationID); TypeDeclaration typeDeclaration = new TypeDeclaration(); typeDeclaration.setRole(Role.Type.FACT); typeDeclaration.setKind(TypeDeclaration.Kind.CLASS); typeDeclaration.setValid(true); typeDeclaration.setFormat(TypeDeclaration.Format.POJO); typeDeclaration.setNature(TypeDeclaration.Nature.DECLARATION); TypeMetaInfo info = new TypeMetaInfo(typeDeclaration); TypeDeclaration typeDec = new TypeDeclaration(); typeDec.setRole(Role.Type.FACT); typeDec.setKind(TypeDeclaration.Kind.ENUM); typeDec.setValid(true); typeDec.setFormat(TypeDeclaration.Format.TEMPLATE); typeDec.setNature(TypeDeclaration.Nature.DEFINITION); TypeMetaInfo infoTwo = new TypeMetaInfo(typeDec);
@Test public void testTypeDeclaration() throws Exception { TypeDeclaration typeDec1 = new TypeDeclaration(TEST_NAME); TypeDeclaration typeDec2 = SerializationHelper.serializeObject(typeDec1); assertEquals(typeDec1, typeDec2); } }
@Test public void testTypeDeclaration() throws Exception { PackageDescr pkgDescr = new PackageDescr( "org.drools.compiler" ); TypeDeclarationDescr typeDescr = new TypeDeclarationDescr( "StockTick" ); typeDescr.addAnnotation( Role.class.getCanonicalName(), "Event" ); typeDescr.addAnnotation( TypeSafe.class.getCanonicalName(), "true" ); pkgDescr.addTypeDeclaration( typeDescr ); KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl(); builder.addPackage( pkgDescr ); if ( builder.hasErrors() ) { fail( builder.getErrors().toString() ); } InternalKnowledgePackage pkg = builder.getPackage(pkgDescr.getName()); assertEquals( 1, pkg.getTypeDeclarations().size() ); TypeDeclaration type = pkg.getTypeDeclaration( "StockTick" ); assertTrue( type.isTypesafe() ); assertEquals( Role.Type.EVENT, type.getRole() ); assertEquals( StockTick.class, type.getTypeClass() ); }
@Test public void testTypeDeclarationNewBean() throws Exception { PackageDescr pkgDescr = new PackageDescr( "org.drools.compiler.test" ); TypeDeclarationDescr typeDescr = new TypeDeclarationDescr( "NewBean" ); TypeFieldDescr f1 = new TypeFieldDescr( "name", new PatternDescr( "String" ) ); TypeFieldDescr f2 = new TypeFieldDescr( "age", new PatternDescr( "int" ) ); typeDescr.addField( f1 ); typeDescr.addField( f2 ); pkgDescr.addTypeDeclaration( typeDescr ); KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl(); builder.addPackage( pkgDescr ); InternalKnowledgePackage pkg = builder.getPackage(pkgDescr.getName()); assertEquals( 1, pkg.getTypeDeclarations().size() ); TypeDeclaration type = pkg.getTypeDeclaration( "NewBean" ); assertEquals( "NewBean", type.getTypeName() ); assertEquals( Role.Type.FACT, type.getRole() ); assertEquals( "org.drools.compiler.test.NewBean", type.getTypeClass().getName() ); assertFalse( builder.hasErrors() ); InternalKnowledgePackage bp = builder.getPackage(pkgDescr.getName()); Class newBean = bp.getPackageClassLoader().loadClass( "org.drools.compiler.test.NewBean" ); assertNotNull( newBean ); }
assertEquals(Role.Type.EVENT, typeDeclaration.getRole()); assertEquals("duration", typeDeclaration.getDurationAttribute());
compilationID); TypeDeclaration typeDeclaration = new TypeDeclaration(); typeDeclaration.setRole(Role.Type.EVENT); typeDeclaration.setKind(TypeDeclaration.Kind.CLASS); typeDeclaration.setValid(true); typeDeclaration.setFormat(TypeDeclaration.Format.POJO); typeDeclaration.setNature(TypeDeclaration.Nature.DECLARATION); TypeMetaInfo info = new TypeMetaInfo(typeDeclaration); TypeDeclaration typeDec = new TypeDeclaration(); typeDec.setRole(Role.Type.FACT); typeDec.setKind(TypeDeclaration.Kind.ENUM); typeDec.setValid(true); typeDec.setFormat(TypeDeclaration.Format.TEMPLATE); typeDec.setNature(TypeDeclaration.Nature.DEFINITION); TypeMetaInfo infoTwo = new TypeMetaInfo(typeDec);
@Test public void testInheritExitenceFromParentInterface() { // inherits role and typesafe String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IB.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( true, tdecl.isTypesafe() ); assertEquals( Role.Type.EVENT, tdecl.getRole() ); }
@Test public void testInheritNoneExitenceFromParentInterface() { // inherits role and typesafe String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IB.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( true, tdecl.isTypesafe() ); assertEquals( Role.Type.EVENT, tdecl.getRole() ); }
@Test public void testOverrideFromDeeperHierarchyParentInterface() { // inherits role from and typesafe from the other String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IA.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + IB.class.getCanonicalName() + "\n" + " @role(fact)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( true, tdecl.isTypesafe() ); assertEquals( Role.Type.FACT, tdecl.getRole() ); }
@Test public void testOverrideFromParentInterface() { // inherits role but not typesafe String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IB.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + " @typesafe(false)\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( false, tdecl.isTypesafe() ); assertEquals( Role.Type.EVENT, tdecl.getRole() ); }
@Test public void testOverrideFromDeeperParentInterface() { // inherits role but not typesafe String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IA.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + " @typesafe(false)\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( false, tdecl.isTypesafe() ); assertEquals( Role.Type.EVENT, tdecl.getRole() ); }
@Test public void testInheritNoneExitenceFromParentClass() { // inherits role and typesafe String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( true, tdecl.isTypesafe() ); assertEquals( Role.Type.EVENT, tdecl.getRole() ); }
@Test public void testOverrideFromMixedHierarchyParentInterface() { // inherits role from and typesafe from the other String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IA.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @role(fact)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( true, tdecl.isTypesafe() ); assertEquals( Role.Type.FACT, tdecl.getRole() ); }
@Test public void testOverrideFromParentClass() { // inherits role, but not typesafe String str = ""+ "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + " @typesafe(false)\n" + "end\n"; KnowledgeBuilderImpl builder = getPackageBuilder( str ); TypeDeclaration tdecl = builder.getTypeDeclaration( DImpl.class ); assertEquals( false, tdecl.isTypesafe() ); assertEquals( Role.Type.EVENT, tdecl.getRole() ); }