Search in sources :

Example 11 with JAXRSArchive

use of org.wildfly.swarm.jaxrs.JAXRSArchive in project wildfly-swarm by wildfly-swarm.

the class OpenApiDeploymentProcessorTest method archive.

/**
 * Creates and returns the shrinkwrap archive for this test.
 */
private Archive archive(String staticResource) {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class, "app.war");
    archive.addClass(TestApplication.class);
    archive.addClass(HelloResource.class);
    if (staticResource != null) {
        archive.addAsManifestResource(new UrlAsset(getClass().getResource(staticResource)), "openapi.json");
    }
    return archive;
}
Also used : JAXRSArchive(org.wildfly.swarm.jaxrs.JAXRSArchive) UrlAsset(org.jboss.shrinkwrap.api.asset.UrlAsset)

Example 12 with JAXRSArchive

use of org.wildfly.swarm.jaxrs.JAXRSArchive in project wildfly-swarm by wildfly-swarm.

the class Main method main.

public static void main(String... args) throws Exception {
    swarm = new Swarm(args);
    swarm.start();
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
    deployment.addClass(MyResource.class);
    deployment.setContextRoot("rest");
    deployment.addAllDependencies();
    swarm.deploy(deployment);
}
Also used : Swarm(org.wildfly.swarm.Swarm) JAXRSArchive(org.wildfly.swarm.jaxrs.JAXRSArchive)

Example 13 with JAXRSArchive

use of org.wildfly.swarm.jaxrs.JAXRSArchive in project wildfly-swarm by wildfly-swarm.

the class DefaultApplicationDeploymentProcessorTest method testApplicationPathAnnotation_InWebInfLibArchive.

@Test
public void testApplicationPathAnnotation_InWebInfLibArchive() throws Exception {
    JavaArchive subArchive = ShrinkWrap.create(JavaArchive.class, "mysubarchive.jar");
    subArchive.addClass(MySampleApplication.class);
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    archive.addAsLibrary(subArchive);
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);
    processor.process();
    Node generated = archive.get(PATH);
    assertThat(generated).isNull();
}
Also used : AnnotationNode(org.objectweb.asm.tree.AnnotationNode) Node(org.jboss.shrinkwrap.api.Node) ClassNode(org.objectweb.asm.tree.ClassNode) JAXRSArchive(org.wildfly.swarm.jaxrs.JAXRSArchive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Test(org.junit.Test)

Example 14 with JAXRSArchive

use of org.wildfly.swarm.jaxrs.JAXRSArchive in project wildfly-swarm by wildfly-swarm.

the class DefaultApplicationDeploymentProcessorTest method testApplicationPathAnnotation_SpecifiedInProjectDefaults.

@Test
public void testApplicationPathAnnotation_SpecifiedInProjectDefaults() throws Exception {
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class, "app.war");
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);
    // Simulate the behavior of loading the project defaults.
    processor.applicationPath.set("/api-test");
    processor.process();
    Node generated = archive.get(PATH);
    Asset asset = generated.getAsset();
    assertThat(generated).isNotNull();
    assertThat(asset).isNotNull();
}
Also used : AnnotationNode(org.objectweb.asm.tree.AnnotationNode) Node(org.jboss.shrinkwrap.api.Node) ClassNode(org.objectweb.asm.tree.ClassNode) JAXRSArchive(org.wildfly.swarm.jaxrs.JAXRSArchive) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) Test(org.junit.Test)

Example 15 with JAXRSArchive

use of org.wildfly.swarm.jaxrs.JAXRSArchive in project wildfly-swarm by wildfly-swarm.

the class DefaultApplicationDeploymentProcessorTest method testApplicationPathAnnotation_None_And_ChangeThePath.

@Test
public void testApplicationPathAnnotation_None_And_ChangeThePath() throws Exception {
    String applicationPath = "/api";
    JAXRSArchive archive = ShrinkWrap.create(JAXRSArchive.class);
    DefaultApplicationDeploymentProcessor processor = new DefaultApplicationDeploymentProcessor(archive);
    processor.applicationPath.set(applicationPath);
    processor.process();
    try (InputStream in = archive.get(PATH).getAsset().openStream()) {
        ClassReader reader = new ClassReader(in);
        ClassNode node = new ClassNode();
        reader.accept(node, 0);
        List<AnnotationNode> visibleAnnotations = node.visibleAnnotations;
        assertThat(visibleAnnotations.size()).isEqualTo(1);
        assertThat(visibleAnnotations.get(0).values).contains(applicationPath);
    } catch (IOException ignored) {
    }
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) AnnotationNode(org.objectweb.asm.tree.AnnotationNode) InputStream(java.io.InputStream) JAXRSArchive(org.wildfly.swarm.jaxrs.JAXRSArchive) ClassReader(org.objectweb.asm.ClassReader) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

JAXRSArchive (org.wildfly.swarm.jaxrs.JAXRSArchive)21 Test (org.junit.Test)12 AnnotationNode (org.objectweb.asm.tree.AnnotationNode)7 ClassNode (org.objectweb.asm.tree.ClassNode)7 File (java.io.File)6 Node (org.jboss.shrinkwrap.api.Node)6 Deployment (org.jboss.arquillian.container.test.api.Deployment)5 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)4 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 SwaggerArchive (org.wildfly.swarm.swagger.SwaggerArchive)3 Files (java.nio.file.Files)2 TemporalField (java.time.temporal.TemporalField)2 Assertions.assertThat (org.fest.assertions.Assertions.assertThat)2 ShrinkWrap (org.jboss.shrinkwrap.api.ShrinkWrap)2 ByteArrayAsset (org.jboss.shrinkwrap.api.asset.ByteArrayAsset)2 EmptyAsset (org.jboss.shrinkwrap.api.asset.EmptyAsset)2 ExplodedExporter (org.jboss.shrinkwrap.api.exporter.ExplodedExporter)2 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)2 After (org.junit.After)2 TempFileManager (org.wildfly.swarm.bootstrap.util.TempFileManager)2