Java Code Examples for org.jboss.shrinkwrap.api.spec.JavaArchive#addAsManifestResource()

The following examples show how to use org.jboss.shrinkwrap.api.spec.JavaArchive#addAsManifestResource() . 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: DeploymentRolloutFailureTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@BeforeClass
public static void setupDomain() throws Exception {
    testSupport = DomainTestSuite.createSupport(DeploymentRolloutFailureTestCase.class.getSimpleName());
    masterClient = testSupport.getDomainMasterLifecycleUtil().getDomainClient();

    File tmpRoot = new File(System.getProperty("java.io.tmpdir"));
    tmpDir = new File(tmpRoot, DeploymentRolloutFailureTestCase.class.getSimpleName() + System.currentTimeMillis());
    Files.createDirectory(tmpDir.toPath());
    deployment = new File(tmpDir, BROKEN_DEPLOYMENT);
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, BROKEN_DEPLOYMENT);
    archive.addClass(ServiceActivatorDeployment.class);
    archive.addAsServiceProvider(ServiceActivator.class, ServiceActivatorDeployment.class);
    archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc\n"), "MANIFEST.MF");
    archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(
            new PropertyPermission("test.deployment.broken.fail", "read")),
            "permissions.xml");
    archive.as(ZipExporter.class).exportTo(deployment);
}
 
Example 2
Source File: CustomVaultInModuleTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void createTestModule() throws Exception {
    File moduleXml = new File(CustomSecurityVault.class.getResource(CustomVaultInModuleTestCase.class.getSimpleName() + "-module.xml").toURI());
    testModule = new TestModule(MODULE_NAME, moduleXml);

    JavaArchive archive = testModule.addResource("test-custom-vault-in-module.jar")
            .addClass(CustomSecurityVault.class)
            .addClass(TestVaultExtension.class)
            .addClass(TestVaultParser.class)
            .addClass(TestVaultRemoveHandler.class)
            .addClass(TestVaultResolveExpressionHandler.class)
            .addClass(TestVaultSubsystemResourceDescription.class);

    ArchivePath path = ArchivePaths.create("/");
    path = ArchivePaths.create(path, "services");
    path = ArchivePaths.create(path, Extension.class.getName());
    archive.addAsManifestResource(CustomSecurityVault.class.getPackage(), Extension.class.getName(), path);
    testModule.create(true);
}
 
Example 3
Source File: JdkModuleDependencyTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private JavaArchive prepareTestDeployment(String dependency) throws Exception {
    final String deploymentName = dependency + DEPLOYMENT_NAME_SUFFIX;
    final Properties properties = new Properties();
    properties.put(deploymentName + "Service", "isNew");
    final JavaArchive archive = ServiceActivatorDeploymentUtil.createServiceActivatorDeploymentArchive(deploymentName,
            properties);
    archive.delete("META-INF/permissions.xml");
    archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(
            new PropertyPermission("test.deployment.trivial.prop", "write"),
            new PropertyPermission(deploymentName + "Service", "write"),
            new PropertyPermission("service", "write")
    ), "permissions.xml");
    archive.addAsResource(new StringAsset(prepareJBossDeploymentStructure(dependency)),
            "META-INF/jboss-deployment-structure.xml");
    return archive;
}
 
Example 4
Source File: ServiceActivatorDeploymentUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static JavaArchive createServiceActivatorDeploymentArchive(String name, Properties properties) throws IOException {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, name);
    archive.addClass(ServiceActivatorDeployment.class);
    archive.addAsServiceProvider(ServiceActivator.class, ServiceActivatorDeployment.class);
    archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(
            new PropertyPermission("test.deployment.trivial.prop", "write"),
            new PropertyPermission("service", "write")
    ), "permissions.xml");
    if (properties != null && properties.size() > 0) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Object, Object> prop : properties.entrySet()) {
            sb.append(prop.getKey());
            sb.append('=');
            sb.append(prop.getValue());
            sb.append("\n");
        }
        archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc\n"), "MANIFEST.MF");
        archive.addAsResource(new StringAsset(sb.toString()), ServiceActivatorDeployment.PROPERTIES_RESOURCE);
    }
    return archive;
}
 
