}
String rhqPlatformPluginVersion = System.getProperty("rhq-platform-plugin.version");
if ((rhqPlatformPluginVersion == null) || rhqPlatformPluginVersion.trim().isEmpty()) {
rhqPlatformPluginVersion = projectVersion;
}
MavenResolverSystem earResolver = Resolvers.use(MavenResolverSystem.class);
// this must be named rhq.ear because the "rhq" portion is used in the jndi names
earResolver.offline();
EnterpriseArchive testEar = ShrinkWrap.create(EnterpriseArchive.class, "rhq.ear");
EnterpriseArchive rhqEar = earResolver.resolve("org.rhq:rhq-enterprise-server-ear:ear:" + projectVersion)
.withoutTransitivity().asSingle(EnterpriseArchive.class);
// merge rhq.ear into testEar but include only the EJB jars and the supporting libraries. Note that we
// don't include the services sar because tests are responsible for prepare/unprepare of all required services,
// we don't want the production services performing any unexpected work.
testEar = testEar.merge(rhqEar, Filters.include("/lib.*|/rhq.*ejb3\\.jar.*|/rhq-server.jar.*"));
// remove startup beans and shutdown listeners, we don't want this to be a full server deployment. The tests
// start/stop what they need, typically with test services or mocks.
testEar.delete(ArchivePaths
.create("/rhq-server.jar/org/rhq/enterprise/server/core/StartupBean.class"));
testEar.delete(ArchivePaths
.create("/rhq-server.jar/org/rhq/enterprise/server/core/StartupBean$1.class"));
testEar.delete(ArchivePaths
.create("/rhq-server.jar/org/rhq/enterprise/server/core/ShutdownListener.class"));
testEar.delete(ArchivePaths
.create("/rhq-server.jar/org/rhq/enterprise/server/storage/StorageClusterSettingsManagerBean.class"));
//replace the above startup beans with stripped down versions
testEar.add(new ClassAsset(StrippedDownStartupBean.class), ArchivePaths
.create("/rhq-server.jar/org/rhq/enterprise/server/test/StrippedDownStartupBean.class"));
testEar.add(new ClassAsset(StrippedDownStartupBeanPreparation.class), ArchivePaths
.create("/rhq-server.jar/org/rhq/enterprise/server/test/"
+ "StrippedDownStartupBeanPreparation.class"));
testEar.add(new ClassAsset(FakeStorageClusterSettingsManagerBean.class), ArchivePaths
.create("/rhq-server.jar/org/rhq/enterprise/server/storage/FakeStorageClusterSettingsManagerBean.class"));
testEar.addAsManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
// add the test classes to the deployment
testEar.addAsLibrary(testClassesJar);
// add the necessary AS7 dependency modules
testEar.addAsManifestResource("jboss-deployment-structure.xml");
// add the application xml declaring the ejb jars
testEar.setApplicationXML("application.xml");
// add additional 3rd party dependent jars needed to support test classes
Collection<String> thirdPartyDeps = new ArrayList<String>();
thirdPartyDeps.add("joda-time:joda-time");
thirdPartyDeps.add("org.jboss.shrinkwrap:shrinkwrap-impl-base");
thirdPartyDeps.add("org.liquibase:liquibase-core");
thirdPartyDeps.add("org.powermock:powermock-api-mockito");
thirdPartyDeps.add("org.rhq.helpers:perftest-support:" + projectVersion);
thirdPartyDeps.add("org.rhq:rhq-core-client-api:jar:tests:" + rhqCoreClientApiVersion);
thirdPartyDeps.add("org.rhq:rhq-platform-plugin:jar:" + rhqPlatformPluginVersion);
thirdPartyDeps.add("org.rhq:test-utils:" + projectVersion);
MavenResolverSystem resolver = Maven.resolver();
Collection<JavaArchive> dependencies = new HashSet<JavaArchive>();
dependencies.addAll(Arrays.asList(resolver.loadPomFromFile("pom.xml").resolve(thirdPartyDeps)
.withTransitivity().as(JavaArchive.class)));
// If we're running oracle we need to include the OJDBC driver because dbunit needs it. Note that we need
// add it explicitly even though it is a provided module used by the datasource.
if (!Boolean.valueOf(System.getProperty("rhq.skip.oracle"))) {
// in proxy situations (like Jenkins) shrinkwrap won't be able to find repositories defined in
// settings.xml profiles. We know at this point the driver is in the local repo, try going offline
// at this point to force local repo resolution since the oracle driver is not in public repos.
// see http://stackoverflow.com/questions/6291146/arquillian-shrinkwrap-mavendependencyresolver-behind-proxy
// Last verified this problem using: Arquillian 1.0.3 bom
resolver.offline();
dependencies.addAll(Arrays.asList(resolver
.resolve("com.oracle:ojdbc6:jar:" + System.getProperty("rhq.ojdbc.version")).withTransitivity()
.as(JavaArchive.class)));
}
// Transitive test dep required by rhq-core-client-api above and for some reason not sucked in.
// TODO: pass in version from pom property
dependencies.addAll(Arrays.asList(resolver.resolve("commons-jxpath:commons-jxpath:1.3").withTransitivity()
.as(JavaArchive.class)));
// exclude any transitive deps we don't want
String[] excludeFilters = { "testng.*jdk", "rhq-core-domain.*jar" };
dependencies = exclude(dependencies, excludeFilters);