private static Map<String, String> extractStringValues(final AnnotationDescr descr) { final Map<String, String> values = new HashMap<String, String>(); for (Map.Entry<String, Object> e : descr.getValues().entrySet()) { values.put(e.getKey(), descr.getValueAsString(e.getKey())); } return values; } }
@Test public void testMultiValueAnnotationsBackwardCompatibility() throws Exception { // multiple values with no keys are parsed as a single value final String text = "rule X @ann1( val1, val2 ) @ann2( \"val1\", \"val2\" ) when then end"; RuleDescr rule = (RuleDescr) parse( "rule", text ); AnnotationDescr ann = rule.getAnnotation( "ann1" ); assertNotNull( ann ); assertEquals( "val1, val2", ann.getValue() ); ann = rule.getAnnotation( "ann2" ); assertNotNull( ann ); assertEquals( "\"val1\", \"val2\"", ann.getValue() ); }
protected void visit(final AnnotationDescr descr) { addResourceReference(descr.getName(), ResourceType.DRL_ANNOTATION); }
model.addMetadata(new RuleMetadata(annotation.getName(), annotation.getValuesAsString()));
final String annotationName = en.getKey(); final AnnotationDescr descr = en.getValue(); final Map<String, String> values = descr.getValues(); final AnnotationMetaModel am = new AnnotationMetaModel( annotationName, values );
final String annotationName = descr.getName(); final Map<String, String> values = extractStringValues(descr); final AnnotationMetaModel am = new AnnotationMetaModel(annotationName,
@Test public void testRuleMetadata() throws Exception { final PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit", "Rule_with_Metadata.drl" ); assertFalse( parser.getErrors().toString(), parser.hasErrors() ); // @fooAttribute(barValue) // @fooAtt2(barVal2) RuleDescr rule = pkg.getRules().get( 0 ); assertTrue( rule.getAnnotationNames().contains( "fooMeta1" ) ); assertEquals( "barVal1", rule.getAnnotation( "fooMeta1" ).getValue() ); assertTrue( rule.getAnnotationNames().contains( "fooMeta2" ) ); assertEquals( "barVal2", rule.getAnnotation( "fooMeta2" ).getValue() ); assertEqualsIgnoreWhitespace( "System.out.println(\"Consequence\");", (String) rule.getConsequence() ); }
@Test public void testEntryPointDeclaration() throws Exception { final String text = "package org.drools\n" + "declare entry-point eventStream\n" + " @source(\"jndi://queues/events\")\n" + " @foo( true )\n" + "end"; PackageDescr pkg = (PackageDescr) parse( "compilationUnit", text ); assertEquals( "org.drools", pkg.getName() ); assertEquals( 1, pkg.getEntryPointDeclarations().size() ); EntryPointDeclarationDescr epd = pkg.getEntryPointDeclarations().iterator().next(); assertEquals( "eventStream", epd.getEntryPointId() ); assertEquals( 2, epd.getAnnotations().size() ); assertEquals( "\"jndi://queues/events\"", epd.getAnnotation( "source" ).getValue() ); assertEquals( "true", epd.getAnnotation( "foo" ).getValue() ); }
type.getAnnotation( "role" ).getValue() ); assertEquals( "\"Models a person\"", type.getAnnotation( "doc" ).getValue( "descr" ) ); assertEquals( "\"Bob\"", type.getAnnotation( "doc" ).getValue( "author" ) ); assertEquals( "Calendar.getInstance().getDate()", type.getAnnotation( "doc" ).getValue( "date" ) ); field.getInitExpr() ); assertEquals( "50", field.getAnnotation( "length" ).getValue( "max" ) ); assertNotNull( field.getAnnotation( "key" ) ); field.getInitExpr() ); assertEquals( "0", field.getAnnotation( "ranged" ).getValue( "min" ) ); assertEquals( "150", field.getAnnotation( "ranged" ).getValue( "max" ) ); assertEquals( "-1", field.getAnnotation( "ranged" ).getValue( "unknown" ) );
wdd.getAnnotations().size() ); assertEquals( "\"last 10 stock ticks\"", wdd.getAnnotation( "doc" ).getValue() );