org.jboss.shrinkwrap.api.asset.ClassLoaderAsset Java Examples

The following examples show how to use org.jboss.shrinkwrap.api.asset.ClassLoaderAsset. 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: TomcatNamingFailOnWriteConfigurationTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static WebArchive createWebArchive(String archiveName, String contextXmlLocation) {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
            .version(WebAppVersionType._3_0)
            .createServlet()
            .servletName(SERVLET_NAME)
            .servletClass(NamingServlet.class.getName()).up()
            .createServletMapping()
            .servletName(SERVLET_NAME)
            .urlPattern("/" + TEST_NAME).up();

    WebArchive archive = ShrinkWrap.create(WebArchive.class, archiveName + ".war")
            .addClass(TomcatNamingFailOnWriteConfigurationTest.class)
            .addClass(NamingServlet.class)
            .addClass(Runner.class)
            .addAsLibraries(JarLocation.jarLocation(Test.class))
            .add(new ClassLoaderAsset(contextXmlLocation), RESOURCE_CONTEXT_XML)
            .setWebXML(new StringAsset(descriptor.exportAsString()));

    return archive;
}
 
Example #2
Source File: SWARM_513Test.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = true)
public static Archive createDeployment() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("project-test-defaults-path.yml");
    assertThat(url).isNotNull();
    File projectDefaults = new File(url.toURI());
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class, "myapp.war");
    deployment.addResource(TicketEndpoint.class);
    deployment.addClass(Ticket.class);
    deployment.addClass(Tickets.class);
    deployment.addClass(TicketDTO.class);

    deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml", SWARM_513Test.class.getClassLoader()), "classes/META-INF/persistence.xml");
    deployment.addAsWebInfResource(new ClassLoaderAsset("META-INF/import.sql", SWARM_513Test.class.getClassLoader()), "classes/META-INF/import.sql");

    deployment.addAsResource(projectDefaults, "/project-defaults.yml");
    return deployment;
}
 
Example #3
Source File: TopologyWebAppDeploymentProducer.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent()
Archive deployment() {

    String context = TopologyWebAppFraction.DEFAULT_CONTEXT;
    if (this.contextPath != null) {
        context = this.contextPath;
    }

    if (fraction.exposeTopologyEndpoint()) {
        WARArchive war = ShrinkWrap.create(WARArchive.class, "topology-webapp.war");
        war.addAsWebInfResource(new StringAsset(getWebXml(fraction)), "web.xml");
        war.addClass(TopologySSEServlet.class);
        war.addModule("thorntail.application");
        war.addModule("org.wildfly.swarm.topology");
        war.addAsWebResource(new ClassLoaderAsset("topology.js", this.getClass().getClassLoader()), "topology.js");
        war.setContextRoot(context);
        war.as(TopologyArchive.class);
        return war;
    }
    return null;
}
 
Example #4
Source File: JMSInjectionTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive getArchive() {

    return ShrinkWrap.create(WebArchive.class, "jsf-jms-test.war")
            .addClasses(DummyManagedBean.class)
            .addAsWebResource(new ClassLoaderAsset(
                    JMSInjectionTest.class.getPackage().getName().replace('.', '/').concat("/").concat("dummy.xhtml")), "dummy.xhtml")
            .setWebXML(new StringAsset(Descriptors.create(WebAppDescriptor.class)
                    .version("3.0")
                    .createServlet()
                        .servletName("jsf")
                        .servletClass(FacesServlet.class.getName())
                        .loadOnStartup(1)
                    .up()
                    .createServletMapping()
                        .servletName("jsf")
                        .urlPattern("*.xhtml") // not the default
                    .up()
                    .exportAsString()));
}
 
Example #5
Source File: TopologyWebAppConfiguration.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public List<Archive> getImplicitDeployments(TopologyWebAppFraction fraction) throws Exception {
    String context = System.getProperty(TopologyProperties.CONTEXT_PATH);
    if (context == null) context = DEFAULT_CONTEXT;

    List<Archive> list = new ArrayList<>();
    WARArchive war = ShrinkWrap.create(WARArchive.class, "topology-webapp.war");
    war.addAsWebInfResource(new StringAsset(getWebXml(fraction)), "web.xml");
    war.addClass(TopologySSEServlet.class);
    war.addModule("swarm.application");
    war.addModule("org.wildfly.swarm.topology");
    war.addAsWebResource(new ClassLoaderAsset("topology.js", this.getClass().getClassLoader()), "topology.js");
    war.setContextRoot(context);
    war.as(TopologyArchive.class);
    list.add(war);
    return list;
}
 
