http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java index 93572fe..dd0939e 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java @@ -16,6 +16,7 @@ package org.apache.geode.test.dunit.rules; import static org.assertj.core.api.Assertions.assertThat; +import org.apache.geode.internal.lang.StringUtils; import org.apache.geode.management.cli.Result; import org.apache.geode.management.internal.cli.CliUtil; import org.apache.geode.management.internal.cli.HeadlessGfsh; @@ -23,6 +24,8 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings; import org.apache.geode.management.internal.cli.result.CommandResult; import org.apache.geode.management.internal.cli.util.CommandStringBuilder; import org.apache.geode.test.junit.rules.DescribedExternalResource; +import org.json.JSONArray; +import org.junit.rules.TemporaryFolder; import org.junit.runner.Description; /** @@ -53,6 +56,7 @@ public class GfshShellConnectionRule extends DescribedExternalResource { private PortType portType = PortType.jmxManger; private HeadlessGfsh gfsh = null; private boolean connected = false; + private TemporaryFolder temporaryFolder = new TemporaryFolder(); public GfshShellConnectionRule() {} @@ -63,7 +67,9 @@ public class GfshShellConnectionRule extends DescribedExternalResource { @Override protected void before(Description description) throws Throwable { - this.gfsh = new HeadlessGfsh(getClass().getName(), 30, "gfsh_files"); + temporaryFolder.create(); + this.gfsh = new HeadlessGfsh(getClass().getName(), 30, + temporaryFolder.newFolder("gfsh_files").getAbsolutePath()); // do not auto connect if no port initialized if (port < 0) { return; @@ -89,6 +95,11 @@ public class GfshShellConnectionRule extends DescribedExternalResource { assertThat(this.connected).isTrue(); } + public void connectAndVerify(int port, PortType type, String... options) throws Exception { + connect(port, type, options); + assertThat(this.connected).isTrue(); + } + public void connect(int port, PortType type, String... options) throws Exception { CliUtil.isGfshVM = true; final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT); @@ -131,6 +142,7 @@ public class GfshShellConnectionRule extends DescribedExternalResource { @Override protected void after(Description description) throws Throwable { + temporaryFolder.delete(); if (connected) { disconnect(); } @@ -157,19 +169,27 @@ public class GfshShellConnectionRule extends DescribedExternalResource { public CommandResult executeCommand(String command) throws Exception { gfsh.executeCommand(command); CommandResult result = (CommandResult) gfsh.getResult(); - System.out.println("Command Result: \n" + gfsh.outputString); + if (StringUtils.isBlank(gfsh.outputString)) { + // print out the message body as the command result + JSONArray messages = ((JSONArray) result.getContent().get("message")); + if (messages != null) { + for (int i = 0; i < messages.length(); i++) { + gfsh.outputString += messages.getString(i) + "\n"; + } + } + } + System.out.println("Command result for <" + command + ">: \n" + gfsh.outputString); return result; } + public String getGfshOutput() { + return gfsh.outputString; + } + public CommandResult executeAndVerifyCommand(String command) throws Exception { CommandResult result = executeCommand(command); - - if (result.getStatus() != Result.Status.OK) { - System.out.println("broken"); - } - assertThat(result.getStatus()).describedAs(result.getContent().toString()) - .isEqualTo(Result.Status.OK); + assertThat(result.getStatus()).isEqualTo(Result.Status.OK); return result; }
http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java deleted file mode 100644 index 0a63962..0000000 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerConfigurationRule.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package org.apache.geode.test.dunit.rules; - -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.apache.geode.test.dunit.Host.*; -import static org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase.*; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.Serializable; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import org.awaitility.Awaitility; -import org.junit.rules.ExternalResource; - -import org.apache.geode.distributed.Locator; -import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; -import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; - - -public class LocatorServerConfigurationRule extends ExternalResource implements Serializable { - - private int locatorPort = 0; - - private boolean locatorInitialized = false; - - private JUnit4DistributedTestCase testCase; - - public LocatorServerConfigurationRule(JUnit4DistributedTestCase testCase) { - this.testCase = testCase; - } - - Host host = getHost(0); - VM locator = host.getVM(0); - - @Override - protected void before() { - // Add initialization requirement if any. - disconnectAllFromDS(); - } - - @Override - protected void after() { - disconnectAllFromDS(); - } - - /** - * Returns getHost(0).getVM(0) as a locator instance with the given configuration properties. - * - * @param locatorProperties - * - * @return VM locator vm - * - * @throws IOException - */ - public VM getLocatorVM(Properties locatorProperties) throws IOException { - if (!locatorProperties.containsKey(MCAST_PORT)) { - locatorProperties.setProperty(MCAST_PORT, "0"); - } - - locatorPort = locator.invoke(() -> { - InternalLocator locator = - (InternalLocator) Locator.startLocatorAndDS(0, null, locatorProperties); - locator.resetInternalLocatorFileNamesWithCorrectPortNumber(locatorPort); - - if (locator.getConfig().getEnableClusterConfiguration()) { - Awaitility.await().atMost(65, TimeUnit.SECONDS) - .until(() -> assertTrue(locator.isSharedConfigurationRunning())); - } - return locator.getPort(); - }); - - this.locatorInitialized = true; - return locator; - } - - /** - * Returns a node VM with given configuration properties. - * - * @param index valid 1 to 3 (returns getHist(0).getVM(index) - * @param properties - * - * @return VM node vm - */ - public VM getServerVM(int index, Properties properties) { - assertTrue("Locator not initialized. Initialize locator by calling getLocatorVM()", - this.locatorInitialized); - assertTrue("VM with index 0 is used for locator service.", (index != 0)); - VM nodeVM = getNodeVM(index); - nodeVM.invoke(() -> { - getSystem(properties); - }); - return nodeVM; - } - - /** - * this will simply returns the node - * - * @param index - * @return - */ - public VM getNodeVM(int index) { - return host.getVM(index); - } - - public InternalDistributedSystem getSystem(Properties properties) { - if (!properties.containsKey(MCAST_PORT)) { - properties.setProperty(MCAST_PORT, "0"); - } - properties.setProperty(LOCATORS, getHostName() + "[" + locatorPort + "]"); - InternalDistributedSystem ds = testCase.getSystem(properties); - if (testCase instanceof JUnit4CacheTestCase) { - ((JUnit4CacheTestCase) testCase).getCache(); - } - return ds; - } - - public int getLocatorPort() { - return locatorPort; - } - - private String getHostName() { - try { - return InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException ignore) { - return "localhost"; - } - } - -} http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java index 39c13d0..ad8c033 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java @@ -16,6 +16,7 @@ package org.apache.geode.test.dunit.rules; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; import static org.apache.geode.distributed.ConfigurationProperties.NAME; import static org.apache.geode.test.dunit.Host.getHost; @@ -106,7 +107,8 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial } /** - * starts a cache server that does not connect to a locator + * starts a cache server that does not connect to a locator, unless the properties it passes in + * has "locators" property. * * @return VM node vm */ @@ -114,16 +116,39 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial return startServerVM(index, properties, -1); } + /** + * start a server that connects to this locatorPort + * + * @param index + * @param locatorPort + * @return + * @throws IOException + */ public Server startServerVM(int index, int locatorPort) throws IOException { return startServerVM(index, new Properties(), locatorPort); } + public Server startServerAsJmxManager(int index, int jmxManagerPort) throws IOException { + Properties properties = new Properties(); + properties.setProperty(JMX_MANAGER_PORT, jmxManagerPort + ""); + return startServerVM(index, properties); + } + + public Server startServerAsEmbededLocator(int index, int locatorPort, int jmxManagerPort) + throws IOException { + Properties properties = new Properties(); + properties.setProperty("start-locator", "localhost[" + locatorPort + "]"); + if (jmxManagerPort > 0) { + properties.setProperty(JMX_MANAGER_PORT, jmxManagerPort + ""); + } + return startServerVM(index, properties); + } + /** * Starts a cache server that connect to the locator running at the given port. */ public Server startServerVM(int index, Properties properties, int locatorPort) throws IOException { - String name = "server-" + index; properties.setProperty(NAME, name); http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt ---------------------------------------------------------------------- diff --git a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt index 8c0fb45..b1d6887 100755 --- a/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt +++ b/geode-core/src/test/resources/org/apache/geode/codeAnalysis/sanctionedSerializables.txt @@ -563,6 +563,8 @@ org/apache/geode/management/internal/cli/functions/DestroyDiskStoreFunction,true org/apache/geode/management/internal/cli/functions/DestroyIndexFunction,true,1 org/apache/geode/management/internal/cli/functions/ExportConfigFunction,true,1 org/apache/geode/management/internal/cli/functions/ExportDataFunction,true,1 +org/apache/geode/management/internal/cli/functions/ExportLogsFunction,true,1 +org/apache/geode/management/internal/cli/functions/ExportLogsFunction$Args,false,endTime:java/lang/String,logLevel:java/lang/String,logLevelOnly:boolean,startTime:java/lang/String org/apache/geode/management/internal/cli/functions/FetchRegionAttributesFunction,true,4366812590788342070 org/apache/geode/management/internal/cli/functions/FetchRegionAttributesFunction$FetchRegionAttributesFunctionResult,true,-3970828263897978845,cacheListenerClasses:java/lang/String[],cacheLoaderClass:java/lang/String,cacheWriterClass:java/lang/String,regionAttributes:org/apache/geode/cache/RegionAttributes org/apache/geode/management/internal/cli/functions/FetchSharedConfigurationStatusFunction,true,1 @@ -618,8 +620,10 @@ org/apache/geode/management/internal/cli/shell/JMXInvocationException,true,-4265 org/apache/geode/management/internal/cli/shell/jline/ANSIHandler$ANSIStyle,false org/apache/geode/management/internal/cli/util/DiskStoreNotFoundException,true,-5184836041554948093 org/apache/geode/management/internal/cli/util/EvictionAttributesInfo,true,1,evictionAction:java/lang/String,evictionAlgorithm:java/lang/String,evictionMaxValue:int +org/apache/geode/management/internal/cli/util/ExportLogsCacheWriter,false,currentFile:java/nio/file/Path,currentOutputStream:java/io/BufferedOutputStream org/apache/geode/management/internal/cli/util/FixedPartitionAttributesInfo,false,isPrimary:boolean,numBuckets:int,partitionName:java/lang/String org/apache/geode/management/internal/cli/util/JConsoleNotFoundException,true,-1485615321440327206 +org/apache/geode/management/internal/cli/util/LogFilter$LineFilterResult,false org/apache/geode/management/internal/cli/util/MemberInformation,true,1,cacheXmlFilePath:java/lang/String,cpuUsage:java/lang/String,groups:java/lang/String,heapUsage:java/lang/String,host:java/lang/String,id:java/lang/String,initHeapSize:java/lang/String,locatorBindAddress:java/lang/String,locatorPort:int,locators:java/lang/String,logFilePath:java/lang/String,maxHeapSize:java/lang/String,name:java/lang/String,processId:java/lang/String,serverBindAddress:java/lang/String,statArchiveFilePath:java/lang/String,workingDirPath:java/lang/String org/apache/geode/management/internal/cli/util/MemberNotFoundException,true,5686788909239181174 org/apache/geode/management/internal/cli/util/VisualVmNotFoundException,true,-8491645604829510102 http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties ---------------------------------------------------------------------- diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties index 694d4ff..2c27654 100644 --- a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties +++ b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties @@ -1468,12 +1468,14 @@ IS AVAILABLE\n\ SYNOPSIS\n\ \ \ \ \ Export the log files for a member or members.\n\ SYNTAX\n\ -\ \ \ \ export logs --dir=value [--group=value(nullvalue)*] [--member=value] [--log-level=value]\n\ -\ \ \ \ [--only-log-level=value] [--merge-log=value] [--start-time=value] [--end-time=value]\n\ +\ \ \ \ export logs [--dir=value] [--group=value(nullvalue)*] [--member=value(nullvalue)*]\n\ +\ \ \ \ [--log-level=value] [--only-log-level=value] [--merge-log=value] [--start-time=value]\n\ +\ \ \ \ [--end-time=value]\n\ PARAMETERS\n\ \ \ \ \ dir\n\ -\ \ \ \ \ \ \ \ Directory to which log files will be written.\n\ -\ \ \ \ \ \ \ \ Required: true\n\ +\ \ \ \ \ \ \ \ Local directory to which log files will be written. This is only used when you are\n\ +\ \ \ \ \ \ \ \ exporting logs using http connection. If not specified, user.dir will be used.\n\ +\ \ \ \ \ \ \ \ Required: false\n\ \ \ \ \ group\n\ \ \ \ \ \ \ \ \ Group of members whose log files will be exported.\n\ \ \ \ \ \ \ \ \ Required: false\n\ http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-web/build.gradle ---------------------------------------------------------------------- diff --git a/geode-web/build.gradle b/geode-web/build.gradle index ffab391..d6de656 100755 --- a/geode-web/build.gradle +++ b/geode-web/build.gradle @@ -54,6 +54,10 @@ dependencies { testRuntime project(':geode-core') testCompile files(project(':geode-core').sourceSets.test.output) + testCompile 'com.pholser:junit-quickcheck-core:' + project.'junit-quickcheck.version' + testCompile 'com.pholser:junit-quickcheck-generators:' + project.'junit-quickcheck.version' + testCompile 'com.pholser:junit-quickcheck-guava:' + project.'junit-quickcheck.version' + testRuntime files(war.destinationDir) } http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java index 3f3358d..5f4cd74 100644 --- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java +++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java @@ -31,9 +31,9 @@ import org.apache.geode.test.junit.runner.SuiteRunner; GemfireDataCommandsDUnitTest.class, GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.class, IndexCommandsDUnitTest.class, ListAndDescribeDiskStoreCommandsDUnitTest.class, ListIndexCommandDUnitTest.class, - MemberCommandsDUnitTest.class, MiscellaneousCommandsDUnitTest.class,QueueCommandsDUnitTest.class, - ShellCommandsDUnitTest.class, ShowDeadlockDUnitTest.class, ShowMetricsDUnitTest.class, - ShowStackTraceDUnitTest.class, UserCommandsDUnitTest.class}) + MemberCommandsDUnitTest.class, MiscellaneousCommandsDUnitTest.class, + QueueCommandsDUnitTest.class, ShellCommandsDUnitTest.class, ShowDeadlockDUnitTest.class, + ShowMetricsDUnitTest.class, ShowStackTraceDUnitTest.class, UserCommandsDUnitTest.class}) public class CommandOverHttpDUnitTest { @ClassRule public static ProvideSystemProperty provideSystemProperty = http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDUnitTest.java new file mode 100644 index 0000000..8f8342f --- /dev/null +++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ExportLogsOverHttpDUnitTest.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.geode.management.internal.cli.commands; + +import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS; +import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT; +import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.collect.Sets; + +import org.apache.geode.internal.AvailablePortHelper; +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; +import org.apache.geode.test.dunit.rules.Locator; +import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +@Category(DistributedTest.class) +public class ExportLogsOverHttpDUnitTest { + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @ClassRule + public static LocatorServerStartupRule lsRule = new LocatorServerStartupRule(); + + @ClassRule + public static GfshShellConnectionRule gfshConnector = new GfshShellConnectionRule(); + + private static int jmxPort, httpPort; + private static Properties locatorProperties; + private static Set<String> expectedZipEntries = new HashSet<>(); + + @BeforeClass + public static void beforeClass() throws Exception { + int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); + httpPort = ports[0]; + jmxPort = ports[1]; + locatorProperties = new Properties(); + locatorProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost"); + locatorProperties.setProperty(HTTP_SERVICE_PORT, httpPort + ""); + locatorProperties.setProperty(JMX_MANAGER_PORT, jmxPort + ""); + + // start the locator in vm0 and then connect to it over http + Locator locator = lsRule.startLocatorVM(0, locatorProperties); + lsRule.startServerVM(1, locator.getPort()); + gfshConnector.connectAndVerify(httpPort, GfshShellConnectionRule.PortType.http); + + expectedZipEntries = Sets.newHashSet("locator-0/locator-0.log", "server-1/server-1.log"); + } + + @Test + public void testExportWithNoDir() throws Exception { + // export the logs + gfshConnector.executeCommand("export logs"); + // verify that the message contains a path to the user.dir + String message = gfshConnector.getGfshOutput(); + assertThat(message).contains("Logs exported to: "); + assertThat(message).contains(System.getProperty("user.dir")); + + String zipPath = getZipPathFromCommandResult(message); + verifyZipContent(zipPath); + } + + @Test + public void testExportWithDir() throws Exception { + File dir = temporaryFolder.newFolder(); + // export the logs + gfshConnector.executeCommand("export logs --dir=" + dir.getAbsolutePath()); + // verify that the message contains a path to the user.dir + String message = gfshConnector.getGfshOutput(); + assertThat(message).contains("Logs exported to: "); + assertThat(message).contains(dir.getAbsolutePath()); + + String zipPath = getZipPathFromCommandResult(message); + verifyZipContent(zipPath); + } + + private void verifyZipContent(String zipPath) throws Exception { + Set<String> actualZipEnries = + new ZipFile(zipPath).stream().map(ZipEntry::getName).collect(Collectors.toSet()); + + assertThat(actualZipEnries).isEqualTo(expectedZipEntries); + } + + private String getZipPathFromCommandResult(String message) { + return message.replaceAll("Logs exported to: ", "").trim(); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/RestHttpOperationInvokerJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/RestHttpOperationInvokerJUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/RestHttpOperationInvokerJUnitTest.java index 808c78f..1ebe89a 100644 --- a/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/RestHttpOperationInvokerJUnitTest.java +++ b/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/RestHttpOperationInvokerJUnitTest.java @@ -14,22 +14,12 @@ */ package org.apache.geode.management.internal.web.shell; -import static org.junit.Assert.*; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.springframework.core.io.Resource; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.ResourceAccessException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import org.apache.geode.internal.lang.StringUtils; import org.apache.geode.management.internal.cli.CommandRequest; @@ -39,6 +29,18 @@ import org.apache.geode.management.internal.web.domain.LinkIndex; import org.apache.geode.management.internal.web.http.ClientHttpRequest; import org.apache.geode.management.internal.web.http.HttpMethod; import org.apache.geode.test.junit.categories.UnitTest; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.springframework.core.io.Resource; +import org.springframework.web.client.ResourceAccessException; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; /** * The RestHttpOperationInvokerJUnitTest class is a test suite of test cases testing the contract @@ -315,13 +317,13 @@ public class RestHttpOperationInvokerJUnitTest extends AbstractWebTestCase { @Override @SuppressWarnings("unchecked") - protected <T> ResponseEntity<T> send(final ClientHttpRequest request, - final Class<T> responseType, final Map<String, ?> uriVariables) { - return new ResponseEntity(expectedResult, HttpStatus.OK); + protected <T> T send(final ClientHttpRequest request, final Class<T> responseType, + final Map<String, ?> uriVariables) { + return (T) expectedResult; } }; - final String actualResult = operationInvoker.processCommand( + final Object actualResult = operationInvoker.processCommand( createCommandRequest("list-libraries", Collections.<String, String>emptyMap())); assertEquals(expectedResult, actualResult); @@ -351,7 +353,7 @@ public class RestHttpOperationInvokerJUnitTest extends AbstractWebTestCase { protected void printWarning(final String message, final Object... args) {} }; - final String actualResult = operationInvoker.processCommand( + final Object actualResult = operationInvoker.processCommand( createCommandRequest("get resource", Collections.<String, String>emptyMap())); assertEquals(expectedResult, actualResult); @@ -371,8 +373,8 @@ public class RestHttpOperationInvokerJUnitTest extends AbstractWebTestCase { protected void printWarning(final String message, final Object... args) {} @Override - protected <T> ResponseEntity<T> send(final ClientHttpRequest request, - final Class<T> responseType, final Map<String, ?> uriVariables) { + protected <T> T send(final ClientHttpRequest request, final Class<T> responseType, + final Map<String, ?> uriVariables) { throw new ResourceAccessException("test"); } @@ -389,7 +391,7 @@ public class RestHttpOperationInvokerJUnitTest extends AbstractWebTestCase { + "Please try reconnecting or see the GemFire Manager's log file for further details.", operationInvoker.getBaseUrl(), "test"); - final String actualResult = operationInvoker.processCommand( + final Object actualResult = operationInvoker.processCommand( createCommandRequest("list-libraries", Collections.<String, String>emptyMap())); assertFalse(operationInvoker.isConnected()); http://git-wip-us.apache.org/repos/asf/geode/blob/92582fbd/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/SimpleHttpOperationInvokerJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/SimpleHttpOperationInvokerJUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/SimpleHttpOperationInvokerJUnitTest.java index 8afbcf6..a704654 100644 --- a/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/SimpleHttpOperationInvokerJUnitTest.java +++ b/geode-web/src/test/java/org/apache/geode/management/internal/web/shell/SimpleHttpOperationInvokerJUnitTest.java @@ -14,9 +14,10 @@ */ package org.apache.geode.management.internal.web.shell; -import static org.junit.Assert.*; - -import java.util.Collections; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import org.apache.geode.management.internal.cli.CommandRequest; import org.apache.geode.management.internal.web.AbstractWebTestCase; @@ -25,15 +26,14 @@ import org.apache.geode.management.internal.web.http.ClientHttpRequest; import org.apache.geode.management.internal.web.http.HttpHeader; import org.apache.geode.management.internal.web.http.HttpMethod; import org.apache.geode.test.junit.categories.UnitTest; - import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; +import java.util.Collections; + /** * The SimpleHttpOperationInvokerJUnitTest class is a test suite of test cases testing the contract * and functionality of the SimpleHttpOperationInvoker class. @@ -128,9 +128,8 @@ public class SimpleHttpOperationInvokerJUnitTest extends AbstractWebTestCase { @Override @SuppressWarnings("unchecked") - protected <T> ResponseEntity<T> send(final ClientHttpRequest request, - final Class<T> responseType) { - return new ResponseEntity(expectedResult, HttpStatus.OK); + protected <T> T send(final ClientHttpRequest request, final Class<T> responseType) { + return (T) expectedResult; } }; @@ -151,8 +150,7 @@ public class SimpleHttpOperationInvokerJUnitTest extends AbstractWebTestCase { } @Override - protected <T> ResponseEntity<T> send(final ClientHttpRequest request, - final Class<T> responseType) { + protected <T> T send(final ClientHttpRequest request, final Class<T> responseType) { throw new ResourceAccessException("test"); }
