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;
}
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();
}
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");
}
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;
}
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;
}
Aggregations