Example #6
Source File: ExtensionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void storeMiscPackageContentsFromArchive(String archivePath, String packagePath,
                                                          ClassLoader classLoader, JavaArchive archive) throws IOException {

    try {
        if (archivePath.startsWith("file:")) {
            archivePath = archivePath.substring(5);
        }
        ZipFile zip = new ZipFile(archivePath);
        Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();
            if (name.startsWith(packagePath) && !name.endsWith(".class")
                    && !name.substring(packagePath.length() + 1).contains("/")
                    && name.charAt(name.length() - 1) != '/') {
                archive.addAsResource(new ClassLoaderAsset(name, classLoader), name);
            }
        }
    } catch (ZipException e) {
        throw new RuntimeException("Error handling file " + archivePath, e);
    }

}
 
Example #7
Source File: DescriptorComplementsAnnotationsTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
            .version(WebAppVersionType._3_0)
            .createServlet()
            .servletName(SERVLET_NAME)
            .servletClass(DescriptorComplementsAnnotationsServlet.class.getName()).up()
            .createServletMapping()
            .servletName(SERVLET_NAME)
            .urlPattern("/" + TEST_NAME).up();

    WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
            .addClass(DescriptorComplementsAnnotationsTest.class)
            .addClass(DescriptorComplementsAnnotationsServlet.class)
            .addClass(Bean.class)
            .addClass(FirstBean.class)
            .addClass(SecondBean.class)
            .addClass(Runner.class)
            .addAsLibraries(JarLocation.jarLocation(Test.class))
            .addAsWebInfResource(new ClassLoaderAsset(CONTENT_LOCATION_EJB_JAR_XML), RESOURCE_EJB_JAR_XML)
            .setWebXML(new StringAsset(descriptor.exportAsString()));

    return archive;
}
 
Example #8
Source File: SubjectServiceTomEETest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive archive() {
    return new WebModule(SubjectServiceTomEETest.class).getArchive()
            .addClass(VoteCounter.class)
            .addPackage(Subject.class.getPackage()) // domain
            .addAsWebInfResource(new ClassLoaderAsset("META-INF/persistence.xml"), "persistence.xml")
            .addAsWebInfResource(new ClassLoaderAsset("META-INF/env-entries.properties"), "env-entries.properties")
            .addAsWebInfResource(new ClassLoaderAsset("META-INF/resources.xml"), "resources.xml")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsWebInfResource(new StringAsset("polling-domain"), "exclusions.list")
            .addPackage(PollingRouter.class.getPackage()) // core
            .addPackage(SubjectDao.class.getPackage()) // core
            .addPackage(SubjectService.class.getPackage()) // front
            .addAsLibrary(JarLocation.jarLocation(IOUtils.class)) // helper for client test
            .addAsLibrary(JarLocation.jarLocation(Test.class)); // junit
}
 
Example #9
Source File: CustomOrmXmlCastTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, CustomOrmXmlCastTest.class.getSimpleName() + ".war")
            .addClasses(ActorBean.class, ActorDetails.class, LocalActor.class, LocalActorHome.class,
                    LocalMovie.class, LocalMovieHome.class, MovieBean.class, MovieDetails.class,
                    MoviesBusiness.class, MoviesBusinessBean.class, MoviesBusinessHome.class, MoviesServlet.class,
                    MoviesServlet2.class)
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/custom-orm.xml")
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml"), "META-INF/persistence.xml")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/openejb-jar.xml"), "openejb-jar.xml")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/ejb-jar.xml"), "ejb-jar.xml")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/web.xml"), "web.xml");

    System.out.println(archive.toString(true));
    return archive;
}
 