Example 5
Source File: PatchingTestUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static ResourceItem createVersionItem(final String targetVersion) {
    final Asset newManifest = new Asset() {
        @Override
        public InputStream openStream() {
            return new ByteArrayInputStream(ProductInfo.createVersionString(targetVersion).getBytes(StandardCharsets.UTF_8));
        }
    };

    final JavaArchive versionModuleJar = ShrinkWrap.create(JavaArchive.class);
    if (!ProductInfo.isProduct) {
        versionModuleJar.addPackage("org.jboss.as.version");
    }
    versionModuleJar.addAsManifestResource(newManifest, "MANIFEST.MF");

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    versionModuleJar.as(ZipExporter.class).exportTo(baos);
    return new ResourceItem("as-version.jar", baos.toByteArray());
}
 
Example 6
Source File: DeploymentOverlayScenario.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private File createDeployment(Class<? extends ServiceActivator> clazz) throws Exception{
    File tmpRoot = new File(System.getProperty("java.io.tmpdir"));
    File tmpDir = new File(tmpRoot, this.getClass().getSimpleName() + System.currentTimeMillis());
    Files.createDirectory(tmpDir.toPath());
    tmpDirs.add(tmpDir);
    String deploymentName = DEPLOYMENT_NAME;
    File deployment = new File(tmpDir, deploymentName);
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, deploymentName);
    archive.addClasses(clazz, ServiceActivatorBaseDeployment.class);
    archive.addAsServiceProvider(ServiceActivator.class, clazz);
    archive.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc\n"), "MANIFEST.MF");
    archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(
            new PropertyPermission("test.deployment.broken.fail", "read"),
            new PropertyPermission("test.deployment.prop.one", "write"),
            new PropertyPermission("test.deployment.prop.two", "write"),
            new PropertyPermission("test.deployment.prop.three", "write"),
            new PropertyPermission("test.deployment.prop.four", "write"),
            new PropertyPermission("test.overlay.prop.one", "write"),
            new PropertyPermission("test.overlay.prop.two", "write"),
            new PropertyPermission("test.overlay.prop.three", "write"),
            new PropertyPermission("test.overlay.prop.four", "write")
    ), "permissions.xml");
    archive.as(ZipExporter.class).exportTo(deployment);
    return deployment;
}
 
Example 7
Source File: EJBSecurityTestCase.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "ejb-security-test.jar");
    archive.addClasses(AnnotatedSLSB.class, SecureRouteBuilder.class);
    archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return archive;
}
 
Example 8
Source File: CustomFailoverExceptionTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "custom-failover.jar");
    archive.addAsManifestResource("classloading/custom-failover-context.xml", "jboss-camel-context.xml");
    archive.addClasses(CustomFailoverException.class);
    return archive;
}
 
Example 9
Source File: MailIntegrationCDITest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment(order = 2)
public static JavaArchive createDeployment() throws IOException {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-mail-cdi-tests.jar");
    archive.addPackage(MailSessionProducer.class.getPackage());
    archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return archive;
}
 
Example 10
Source File: EC2IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "aws-ec2-tests.jar");
    archive.addClasses(EC2ClientProducer.class, EC2Utils.class, BasicCredentialsProvider.class);
    archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return archive;
}
 
Example 11
Source File: QuartzPersistentStoreTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "quartz-tests");
    archive.addAsManifestResource("quartz/quartz-camel-context.xml");
    archive.addAsResource("quartz/sql/db-schema.sql", "db-schema.sql");
    return archive;
}
 
Example 12
Source File: PropertiesFromClasspathTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "classpath-properties.jar");
    archive.addAsManifestResource("classloading/classpath-properties-context.xml", "jboss-camel-context.xml");
    archive.addAsResource("classloading/test.properties", "test.properties");
    return archive;
}
 
Example 13
Source File: CloudWatchIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "aws-cw-tests.jar");
    archive.addClasses(CloudWatchClientProducer.class, CloudWatchUtils.class, BasicCredentialsProvider.class,
            AWSUtils.class);
    archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return archive;
}
 
Example 14
Source File: SQSIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "aws-sqs-tests.jar");
    archive.addClasses(SQSClientProducer.class, SQSUtils.class, BasicCredentialsProvider.class, AWSUtils.class);
    archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return archive;
}
 
Example 15
Source File: DomainGracefulShutdownTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static JavaArchive createDeployment() throws Exception {
    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, WEB_SUSPEND_JAR);
    jar.addPackage(SuspendResumeHandler.class.getPackage());
    jar.addAsServiceProvider(ServiceActivator.class, TestSuspendServiceActivator.class);
    jar.addAsResource(new StringAsset("Dependencies: org.jboss.dmr, org.jboss.as.controller, io.undertow.core, org.jboss.as.server,org.wildfly.extension.request-controller, org.jboss.as.network\n"), "META-INF/MANIFEST.MF");
    jar.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(
            new ReflectPermission("suppressAccessChecks"),
            new RuntimePermission("createXnioWorker"),
            new SocketPermission(TestSuiteEnvironment.getServerAddress() + ":8080", "listen,resolve"),
            new SocketPermission("*", "accept,resolve")
    ), "permissions.xml");
    return jar;
}
 
