Java Code Examples for org.apache.cxf.helpers.FileUtils#getFilesRecurseUsingSuffix()

The following examples show how to use org.apache.cxf.helpers.FileUtils#getFilesRecurseUsingSuffix() . 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: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoTargetNamespace() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceSchemaNoTargetNamespace.xml"));
    context.put(WadlToolConstants.CFG_SCHEMA_PACKAGENAME, "=custom");
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());
    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(3, files.size());
    assertTrue(checkContains(files, "application" + ".Resource.class"));
    assertTrue(checkContains(files, "custom" + ".TestCompositeObject.class"));
    assertTrue(checkContains(files, "custom" + ".ObjectFactory.class"));
}
 
Example 2
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInheritParameters() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/test.xml"));
    context.put(WadlToolConstants.CFG_COMPILE, "true");
    context.put(WadlToolConstants.CFG_SCHEMA_TYPE_MAP,
                "{http://www.w3.org/2001/XMLSchema}anyType="
                + "java.io.InputStream");
    context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "last");
    context.put(WadlToolConstants.CFG_CREATE_JAVA_DOCS, "true");
    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(1, files.size());
}
 
Example 3
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void verifyFiles(String ext, boolean subresourceExpected, boolean interfacesAndImpl,
                         String schemaPackage, String resourcePackage, int expectedCount,
                         boolean enumTypeExpected) {
    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, "." + ext);
    int offset = enumTypeExpected ? 1 : 2;
    int size = interfacesAndImpl ? expectedCount : expectedCount - offset;
    if (!subresourceExpected) {
        size--;
    }
    assertEquals(size, files.size());
    doVerifyTypes(files, schemaPackage, ext);
    if (subresourceExpected) {
        assertTrue(checkContains(files, resourcePackage + ".FormInterface." + ext));
        assertTrue(checkContains(files, resourcePackage + ".FormInterface2." + ext));
    }
    assertTrue(checkContains(files, resourcePackage + ".BookStore." + ext));
    if (interfacesAndImpl) {
        if (subresourceExpected) {
            assertTrue(checkContains(files, resourcePackage + ".FormInterfaceImpl." + ext));
            assertTrue(checkContains(files, resourcePackage + ".FormInterface2Impl." + ext));
        }
        assertTrue(checkContains(files, resourcePackage + ".BookStoreImpl." + ext));
    }
}
 
Example 4
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCodeGenInterfacesWithJaxbClassNameSuffix() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstore.xml"));
    context.put(WadlToolConstants.CFG_JAXB_CLASS_NAME_SUFFIX, "DTO");
    context.put(WadlToolConstants.CFG_BINDING, getLocation("/wadl/jaxbSchemaBindings.xml"));
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());
    List<File> schemafiles = FileUtils.getFilesRecurseUsingSuffix(output, ".java");
    assertEquals(10, schemafiles.size());
    doVerifyTypesWithSuffix(schemafiles, "superbooks", "java");

    List<File> classfiles = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(10, classfiles.size());
    doVerifyTypesWithSuffix(classfiles, "superbooks", "class");
}
 
Example 5
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void doTestInlinedSchemasWithImport(String loc) throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation(loc));
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(7, files.size());
    assertTrue(checkContains(files, "org.apache.cxf.jaxrs.model.wadl" + ".BookStore.class"));
    assertTrue(checkContains(files, "superbooks" + ".Book.class"));
    assertTrue(checkContains(files, "superbooks" + ".ObjectFactory.class"));
    assertTrue(checkContains(files, "superbooks" + ".package-info.class"));
    assertTrue(checkContains(files, "superchapters" + ".Chapter.class"));
    assertTrue(checkContains(files, "superchapters" + ".ObjectFactory.class"));
    assertTrue(checkContains(files, "superchapters" + ".package-info.class"));
}
 
Example 6
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testResourceWithEPR() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceWithEPR.xml"));
    context.put(WadlToolConstants.CFG_SCHEMA_TYPE_MAP,
                "{http://www.w3.org/2001/XMLSchema}date=javax.xml.datatype.XMLGregorianCalendar");
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(4, files.size());
    assertTrue(checkContains(files, "application" + ".BookstoreResource.class"));
    assertTrue(checkContains(files, "superbooks" + ".Book.class"));
    assertTrue(checkContains(files, "superbooks" + ".ObjectFactory.class"));
    assertTrue(checkContains(files, "superbooks" + ".package-info.class"));
}
 