Example #10
Source File: MoviesSeleniumTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
  public static WebArchive createDeployment() {
      WebArchive archive = ShrinkWrap.create(WebArchive.class, "moviefun.war")
      		.addClasses(ActionServlet.class, SetupServlet.class, Movie.class, MovieController.class, Movies.class, MoviesImpl.class, MoviesRemote.class, JsfUtil.class, PaginationHelper.class, ExampleDataProducer.class, Examples.class, Setup.class)
      		.addAsResource(new ClassLoaderAsset("META-INF/ejb-jar.xml") , "META-INF/ejb-jar.xml")
      		.addAsResource(new ClassLoaderAsset("META-INF/persistence.xml") , "META-INF/persistence.xml")
      		.addAsLibraries(new File("target/test-libs/commons-beanutils.jar"),
      				new File("target/test-libs/commons-codec.jar"),
      				new File("target/test-libs/commons-collections.jar"),
      				new File("target/test-libs/commons-digester.jar"),
      				new File("target/test-libs/commons-logging.jar"),
      				new File("target/test-libs/jstl.jar"),
      				new File("target/test-libs/log4j.jar"),
      				new File("target/test-libs/standard.jar"));
      
      addResources("src/main/webapp", "", archive);
      System.out.println(archive.toString(true));
return archive;
  }
 
Example #11
Source File: DataSourceDefinitionTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
            .version(WebAppVersionType._3_0)
            .createServlet()
            .servletName(SERVLET_NAME)
            .servletClass(DataSourceServlet.class.getName()).up()
            .createServletMapping()
            .servletName(SERVLET_NAME)
            .urlPattern("/" + TEST_NAME).up();

    WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
            .addClass(DataSourceDefinitionTest.class)
            .addClass(DataSourceServlet.class)
            .addClass(DataSourceBean.class)
            .addClass(DataSourcePojo.class)
            .addClass(Runner.class)
            .addAsLibraries(JarLocation.jarLocation(Test.class))
            .addAsWebInfResource(new ClassLoaderAsset(CONTENT_LOCATION_EJB_JAR_XML), RESOURCE_EJB_JAR_XML)
            .setWebXML(new StringAsset(descriptor.exportAsString()));

    return archive;
}
 
Example #12
Source File: DataEarTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static EnterpriseArchive createDeployment() {

    final JavaArchive clientJar = ShrinkWrap.create(JavaArchive.class, "client.jar")
            .addClasses(Data.class, DataBusiness.class, DataBusinessHome.class);

    final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb-jar.jar")
            .addClasses(DataBusinessBean.class)
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/jsp/ejb-jar.xml"), "META-INF/ejb-jar.xml");

    final WebArchive testWar = ShrinkWrap.create(WebArchive.class, "test.war")
            .add(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/jsp/test.jsp"), "test.jsp")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/jsp/web.xml"), "web.xml");

    final EnterpriseArchive archive = ShrinkWrap.create(EnterpriseArchive.class, "test.ear")
            .addAsLibrary(clientJar)
            .addAsModule(ejbJar)
            .addAsModule(testWar);

    System.out.println(archive.toString(true));
    return archive;
}
 
Example #13
Source File: IvmContextTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
            .version(WebAppVersionType._3_0)
            .createServlet()
            .servletName(SERVLET_NAME)
            .servletClass(IvmContextServlet.class.getName()).up()
            .createServletMapping()
            .servletName(SERVLET_NAME)
            .urlPattern("/" + TEST_NAME).up();

    WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
            .addClass(IvmContextTest.class)
            .addClass(IvmContextServlet.class)
            .addClass(NamingBean.class)
            .addClass(Runner.class)
            .addAsLibraries(JarLocation.jarLocation(Test.class))
            .addAsWebInfResource(new ClassLoaderAsset(CONTENT_LOCATION_EJB_JAR_XML), RESOURCE_EJB_JAR_XML)
            .setWebXML(new StringAsset(descriptor.exportAsString()));

    return archive;
}
 
