Java Code Examples for org.jboss.forge.roaster.model.source.JavaClassSource#getAnnotation()

The following examples show how to use org.jboss.forge.roaster.model.source.JavaClassSource#getAnnotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomPrefixDataProvider.java    From Entitas-Java with MIT License 5 votes vote down vote up
private String getUniqueComponentPrefix(JavaClassSource clazz) {
    AnnotationSource<JavaClassSource> annotation = clazz.getAnnotation(Unique.class);
    if (annotation != null) {
        return annotation.getStringValue("prefix");
    }
    return "is";
}
 
Example 2
Source File: ContextsComponentDataProvider.java    From Entitas-Java with MIT License 5 votes vote down vote up
private List<String> extractContextNames(JavaClassSource clazz) {
    AnnotationSource<JavaClassSource> annotation =  clazz.getAnnotation(Contexts.class);
    if (annotation != null) {
        return Arrays.asList(annotation.getStringArrayValue("names"));
    }
    return new ArrayList<>();
}
 
Example 3
Source File: ComponentDataProvider.java    From Entitas-Java with MIT License 5 votes vote down vote up
List<String> getComponentNames(JavaClassSource type) {
    AnnotationSource<JavaClassSource> annotation = type.getAnnotation(CustomComponentName.class);
    if (annotation != null) {
        return Arrays.asList(annotation.getStringArrayValue("componentNames"));

    } else {
        return new ArrayList<>();
    }

}
 
Example 4
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_incontainer_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }
   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));
   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   assertThat(defaultDeployment.getValues().size(), is(0));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example 5
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_create_asclient_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("asClient", true);

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("testable");
   assertThat(testable, is("false"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}
 
Example 6
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void should_set_archivetype_test() throws Exception
{
   assertThat(project.hasFacet(ThorntailFacet.class), is(true));
   try (CommandController controller = uiTestHarness.createCommandController(CreateTestClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      controller.setValueFor("named", "HelloWorldTest");
      controller.setValueFor("archiveType", "WAR");

      assertThat(controller.isValid(), is(true));
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Test Class org.example.HelloWorldTest was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      assertThat(flag.get(), is(true));
   }

   JavaResource javaResource = project.getFacet(JavaSourceFacet.class)
            .getTestJavaResource("org.example.HelloWorldTest");
   assertThat(javaResource.exists(), is(true));
   JavaClassSource testClass = Roaster.parse(JavaClassSource.class, javaResource.getContents());
   assertThat(testClass.getAnnotation(RunWith.class), is((notNullValue())));

   final AnnotationSource<JavaClassSource> defaultDeployment = testClass.getAnnotation("DefaultDeployment");
   assertThat(defaultDeployment, is((notNullValue())));
   final String testable = defaultDeployment.getLiteralValue("type");
   assertThat(testable, is("DefaultDeployment.Type.WAR"));

   final MethodSource<JavaClassSource> testMethod = testClass.getMethod("should_start_service");
   assertThat(testMethod, is(notNullValue()));
   assertThat(testMethod.getAnnotation(Test.class), is(notNullValue()));

}