Example 7
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testResourceWithEPRNoSchemaGen() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceWithEPR.xml"));
    context.put(WadlToolConstants.CFG_SCHEMA_TYPE_MAP,
        "{http://www.w3.org/2005/08/addressing}EndpointReferenceType="
        + "javax.xml.ws.wsaddressing.W3CEndpointReference");
    context.put(WadlToolConstants.CFG_NO_ADDRESS_BINDING, "true");
    context.put(WadlToolConstants.CFG_NO_TYPES, "true");

    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(1, files.size());
    assertTrue(checkContains(files, "application" + ".BookstoreResource.class"));
}
 
Example 8
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCodeGenHyphen() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstoreHyphen.xml"));
    context.put(WadlToolConstants.CFG_IMPL, "true");
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(3, files.size());
    assertTrue(checkContains(files, "application" + ".BookstoreResource.class"));
    assertTrue(checkContains(files, "generated" + ".TestCompositeObject.class"));
    assertTrue(checkContains(files, "generated" + ".ObjectFactory.class"));
}
 
Example 9
Source File: WADLToJavaTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void verifyFiles(String ext, boolean subresourceExpected, boolean interfacesAndImpl,
                         String schemaPackage, String resourcePackage) {
    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, "." + ext);
    int size = interfacesAndImpl ? 11 : 10;
    if (!subresourceExpected) {
        size--;
    }
    assertEquals(size, files.size());
    doVerifyTypes(files, schemaPackage, ext);
    if (subresourceExpected) {
        assertTrue(checkContains(files, resourcePackage + ".FormInterface." + ext));
    }
    assertTrue(checkContains(files, resourcePackage + ".BookStore." + ext));
    if (interfacesAndImpl) {
        if (subresourceExpected) {
            assertTrue(checkContains(files, resourcePackage + ".FormInterfaceImpl." + ext));
        }
        assertTrue(checkContains(files, resourcePackage + ".BookStoreImpl." + ext));
    }
}
 
Example 10
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCodeGenWithResourceSet() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/singleResourceWithRefs.xml"));
    context.put(WadlToolConstants.CFG_RESOURCENAME, "CustomResource");
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> javaFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".java");
    assertEquals(1, javaFiles.size());
    assertTrue(checkContains(javaFiles, "application.CustomResource.java"));

    List<File> classFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(1, classFiles.size());
    assertTrue(checkContains(classFiles, "application.CustomResource.class"));
}
 
Example 11
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCodeGenNoIds() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/singleResource.xml"));
    context.put(WadlToolConstants.CFG_RESOURCENAME, "CustomResource");
    context.put(WadlToolConstants.CFG_GENERATE_ENUMS, "true");
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> javaFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".java");
    assertEquals(2, javaFiles.size());
    assertTrue(checkContains(javaFiles, "application.CustomResource.java"));
    assertTrue(checkContains(javaFiles, "application.Theid.java"));

    List<File> classFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(2, classFiles.size());
    assertTrue(checkContains(classFiles, "application.CustomResource.class"));
    assertTrue(checkContains(classFiles, "application.Theid.class"));
}
 
Example 12
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCodeGenNoIds2() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/multipleResources.xml"));
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> javaFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".java");
    assertEquals(2, javaFiles.size());
    assertTrue(checkContains(javaFiles, "application.BookstoreResource.java"));
    assertTrue(checkContains(javaFiles, "application.BooksResource.java"));
    List<File> classFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(2, classFiles.size());
    assertTrue(checkContains(classFiles, "application.BookstoreResource.class"));
    assertTrue(checkContains(classFiles, "application.BooksResource.class"));
}
 
Example 13
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCodeGenNoIds3() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourcesNoId.xml"));
    context.put(WadlToolConstants.CFG_COMPILE, "true");
    context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> javaFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".java");
    assertEquals(1, javaFiles.size());
    assertTrue(checkContains(javaFiles, "application.TestRsResource.java"));
    List<File> classFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(1, classFiles.size());
    assertTrue(checkContains(classFiles, "application.TestRsResource.class"));
}
 