Example #14
Source File: JPAInjectionTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive getArchive() {
    PersistenceDescriptor persistenceDescriptor = Descriptors.create(PersistenceDescriptor.class)
            .createPersistenceUnit()
                .name("test-pu")
                .transactionType("JTA")
                .clazz(PersistenceDescriptor.class.getName())
                .jtaDataSource("test-ds")
            .up();


    Asset persistenceAsset = new StringAsset(persistenceDescriptor.exportAsString());
    return base("jsf-jpa-test.war").addAsWebInfResource(persistenceAsset, "persistence.xml")
            .addClasses(DummyManagedBean.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsWebResource(new ClassLoaderAsset(
                    JPAInjectionTest.class.getPackage().getName().replace('.', '/').concat("/").concat("dummy.xhtml")), "dummy.xhtml");


}
 
Example #15
Source File: MultiplePersistenceTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
            .version(WebAppVersionType._3_0)
            .createServlet()
                .servletName("check").servletClass(MultiplePUServlet.class.getName()).up()
            .createServletMapping()
                .servletName("check").urlPattern("/" + TEST_NAME).up();

    WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
            .addClass(MultiplePUServlet.class)
            .addClass(Person1.class).addClass(Person2.class)
            .addClass(Runner.class)
            .addAsLibraries(JarLocation.jarLocation(Test.class))
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/persistence/multiple/persistence.xml"), "META-INF/persistence.xml")
            .setWebXML(new StringAsset(descriptor.exportAsString()));

    return archive;
}
 
Example #16
Source File: SessionSynchronizationCallbackTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
            .version(WebAppVersionType._3_0)
            .createServlet()
            .servletName(SERVLET_NAME)
            .servletClass(SessionSynchronizationCallbackServlet.class.getName()).up()
            .createServletMapping()
            .servletName(SERVLET_NAME)
            .urlPattern("/" + TEST_NAME).up();

    WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war")
            .addClass(SessionSynchronizationCallbackServlet.class)
            .addClass(StatefulBean.class)
            .addClass(TestEntity.class)
            .addClass(Runner.class)
            .addAsLibraries(JarLocation.jarLocation(Test.class))
            .addAsResource(new ClassLoaderAsset(PERSISTENCE_XML_SOURCE), PERSISTENCE_XML_DESTINATION)
            .setWebXML(new StringAsset(descriptor.exportAsString()));

    return archive;
}
 
Example #17
Source File: CustomOrmXmlTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, CustomOrmXmlTest.class.getSimpleName() + ".war")
            .addClasses(ActorBean.class, ActorDetails.class, LocalActor.class, LocalActorHome.class,
                    LocalMovie.class, LocalMovieHome.class, MovieBean.class, MovieDetails.class,
                    MoviesBusiness.class, MoviesBusinessBean.class, MoviesBusinessHome.class,
                    MoviesServlet.class)
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/custom-orm.xml")
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml"), "META-INF/persistence.xml")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/openejb-jar.xml"), "openejb-jar.xml")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/ejb-jar.xml"), "ejb-jar.xml")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/web.xml"), "web.xml");

    System.out.println(archive.toString(true));
    return archive;
}
 
Example #18
Source File: ExtensionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void storeMiscPackageContentsFromDirectory(URL directory, String packagePath,
                                                          ClassLoader classLoader, JavaArchive archive) {
    try {
        File file = new File(directory.toURI());
        File[] children;
        if (file.isDirectory() && (children = file.listFiles()) != null) {
            for (File child : children) {
                if (!child.isDirectory() && !child.getName().endsWith(".class")) {
                    String name = packagePath + '/' + child.getName() ;
                    archive.addAsResource(new ClassLoaderAsset(name, classLoader), name);
                }

            }
        }
    } catch (URISyntaxException | IllegalArgumentException e) {
        // ignore; sometimes the package is also visible on the classpath inside other jars
        // resulting in a URL that cannot be used to create a file
    }

}
 
Example #19
Source File: SslHostnameVerifierTest.java    From microprofile-rest-client with Apache License 2.0 5 votes vote down vote up
@Deployment
public static WebArchive createDeployment() {
    // @formatter:off
    String config =
        configLine(JsonPClient.class, "uri", BASE_URI_STRING) +
        configLine(JsonPClient.class, "hostnameVerifier", ConfigurableHostnameVerifier.class.getCanonicalName()) +
        configLine(JsonPClient.class, "trustStore", "classpath:/META-INF/" + clientWrongHostnameTruststoreFromClasspath) +
        configLine(JsonPClient.class, "trustStoreType", "pkcs12") +
        configLine(JsonPClient.class, "trustStorePassword", PASSWORD);
    // @formatter:on


    WebArchive webArchive = ShrinkWrap.create(WebArchive.class, SslHostnameVerifierTest.class.getSimpleName() + ".war")
        .addClasses(
            JsonPClient.class,
            HttpsServer.class,
            AbstractSslTest.class,
            ConfigurableHostnameVerifier.class)
        .addAsWebInfResource(new StringAsset(config), "classes/META-INF/microprofile-config.properties")
        .addAsWebInfResource(
            new ClassLoaderAsset("ssl/" + clientWrongHostnameTruststoreFromClasspath),
            "classes/META-INF/" + clientWrongHostnameTruststoreFromClasspath
        )
        .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

    initializeTest(webArchive, server -> server.keyStore(serverWrongHostnameKeystore.getAbsolutePath(), PASSWORD));
    return webArchive;
}
 
