コード例 #1
0
  @Test
  public void testCreateEndpoint() throws Exception {
    Project project = getProject();
    JavaClass entity = generateEntity(project, null, "User");
    assertFalse(entity.hasAnnotation(XmlRootElement.class));

    setupRest();

    queueInputLines("");
    getShell().execute("rest endpoint-from-entity");

    JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
    JavaResource resource = java.getJavaResource(java.getBasePackage() + ".rest.UserEndpoint");
    JavaClass endpoint = (JavaClass) resource.getJavaSource();

    assertEquals("/user", endpoint.getAnnotation(Path.class).getStringValue());
    assertEquals("java.util.List", endpoint.getMethod("listAll").getQualifiedReturnType());
    Method<JavaClass> method = endpoint.getMethod("findById", Long.class);
    Type<JavaClass> returnTypeInspector = method.getReturnTypeInspector();
    assertEquals(
        "com.test." + PersistenceFacetImpl.DEFAULT_ENTITY_PACKAGE + ".User",
        returnTypeInspector.getQualifiedName());

    assertTrue(java.getJavaResource(entity).getJavaSource().hasAnnotation(XmlRootElement.class));
    getShell().execute("build");
  }
コード例 #2
0
  @Test
  public void testCreateEndpointPrimitiveNonStandardGetterId() throws Exception {
    Project project = getProject();
    JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
    JavaClass entity =
        JavaParser.parse(JavaClass.class, RestPluginTest.class.getResourceAsStream("User3.java"));
    entity.setPackage(java.getBasePackage() + ".model");
    java.saveJavaSource(entity);

    getShell().setCurrentResource(java.getJavaResource(entity));

    setupRest();

    queueInputLines("");
    getShell().execute("rest endpoint-from-entity");

    JavaResource resource = java.getJavaResource(java.getBasePackage() + ".rest.User3Endpoint");
    JavaClass endpoint = (JavaClass) resource.getJavaSource();

    assertEquals("/user3", endpoint.getAnnotation(Path.class).getStringValue());
    assertTrue(endpoint.toString().contains("entity.setObjectId(id);"));
    getShell().execute("build");
  }