Skip to content

Commit

Permalink
FORGE-2466: Allow usage of '~' in interceptorBinding parameter of cdi…
Browse files Browse the repository at this point in the history
…-new-interceptor
  • Loading branch information
gastaldi committed Sep 14, 2015
1 parent 37d3807 commit 612856b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

import org.jboss.forge.addon.parser.java.converters.PackageRootConverter;
import org.jboss.forge.addon.projects.Project;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
Expand Down Expand Up @@ -44,6 +45,7 @@ public Metadata getMetadata(UIContext context)
public void initializeUI(UIBuilder builder) throws Exception
{
super.initializeUI(builder);
interceptorBinding.setValueConverter(new PackageRootConverter(getProjectFactory(), builder));
builder.add(interceptorBinding);
}

Expand Down Expand Up @@ -73,7 +75,8 @@ public JavaClassSource decorateSource(UIExecutionContext context, Project projec
"try {\n" +
" return ic.proceed();\n" +
" } finally {\n" +
" }").addAnnotation(AroundInvoke.class);
" }")
.addAnnotation(AroundInvoke.class);
return interceptor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,43 @@ public void testCreateNewInterceptor() throws Exception
Assert.assertTrue(interceptor.getMethods().get(0).hasAnnotation(AroundInvoke.class));
Assert.assertFalse(interceptor.hasAnnotation(Inherited.class));
}

@Test
public void testCreateNewInterceptorUsingPackageWildcard() throws Exception
{
try (CommandController controller = uiTestHarness.createCommandController(CDINewInterceptorBindingCommand.class,
project.getRoot()))
{
controller.initialize();
controller.setValueFor("named", "MyInterceptorBinding");
controller.setValueFor("targetPackage", "~.interceptors");
Assert.assertTrue(controller.isValid());
Assert.assertTrue(controller.canExecute());
Result result = controller.execute();
Assert.assertThat(result, is(not(instanceOf(Failed.class))));
}
try (CommandController controller = uiTestHarness.createCommandController(CDINewInterceptorCommand.class,
project.getRoot()))
{
controller.initialize();
controller.setValueFor("named", "MyInterceptor");
controller.setValueFor("targetPackage", "org.jboss.forge.test");
controller.setValueFor("interceptorBinding", "~.interceptors.MyInterceptorBinding");
Assert.assertTrue(controller.isValid());
Assert.assertTrue(controller.canExecute());
Result result = controller.execute();
Assert.assertThat(result, is(not(instanceOf(Failed.class))));
}

JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.MyInterceptor");
Assert.assertNotNull(javaResource);
Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaClass.class)));
JavaClass<?> interceptor = javaResource.getJavaType();
Assert.assertTrue(interceptor.hasAnnotation(facet.getBasePackage() + ".interceptors.MyInterceptorBinding"));
Assert.assertTrue(interceptor.hasAnnotation(Interceptor.class));
Assert.assertTrue(interceptor.getMethods().get(0).hasAnnotation(AroundInvoke.class));
Assert.assertFalse(interceptor.hasAnnotation(Inherited.class));
}

}

0 comments on commit 612856b

Please sign in to comment.