Example #20
Source File: DataSourceTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, DataSourceTest.class.getSimpleName() + ".war")
            .addClass(PojoServlet.class)
            .addAsManifestResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/contextxml/datasource/context.xml"), "context.xml");

    return archive;
}
 
Example #21
Source File: OpenEJBArchiveProcessor.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static void addPersistenceXml(final Archive<?> archive, final String prefix, final AppModule appModule) {
    Node persistenceXml = archive.get(prefix.concat(PERSISTENCE_XML));
    if (persistenceXml == null && WEB_INF.equals(prefix)) {
        persistenceXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(PERSISTENCE_XML));
    }
    if (persistenceXml != null) {
        final Asset asset = persistenceXml.getAsset();
        if (UrlAsset.class.isInstance(asset)) {
            appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(URL.class, "url", asset)));
        } else if (FileAsset.class.isInstance(asset)) {
            try {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(File.class, "file", asset).toURI().toURL()));
            } catch (final MalformedURLException e) {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
            }
        } else if (ClassLoaderAsset.class.isInstance(asset)) {
            final URL url = get(ClassLoader.class, "classLoader", asset).getResource(get(String.class, "resourceName", asset));
            if (url != null) {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(url));
            } else {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
            }
        } else {
            appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
        }
    }
}
 
Example #22
Source File: SWClassLoader.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
protected URLConnection openConnection(final URL u) throws IOException {
    final String arName = key(u);

    final Archive<?> archive = archives.get(arName);
    final String path = path(archive.getName(), WebArchive.class.isInstance(archive) ? "/WEB-INF/classes/" : "", u);
    Node node = archive.get(path);
    if (node == null) {
        node = archive.get(path(archive.getName(), "", u)); // web resources
        if (node == null) {
            throw new IOException(u.toExternalForm() + " not found");
        }
    }

    final Asset asset = node.getAsset();
    if (UrlAsset.class.isInstance(asset)) {
        return URL.class.cast(Reflections.get(asset, "url")).openConnection();
    } else if (FileAsset.class.isInstance(asset)) {
        return File.class.cast(Reflections.get(asset, "file")).toURI().toURL().openConnection();
    } else if (ClassLoaderAsset.class.isInstance(asset)) {
        return ClassLoader.class.cast(Reflections.get(asset, "classLoader")).getResource(String.class.cast(Reflections.get(asset, "resourceName"))).openConnection();
    }

    return new URLConnection(u) {
        @Override
        public void connect() throws IOException {
            // no-op
        }

        @Override
        public InputStream getInputStream() throws IOException {
            final InputStream input = asset.openStream();
            final Collection<Closeable> c = closeables.get(arName);
            c.add(input);
            return input;
        }
    };
}
 
Example #23
Source File: MoviesEJBTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment
   public static WebArchive createDeployment() {
	return ShrinkWrap.create(WebArchive.class, "test.war")
               .addClasses(Movie.class, MoviesImpl.class, Movies.class, MoviesRemote.class, MoviesEJBTest.class, Setup.class, Examples.class, ExampleDataProducer.class)
               .addAsResource(new ClassLoaderAsset("META-INF/ejb-jar.xml"), "META-INF/ejb-jar.xml")
               .addAsResource(new ClassLoaderAsset("META-INF/persistence.xml"), "META-INF/persistence.xml")
               .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example #24
Source File: AppWithNoLoginConfigAndConfiguredJwtRealmTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected static WARArchive initDeployment() {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);
    deployment.addClass(ApplicationScopedSubjectExposingResource.class);
    deployment.addClass(ApplicationWithoutLoginConfig.class);
    deployment.addAsResource(new ClassLoaderAsset("keys/public-key.pem"), "public-key.pem");
    return deployment;
}
 
