Skip to content

Commit

Permalink
Add mixed domain tests of the WFCORE-621 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Sep 3, 2015
1 parent d755c52 commit 0fccaf4
Show file tree
Hide file tree
Showing 11 changed files with 698 additions and 16 deletions.
@@ -0,0 +1,42 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.test.integration.domain.mixed;

/**
* Base class for a test suite that uses a minimal domain config in order
* to not have to deal with subsystem configuration compatibility issues
* across releases in tests that are focused on the behavior of the kernel.
*
* @author Brian Stansberry
*/
public class KernelBehaviorTestSuite extends MixedDomainTestSuite {

/**
* Call this from a @BeforeClass method
*
* @param testClass the test/suite class
*/
protected static MixedDomainTestSupport getSupport(Class<?> testClass) {
return getSupport(testClass, "master-config/domain-minimal.xml", false);
}
}
Expand Up @@ -52,11 +52,24 @@ static Version.AsVersion getVersion(Class<?> testClass) {
* @param testClass the test/suite class
*/
protected static MixedDomainTestSupport getSupport(Class<?> testClass) {
final Version.AsVersion version = getVersion(testClass);
if (support == null) {
final String copiedDomainXml = MixedDomainTestSupport.copyDomainFile();
return getSupport(testClass, copiedDomainXml, true);
} else {
return support;
}
}

static MixedDomainTestSupport getSupport(Class<?> testClass, String domainConfig, boolean adjustDomain) {
if (support == null) {
final Version.AsVersion version = getVersion(testClass);
final MixedDomainTestSupport testSupport;
try {
testSupport = MixedDomainTestSupport.create(testClass.getSimpleName(), version);
if (domainConfig != null) {
testSupport = MixedDomainTestSupport.create(testClass.getSimpleName(), version, domainConfig, adjustDomain);
} else {
testSupport = MixedDomainTestSupport.create(testClass.getSimpleName(), version);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Expand Up @@ -49,23 +49,39 @@
*/
public class MixedDomainTestSupport extends DomainTestSupport {

public static final String STANDARD_DOMAIN_CONFIG = "copied-master-config/domain.xml";

private final Version.AsVersion version;
private final boolean adjustDomain;

private MixedDomainTestSupport(Version.AsVersion version, String testClass, String domainConfig, String masterConfig, String slaveConfig,
String jbossHome)
String jbossHome, boolean adjustDomain)
throws Exception {
super(testClass, domainConfig, masterConfig, slaveConfig, new WildFlyManagedConfiguration(), new WildFlyManagedConfiguration(jbossHome));
this.version = version;
this.adjustDomain = adjustDomain;
}

public static MixedDomainTestSupport create(String testClass, Version.AsVersion version) throws Exception {
return create(testClass, version, STANDARD_DOMAIN_CONFIG, true);
}

public static MixedDomainTestSupport create(String testClass, Version.AsVersion version, String domainConfig, boolean adjustDomain) throws Exception {
final File dir = OldVersionCopier.expandOldVersion(version);
final String copiedDomainXml = copyDomainFile();
return new MixedDomainTestSupport(version, testClass, copiedDomainXml, "master-config/host.xml",
"slave-config/host-slave.xml", dir.getAbsolutePath());
return new MixedDomainTestSupport(version, testClass, domainConfig, "master-config/host.xml",
"slave-config/host-slave.xml", dir.getAbsolutePath(), adjustDomain);
}

public void start() {
if (adjustDomain) {
startAndAdjust();
} else {
super.start();
}
}

private void startAndAdjust() {

try {
//Start the master in admin only and reconfigure the domain with what
//we want to test in the mixed domain and have the DomainAdjuster
Expand Down Expand Up @@ -95,16 +111,15 @@ public void start() {
}
}

private static String copyDomainFile() throws Exception {
static String copyDomainFile() {

final File originalDomainXml = loadFile("target", "jbossas", "domain", "configuration", "domain.xml");
final File targetDirectory = createDirectory("target", "test-classes", "copied-master-config");
final File copiedDomainXml = new File(targetDirectory, "domain.xml");
if (copiedDomainXml.exists()) {
Assert.assertTrue(copiedDomainXml.delete());
}
final InputStream in = new BufferedInputStream(new FileInputStream(originalDomainXml));
try {
try (InputStream in = new BufferedInputStream(new FileInputStream(originalDomainXml))) {
final OutputStream out = new BufferedOutputStream(new FileOutputStream(copiedDomainXml));
try {
byte[] bytes = new byte[1024];
Expand All @@ -116,10 +131,10 @@ private static String copyDomainFile() throws Exception {
} finally {
safeClose(out);
}
} finally {
safeClose(in);
} catch (IOException e) {
throw new RuntimeException(e);
}
return "copied-master-config/domain.xml";
return STANDARD_DOMAIN_CONFIG;
}

private static File loadFile(String first, String... parts) {
Expand All @@ -130,10 +145,14 @@ private static File loadFile(String first, String... parts) {
}


private static File createDirectory(String first, String... parts) throws IOException {
private static File createDirectory(String first, String... parts) {
Path p = Paths.get(first, parts);
File dir = Files.createDirectories(p).toFile();
Assert.assertTrue(dir.exists());
return dir;
try {
File dir = Files.createDirectories(p).toFile();
Assert.assertTrue(dir.exists());
return dir;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 0fccaf4

Please sign in to comment.