GEODE-37 change package name from com.gemstone.gemfire (for ./geode-web/src/test/java/com/gemstone/gemfire)to org.apache.geode for(to ./geode-web/src/test/java/org/apache/geode)
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/7c20e693 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/7c20e693 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/7c20e693 Branch: refs/heads/feature/GEODE-37_2 Commit: 7c20e693180198ff6787b2ac4508eb375b7199e5 Parents: 92e2464 Author: Hitesh Khamesra <[email protected]> Authored: Tue Sep 13 15:43:20 2016 -0700 Committer: Hitesh Khamesra <[email protected]> Committed: Tue Sep 13 15:43:20 2016 -0700 ---------------------------------------------------------------------- .../cli/commands/CommandOverHttpDUnitTest.java | 58 --- .../ConnectCommandWithHttpAndSSLDUnitTest.java | 319 ------------ .../DataCommandsOverHttpDistributedTest.java | 151 ------ .../GfshCommandsOverHttpSecurityTest.java | 30 -- .../internal/web/AbstractWebTestCase.java | 96 ---- .../ShellCommandsControllerJUnitTest.java | 238 --------- .../LoginHandlerInterceptorJUnitTest.java | 273 ---------- .../internal/web/domain/LinkIndexJUnitTest.java | 236 --------- .../internal/web/domain/LinkJUnitTest.java | 123 ----- .../domain/QueryParameterSourceJUnitTest.java | 92 ---- .../web/http/ClientHttpRequestJUnitTest.java | 509 ------------------- ...ableObjectHttpMessageConverterJUnitTest.java | 165 ------ .../RestHttpOperationInvokerJUnitTest.java | 453 ----------------- .../SimpleHttpOperationInvokerJUnitTest.java | 198 -------- .../web/util/ConvertUtilsJUnitTest.java | 170 ------- .../internal/web/util/UriUtilsJUnitTest.java | 118 ----- .../cli/commands/CommandOverHttpDUnitTest.java | 58 +++ .../ConnectCommandWithHttpAndSSLDUnitTest.java | 319 ++++++++++++ .../DataCommandsOverHttpDistributedTest.java | 151 ++++++ .../GfshCommandsOverHttpSecurityTest.java | 30 ++ .../internal/web/AbstractWebTestCase.java | 96 ++++ .../ShellCommandsControllerJUnitTest.java | 238 +++++++++ .../LoginHandlerInterceptorJUnitTest.java | 273 ++++++++++ .../internal/web/domain/LinkIndexJUnitTest.java | 236 +++++++++ .../internal/web/domain/LinkJUnitTest.java | 123 +++++ .../domain/QueryParameterSourceJUnitTest.java | 92 ++++ .../web/http/ClientHttpRequestJUnitTest.java | 509 +++++++++++++++++++ ...ableObjectHttpMessageConverterJUnitTest.java | 165 ++++++ .../RestHttpOperationInvokerJUnitTest.java | 453 +++++++++++++++++ .../SimpleHttpOperationInvokerJUnitTest.java | 198 ++++++++ .../web/util/ConvertUtilsJUnitTest.java | 170 +++++++ .../internal/web/util/UriUtilsJUnitTest.java | 118 +++++ 32 files changed, 3229 insertions(+), 3229 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java deleted file mode 100644 index 2f5348f..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CommandOverHttpDUnitTest.java +++ /dev/null @@ -1,58 +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 com.gemstone.gemfire.management.internal.cli.commands; - -import org.junit.ClassRule; -import org.junit.contrib.java.lang.system.ProvideSystemProperty; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -import com.gemstone.gemfire.test.junit.categories.DistributedTest; -import com.gemstone.gemfire.test.junit.categories.SecurityTest; -import com.gemstone.gemfire.test.junit.runner.SuiteRunner; - -@Category({ DistributedTest.class, SecurityTest.class }) -@RunWith(SuiteRunner.class) [email protected]({ - ConfigCommandsDUnitTest.class, - DeployCommandsDUnitTest.class, - DiskStoreCommandsDUnitTest.class, - FunctionCommandsDUnitTest.class, - GemfireDataCommandsDUnitTest.class, - GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.class, - IndexCommandsDUnitTest.class, - ListAndDescribeDiskStoreCommandsDUnitTest.class, - ListIndexCommandDUnitTest.class, - MemberCommandsDUnitTest.class, - MiscellaneousCommandsDUnitTest.class, - MiscellaneousCommandsExportLogsPart1DUnitTest.class, - MiscellaneousCommandsExportLogsPart2DUnitTest.class, - MiscellaneousCommandsExportLogsPart3DUnitTest.class, - MiscellaneousCommandsExportLogsPart4DUnitTest.class, - QueueCommandsDUnitTest.class, - SharedConfigurationCommandsDUnitTest.class, - ShellCommandsDUnitTest.class, - ShowDeadlockDUnitTest.class, - ShowMetricsDUnitTest.class, - ShowStackTraceDUnitTest.class, - UserCommandsDUnitTest.class -}) -public class CommandOverHttpDUnitTest { - @ClassRule - public static ProvideSystemProperty provideSystemProperty = new ProvideSystemProperty(CliCommandTestBase.USE_HTTP_SYSTEM_PROPERTY, "true"); -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java deleted file mode 100644 index dab762b..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConnectCommandWithHttpAndSSLDUnitTest.java +++ /dev/null @@ -1,319 +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 com.gemstone.gemfire.management.internal.cli.commands; - -import static com.gemstone.gemfire.distributed.ConfigurationProperties.*; -import static com.gemstone.gemfire.management.internal.cli.i18n.CliStrings.*; -import static com.gemstone.gemfire.util.test.TestUtil.*; -import static org.junit.Assert.*; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; -import java.util.Properties; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSession; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - -import com.gemstone.gemfire.management.internal.cli.HeadlessGfsh; -import com.gemstone.gemfire.management.internal.cli.result.CommandResult; -import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder; -import com.gemstone.gemfire.test.junit.categories.DistributedTest; -import com.gemstone.gemfire.test.junit.categories.SecurityTest; -import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory; - -/** - * @since GemFire 8.1 - */ -@Category({ DistributedTest.class, SecurityTest.class }) -@RunWith(Parameterized.class) [email protected](CategoryWithParameterizedRunnerFactory.class) -public class ConnectCommandWithHttpAndSSLDUnitTest extends CliCommandTestBase { - - private static final ThreadLocal<Properties> sslInfoHolder = new ThreadLocal<>(); - - private File jks; - - @Parameterized.Parameter - public String urlContext; - - @Parameterized.Parameters - public static Collection<String> data() { - return Arrays.asList("/geode-mgmt", "/gemfire"); - } - - @Override - public final void postSetUpCliCommandTestBase() throws Exception { - this.jks = new File(getResourcePath(getClass(), "/ssl/trusted.keystore")); - } - - @Override - protected final void preTearDownCliCommandTestBase() throws Exception { - destroyDefaultSetup(); - } - - @Override - public final void postTearDownCacheTestCase() throws Exception { - sslInfoHolder.set(null); - } - - @Test - public void testMutualAuthentication() throws Exception { - Properties serverProps = new Properties(); - serverProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - serverProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - serverProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - serverProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_TYPE, "JKS"); - serverProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "SSL"); - serverProps.setProperty(HTTP_SERVICE_SSL_REQUIRE_AUTHENTICATION, "true"); - serverProps.setProperty(HTTP_SERVICE_SSL_TRUSTSTORE, jks.getCanonicalPath()); - serverProps.setProperty(HTTP_SERVICE_SSL_TRUSTSTORE_PASSWORD, "password"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__KEY_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__KEY_STORE_PASSWORD, "password"); - clientProps.setProperty(CONNECT__SSL_PROTOCOLS, "SSL"); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(serverProps); - } - - @Test - public void testSimpleSSL() throws Exception { - Properties serverProps = new Properties(); - serverProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - serverProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - serverProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - serverProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_TYPE, "JKS"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(serverProps); - } - - @Test - public void testSSLWithoutKeyStoreType() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Test - public void testSSLWithSSLProtocol() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "SSL"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Test - public void testSSLWithTLSProtocol() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "TLS"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Test - public void testSSLWithTLSv11Protocol() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "TLSv1.1"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Test - public void testSSLWithTLSv12Protocol() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "TLSv1.2"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Test - public void testWithMultipleProtocol() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "SSL,TLSv1.2"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Ignore("TODO: disabled for unknown reason") - @Test - public void testSSLWithCipherSuite() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "TLSv1.2"); - - //Its bad to hard code here. But using SocketFactory.getDefaultCiphers() somehow is not working with the option - //"https.cipherSuites" which is required to restrict cipher suite with HttpsURLConnection - //Keeping the below code for further investigation on different Java versions ( 7 & 8) @TODO - - /*SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); - - sslContext.init(null, null, new java.security.SecureRandom()); - String[] cipherSuites = sslContext.getSocketFactory().getSupportedCipherSuites();*/ - - localProps.setProperty(HTTP_SERVICE_SSL_CIPHERS, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - clientProps.setProperty(CONNECT__SSL_CIPHERS, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"); - clientProps.setProperty(CONNECT__SSL_PROTOCOLS, "TLSv1.2"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Ignore("TODO: disabled for unknown reason") - @Test - public void testSSLWithMultipleCipherSuite() throws Exception { - System.setProperty("javax.net.debug", "ssl,handshake,failure"); - - Properties localProps = new Properties(); - localProps.setProperty(HTTP_SERVICE_SSL_ENABLED, "true"); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE, jks.getCanonicalPath()); - localProps.setProperty(HTTP_SERVICE_SSL_KEYSTORE_PASSWORD, "password"); - localProps.setProperty(HTTP_SERVICE_SSL_PROTOCOLS, "TLSv1.2"); - localProps.setProperty(HTTP_SERVICE_SSL_CIPHERS, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_EMPTY_RENEGOTIATION_INFO_SCSV"); - - Properties clientProps = new Properties(); - clientProps.setProperty(CONNECT__TRUST_STORE, jks.getCanonicalPath()); - clientProps.setProperty(CONNECT__TRUST_STORE_PASSWORD, "password"); - clientProps.setProperty(CONNECT__SSL_PROTOCOLS, "TLSv1.2"); - - sslInfoHolder.set(clientProps); - setUpJmxManagerOnVm0ThenConnect(localProps); - } - - @Override - protected void connect(final String host, final int jmxPort, final int httpPort, final HeadlessGfsh shell) { - assertNotNull(host); - assertNotNull(shell); - - final CommandStringBuilder command = new CommandStringBuilder(CONNECT); - String endpoint; - - // This is for testing purpose only. If we remove this piece of code we will - // get a java.security.cert.CertificateException - // as matching hostname can not be obtained in all test environment. - HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { - @Override - public boolean verify(String string, SSLSession ssls) { - return true; - } - }); - - endpoint = "https://" + host + ":" + httpPort + urlContext + "/v1"; - - command.addOption(CONNECT__USE_HTTP, Boolean.TRUE.toString()); - command.addOption(CONNECT__URL, endpoint); - command.addOption(CONNECT__USE_SSL,Boolean.TRUE.toString()); - - if(sslInfoHolder.get().getProperty(CONNECT__KEY_STORE) != null){ - command.addOption(CONNECT__KEY_STORE, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE)); - } - if(sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD) != null){ - command.addOption(CONNECT__KEY_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__KEY_STORE_PASSWORD)); - } - if(sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE) != null){ - command.addOption(CONNECT__TRUST_STORE, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE)); - } - if(sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD) != null){ - command.addOption(CONNECT__TRUST_STORE_PASSWORD, sslInfoHolder.get().getProperty(CONNECT__TRUST_STORE_PASSWORD)); - } - if(sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS) != null){ - command.addOption(CONNECT__SSL_PROTOCOLS, sslInfoHolder.get().getProperty(CONNECT__SSL_PROTOCOLS)); - } - if(sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS) != null){ - command.addOption(CONNECT__SSL_CIPHERS, sslInfoHolder.get().getProperty(CONNECT__SSL_CIPHERS)); - } - - CommandResult result = executeCommand(shell, command.toString()); - - if (!shell.isConnectedAndReady()) { - fail("Connect command failed to connect to manager " + endpoint + " result=" + commandResultToString(result)); - } - - info("Successfully connected to managing node using HTTPS"); - assertEquals(true, shell.isConnectedAndReady()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommandsOverHttpDistributedTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommandsOverHttpDistributedTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommandsOverHttpDistributedTest.java deleted file mode 100644 index 11b8ab1..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommandsOverHttpDistributedTest.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 com.gemstone.gemfire.management.internal.cli.commands; - -import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*; -import static com.gemstone.gemfire.test.dunit.Wait.*; -import static org.junit.Assert.*; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.RegionFactory; -import com.gemstone.gemfire.cache.RegionShortcut; -import com.gemstone.gemfire.management.DistributedRegionMXBean; -import com.gemstone.gemfire.management.ManagementService; -import com.gemstone.gemfire.management.cli.Result; -import com.gemstone.gemfire.management.internal.cli.result.CommandResult; -import com.gemstone.gemfire.test.dunit.Host; -import com.gemstone.gemfire.test.dunit.SerializableRunnable; -import com.gemstone.gemfire.test.dunit.VM; -import com.gemstone.gemfire.test.dunit.WaitCriterion; -import com.gemstone.gemfire.test.junit.categories.DistributedTest; - -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.ProvideSystemProperty; -import org.junit.experimental.categories.Category; - -@Category(DistributedTest.class) -@SuppressWarnings("deprecated") -public class DataCommandsOverHttpDistributedTest extends CliCommandTestBase { - - private static final String REBALANCE_REGION_NAME = DataCommandsOverHttpDistributedTest.class.getSimpleName() + "Region"; - - @ClassRule - public static ProvideSystemProperty provideSystemProperty = new ProvideSystemProperty(CliCommandTestBase.USE_HTTP_SYSTEM_PROPERTY, "true"); - - @Test - public void testSimulateForEntireDSWithTimeout() { - setupTestRebalanceForEntireDS(); - //check if DistributedRegionMXBean is available so that command will not fail - final VM manager = Host.getHost(0).getVM(0); - manager.invoke(checkRegionMBeans); - - getLogWriter().info("testSimulateForEntireDS verified MBean and executing command"); - - String command = "rebalance --simulate=true --time-out=-1"; - - CommandResult cmdResult = executeCommand(command); - - getLogWriter().info("testSimulateForEntireDS just after executing " + cmdResult); - - if (cmdResult != null) { - String stringResult = commandResultToString(cmdResult); - getLogWriter().info("testSimulateForEntireDS stringResult : " + stringResult); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - } else { - fail("testRebalanceForIncludeRegionFunction failed as did not get CommandResult"); - } - } - - SerializableRunnable checkRegionMBeans = new SerializableRunnable() { - @Override - public void run() { - final WaitCriterion waitForMaangerMBean = new WaitCriterion() { - @Override - public boolean done() { - final ManagementService service = ManagementService.getManagementService(getCache()); - final DistributedRegionMXBean bean = service.getDistributedRegionMXBean( - Region.SEPARATOR + REBALANCE_REGION_NAME); - if (bean == null) { - getLogWriter().info("Still probing for checkRegionMBeans ManagerMBean"); - return false; - } else { - // verify that bean is proper before executing tests - if (bean.getMembers() != null && bean.getMembers().length > 1 && bean.getMemberCount() > 0 && service.getDistributedSystemMXBean().listRegions().length >= 2) { - return true; - } else { - return false; - } - } - } - - @Override - public String description() { - return "Probing for testRebalanceCommandForSimulateWithNoMember ManagerMBean"; - } - }; - waitForCriterion(waitForMaangerMBean, 2 * 60 * 1000, 2000, true); - DistributedRegionMXBean bean = ManagementService.getManagementService(getCache()).getDistributedRegionMXBean( - "/" + REBALANCE_REGION_NAME); - assertNotNull(bean); - } - }; - - void setupTestRebalanceForEntireDS() { - final VM vm1 = Host.getHost(0).getVM(1); - final VM vm2 = Host.getHost(0).getVM(2); - setUpJmxManagerOnVm0ThenConnect(null); - - vm1.invoke(new SerializableRunnable() { - public void run() { - - // no need to close cache as it will be closed as part of teardown2 - Cache cache = getCache(); - - RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION); - Region region = dataRegionFactory.create(REBALANCE_REGION_NAME); - for (int i = 0; i < 10; i++) { - region.put("key" + (i + 200), "value" + (i + 200)); - } - region = dataRegionFactory.create(REBALANCE_REGION_NAME + "Another1"); - for (int i = 0; i < 100; i++) { - region.put("key" + (i + 200), "value" + (i + 200)); - } - } - }); - - vm2.invoke(new SerializableRunnable() { - public void run() { - - // no need to close cache as it will be closed as part of teardown2 - Cache cache = getCache(); - - RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION); - Region region = dataRegionFactory.create(REBALANCE_REGION_NAME); - for (int i = 0; i < 100; i++) { - region.put("key" + (i + 400), "value" + (i + 400)); - } - region = dataRegionFactory.create(REBALANCE_REGION_NAME + "Another2"); - for (int i = 0; i < 10; i++) { - region.put("key" + (i + 200), "value" + (i + 200)); - } - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/security/GfshCommandsOverHttpSecurityTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/security/GfshCommandsOverHttpSecurityTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/security/GfshCommandsOverHttpSecurityTest.java deleted file mode 100644 index 313f31a..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/security/GfshCommandsOverHttpSecurityTest.java +++ /dev/null @@ -1,30 +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 com.gemstone.gemfire.management.internal.security; - -import com.gemstone.gemfire.test.junit.categories.IntegrationTest; - -import com.gemstone.gemfire.test.junit.categories.SecurityTest; -import org.junit.experimental.categories.Category; - -@Category({ IntegrationTest.class, SecurityTest.class }) -public class GfshCommandsOverHttpSecurityTest extends GfshCommandsSecurityTest { - public GfshCommandsOverHttpSecurityTest(){ - gfshConnection = new GfshShellConnectionRule(jmxPort, httpPort, true); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/AbstractWebTestCase.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/AbstractWebTestCase.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/AbstractWebTestCase.java deleted file mode 100644 index ae5c749..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/AbstractWebTestCase.java +++ /dev/null @@ -1,96 +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 com.gemstone.gemfire.management.internal.web; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Map; - -import com.gemstone.gemfire.internal.lang.StringUtils; -import com.gemstone.gemfire.management.internal.web.domain.Link; - -/** - * The AbstractWebDomainTests class is abstract base class containing functionality common to a test suite classes - * in the com.gemstone.gemfire.management.internal.web.domain package. - * <p/> - * @see java.net.URI - * @see java.net.URLDecoder - * @see java.net.URLEncoder - * @see com.gemstone.gemfire.management.internal.web.domain.Link - * @since GemFire 8.0 - */ -@SuppressWarnings("unused") -public abstract class AbstractWebTestCase { - - protected <E> E[] createArray(final E... array) { - return array; - } - - protected <K, V> Map<K, V> createMap(final K[] keys, final V[] values) { - assert keys != null : "The Keys for the Map cannot be null!"; - assert values != null : "The Values for the Map cannot be null!"; - assert keys.length == values.length; - - final Map<K, V> map = new HashMap<K, V>(keys.length); - int index = 0; - - for (final K key : keys) { - map.put(key, values[index++]); - } - - return map; - } - - protected String decode(final String encodedValue) throws UnsupportedEncodingException { - return URLDecoder.decode(encodedValue, StringUtils.UTF_8); - } - - protected String encode(final String value) throws UnsupportedEncodingException { - return URLEncoder.encode(value, StringUtils.UTF_8); - } - - protected String toString(final Link... links) throws UnsupportedEncodingException { - final StringBuilder buffer = new StringBuilder("["); - int count = 0; - - for (final Link link : links) { - buffer.append(count++ > 0 ? ", " : StringUtils.EMPTY_STRING).append(toString(link)); - - } - - buffer.append("]"); - - return buffer.toString(); - } - - protected String toString(final Link link) throws UnsupportedEncodingException { - return link.toHttpRequestLine(); - } - - protected String toString(final URI uri) throws UnsupportedEncodingException { - return decode(uri.toString()); - } - - protected URI toUri(final String uriString) throws UnsupportedEncodingException, URISyntaxException { - return new URI(encode(uriString)); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/ShellCommandsControllerJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/ShellCommandsControllerJUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/ShellCommandsControllerJUnitTest.java deleted file mode 100644 index 8fd3127..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/ShellCommandsControllerJUnitTest.java +++ /dev/null @@ -1,238 +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 com.gemstone.gemfire.management.internal.web.controllers; - -import static org.junit.Assert.*; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; - -import com.gemstone.gemfire.management.cli.CliMetaData; -import com.gemstone.gemfire.management.internal.cli.util.ClasspathScanLoadHelper; -import com.gemstone.gemfire.management.internal.web.domain.Link; -import com.gemstone.gemfire.management.internal.web.domain.LinkIndex; -import com.gemstone.gemfire.management.internal.web.util.UriUtils; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -/** - * The ShellCommandsControllerJUnitTest class is a test suite of test cases testing the contract and functionality of the - * ShellCommandsController class, and specifically ensuring that all GemFire Gfsh commands have a corresponding - * Management REST API call and web service endpoint in the GemFire Management REST Interface. - * <p/> - * @see org.junit.Test - * @see com.gemstone.gemfire.management.internal.web.controllers.ShellCommandsController - * @since GemFire 8.0 - */ -@Category(UnitTest.class) -public class ShellCommandsControllerJUnitTest { - - private static ShellCommandsController controller; - - @BeforeClass - public static void setupBeforeClass() { - controller = new ShellCommandsController(); - MockHttpServletRequest request = new MockHttpServletRequest(); - request.setContextPath("gemfire"); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); - } - - @AfterClass - public static void tearDownAfterClass() { - controller = null; - } - - private List<String> getCliCommands() { - try { - Set<Class<?>> commandClasses = ClasspathScanLoadHelper.loadAndGet( - "com.gemstone.gemfire.management.internal.cli.commands", CommandMarker.class, true); - - List<String> commands = new ArrayList<>(commandClasses.size()); - - for (Class<?> commandClass : commandClasses) { - for (Method method : commandClass.getMethods()) { - if (method.isAnnotationPresent(CliCommand.class)) { - if (!(method.isAnnotationPresent(CliMetaData.class) - && method.getAnnotation(CliMetaData.class).shellOnly())) - { - CliCommand commandAnnotation = method.getAnnotation(CliCommand.class); - commands.addAll(Arrays.asList(commandAnnotation.value())); - } - } - } - } - - return commands; - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - - private List<String> getControllerWebServiceEndpoints() { - RequestAttributes requestAttrs = RequestContextHolder.getRequestAttributes(); - HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttrs).getRequest(); - String scheme = servletRequest.getScheme(); - - try { - Set<Class<?>> controllerClasses = ClasspathScanLoadHelper.loadAndGet( - "com.gemstone.gemfire.management.internal.web.controllers", AbstractCommandsController.class, true); - - List<String> controllerWebServiceEndpoints = new ArrayList<>(controllerClasses.size()); - - for (Class<?> controllerClass : controllerClasses) { - if (!AbstractCommandsController.class.equals(controllerClass)) { - for (Method method : controllerClass.getMethods()) { - if (method.isAnnotationPresent(RequestMapping.class)) { - RequestMapping requestMappingAnnotation = method.getAnnotation(RequestMapping.class); - - String webServiceEndpoint = String.format("%1$s %2$s", requestMappingAnnotation.method()[0], - UriUtils.decode(controller.toUri(requestMappingAnnotation.value()[0], scheme).toString())); - - String[] requestParameters = requestMappingAnnotation.params(); - - if (requestParameters.length > 0) { - webServiceEndpoint += "?".concat( - com.gemstone.gemfire.internal.lang.StringUtils.concat(requestParameters, "&")); - } - - controllerWebServiceEndpoints.add(webServiceEndpoint); - } - } - } - } - - return controllerWebServiceEndpoints; - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Test - public void testUniqueIndex() { - LinkIndex linkIndex = controller.index("https"); - - List<String> conflicts = new ArrayList<>(); - Map<String, String> uriRelationMapping = new HashMap<>(linkIndex.size()); - - for (Link link : linkIndex) { - if (uriRelationMapping.containsKey(link.toHttpRequestLine())) { - conflicts.add(String.format("REST API endpoint (%1$s) for (%2$s) conflicts with the REST API endpoint for (%3$s)", - link.toHttpRequestLine(), link.getRelation(), uriRelationMapping.get(link.toHttpRequestLine()))); - } - else { - uriRelationMapping.put(link.toHttpRequestLine(), link.getRelation()); - } - } - - assertTrue(String.format("Conflicts: %1$s!", conflicts), conflicts.isEmpty()); - } - - @Test - public void testIndex() { - List<String> commands = getCliCommands(); - - assertNotNull(commands); - assertFalse(commands.isEmpty()); - - LinkIndex linkIndex = controller.index("https"); - - assertNotNull(linkIndex); - assertFalse(linkIndex.isEmpty()); - - List<String> linkCommands = new ArrayList<>(linkIndex.size()); - - for (Link link : linkIndex) { - linkCommands.add(link.getRelation()); - } - - assertEquals(linkIndex.size(), linkCommands.size()); - - List<String> missingLinkCommands = new ArrayList<>(commands); - - missingLinkCommands.removeAll(linkCommands); - - assertTrue(String.format( - "The GemFire Management REST API Link Index is missing Link(s) for the following command(s): %1$s", - missingLinkCommands), missingLinkCommands.isEmpty()); - } - - @Test - public void testCommandHasRestApiControllerWebServiceEndpoint() { - List<String> controllerWebServiceEndpoints = getControllerWebServiceEndpoints(); - - assertNotNull(controllerWebServiceEndpoints); - assertFalse(controllerWebServiceEndpoints.isEmpty()); - - LinkIndex linkIndex = controller.index("http"); - - assertNotNull(linkIndex); - assertFalse(linkIndex.isEmpty()); - - List<String> linkWebServiceEndpoints = new ArrayList<>(linkIndex.size()); - - for (Link link : linkIndex) { - linkWebServiceEndpoints.add(link.toHttpRequestLine()); - } - - assertEquals(linkIndex.size(), linkWebServiceEndpoints.size()); - - List<String> missingControllerWebServiceEndpoints = new ArrayList<>(linkWebServiceEndpoints); - - missingControllerWebServiceEndpoints.removeAll(controllerWebServiceEndpoints); - - assertTrue(String.format( - "The Management REST API Web Service Controllers in (%1$s) are missing the following REST API Web Service Endpoint(s): %2$s!", - getClass().getPackage().getName(), missingControllerWebServiceEndpoints), missingControllerWebServiceEndpoints.isEmpty()); - } - - @Test - public void testIndexUrisHaveCorrectScheme() { - String versionCmd = "version"; - List<String> controllerWebServiceEndpoints = getControllerWebServiceEndpoints(); - - assertNotNull(controllerWebServiceEndpoints); - assertFalse(controllerWebServiceEndpoints.isEmpty()); - - String testScheme = "xyz"; - LinkIndex linkIndex = controller.index(testScheme); - - assertNotNull(linkIndex); - assertFalse(linkIndex.isEmpty()); - - assertTrue(String.format("Link does not have correct scheme %1$s", linkIndex.find(versionCmd)), - testScheme.equals(linkIndex.find(versionCmd).getHref().getScheme())); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptorJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptorJUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptorJUnitTest.java deleted file mode 100644 index 0037a48..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/controllers/support/LoginHandlerInterceptorJUnitTest.java +++ /dev/null @@ -1,273 +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 com.gemstone.gemfire.management.internal.web.controllers.support; - -import static org.junit.Assert.*; - -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; - -import edu.umd.cs.mtc.MultithreadedTestCase; -import edu.umd.cs.mtc.TestFramework; -import org.jmock.Expectations; -import org.jmock.Mockery; -import org.jmock.lib.concurrent.Synchroniser; -import org.jmock.lib.legacy.ClassImposteriser; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -/** - * The LoginHandlerInterceptorJUnitTest class is a test suite of test cases to test the contract - * and functionality of the Spring HandlerInterceptor, LoginHandlerInterceptor class. - * - * @see org.jmock.Mockery - * @see org.junit.Assert - * @see org.junit.Test - * @since GemFire 8.0 - */ -@Category(UnitTest.class) -public class LoginHandlerInterceptorJUnitTest { - - private Mockery mockContext; - - @Before - public void setUp() { - mockContext = new Mockery(); - mockContext.setImposteriser(ClassImposteriser.INSTANCE); - mockContext.setThreadingPolicy(new Synchroniser()); - } - - @After - public void tearDown() { - mockContext.assertIsSatisfied(); - mockContext = null; - } - - private String createEnvironmentVariable(final String name) { - return (LoginHandlerInterceptor.ENVIRONMENT_VARIABLE_REQUEST_PARAMETER_PREFIX + name); - } - - private <T> Enumeration<T> enumeration(final Iterator<T> iterator) { - return new Enumeration<T>() { - public boolean hasMoreElements() { - return iterator.hasNext(); - } - public T nextElement() { - return iterator.next(); - } - }; - } - - @Test - public void testPreHandleAfterCompletion() throws Exception { - final Map<String, String> requestParameters = new HashMap<>(2); - final Map<String, String> requestHeaders = new HashMap<>(); - - requestParameters.put("parameter", "one"); - requestParameters.put(createEnvironmentVariable("variable"), "two"); - - final HttpServletRequest mockHttpRequest = mockContext.mock(HttpServletRequest.class, "testPreHandleAfterCompletion.HttpServletRequest"); - - mockContext.checking(new Expectations() {{ - oneOf(mockHttpRequest).getParameterNames(); - will(returnValue(enumeration(requestParameters.keySet().iterator()))); - oneOf(mockHttpRequest).getHeaderNames(); - will(returnValue(enumeration(requestHeaders.keySet().iterator()))); - oneOf(mockHttpRequest).getParameter(with(equal(createEnvironmentVariable("variable")))); - will(returnValue(requestParameters.get(createEnvironmentVariable("variable")))); - }}); - - LoginHandlerInterceptor handlerInterceptor = new LoginHandlerInterceptor(); - - Map<String, String> envBefore = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(envBefore); - assertTrue(envBefore.isEmpty()); - assertTrue(handlerInterceptor.preHandle(mockHttpRequest, null, null)); - - Map<String, String> envSet = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(envSet); - assertNotSame(envBefore, envSet); - assertEquals(1, envSet.size()); - assertTrue(envSet.containsKey("variable")); - assertEquals("two", envSet.get("variable")); - - handlerInterceptor.afterCompletion(mockHttpRequest, null, null, null); - - Map<String, String> envAfter = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(envAfter); - assertTrue(envAfter.isEmpty()); - } - - @Test - public void testHandlerInterceptorThreadSafety() throws Throwable { - TestFramework.runOnce(new HandlerInterceptorThreadSafetyMultiThreadedTestCase()); - } - - private final class HandlerInterceptorThreadSafetyMultiThreadedTestCase extends MultithreadedTestCase { - - private LoginHandlerInterceptor handlerInterceptor; - - private HttpServletRequest mockHttpRequestOne; - private HttpServletRequest mockHttpRequestTwo; - - @Override - public void initialize() { - super.initialize(); - - final Map<String, String> requestParametersOne = new HashMap<>(3); - final Map<String, String> requestHeaders = new HashMap<>(); - - requestParametersOne.put("param", "one"); - requestParametersOne.put(createEnvironmentVariable("STAGE"), "test"); - requestParametersOne.put(createEnvironmentVariable("GEMFIRE"), "/path/to/gemfire/700"); - - mockHttpRequestOne = mockContext.mock(HttpServletRequest.class, "testHandlerInterceptorThreadSafety.HttpServletRequest.1"); - - mockContext.checking(new Expectations() {{ - oneOf(mockHttpRequestOne).getParameterNames(); - will(returnValue(enumeration(requestParametersOne.keySet().iterator()))); - oneOf(mockHttpRequestOne).getHeaderNames(); - will(returnValue(enumeration(requestHeaders.keySet().iterator()))); - oneOf(mockHttpRequestOne).getParameter(with(equal(createEnvironmentVariable("STAGE")))); - will(returnValue(requestParametersOne.get(createEnvironmentVariable("STAGE")))); - oneOf(mockHttpRequestOne).getParameter(with(equal(createEnvironmentVariable("GEMFIRE")))); - will(returnValue(requestParametersOne.get(createEnvironmentVariable("GEMFIRE")))); - }}); - - mockHttpRequestTwo = mockContext.mock(HttpServletRequest.class, "testHandlerInterceptorThreadSafety.HttpServletRequest.2"); - - final Map<String, String> requestParametersTwo = new HashMap<>(3); - - requestParametersTwo.put("parameter", "two"); - requestParametersTwo.put(createEnvironmentVariable("HOST"), "localhost"); - requestParametersTwo.put(createEnvironmentVariable("GEMFIRE"), "/path/to/gemfire/75"); - - mockContext.checking(new Expectations() {{ - oneOf(mockHttpRequestTwo).getParameterNames(); - will(returnValue(enumeration(requestParametersTwo.keySet().iterator()))); - oneOf(mockHttpRequestTwo).getHeaderNames(); - will(returnValue(enumeration(requestHeaders.keySet().iterator()))); - oneOf(mockHttpRequestTwo).getParameter(with(equal(createEnvironmentVariable("HOST")))); - will(returnValue(requestParametersTwo.get(createEnvironmentVariable("HOST")))); - oneOf(mockHttpRequestTwo).getParameter(with(equal(createEnvironmentVariable("GEMFIRE")))); - will(returnValue(requestParametersTwo.get(createEnvironmentVariable("GEMFIRE")))); - }}); - - handlerInterceptor = new LoginHandlerInterceptor(); - } - - public void thread1() throws Exception { - assertTick(0); - Thread.currentThread().setName("HTTP Request Processing Thread 1"); - - Map<String, String> env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertTrue(env.isEmpty()); - assertTrue(handlerInterceptor.preHandle(mockHttpRequestOne, null, null)); - - env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertEquals(2, env.size()); - assertFalse(env.containsKey("param")); - assertFalse(env.containsKey("parameter")); - assertFalse(env.containsKey("HOST")); - assertEquals("test", env.get("STAGE")); - assertEquals("/path/to/gemfire/700", env.get("GEMFIRE")); - - waitForTick(2); - - env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertEquals(2, env.size()); - assertFalse(env.containsKey("param")); - assertFalse(env.containsKey("parameter")); - assertFalse(env.containsKey("HOST")); - assertEquals("test", env.get("STAGE")); - assertEquals("/path/to/gemfire/700", env.get("GEMFIRE")); - - waitForTick(4); - - env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertEquals(2, env.size()); - assertFalse(env.containsKey("param")); - assertFalse(env.containsKey("parameter")); - assertFalse(env.containsKey("HOST")); - assertEquals("test", env.get("STAGE")); - assertEquals("/path/to/gemfire/700", env.get("GEMFIRE")); - - handlerInterceptor.afterCompletion(mockHttpRequestOne, null, null, null); - - env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertTrue(env.isEmpty()); - } - - public void thread2() throws Exception { - assertTick(0); - Thread.currentThread().setName("HTTP Request Processing Thread 2"); - waitForTick(1); - - Map<String, String> env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertTrue(env.isEmpty()); - assertTrue(handlerInterceptor.preHandle(mockHttpRequestTwo, null, null)); - - env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertEquals(2, env.size()); - assertFalse(env.containsKey("parameter")); - assertFalse(env.containsKey("param")); - assertFalse(env.containsKey("STAGE")); - assertEquals("localhost", env.get("HOST")); - assertEquals("/path/to/gemfire/75", env.get("GEMFIRE")); - - waitForTick(3); - - handlerInterceptor.afterCompletion(mockHttpRequestTwo, null, null, null); - - env = LoginHandlerInterceptor.getEnvironment(); - - assertNotNull(env); - assertTrue(env.isEmpty()); - } - - @Override - public void finish() { - super.finish(); - handlerInterceptor = null; - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkIndexJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkIndexJUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkIndexJUnitTest.java deleted file mode 100644 index 61a9736..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkIndexJUnitTest.java +++ /dev/null @@ -1,236 +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 com.gemstone.gemfire.management.internal.web.domain; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.gemstone.gemfire.internal.util.CollectionUtils; -import com.gemstone.gemfire.management.internal.web.AbstractWebTestCase; -import com.gemstone.gemfire.management.internal.web.http.HttpMethod; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -/** - * The LinkIndexJUnitTest class is a test suite of test cases testing the contract and functionality of the LinkIndex class. - * <p/> - * @see java.net.URI - * @see com.gemstone.gemfire.management.internal.web.AbstractWebTestCase - * @see com.gemstone.gemfire.management.internal.web.domain.LinkIndex - * @see org.junit.Assert - * @see org.junit.Test - * @since GemFire 8.0 - */ -@Category(UnitTest.class) -public class LinkIndexJUnitTest extends AbstractWebTestCase { - - @Test - public void testAdd() throws Exception { - final Link link = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - assertEquals(0, linkIndex.size()); - assertEquals(linkIndex, linkIndex.add(link)); - assertFalse(linkIndex.isEmpty()); - assertEquals(1, linkIndex.size()); - assertEquals(linkIndex, linkIndex.add(link)); // test duplicate addition - assertFalse(linkIndex.isEmpty()); - assertEquals(1, linkIndex.size()); - } - - @Test(expected = AssertionError.class) - public void testAddNullLink() { - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - - try { - linkIndex.add(null); - } - finally { - assertTrue(linkIndex.isEmpty()); - } - } - - @Test - public void testAddAll() throws Exception { - final Link create = new Link("create-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.POST); - final Link retrieve = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - final Link update = new Link("update-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.PUT); - final Link delete = new Link("delete-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}"), HttpMethod.DELETE); - - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - assertEquals(linkIndex, linkIndex.addAll(create, retrieve, update, delete)); - assertFalse(linkIndex.isEmpty()); - assertEquals(4, linkIndex.size()); - } - - @Test(expected = AssertionError.class) - public void testAddAllWithNullLinks() { - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - - try { - linkIndex.addAll((Iterable<Link>) null); - } - finally { - assertTrue(linkIndex.isEmpty()); - } - } - - @Test - public void testFind() throws Exception { - final Link list = new Link("get-resources", toUri("http://host.domain.com:port/service/v1/resources")); - final Link create = new Link("create-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.POST); - final Link retrieve = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - final Link update = new Link("update-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.PUT); - final Link delete = new Link("delete-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}"), HttpMethod.DELETE); - - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - assertEquals(linkIndex, linkIndex.addAll(list, create, retrieve, update, delete)); - assertFalse(linkIndex.isEmpty()); - assertEquals(5, linkIndex.size()); - assertEquals(list, linkIndex.find("get-resources")); - assertEquals(retrieve, linkIndex.find("get-resource")); - assertEquals(update, linkIndex.find("UPDATE-RESOURCE")); - assertEquals(delete, linkIndex.find("Delete-Resource")); - assertNull(linkIndex.find("destroy-resource")); - assertNull(linkIndex.find("save-resource")); - } - - @Test - public void testFindAll() throws Exception { - final Link list = new Link("get-resources", toUri("http://host.domain.com:port/service/v1/resources")); - final Link create = new Link("create-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.POST); - final Link retrieveById = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - final Link retrieveByName = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{name}")); - final Link update = new Link("update-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.PUT); - final Link delete = new Link("delete-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}"), HttpMethod.DELETE); - - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - assertEquals(linkIndex, linkIndex.addAll(list, create, retrieveById, retrieveByName, update, delete)); - assertFalse(linkIndex.isEmpty()); - assertEquals(6, linkIndex.size()); - - final Link[] retrieveLinks = linkIndex.findAll("get-resource"); - - assertNotNull(retrieveLinks); - assertEquals(2, retrieveLinks.length); - assertTrue(Arrays.asList(retrieveLinks).containsAll(Arrays.asList(retrieveById, retrieveByName))); - - final Link[] saveLinks = linkIndex.findAll("save-resource"); - - assertNotNull(saveLinks); - assertEquals(0, saveLinks.length); - } - - @Test - public void testIterator() throws Exception { - final Link list = new Link("get-resources", toUri("http://host.domain.com:port/service/v1/resources")); - final Link create = new Link("create-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.POST); - final Link retrieveById = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - final Link retrieveByName = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{name}")); - final Link update = new Link("update-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.PUT); - final Link delete = new Link("delete-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}"), HttpMethod.DELETE); - - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - assertEquals(linkIndex, linkIndex.addAll(list, create, retrieveById, retrieveByName, update, delete)); - assertFalse(linkIndex.isEmpty()); - assertEquals(6, linkIndex.size()); - - final Collection<Link> expectedLinks = Arrays.asList(list, create, retrieveById, retrieveByName, update, delete); - - final Collection<Link> actualLinks = new ArrayList<Link>(linkIndex.size()); - - for (final Link link : linkIndex) { - actualLinks.add(link); - } - - assertTrue(actualLinks.containsAll(expectedLinks)); - } - - @Test - public void testToList() throws Exception { - final Link list = new Link("get-resources", toUri("http://host.domain.com:port/service/v1/resources")); - final Link create = new Link("create-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.POST); - final Link retrieveById = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - final Link retrieveByName = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{name}")); - final Link update = new Link("update-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.PUT); - final Link delete = new Link("delete-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}"), HttpMethod.DELETE); - - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - assertEquals(linkIndex, linkIndex.addAll(list, create, retrieveById, retrieveByName, update, delete)); - assertFalse(linkIndex.isEmpty()); - assertEquals(6, linkIndex.size()); - - final List<Link> expectedList = CollectionUtils.asList(list, create, retrieveById, retrieveByName, update, delete); - - Collections.sort(expectedList); - - assertEquals(expectedList, linkIndex.toList()); - } - - @Test - public void testToMap() throws Exception { - final Link list = new Link("get-resources", toUri("http://host.domain.com:port/service/v1/resources")); - final Link create = new Link("create-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.POST); - final Link retrieveById = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - final Link retrieveByName = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{name}")); - final Link update = new Link("update-resource", toUri("http://host.domain.com:port/service/v1/resources"), HttpMethod.PUT); - final Link delete = new Link("delete-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}"), HttpMethod.DELETE); - - final LinkIndex linkIndex = new LinkIndex(); - - assertTrue(linkIndex.isEmpty()); - assertEquals(linkIndex, linkIndex.addAll(list, create, retrieveById, retrieveByName, update, delete)); - assertFalse(linkIndex.isEmpty()); - assertEquals(6, linkIndex.size()); - - final Map<String, List<Link>> expectedMap = new HashMap<String, List<Link>>(5); - - expectedMap.put("get-resources", Arrays.asList(list)); - expectedMap.put("create-resource", Arrays.asList(create)); - expectedMap.put("get-resource", Arrays.asList(retrieveById, retrieveByName)); - expectedMap.put("update-resource", Arrays.asList(update)); - expectedMap.put("delete-resource", Arrays.asList(delete)); - - assertEquals(expectedMap, linkIndex.toMap()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkJUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkJUnitTest.java deleted file mode 100644 index c0b1620..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/LinkJUnitTest.java +++ /dev/null @@ -1,123 +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 com.gemstone.gemfire.management.internal.web.domain; - -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import com.gemstone.gemfire.internal.util.CollectionUtils; -import com.gemstone.gemfire.management.internal.web.AbstractWebTestCase; -import com.gemstone.gemfire.management.internal.web.http.HttpMethod; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -/** - * The LinkJUnitTest class is a test suite of test cases testing the contract and functionality of the Link class. - * <p/> - * @see java.net.URI - * @see com.gemstone.gemfire.management.internal.web.AbstractWebTestCase - * @see com.gemstone.gemfire.management.internal.web.domain.Link - * @see org.junit.Assert - * @see org.junit.Test - * @since GemFire 8.0 - */ -@Category(UnitTest.class) -public class LinkJUnitTest extends AbstractWebTestCase { - - @Test - public void testConstructDefaultLink() { - final Link link = new Link(); - - assertNotNull(link); - assertNull(link.getHref()); - assertNull(link.getMethod()); - assertNull(link.getRelation()); - } - - @Test - public void testConstructLinkWithRelationAndHref() throws Exception { - final Link link = new Link("get-resource", toUri("http://host:port/service/v1/resources/{id}")); - - assertNotNull(link); - assertEquals("http://host:port/service/v1/resources/{id}", toString(link.getHref())); - assertEquals(HttpMethod.GET, link.getMethod()); - assertEquals("get-resource", link.getRelation()); - } - - @Test - public void testConstructLinkWithRelationHrefAndMethod() throws Exception { - final Link link = new Link("create-resource", toUri("http://host:port/service/v1/resources"), HttpMethod.POST); - - assertNotNull(link); - assertEquals("http://host:port/service/v1/resources", toString(link.getHref())); - assertEquals(HttpMethod.POST, link.getMethod()); - assertEquals("create-resource", link.getRelation()); - } - - @Test - public void testSetAndGetMethod() { - final Link link = new Link(); - - assertNotNull(link); - assertNull(link.getMethod()); - - link.setMethod(HttpMethod.POST); - - assertEquals(HttpMethod.POST, link.getMethod()); - - link.setMethod(null); - - assertEquals(HttpMethod.GET, link.getMethod()); - } - - @Test - public void testCompareTo() throws Exception { - final Link link0 = new Link("resources", toUri("http://host:port/service/v1/resources")); - final Link link1 = new Link("resource", toUri("http://host:port/service/v1/resources"), HttpMethod.POST); - final Link link2 = new Link("resource", toUri("http://host:port/service/v1/resources/{id}")); - final Link link3 = new Link("resource", toUri("http://host:port/service/v1/resources/{name}")); - final Link link4 = new Link("resource", toUri("http://host:port/service/v1/resources/{id}"), HttpMethod.DELETE); - - final List<Link> expectedList = new ArrayList<Link>(Arrays.asList(link1, link4, link2, link3, link0)); - - final List<Link> actualList = CollectionUtils.asList(link0, link1, link2, link3, link4); - - Collections.sort(actualList); - - System.out.println(toString(expectedList.toArray(new Link[expectedList.size()]))); - System.out.println(toString(actualList.toArray(new Link[actualList.size()]))); - - assertEquals(expectedList, actualList); - } - - @Test - public void testToHttpRequestLine() throws Exception { - final Link link = new Link("get-resource", toUri("http://host.domain.com:port/service/v1/resources/{id}")); - - assertNotNull(link); - assertEquals(HttpMethod.GET, link.getMethod()); - assertEquals("http://host.domain.com:port/service/v1/resources/{id}", toString(link.getHref())); - assertEquals("GET ".concat("http://host.domain.com:port/service/v1/resources/{id}"), link.toHttpRequestLine()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7c20e693/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/QueryParameterSourceJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/QueryParameterSourceJUnitTest.java b/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/QueryParameterSourceJUnitTest.java deleted file mode 100644 index ae2f87b..0000000 --- a/geode-web/src/test/java/com/gemstone/gemfire/management/internal/web/domain/QueryParameterSourceJUnitTest.java +++ /dev/null @@ -1,92 +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 com.gemstone.gemfire.management.internal.web.domain; - -import static org.junit.Assert.*; - -import java.io.IOException; - -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; -import javax.management.Query; -import javax.management.QueryExp; - -import com.gemstone.gemfire.internal.util.IOUtils; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -/** - * The QueryParameterSourceJUnitTest class is a test suite of test cases testing the contract and functionality of the - * QueryParameterSource class. - * <p/> - * @see com.gemstone.gemfire.management.internal.web.domain.QueryParameterSource - * @see org.junit.Assert - * @see org.junit.Test - * @since GemFire 8.0 - */ -@Category(UnitTest.class) -public class QueryParameterSourceJUnitTest { - - @Test - public void testCreateQueryParameterSource() throws MalformedObjectNameException { - final ObjectName expectedObjectName = ObjectName.getInstance("GemFire:type=Member,*"); - - final QueryExp expectedQueryExpression = Query.eq(Query.attr("id"), Query.value("12345")); - - final QueryParameterSource query = new QueryParameterSource(expectedObjectName, expectedQueryExpression); - - assertNotNull(query); - assertSame(expectedObjectName, query.getObjectName()); - assertSame(expectedQueryExpression, query.getQueryExpression()); - } - - @Test - public void testSerialization() throws ClassNotFoundException, IOException, MalformedObjectNameException { - final ObjectName expectedObjectName = ObjectName.getInstance("GemFire:type=Member,*"); - - final QueryExp expectedQueryExpression = Query.or( - Query.eq(Query.attr("name"), Query.value("myName")), - Query.eq(Query.attr("id"), Query.value("myId")) - ); - - final QueryParameterSource expectedQuery = new QueryParameterSource(expectedObjectName, expectedQueryExpression); - - assertNotNull(expectedQuery); - assertSame(expectedObjectName, expectedQuery.getObjectName()); - assertSame(expectedQueryExpression, expectedQuery.getQueryExpression()); - - final byte[] queryBytes = IOUtils.serializeObject(expectedQuery); - - assertNotNull(queryBytes); - assertTrue(queryBytes.length != 0); - - final Object queryObj = IOUtils.deserializeObject(queryBytes); - - assertTrue(queryObj instanceof QueryParameterSource); - - final QueryParameterSource actualQuery = (QueryParameterSource) queryObj; - - assertNotSame(expectedQuery, actualQuery); - assertNotNull(actualQuery.getObjectName()); - assertEquals(expectedQuery.getObjectName().toString(), actualQuery.getObjectName().toString()); - assertNotNull(actualQuery.getQueryExpression()); - assertEquals(expectedQuery.getQueryExpression().toString(), actualQuery.getQueryExpression().toString()); - } - -}