Example 16
Source File: BeanValidatorXMLIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "bean-validator-xml-tests");
    archive.addPackage(CarWithoutAnnotations.class.getPackage());
    archive.addAsManifestResource("beanvalidator/validation.xml", "validation.xml");
    archive.addAsResource("beanvalidator/constraints-car.xml", "constraints-car.xml");
    return archive;
}
 
Example 17
Source File: S3IntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "aws-s3-tests.jar");
    archive.addClasses(S3ClientProducer.class, S3Utils.class, BasicCredentialsProvider.class, AWSUtils.class);
    archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return archive;
}
 
Example 18
Source File: GroovyShellFactoryTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "script-tests.jar");
    archive.addPackage(CustomGroovyShellFactory.class.getPackage());
    archive.addAsResource("groovy/groovy-transform-camel-context.xml");
    archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    return archive;
}
 
Example 19
Source File: DeploymentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testReplaceWithRuntimeName() throws Exception {
    final JavaArchive archive1 = ServiceActivatorDeploymentUtil.createServiceActivatorDeploymentArchive("test-deployment1.jar", properties);
    final JavaArchive archive2 = ServiceActivatorDeploymentUtil.createServiceActivatorDeploymentArchive("test-deployment2.jar", properties2);
    archive2.addAsManifestResource(DeploymentTestCase.class.getPackage(), "marker.txt", "marker.txt");

    final ModelControllerClient client = managementClient.getControllerClient();
    final ServerDeploymentManager manager = ServerDeploymentManager.Factory.create(client);
    try (InputStream is1 = archive1.as(ZipExporter.class).exportAsInputStream();
            InputStream is2 = archive2.as(ZipExporter.class).exportAsInputStream();) {
        Future<?> future = manager.execute(manager.newDeploymentPlan()
                .add("test-deployment1.jar", "test-deployment1.jar", is1)
                .add("test-deployment2.jar", "test-deployment2.jar", is2)
                .build());
        awaitDeploymentExecution(future);
        checkDeploymentStatus(client, "test-deployment1.jar", "STOPPED");
        checkDeploymentStatus(client, "test-deployment2.jar", "STOPPED");
        future = manager.execute(manager.newDeploymentPlan().deploy("test-deployment1.jar").build());
        awaitDeploymentExecution(future);
        checkDeploymentStatus(client, "test-deployment1.jar", "OK");
        checkDeploymentStatus(client, "test-deployment2.jar", "STOPPED");
        ModelNode response = client.execute(Util.getReadAttributeOperation(pathAddress(pathElement("deployment", "test-deployment1.jar")), "runtime-name"));
        Assert.assertEquals("success", response.get("outcome").asString());
        Assert.assertEquals("test-deployment1.jar", response.get("result").asString());
        ServiceActivatorDeploymentUtil.validateProperties(managementClient.getControllerClient(), properties);
        ModelNode op = Operations.createOperation("replace-deployment");
        op.get("name").set("test-deployment2.jar");
        op.get("to-replace").set("test-deployment1.jar");
        op.get("runtime-name").set("test-deployment1.jar");
        future = client.executeAsync(op);
        awaitDeploymentExecution(future);
        checkDeploymentStatus(client, "test-deployment1.jar", "STOPPED");
        checkDeploymentStatus(client, "test-deployment2.jar", "OK");
        response = client.execute(Util.getReadAttributeOperation(pathAddress(pathElement("deployment", "test-deployment2.jar")), "runtime-name"));
        Assert.assertEquals("success", response.get("outcome").asString());
        Assert.assertEquals("test-deployment1.jar", response.get("result").asString());
        ServiceActivatorDeploymentUtil.validateProperties(managementClient.getControllerClient(), properties2);
        future = manager.execute(manager.newDeploymentPlan()
                .undeploy("test-deployment1.jar")
                .remove("test-deployment1.jar")
                .undeploy("test-deployment2.jar")
                .remove("test-deployment2.jar")
                .build());
        awaitDeploymentExecution(future);
    }
}
 
Example 20
Source File: AbstractLoggingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static JavaArchive addPermissions(final JavaArchive archive, final Permission... additionalPermissions) {
    final Permission[] permissions = LoggingServiceActivator.appendPermissions(additionalPermissions);
    return archive.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(permissions), "permissions.xml");
}