Example 14
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testComplexPath() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/testComplexPath.xml"));
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(1, files.size());
    assertTrue(checkContains(files, "application.Resource.class"));
    @SuppressWarnings("resource")
    ClassLoader loader = new URLClassLoader(new URL[] {output.toURI().toURL() });

    Class<?> test1 = loader.loadClass("application.Resource");
    Method[] test1Methods = test1.getDeclaredMethods();
    assertEquals(2, test1Methods.length);
    assertEquals(2, test1Methods[0].getAnnotations().length);
    if ("getGetaddmethod2".equals(test1Methods[0].getName())) {
        Method tmp = test1Methods[0];
        test1Methods[0] = test1Methods[1];
        test1Methods[1] = tmp;
    }
    checkComplexPathMethod(test1Methods[0], "");
    checkComplexPathMethod(test1Methods[1], "2");
}
 
Example 15
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCodeTwoSchemasSameTargetNs() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceSameTargetNsSchemas.xml"));
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    List<File> javaFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".java");
    assertEquals(4, javaFiles.size());
    assertTrue(checkContains(javaFiles, "application.Resource.java"));
    assertTrue(checkContains(javaFiles, "com.example.test.ObjectFactory.java"));
    assertTrue(checkContains(javaFiles, "com.example.test.package-info.java"));
    assertTrue(checkContains(javaFiles, "com.example.test.TestCompositeObject.java"));
    List<File> classFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(4, classFiles.size());
    assertTrue(checkContains(classFiles, "application.Resource.class"));
    assertTrue(checkContains(classFiles, "com.example.test.ObjectFactory.class"));
    assertTrue(checkContains(classFiles, "com.example.test.package-info.class"));
    assertTrue(checkContains(classFiles, "com.example.test.TestCompositeObject.class"));


    assertNotNull(output.list());
}
 
Example 16
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testBeanValidation() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourceSameTargetNsSchemas.xml"));
    context.put(WadlToolConstants.CFG_BEAN_VALIDATION, "true");
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(4, files.size());
    assertTrue(checkContains(files, "application.Resource.class"));
    @SuppressWarnings("resource")
    ClassLoader loader = new URLClassLoader(new URL[] {output.toURI().toURL() });

    Class<?> test1 = loader.loadClass("application.Resource");
    Method[] test1Methods = test1.getDeclaredMethods();
    assertEquals(1, test1Methods.length);
    Method m = test1Methods[0];
    assertEquals(5, m.getAnnotations().length);
    assertNotNull(m.getAnnotation(Valid.class));
    assertNotNull(m.getAnnotation(Path.class));
    assertNotNull(m.getAnnotation(Consumes.class));
    assertNotNull(m.getAnnotation(Produces.class));
    assertNotNull(m.getAnnotation(PUT.class));

    Class<?>[] paramTypes = m.getParameterTypes();
    assertEquals(2, paramTypes.length);
    Annotation[][] paramAnns = m.getParameterAnnotations();
    assertEquals(String.class, paramTypes[0]);
    assertEquals(1, paramAnns[0].length);
    PathParam methodPathParam1 = (PathParam)paramAnns[0][0];
    assertEquals("id", methodPathParam1.value());

    assertEquals(1, paramAnns[1].length);
    assertTrue(paramAnns[1][0] instanceof Valid);
}
 
