Search in sources :

Example 21 with JARArchive

use of org.wildfly.swarm.spi.api.JARArchive in project wildfly-swarm by wildfly-swarm.

the class ArquillianTest method createDeployment.

@Deployment
public static Archive<?> createDeployment() {
    JARArchive archive = ShrinkWrap.create(JARArchive.class, "arquillian-test.jar").addClass(ArquillianTest.class);
    archive.addModule("progress");
    return archive;
}
Also used : JARArchive(org.wildfly.swarm.spi.api.JARArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 22 with JARArchive

use of org.wildfly.swarm.spi.api.JARArchive in project wildfly-swarm by wildfly-swarm.

the class SwaggerArchiveTest method testSwaggerArchive.

@Test
public void testSwaggerArchive() {
    JARArchive archive = ShrinkWrap.create(JARArchive.class, "myapp.jar");
    SwaggerArchive swaggerArchive = archive.as(SwaggerArchive.class);
    // we need to set at least one configuration option for the swagger configuration to activate
    swaggerArchive.setHost("localhost");
    Asset asset = archive.get(SwaggerArchive.SWAGGER_CONFIGURATION_PATH).getAsset();
    assertThat(asset).isNotNull();
    assertThat(asset).isInstanceOf(SwaggerConfigurationAsset.class);
    assertThat(archive.as(ServiceActivatorArchive.class).containsServiceActivator(SwaggerArchiveImpl.SERVICE_ACTIVATOR_CLASS_NAME)).isTrue();
}
Also used : ServiceActivatorArchive(org.wildfly.swarm.msc.ServiceActivatorArchive) ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) SwaggerConfigurationAsset(org.wildfly.swarm.swagger.internal.SwaggerConfigurationAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Test(org.junit.Test)

Example 23 with JARArchive

use of org.wildfly.swarm.spi.api.JARArchive in project wildfly-swarm by wildfly-swarm.

the class SwaggerArchiveTest method testSwaggerConfiguration.

@Test
public void testSwaggerConfiguration() throws IOException {
    JARArchive archive = ShrinkWrap.create(JARArchive.class, "myapp.jar");
    archive.as(SwaggerArchive.class).setResourcePackages("com.tester.resource", "com.tester.other.resource").setTitle("My Application API").setLicenseUrl("http://myapplication.com/license.txt").setLicense("Use at will").setContextRoot("/tacos").setDescription("This is a description of my API").setHost("api.myapplication.com").setContact("help@myapplication.com").setPrettyPrint(true).setSchemes("http", "https").setTermsOfServiceUrl("http://myapplication.com/tos.txt").setVersion("1.0");
    Asset asset = archive.get(SwaggerArchive.SWAGGER_CONFIGURATION_PATH).getAsset();
    assertThat(asset).isNotNull();
    assertThat(asset).isInstanceOf(SwaggerConfigurationAsset.class);
    SwaggerConfig config = new SwaggerConfig(asset.openStream());
    assertThat(config.get(SwaggerConfig.Key.VERSION)).isEqualTo("1.0");
    assertThat(config.get(SwaggerConfig.Key.TERMS_OF_SERVICE_URL)).isEqualTo("http://myapplication.com/tos.txt");
    assertThat(Arrays.toString((String[]) config.get(SwaggerConfig.Key.PACKAGES))).isEqualTo("[com.tester.resource, com.tester.other.resource]");
    assertThat(config.get(SwaggerConfig.Key.ROOT)).isEqualTo("/tacos");
}
Also used : ByteArrayAsset(org.jboss.shrinkwrap.api.asset.ByteArrayAsset) SwaggerConfigurationAsset(org.wildfly.swarm.swagger.internal.SwaggerConfigurationAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Test(org.junit.Test)

Example 24 with JARArchive

use of org.wildfly.swarm.spi.api.JARArchive in project wildfly-swarm by wildfly-swarm.

the class SwaggerWebAppFraction method loadFromDirectory.

private Archive<?> loadFromDirectory(File directory) throws IOException {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);
    archive.as(ExplodedImporter.class).importDirectory(directory);
    return archive;
}
Also used : JARArchive(org.wildfly.swarm.spi.api.JARArchive) ExplodedImporter(org.jboss.shrinkwrap.api.importer.ExplodedImporter)

Example 25 with JARArchive

use of org.wildfly.swarm.spi.api.JARArchive in project wildfly-swarm by wildfly-swarm.

the class SwaggerWebAppDeploymentProducer method swaggerWebApp.

@Produces
public Archive swaggerWebApp() throws ModuleLoadException, IOException {
    // Load the swagger-ui webjars.
    Module module = Module.getBootModuleLoader().loadModule("org.webjars.swagger-ui");
    URL resource = module.getExportedResource("swagger-ui.jar");
    JARArchive webJar = ShrinkWrap.create(JARArchive.class);
    webJar.as(ZipImporter.class).importFrom(resource.openStream());
    JARArchive relocatedJar = ShrinkWrap.create(JARArchive.class);
    Map<ArchivePath, Node> content = webJar.getContent();
    for (ArchivePath path : content.keySet()) {
        Node node = content.get(path);
        Asset asset = node.getAsset();
        if (asset != null) {
            Matcher matcher = PATTERN.matcher(path.get());
            if (matcher.matches()) {
                MatchResult result = matcher.toMatchResult();
                String newPath = "/META-INF/resources/" + result.group(2);
                relocatedJar.add(asset, newPath);
            }
        }
    }
    WARArchive war = ShrinkWrap.create(WARArchive.class, "swagger-ui.war").addAsLibrary(relocatedJar).setContextRoot(this.fraction.getContext());
    war.addClass(SwaggerDefaultUrlChangerServlet.class);
    // If any user content has been provided, merge that with the swagger-ui bits
    Archive<?> userContent = this.fraction.getWebContent();
    if (userContent != null) {
        war.merge(userContent);
    }
    return war;
}
Also used : Matcher(java.util.regex.Matcher) Node(org.jboss.shrinkwrap.api.Node) MatchResult(java.util.regex.MatchResult) WARArchive(org.wildfly.swarm.undertow.WARArchive) URL(java.net.URL) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) Asset(org.jboss.shrinkwrap.api.asset.Asset) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Module(org.jboss.modules.Module) Produces(javax.enterprise.inject.Produces)

Aggregations

JARArchive (org.wildfly.swarm.spi.api.JARArchive)84 Deployment (org.jboss.arquillian.container.test.api.Deployment)52 Test (org.junit.Test)25 File (java.io.File)12 ShrinkWrap (org.jboss.shrinkwrap.api.ShrinkWrap)12 Files (java.nio.file.Files)11 ZipExporter (org.jboss.shrinkwrap.api.exporter.ZipExporter)11 Assertions.assertThat (org.fest.assertions.Assertions.assertThat)10 FractionUsageAnalyzer (org.wildfly.swarm.fractions.FractionUsageAnalyzer)10 IOException (java.io.IOException)5 Asset (org.jboss.shrinkwrap.api.asset.Asset)5 ServiceActivatorArchive (org.wildfly.swarm.msc.ServiceActivatorArchive)5 Assertions (org.fest.assertions.Assertions)4 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)4 Node (org.jboss.shrinkwrap.api.Node)4 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)4 InputStream (java.io.InputStream)3 Map (java.util.Map)3 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)3 TopologyArchive (org.wildfly.swarm.topology.TopologyArchive)3