Project project = projectHelper.createWebProject();
projectHelper.installJAXRS_2_0(project, RestConfigurationStrategyFactory.createUsingWebXml("/rest"));
projectHelper.installJPA_2_0(project);
projectHelper.installEJB_3_2(project);
project = projectHelper.refreshProject(project);
JavaResource entity = projectHelper.createJPAEntity(project, "Customer");
try (CommandController controller = testHarness.createCommandController(RestEndpointFromEntityCommand.class,
project.getRoot()))
{
controller.initialize();
controller.setValueFor("targets", Arrays.asList(entity.getJavaType()));
controller.setValueFor("persistenceUnit", "unit");
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 restResource = facet.getJavaResource("unknown.rest.CustomerEndpoint");
Assert.assertTrue(restResource.exists());
Assert.assertThat(restResource.getJavaType(), is(instanceOf(JavaClass.class)));
JavaClass<?> restClass = restResource.getJavaType();
Method<?, ?> method = restClass.getMethod("create", "unknown.model.Customer");
Annotation<?> consumes = method.getAnnotation(Consumes.class);
Assert.assertEquals(MediaType.APPLICATION_JSON, consumes.getStringValue());
}