Example 17
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryMultipartParam() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/testQueryMultipartParam.wadl"));
    context.put(WadlToolConstants.CFG_COMPILE, "true");

    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, ".class");
    assertEquals(2, files.size());
    assertTrue(checkContains(files, "application.Test1.class"));
    assertTrue(checkContains(files, "application.Test2.class"));

    @SuppressWarnings("resource")
    ClassLoader loader = new URLClassLoader(new URL[] {output.toURI().toURL() });

    Class<?> test1 = loader.loadClass("application.Test1");
    Method[] test1Methods = test1.getDeclaredMethods();
    assertEquals(1, test1Methods.length);

    assertEquals(2, test1Methods[0].getAnnotations().length);
    assertNotNull(test1Methods[0].getAnnotation(PUT.class));
    Consumes consumes1 = test1Methods[0].getAnnotation(Consumes.class);
    assertNotNull(consumes1);
    assertEquals(1, consumes1.value().length);
    assertEquals("multipart/mixed", consumes1.value()[0]);

    assertEquals("put", test1Methods[0].getName());
    Class<?>[] paramTypes = test1Methods[0].getParameterTypes();
    assertEquals(3, paramTypes.length);
    Annotation[][] paramAnns = test1Methods[0].getParameterAnnotations();
    assertEquals(Boolean.class, paramTypes[0]);
    assertEquals(1, paramAnns[0].length);
    QueryParam test1QueryParam1 = (QueryParam)paramAnns[0][0];
    assertEquals("standalone", test1QueryParam1.value());
    assertEquals(String.class, paramTypes[1]);
    assertEquals(1, paramAnns[1].length);
    Multipart test1MultipartParam1 = (Multipart)paramAnns[1][0];
    assertEquals("action", test1MultipartParam1.value());
    assertTrue(test1MultipartParam1.required());
    assertEquals(String.class, paramTypes[2]);
    assertEquals(1, paramAnns[2].length);
    Multipart test1MultipartParam2 = (Multipart)paramAnns[2][0];
    assertEquals("sources", test1MultipartParam2.value());
    assertFalse(test1MultipartParam2.required());

    Class<?> test2 = loader.loadClass("application.Test2");
    Method[] test2Methods = test2.getDeclaredMethods();
    assertEquals(1, test2Methods.length);

    assertEquals(2, test2Methods[0].getAnnotations().length);
    assertNotNull(test2Methods[0].getAnnotation(PUT.class));
    Consumes consumes2 = test2Methods[0].getAnnotation(Consumes.class);
    assertNotNull(consumes2);
    assertEquals(1, consumes2.value().length);
    assertEquals("application/json", consumes2.value()[0]);

    assertEquals("put", test2Methods[0].getName());
    Class<?>[] paramTypes2 = test2Methods[0].getParameterTypes();
    assertEquals(2, paramTypes2.length);
    Annotation[][] paramAnns2 = test2Methods[0].getParameterAnnotations();
    assertEquals(boolean.class, paramTypes2[0]);
    assertEquals(1, paramAnns2[0].length);
    QueryParam test2QueryParam1 = (QueryParam)paramAnns2[0][0];
    assertEquals("snapshot", test2QueryParam1.value());
    assertEquals(String.class, paramTypes2[1]);
    assertEquals(0, paramAnns2[1].length);
}
 
Example 18
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testThrows() throws Exception {
    JAXRSContainer container = new JAXRSContainer(null);

    ToolContext context = new ToolContext();
    context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
    context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/test.xml"));
    context.put(WadlToolConstants.CFG_COMPILE, Boolean.TRUE);
    context.put(WadlToolConstants.CFG_INTERFACE, Boolean.TRUE);
    context.put(WadlToolConstants.CFG_IMPL, Boolean.TRUE);
    context.put(WadlToolConstants.CFG_CREATE_JAVA_DOCS, Boolean.TRUE);
    container.setContext(context);
    container.execute();

    assertNotNull(output.list());

    List<File> javaFiles = FileUtils.getFilesRecurseUsingSuffix(output, ".java");
    assertEquals(2, javaFiles.size());
    for (File f : javaFiles) {
        if (!f.getName().endsWith("Impl.java")) {
            assertTrue(
                    Files.readAllLines(f.toPath()).contains("     * @throws IOException if something going wrong"));
        }
    }

    ClassCollector cc = context.get(ClassCollector.class);
    assertEquals(2, cc.getServiceClassNames().size());

    final Map<String, Class<?>[]> methods = new HashMap<>();
    methods.put("listRepositories", new Class<?>[] {});
    methods.put("createRepository", new Class<?>[] {java.io.IOException.class});
    methods.put("deleteRepository",
            new Class<?>[] {javax.ws.rs.NotFoundException.class, java.io.IOException.class});
    methods.put("postThename", new Class<?>[] {java.io.IOException.class, java.lang.NoSuchMethodException.class});
    try (URLClassLoader loader = new URLClassLoader(new URL[]{output.toURI().toURL()})) {
        for (String className : cc.getServiceClassNames().values()) {
            final Class<?> generatedClass = loader.loadClass(className);
            for (Map.Entry<String, Class<?>[]> entry : methods.entrySet()) {
                Method m;
                try {
                    m = generatedClass.getMethod(entry.getKey(), String.class);
                } catch (NoSuchMethodException e) {
                    m = generatedClass.getMethod(entry.getKey(), String.class, String.class);
                }
                assertArrayEquals(entry.getValue(), m.getExceptionTypes());
            }
        }
    }
}
 
Example 19
Source File: JAXRSContainerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void verifyTypes(String schemaPackage, String ext, boolean enumTypeExpected) {
    List<File> files = FileUtils.getFilesRecurseUsingSuffix(output, "." + ext);
    assertEquals(enumTypeExpected ? 6 : 5, files.size());
    doVerifyTypes(files, schemaPackage, ext);
}