Skip to content

Commit

Permalink
Extracting common code in InstallationManagerTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
spyrkob committed Nov 19, 2024
1 parent 61d19cd commit 38671d3
Show file tree
Hide file tree
Showing 19 changed files with 1,017 additions and 791 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package org.wildfly.core.instmgr;

import java.nio.file.Path;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -53,7 +55,10 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
for (HistoryResult hr : history) {
ModelNode entry = new ModelNode();
entry.get(InstMgrConstants.HISTORY_RESULT_HASH).set(hr.getName());
entry.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).set(hr.timestamp().toString());
if (hr.timestamp() != null) {
final java.util.Date timestamp = Date.from(hr.timestamp());
entry.get(InstMgrConstants.HISTORY_RESULT_TIMESTAMP).set(DateFormat.getInstance().format(timestamp));
}
entry.get(InstMgrConstants.HISTORY_RESULT_TYPE).set(hr.getType().toLowerCase(Locale.ENGLISH));
if (hr.getVersions() != null && !hr.getVersions().isEmpty()) {
final ModelNode versions = entry.get(InstMgrConstants.HISTORY_RESULT_CHANNEL_VERSIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,20 @@

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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import org.jboss.as.cli.Util;
import java.util.LinkedHashMap;
import org.jboss.as.test.integration.domain.management.util.DomainTestSupport;
import org.jboss.as.test.integration.management.base.AbstractCliTestBase;
import org.jboss.as.test.module.util.TestModule;
import org.jboss.dmr.ModelNode;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.wildfly.core.instmgr.InstMgrConstants;
import org.wildfly.core.instmgr.cli.UpdateCommand;
import org.wildfly.installationmanager.Channel;
import org.wildfly.installationmanager.Repository;
import org.wildfly.test.installationmanager.TestInstallationManager;
import org.wildfly.test.installationmanager.TestInstallationManagerFactory;
import org.wildfly.test.installationmanager.BaseInstallationManagerTestCase;

/**
* Tests the high-level Installation Manager commands in domain mode environment. It uses a mocked implementation of the
Expand All @@ -59,16 +30,11 @@
* See InstMgrResourceTestCase for low-level management operation unit testing.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class InstallationManagerIntegrationTestCase extends AbstractCliTestBase {

private static final String MODULE_NAME = "org.jboss.prospero";
public class InstallationManagerIntegrationTestCase extends BaseInstallationManagerTestCase {
private static DomainTestSupport testSupport;
private static TestModule testModule;

private static Path primaryPrepareServerDir;
private static Path secondaryPrepareServerDir;

static final Path TARGET_DIR = Paths.get(System.getProperty("basedir", ".")).resolve("target");
static Path primaryCustomPatchBaseDir;
static Path secondaryCustomPatchBaseDir;

Expand Down Expand Up @@ -102,69 +68,22 @@ public static void tearDownDomain() throws Exception {
}
}

private static void createTestModule() throws IOException {
testModule = new TestModule(MODULE_NAME, "org.wildfly.installation-manager.api");
testModule.addResource("test-mock-installation-manager.jar").addClass(TestInstallationManager.class).addClass(TestInstallationManagerFactory.class)
.addAsManifestResource("META-INF/services/org.wildfly.installationmanager.spi.InstallationManagerFactory",
"services/org.wildfly.installationmanager.spi.InstallationManagerFactory");
testModule.create(true);
}

@After
public void clean() throws IOException {
String host = "secondary";
// Clean any previous state
assertTrue(cli.sendLine("installer clean --host=" + host, false));
Assert.assertTrue(!Files.exists(secondaryPrepareServerDir));

host = "primary";
// Clean any previous state
assertTrue(cli.sendLine("installer clean --host=" + host, false));
Assert.assertTrue(!Files.exists(primaryPrepareServerDir));

for(File testZip : TARGET_DIR.toFile().listFiles((dir, name) -> name.startsWith("installation-manager") && name.endsWith(".zip"))) {
Files.deleteIfExists(testZip.toPath());
}
}

@Test
public void requireHost() {
final List<String> commands = List.of("update", "clean", "revert", "history", "channel-list",
"channel-add --channel-name test --manifest test --repositories test", "channel-edit --channel-name test --manifest test --repositories test",
"channel-remove --channel-name test", "upload-custom-patch --custom-patch-file=dummy --manifest=manifest");

for (String command : commands) {
AssertionError exception = assertThrows(AssertionError.class, () -> {
cli.sendLine("installer " + command);
});

String expectedMessage = "The --host option must be used in domain mode.";
String actualMessage = exception.getMessage();

assertTrue(actualMessage, actualMessage.contains(expectedMessage));
}
final String expectedMessage = "The --host option must be used in domain mode.";
testHostParameter(null, (actualMessage)->assertTrue(actualMessage, actualMessage.contains(expectedMessage)));
}

public static String buildChannelOutput(Channel channel) {
final String returnChar = Util.isWindows() ? "\r\n" : "\n";

StringBuilder sb = new StringBuilder("-------").append(returnChar).append("# " + channel.getName()).append(returnChar);

if (channel.getManifestUrl().isPresent()) {
sb.append(" manifest: " + channel.getManifestUrl().get()).append(returnChar);
} else if (channel.getManifestCoordinate().isPresent()) {
sb.append(" manifest: " + channel.getManifestCoordinate().get()).append(returnChar);
}

sb.append(" repositories:").append(returnChar);

for (Repository repository : channel.getRepositories()) {
sb.append(" id: " + repository.getId()).append(returnChar).append(" url: " + repository.getUrl()).append(returnChar);
}

return sb.toString();
@Override
protected LinkedHashMap<String, ServerPaths> getServerDirs() {
// Note: preserve order of insertion using LinkedHashMap
final LinkedHashMap<String, ServerPaths> dirs = new LinkedHashMap<>();
dirs.put("primary", new ServerPaths(primaryPrepareServerDir, primaryCustomPatchBaseDir));
dirs.put("secondary", new ServerPaths(secondaryPrepareServerDir, secondaryCustomPatchBaseDir));
return dirs;
}

<<<<<<< HEAD
@Test
public void _a_listChannel() throws IOException {
cli.sendLine("installer channel-list --host=primary");
Expand Down Expand Up @@ -877,4 +796,9 @@ public boolean directoryOnlyContains(Path directory, Predicate<Path> match) thro
return stream.allMatch(match);
}
}

@Override
protected String getNoPreparedServerErrorCode() {
return "WFLYHC0218:";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jboss.as.test.integration.domain.suites;

import java.io.IOException;
import java.net.URL;

import org.jboss.as.test.integration.domain.extension.ExtensionSetup;
import org.jboss.as.test.integration.domain.management.util.DomainTestSupport;
Expand Down Expand Up @@ -125,10 +126,12 @@ public static boolean isTestSuiteEnabled() {

private static void createTestModule() throws IOException {
testModule = new TestModule(MODULE_NAME, "org.wildfly.installation-manager.api");
final URL serviceLoader = SimpleRbacProviderTestSuite.class.getClassLoader()
.getResource("org/wildfly/test/installationmanager/services/org.wildfly.installationmanager.spi.InstallationManagerFactory");
testModule.addResource("test-mock-installation-manager.jar")
.addClass(TestInstallationManager.class)
.addClass(TestInstallationManagerFactory.class)
.addAsManifestResource("META-INF/services/org.wildfly.installationmanager.spi.InstallationManagerFactory",
.addAsManifestResource(serviceLoader,
"services/org.wildfly.installationmanager.spi.InstallationManagerFactory");
testModule.create(true);
}
Expand Down
Loading

0 comments on commit 38671d3

Please sign in to comment.