Example #25
Source File: AlternateDataSourceTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment
public static WebArchive createDeployment() {

    return ShrinkWrap.create(WebArchive.class, "test.war")
            .addClasses(DataSourceTester.class)
            .addAsResource(new ClassLoaderAsset("META-INF/beans.xml"), "META-INF/beans.xml");
    //We are using src/test/conf/tomee.xml, but this also works - .addAsResource(new ClassLoaderAsset("META-INF/resources.xml"), "META-INF/resources.xml");
    //Or even using a persistence context - .addAsResource(new ClassLoaderAsset("META-INF/persistence.xml"), "META-INF/persistence.xml");
}
 
Example #26
Source File: AppWithNoLoginConfigWithConfiguredJwtRealmTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected static WARArchive initDeployment() {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);
    deployment.addClass(ApplicationScopedSubjectExposingResource.class);
    deployment.addClass(ApplicationWithoutLoginConfig.class);
    deployment.addAsResource(new ClassLoaderAsset("keys/public-key.pem"), "public-key.pem");
    return deployment;
}
 
Example #27
Source File: ConfigTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment
public static WebArchive jar() {
    return ShrinkWrap.create(WebArchive.class)
            .addClasses(Counter.class, MyConfigSource.class, MapConfigurationProvider.class)
            .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
            .addAsResource(new ClassLoaderAsset("my-app-config.properties"), "my-app-config.properties")
            .addAsLibraries(JarLocation.jarLocation(ConfigSourceProvider.class))
            .addAsLibraries(JarLocation.jarLocation(DefaultConfigSourceProvider.class))
            .addAsServiceProvider(ConfigSourceProvider.class, MyConfigSourceProvider.class);
}
 
Example #28
Source File: CustomOrmXmlEarTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
public static EnterpriseArchive createDeployment() {

    final JavaArchive clientJar = ShrinkWrap.create(JavaArchive.class, "client.jar")
            .addClasses(ActorDetails.class, LocalActor.class, LocalActorHome.class,
                    LocalMovie.class, LocalMovieHome.class, MovieDetails.class,
                    MoviesBusiness.class, MoviesBusinessHome.class);

    final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb-jar.jar")
            .addClasses(ActorBean.class, MovieBean.class, MovieDetails.class, MoviesBusinessBean.class)
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/custom-orm.xml")
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml"), "META-INF/persistence.xml")
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/openejb-jar.xml"), "META-INF/openejb-jar.xml")
            .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/ejb-jar.xml"), "META-INF/ejb-jar.xml");

    final WebArchive testWar = ShrinkWrap.create(WebArchive.class, "test.war")
            .addClass(MoviesServlet.class)
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/web.xml"), "web.xml");

    final EnterpriseArchive archive = ShrinkWrap.create(EnterpriseArchive.class, "test.ear")
            .addAsLibrary(clientJar)
            .addAsModule(ejbJar)
            .addAsModule(testWar);

    System.out.println(archive.toString(true));
    return archive;
}
 
Example #29
Source File: ParametrizedPathsTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected static WARArchive initDeployment() throws Exception {
    WARArchive deployment = ShrinkWrap.create(WARArchive.class);
    deployment.addClass(ParametrizedPathsResource.class);
    deployment.addClass(TestApplication.class);
    deployment.addAsManifestResource(new ClassLoaderAsset("keys/public-key.pem"), "/MP-JWT-SIGNER");
    return deployment;
}
 
Example #30
Source File: BmpLocalEntityTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
public static WebArchive createDeployment() {
    WebArchive archive = ShrinkWrap.create(WebArchive.class, BmpLocalEntityTest.class.getSimpleName() + ".war")
            .addClasses(BigFinder.class, BigFinderBean.class, BigFinderHome.class, BigFinderPK.class,
                    FinderServlet.class, FinderTest.class, FinderTestBean.class, FinderTestHome.class, IntegerPK.class,
                    LittleFinder.class, LittleFinderBean.class, LittleFinderHome.class, LittleFinderPK.class, StringPK.class)
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/bmp/local/ejb-jar.xml"), "ejb-jar.xml")
            .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/bmp/local/web.xml"), "web.xml");

    System.out.println(archive.toString(true));
    return archive;
}