/** * This method sets a new application.xml for the provided enterprise * archive. * * @param enterpriseArchive * is the {@link EnterpriseArchive} to be edited. * @param applicationXML * is the content of the application.xml as {@link String}. * @throws IOException * is thrown if the new application.xml was not set. */ public static void setApplicationXml(EnterpriseArchive enterpriseArchive, String applicationXML) throws IOException { File tempApplicationXmlFile = File.createTempFile( APPLICATION_XML_FILE_NAME, ".temp"); tempApplicationXmlFile.deleteOnExit(); IOUtils.write(applicationXML, new FileOutputStream( tempApplicationXmlFile)); // delete old application.xml enterpriseArchive.delete(APPLICATION_XML_PATH); // set the new application.xml enterpriseArchive.setApplicationXML(tempApplicationXmlFile); }
private static final String APPLICATION_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<application xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd\" version=\"6\">" + "<display-name>org.acme.project</display-name>" // the WAR must be added to the application.xml ! + "<module><web><web-uri>test.war</web-uri><context-root>/test</context-root></web></module>" + "</application>"; @Deployment public static Archive<?> createDeployment() { EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class); ear.setApplicationXML(new StringAsset(APPLICATION_XML)); // to add the WAR to the application.xml, it must have a name WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war"); // the test class must be added manually for whatever reason webArchive.addClass(SomeTest.class); ear.addAsModules(Testable.archiveToTest(webArchive)); return ear; }
public static EnterpriseArchive createSsoEar() { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); String resourcesLocation = "org/jboss/as/test/integration/web/sso/resources/"; WebArchive war1 = createSsoWar("sso-form-auth1.war"); WebArchive war2 = createSsoWar("sso-form-auth2.war"); WebArchive war3 = createSsoWar("sso-with-no-auth.war"); // Remove jboss-web.xml so the war will not have an authenticator war3.delete(war3.get("WEB-INF/jboss-web.xml").getPath()); JavaArchive webEjbs = ShrinkWrap.create(JavaArchive.class, "jbosstest-web-ejbs.jar"); webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "ejb-jar.xml"), "ejb-jar.xml"); webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "jboss.xml"), "jboss.xml"); webEjbs.addPackage(StatelessSession.class.getPackage()); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "web-sso.ear"); ear.setApplicationXML(tccl.getResource(resourcesLocation + "application.xml")); ear.addAsModule(war1); ear.addAsModule(war2); ear.addAsModule(war3); ear.addAsModule(webEjbs); return ear; }
public static EnterpriseArchive createSsoEar() { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); String resourcesLocation = "org/jboss/as/test/integration/web/sso/resources/"; WebArchive war1 = createSsoWar("sso-form-auth1.war"); WebArchive war2 = createSsoWar("sso-form-auth2.war"); WebArchive war3 = createSsoWar("sso-with-no-auth.war"); // Remove jboss-web.xml so the war will not have an authenticator war3.delete(war3.get("WEB-INF/jboss-web.xml").getPath()); JavaArchive webEjbs = ShrinkWrap.create(JavaArchive.class, "jbosstest-web-ejbs.jar"); webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "ejb-jar.xml"), "ejb-jar.xml"); webEjbs.addAsManifestResource(tccl.getResource(resourcesLocation + "jboss.xml"), "jboss.xml"); webEjbs.addPackage(StatelessSession.class.getPackage()); EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "web-sso.ear"); ear.setApplicationXML(tccl.getResource(resourcesLocation + "application.xml")); ear.addAsModule(war1); ear.addAsModule(war2); ear.addAsModule(war3); ear.addAsModule(webEjbs); return ear; }
applicationArchive.setApplicationXML( new StringAsset(applicationXml.exportAsString()));
applicationArchive.setApplicationXML( new StringAsset(applicationXml.exportAsString()));
applicationArchive.setApplicationXML( new StringAsset(applicationXml.exportAsString()));
@Deployment public static EnterpriseArchive createTestEAR() { JavaArchive ejb = ShrinkWrap .create( JavaArchive.class, EJB_ARCHIVE_NAME ) .addClasses( Singer.class, SingersSingleton.class ); WebArchive war = ShrinkWrap .create( WebArchive.class, WAR_ARCHIVE_NAME ) .addClasses( ContainerManagedPersistenceWithMassIndexerIT.class ) .addAsResource( warManifest(), "META-INF/MANIFEST.MF" ) .addAsResource( persistenceXml(), "META-INF/persistence.xml" ) .addAsWebInfResource( EmptyAsset.INSTANCE, "beans.xml" ); return ShrinkWrap.create( EnterpriseArchive.class, EAR_ARCHIVE_NAME ) .addAsModules( ejb ) .addAsModule( war ) .setApplicationXML( applicationXml() ); }
@Deployment public static EnterpriseArchive deployEar() { JavaArchive ejbJar = ShrinkWrap .create(JavaArchive.class, "ejb-jar.jar") .addClasses(BaseTestConfigProperty.class, ConfigPropertyEARTest.class, MyBean.class, MyCustomEarPropertyFileConfig.class) .addAsResource(CONFIG_FILE_NAME) .addAsServiceProvider(PropertyFileConfig.class, MyCustomEarPropertyFileConfig.class) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") .addAsManifestResource(new StringAsset("org.apache.deltaspike.ProjectStage = UnitTest"), "apache-deltaspike.properties"); WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); EnterpriseArchive enterpriseArchive = ShrinkWrap.create(EnterpriseArchive.class, "test.ear") .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive()) .addAsModule(ejbJar) .addAsModule(war) .setApplicationXML("application.xml"); return enterpriseArchive; }
@Deployment public static Archive<?> createTestArchive() { JavaArchive ejb = ShrinkWrap .create( JavaArchive.class, "ModuleMemberRegistrationEarArchiveIT.jar" ) .addClasses( ModuleMemberRegistrationEarArchiveIT.class, Member.class, MemberRegistration.class, Resources.class ) .addAsManifestResource( persistenceXml(), "persistence.xml" ) .addAsManifestResource( EmptyAsset.INSTANCE, "beans.xml" ); String applicationXml = Descriptors.create( ApplicationDescriptor.class ).createModule().ejb( ejb.getName() ).up().exportAsString(); EnterpriseArchive ear = ShrinkWrap .create( EnterpriseArchive.class, "ModuleMemberRegistrationEarArchiveIT.ear" ) .addAsManifestResource( "jboss-deployment-structure-hcann.xml", "jboss-deployment-structure.xml" ) .addAsModules( ejb ) .setApplicationXML( new StringAsset( applicationXml ) ); return ear; }
@Deployment(testable = false) public static EnterpriseArchive createDeployment() { return ShrinkWrap .create(EnterpriseArchive.class) .setApplicationXML(new StringAsset(APPLICATION_XML)) .addAsModule(ArquillianUtil.createJarQSDeployment("switchyard-bean-service")) .addAsModule(ArquillianUtil.createJarQSDeployment("switchyard-camel-file-binding")) .addAsModule(ArquillianUtil.createJarQSDeployment("switchyard-transform-jaxb")) .addAsModule(ArquillianUtil.createJarQSDeployment("switchyard-transform-json")) .addAsModule(ArquillianUtil.createJarQSDeployment("switchyard-transform-smooks")) .addAsModule(ArquillianUtil.createJarQSDeployment("switchyard-transform-xslt")); }
@Deployment public static Archive<?> createTestArchive() { JavaArchive ejb = ShrinkWrap .create( JavaArchive.class, "MemberRegistrationEarArchiveIT.jar" ) .addClasses( MemberRegistrationEarArchiveIT.class, Member.class, MemberRegistration.class, Resources.class ) .addAsManifestResource( persistenceXml(), "persistence.xml" ) .addAsManifestResource( EmptyAsset.INSTANCE, "beans.xml" ); String applicationXml = Descriptors.create( ApplicationDescriptor.class ).createModule().ejb( ejb.getName() ).up().exportAsString(); EnterpriseArchive ear = ShrinkWrap .create( EnterpriseArchive.class, "MemberRegistrationEarArchiveIT.ear" ) .addAsModules( ejb ) .addAsManifestResource( "jboss-deployment-structure-hcann.xml", "/jboss-deployment-structure.xml" ) .addAsLibraries( PackagerHelper.hibernateSearchLibraries() ) .setApplicationXML( new StringAsset( applicationXml ) ); return ear; }
@Deployment public static Archive<?> createTestArchive() throws IllegalArgumentException, IOException { WebArchive war = ShrinkWrap .create( WebArchive.class, "ModuleMemberRegistrationEarArchiveWithJbossDeploymentIT.war" ) .addAsWebInfResource( webXml(), "web.xml" ); JavaArchive ejb = ShrinkWrap .create( JavaArchive.class, "ModuleMemberRegistrationEarArchiveWithJbossDeploymentIT.jar" ) .addClasses( ModuleMemberRegistrationEarArchiveWithJbossDeploymentIT.class, Member.class, MemberRegistration.class, Resources.class ) .addAsManifestResource( persistenceXml(), "persistence.xml" ) .addAsManifestResource( EmptyAsset.INSTANCE, "beans.xml" ); String applicationXml = Descriptors.create( ApplicationDescriptor.class ) .createModule() .ejb( ejb.getName() ).up() .createModule() .getOrCreateWeb() .webUri( war.getName() ).up().up() .exportAsString(); EnterpriseArchive ear = ShrinkWrap .create( EnterpriseArchive.class, ModuleMemberRegistrationEarArchiveWithJbossDeploymentIT.class.getSimpleName() + ".ear" ) .addAsModules( ejb ) .addAsModule( war ) .addAsResource( "jboss-deployment-structure-hcann.xml", "/jboss-deployment-structure.xml" ) .setApplicationXML( new StringAsset( applicationXml ) ); return ear; }
@Test public void shouldHandleEnterpriseArchiveWithApplicationXML() throws Exception { Archive<?> archive = new ServletProtocolDeploymentPackager().generateDeployment( new TestDeployment( ShrinkWrap.create(EnterpriseArchive.class, "applicationArchive.ear") .setApplicationXML(createApplicationDescriptor()), createAuxiliaryArchives()), processors()); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /", archive.contains(ArchivePaths.create("arquillian-protocol.war"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive1.jar"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive2.jar"))); String applicationXmlContent = TestUtil.convertToString(archive.get("META-INF/application.xml").getAsset().openStream()); Assert.assertTrue( "verify that the arquillian-protocol.war was added to the application.xml", applicationXmlContent.contains("<web-uri>arquillian-protocol.war</web-uri>")); // ARQ-670 Assert.assertTrue( "verify that the arquillian-protocol.war has correct context-root in application.xml", applicationXmlContent.contains("<context-root>arquillian-protocol</context-root>")); Assert.assertTrue( "Verify protocol Processor SPI was called", DummyProcessor.wasCalled); }
@Test public void shouldHandleEnterpriseArchiveWithApplicationXML() throws Exception { Archive<?> archive = new ServletProtocolDeploymentPackager().generateDeployment( new TestDeployment( ShrinkWrap.create(EnterpriseArchive.class, "applicationArchive.ear") .setApplicationXML(createApplicationDescriptor()), createAuxiliaryArchives()), processors()); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /", archive.contains(ArchivePaths.create("test.war"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive1.jar"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive2.jar"))); String applicationXmlContent = TestUtil.convertToString(archive.get("META-INF/application.xml").getAsset().openStream()); Assert.assertTrue( "verify that the arquillian-protocol.war was added to the application.xml", applicationXmlContent.contains("<web-uri>test.war</web-uri>")); // ARQ-670 Assert.assertTrue( "verify that the arquillian-protocol.war has correct context-root in application.xml", applicationXmlContent.contains("<context-root>test</context-root>")); Assert.assertTrue( "Verify protocol Processor SPI was called", DummyProcessor.wasCalled); }
@Test public void shouldHandleEnterpriseArchiveWithApplicationXML() throws Exception { Archive<?> archive = new ServletProtocolDeploymentPackager().generateDeployment( new TestDeployment( ShrinkWrap.create(EnterpriseArchive.class, "applicationArchive.ear") .setApplicationXML(createApplicationDescriptor()), createAuxiliaryArchives()), processors()); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /", archive.contains(ArchivePaths.create("test.war"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive1.jar"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive2.jar"))); String applicationXmlContent = TestUtil.convertToString(archive.get("META-INF/application.xml").getAsset().openStream()); Assert.assertTrue( "verify that the arquillian-protocol.war was added to the application.xml", applicationXmlContent.contains("test.war")); Assert.assertTrue( "Verify protocol Processor SPI was called", DummyProcessor.wasCalled); }
@Test public void shouldHandleEnterpriseArchiveWithApplicationXML() throws Exception { Archive<?> archive = new ServletProtocolDeploymentPackager().generateDeployment( new TestDeployment( ShrinkWrap.create(EnterpriseArchive.class, "applicationArchive.ear") .setApplicationXML(createApplicationDescriptor()), createAuxiliaryArchives()), processors()); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /", archive.contains(ArchivePaths.create("arquillian-protocol.war"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive1.jar"))); Assert.assertTrue( "Verify that the auxiliaryArchives are placed in /lib", archive.contains(ArchivePaths.create("/lib/auxiliaryArchive2.jar"))); String applicationXmlContent = TestUtil.convertToString(archive.get("META-INF/application.xml").getAsset().openStream()); Assert.assertTrue( "verify that the arquillian-protocol.war was added to the application.xml", applicationXmlContent.contains("arquillian-protocol")); Assert.assertTrue( "Verify protocol Processor SPI was called", DummyProcessor.wasCalled); }
@Deployment(testable = false) public static EnterpriseArchive createTestArchive() { EnterpriseArchive enterpriseArchive = new EnterpriseArchiveBuilder() .notTestArchive() .withClasses(Collector.class, ObserverNames.class, Helper.class).noDefaultWebModule().build(); StringAsset applicationXml = new StringAsset(Descriptors.create(ApplicationDescriptor.class) .version(EnterpriseArchiveBuilder.DEFAULT_APP_VERSION).applicationName("Test").createModule() .ejb(EnterpriseArchiveBuilder.DEFAULT_EJB_MODULE_NAME).up().createModule().getOrCreateWeb().webUri(TEST1_ARCHIVE_NAME+".war") .contextRoot("/"+TEST1_ARCHIVE_NAME).up().up().createModule().getOrCreateWeb().webUri(TEST2_ARCHIVE_NAME+".war").contextRoot("/"+TEST2_ARCHIVE_NAME).up() .up().exportAsString()); enterpriseArchive.setApplicationXML(applicationXml); WebArchive fooArchive = new WebArchiveBuilder().notTestArchive().withName(TEST1_ARCHIVE_NAME+".war") .withClasses(Observer2.class, PingServlet.class).withDefaultEjbModuleDependency().build(); enterpriseArchive.addAsModule(Testable.archiveToTest(fooArchive)); WebArchive barArchive = new WebArchiveBuilder().notTestArchive().withName(TEST2_ARCHIVE_NAME+".war").withClasses(Observer3.class, PingServlet.class) .withDefaultEjbModuleDependency().build(); enterpriseArchive.addAsModule(barArchive); return enterpriseArchive; }
@Deployment public static EnterpriseArchive createTestArchive() { EnterpriseArchive enterpriseArchive = new EnterpriseArchiveBuilder() .withTestClassDefinition(MultiWebModuleWithExtensionTest.class).withClasses(SimpleLogger.class) .noDefaultWebModule().build(); StringAsset applicationXml = new StringAsset(Descriptors.create(ApplicationDescriptor.class) .version(EnterpriseArchiveBuilder.DEFAULT_APP_VERSION).applicationName("Test").createModule() .ejb(EnterpriseArchiveBuilder.DEFAULT_EJB_MODULE_NAME).up().createModule().getOrCreateWeb().webUri("foo.war") .contextRoot("/foo").up().up().createModule().getOrCreateWeb().webUri("bar.war").contextRoot("/bar").up().up() .exportAsString()); enterpriseArchive.setApplicationXML(applicationXml); WebArchive fooArchive = Testable.archiveToTest(new WebArchiveBuilder().notTestArchive().withName("foo.war") .withClasses(MultiWebModuleWithExtensionTest.class, FooWebBean.class) .withBeanLibrary("foo.jar", FooExtension.class, FooBean.class).withDefaultEjbModuleDependency().build()); enterpriseArchive.addAsModule(fooArchive); WebArchive barArchive = new WebArchiveBuilder().notTestArchive().withName("bar.war").withClasses(BarWebBean.class) .withBeanLibrary("bar.jar", BarExtension.class, BarBean.class).withDefaultEjbModuleDependency().build(); enterpriseArchive.addAsModule(barArchive); return enterpriseArchive; }
@Deployment(testable = false) public static EnterpriseArchive createTestArchive() { EnterpriseArchive enterpriseArchive = new EnterpriseArchiveBuilder() .notTestArchive() .withClasses(MyBinding.class, MyInterceptor.class, Animal.class) .noDefaultWebModule().build(); StringAsset applicationXml = new StringAsset(Descriptors.create(ApplicationDescriptor.class) .version(EnterpriseArchiveBuilder.DEFAULT_APP_VERSION).applicationName("Test").createModule() .ejb(EnterpriseArchiveBuilder.DEFAULT_EJB_MODULE_NAME).up().createModule().getOrCreateWeb().webUri("test1.war") .contextRoot("/test1").up().up().createModule().getOrCreateWeb().webUri("test2.war").contextRoot("/test2").up() .up().exportAsString()); enterpriseArchive.setApplicationXML(applicationXml); WebArchive fooArchive = new WebArchiveBuilder().notTestArchive().withName("test1.war") .withClasses(FooServlet.class, Foo.class, Dog.class) .withWebXml( Descriptors.create(WebAppDescriptor.class).createEnvEntry().envEntryName(GREETING) .envEntryType(JAVA_LANG_STRING).envEntryValue(BYE).up()) .withDefaultEjbModuleDependency() .build(); enterpriseArchive.addAsModule(fooArchive); WebArchive barArchive = new WebArchiveBuilder().notTestArchive().withName("test2.war") .withClasses(BarServlet.class, Bar.class, Cat.class) .withWebXml( Descriptors.create(WebAppDescriptor.class).createEnvEntry().envEntryName(GREETING) .envEntryType(JAVA_LANG_STRING).envEntryValue(HELLO).up()) .withDefaultEjbModuleDependency() .build(); enterpriseArchive.addAsModule(barArchive); return enterpriseArchive; }