You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/10/26 22:49:06 UTC
[40/93] [partial] incubator-geode git commit: Added Spotless plugin
to enforce formatting standards. Added Google Java Style guide formatter
templates, removed existing formatter templates.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsJUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsJUnitTest.java
index 7d280c9..8ac5dd5 100755
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsJUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/cli/commands/LauncherLifecycleCommandsJUnitTest.java
@@ -1,18 +1,16 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -44,8 +42,8 @@ import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.test.junit.categories.UnitTest;
/**
- * The LauncherLifecycleCommandsJUnitTest class is a test suite of test cases testing the contract and functionality of
- * the lifecycle launcher GemFire shell (Gfsh) commands.
+ * The LauncherLifecycleCommandsJUnitTest class is a test suite of test cases testing the contract
+ * and functionality of the lifecycle launcher GemFire shell (Gfsh) commands.
*
* @see org.apache.geode.management.internal.cli.commands.LauncherLifecycleCommands
* @see org.junit.Assert
@@ -86,7 +84,8 @@ public class LauncherLifecycleCommandsJUnitTest {
assertTrue(commandLine.isEmpty());
- getLauncherLifecycleCommands().addGemFirePropertyFile(commandLine, "/path/to/gemfire.properties");
+ getLauncherLifecycleCommands().addGemFirePropertyFile(commandLine,
+ "/path/to/gemfire.properties");
assertFalse(commandLine.isEmpty());
assertTrue(commandLine.contains("-DgemfirePropertyFile=/path/to/gemfire.properties"));
@@ -119,10 +118,12 @@ public class LauncherLifecycleCommandsJUnitTest {
final String propertyValue = gemfireProperties.getProperty(propertyName);
if (StringUtils.isBlank(propertyValue)) {
for (final String systemProperty : commandLine) {
- assertFalse(systemProperty.startsWith("-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
+ assertFalse(systemProperty.startsWith(
+ "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
}
} else {
- assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=").concat(propertyValue)));
+ assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
+ + "".concat(propertyName).concat("=").concat(propertyValue)));
}
}
}
@@ -147,7 +148,7 @@ public class LauncherLifecycleCommandsJUnitTest {
gemfireProperties.setProperty(NAME, "machine");
gemfireProperties.setProperty(START_DEV_REST_API, "true");
- gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8080");
+ gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8080");
gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
@@ -160,10 +161,12 @@ public class LauncherLifecycleCommandsJUnitTest {
final String propertyValue = gemfireProperties.getProperty(propertyName);
if (StringUtils.isBlank(propertyValue)) {
for (final String systemProperty : commandLine) {
- assertFalse(systemProperty.startsWith("-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
+ assertFalse(systemProperty.startsWith(
+ "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
}
} else {
- assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=").concat(propertyValue)));
+ assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
+ + "".concat(propertyName).concat("=").concat(propertyValue)));
}
}
}
@@ -202,12 +205,12 @@ public class LauncherLifecycleCommandsJUnitTest {
assertTrue(commandLine.isEmpty());
- getLauncherLifecycleCommands().addJvmArgumentsAndOptions(commandLine, new String[]{});
+ getLauncherLifecycleCommands().addJvmArgumentsAndOptions(commandLine, new String[] {});
assertTrue(commandLine.isEmpty());
getLauncherLifecycleCommands().addJvmArgumentsAndOptions(commandLine,
- new String[]{"-DmyProp=myVal", "-d64", "-server", "-Xprof"});
+ new String[] {"-DmyProp=myVal", "-d64", "-server", "-Xprof"});
assertFalse(commandLine.isEmpty());
assertEquals(4, commandLine.size());
@@ -265,8 +268,8 @@ public class LauncherLifecycleCommandsJUnitTest {
assertEquals(3, commandLine.size());
assertEquals("-Xmx1024M", commandLine.get(0));
assertEquals("-XX:+UseConcMarkSweepGC", commandLine.get(1));
- assertEquals("-XX:CMSInitiatingOccupancyFraction=" + LauncherLifecycleCommands.CMS_INITIAL_OCCUPANCY_FRACTION,
- commandLine.get(2));
+ assertEquals("-XX:CMSInitiatingOccupancyFraction="
+ + LauncherLifecycleCommands.CMS_INITIAL_OCCUPANCY_FRACTION, commandLine.get(2));
}
@Test(expected = AssertionError.class)
@@ -274,7 +277,8 @@ public class LauncherLifecycleCommandsJUnitTest {
try {
getLauncherLifecycleCommands().readPid(null);
} catch (AssertionError expected) {
- assertEquals("The file from which to read the process ID (pid) cannot be null!", expected.getMessage());
+ assertEquals("The file from which to read the process ID (pid) cannot be null!",
+ expected.getMessage());
throw expected;
}
}
@@ -282,28 +286,32 @@ public class LauncherLifecycleCommandsJUnitTest {
@Test
@SuppressWarnings("deprecation")
public void testGetClasspath() {
- assertEquals(System.getProperty("java.class.path"), getLauncherLifecycleCommands().getClasspath(null));
+ assertEquals(System.getProperty("java.class.path"),
+ getLauncherLifecycleCommands().getClasspath(null));
}
@Test
@SuppressWarnings("deprecation")
public void testGetClasspathWithUserDefinedClasspath() {
- assertEquals(System.getProperty("java.class.path") + File.pathSeparator + "/path/to/user/classes",
+ assertEquals(
+ System.getProperty("java.class.path") + File.pathSeparator + "/path/to/user/classes",
getLauncherLifecycleCommands().getClasspath("/path/to/user/classes"));
}
@Test
public void testGetSystemClasspath() {
- assertEquals(System.getProperty("java.class.path"), getLauncherLifecycleCommands().getSystemClasspath());
+ assertEquals(System.getProperty("java.class.path"),
+ getLauncherLifecycleCommands().getSystemClasspath());
}
@Test
public void testLocatorClasspathOrder() {
String userClasspath = "/path/to/user/lib/app.jar:/path/to/user/classes";
- String expectedClasspath = launcherCommands.getGemFireJarPath().concat(File.pathSeparator).concat(
- userClasspath).concat(File.pathSeparator).concat(System.getProperty("java.class.path")).concat(
- File.pathSeparator).concat(LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME);
+ String expectedClasspath = launcherCommands.getGemFireJarPath().concat(File.pathSeparator)
+ .concat(userClasspath).concat(File.pathSeparator)
+ .concat(System.getProperty("java.class.path")).concat(File.pathSeparator)
+ .concat(LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME);
String actualClasspath = launcherCommands.getLocatorClasspath(true, userClasspath);
@@ -314,9 +322,9 @@ public class LauncherLifecycleCommandsJUnitTest {
public void testServerClasspathOrder() {
String userClasspath = "/path/to/user/lib/app.jar:/path/to/user/classes";
- String expectedClasspath = launcherCommands.getGemFireJarPath().concat(File.pathSeparator).concat(
- userClasspath).concat(File.pathSeparator).concat(
- LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME);
+ String expectedClasspath = launcherCommands.getGemFireJarPath().concat(File.pathSeparator)
+ .concat(userClasspath).concat(File.pathSeparator)
+ .concat(LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME);
String actualClasspath = launcherCommands.getServerClasspath(false, userClasspath);
@@ -328,31 +336,35 @@ public class LauncherLifecycleCommandsJUnitTest {
final boolean EXCLUDE_SYSTEM_CLASSPATH = false;
final boolean INCLUDE_SYSTEM_CLASSPATH = true;
- String[] jarFilePathnames = {"/path/to/user/libs/A.jar", "/path/to/user/libs/B.jar", "/path/to/user/libs/C.jar"};
+ String[] jarFilePathnames =
+ {"/path/to/user/libs/A.jar", "/path/to/user/libs/B.jar", "/path/to/user/libs/C.jar"};
- String[] userClasspaths = {"/path/to/classes:/path/to/libs/1.jar:/path/to/libs/2.jar", "/path/to/ext/libs/1.jar:/path/to/ext/classes:/path/to/ext/lib/10.jar"};
+ String[] userClasspaths = {"/path/to/classes:/path/to/libs/1.jar:/path/to/libs/2.jar",
+ "/path/to/ext/libs/1.jar:/path/to/ext/classes:/path/to/ext/lib/10.jar"};
- String expectedClasspath = LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME.concat(File.pathSeparator).concat(
- toClasspath(userClasspaths)).concat(File.pathSeparator).concat(toClasspath(jarFilePathnames));
+ String expectedClasspath = LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME
+ .concat(File.pathSeparator).concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
+ .concat(toClasspath(jarFilePathnames));
- assertEquals(expectedClasspath,
- getLauncherLifecycleCommands().toClasspath(EXCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
+ assertEquals(expectedClasspath, getLauncherLifecycleCommands()
+ .toClasspath(EXCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
- expectedClasspath = LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME.concat(File.pathSeparator).concat(
- toClasspath(userClasspaths)).concat(File.pathSeparator).concat(System.getProperty("java.class.path")).concat(
- File.pathSeparator).concat(toClasspath(jarFilePathnames));
+ expectedClasspath = LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
+ .concat(System.getProperty("java.class.path")).concat(File.pathSeparator)
+ .concat(toClasspath(jarFilePathnames));
- assertEquals(expectedClasspath,
- getLauncherLifecycleCommands().toClasspath(INCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
+ assertEquals(expectedClasspath, getLauncherLifecycleCommands()
+ .toClasspath(INCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
- expectedClasspath = LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME.concat(File.pathSeparator).concat(
- System.getProperty("java.class.path"));
+ expectedClasspath = LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(System.getProperty("java.class.path"));
- assertEquals(expectedClasspath,
- getLauncherLifecycleCommands().toClasspath(INCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
+ assertEquals(expectedClasspath, getLauncherLifecycleCommands()
+ .toClasspath(INCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
- assertEquals(LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME,
- getLauncherLifecycleCommands().toClasspath(EXCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
+ assertEquals(LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME, getLauncherLifecycleCommands()
+ .toClasspath(EXCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
assertEquals(LauncherLifecycleCommands.GEMFIRE_JAR_PATHNAME,
getLauncherLifecycleCommands().toClasspath(EXCLUDE_SYSTEM_CLASSPATH, new String[0], ""));
@@ -361,16 +373,19 @@ public class LauncherLifecycleCommandsJUnitTest {
@Test
public void testToClassPathOrder() {
String userClasspathOne = "/path/to/user/lib/a.jar:/path/to/user/classes";
- String userClasspathTwo = "/path/to/user/lib/x.jar:/path/to/user/lib/y.jar:/path/to/user/lib/z.jar";
+ String userClasspathTwo =
+ "/path/to/user/lib/x.jar:/path/to/user/lib/y.jar:/path/to/user/lib/z.jar";
- String expectedClasspath = launcherCommands.getGemFireJarPath().concat(File.pathSeparator).concat(
- userClasspathOne).concat(File.pathSeparator).concat(userClasspathTwo).concat(File.pathSeparator).concat(
- System.getProperty("java.class.path")).concat(File.pathSeparator).concat(
- LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME).concat(File.pathSeparator).concat(
- LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME);
+ String expectedClasspath = launcherCommands.getGemFireJarPath().concat(File.pathSeparator)
+ .concat(userClasspathOne).concat(File.pathSeparator).concat(userClasspathTwo)
+ .concat(File.pathSeparator).concat(System.getProperty("java.class.path"))
+ .concat(File.pathSeparator).concat(LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME)
+ .concat(File.pathSeparator)
+ .concat(LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME);
String actualClasspath = launcherCommands.toClasspath(true,
- new String[]{LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME, LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME},
+ new String[] {LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME,
+ LauncherLifecycleCommands.CORE_DEPENDENCIES_JAR_PATHNAME},
userClasspathOne, userClasspathTwo);
assertEquals(expectedClasspath, actualClasspath);
@@ -378,18 +393,18 @@ public class LauncherLifecycleCommandsJUnitTest {
@Test
public void testGetJavaPathname() {
- assertEquals(IOUtils.appendToPath(System.getProperty("java.home"), "bin",
- "java" + LauncherLifecycleCommands.getExecutableSuffix()),
- getLauncherLifecycleCommands().getJdkToolPathname("java" + LauncherLifecycleCommands.getExecutableSuffix(),
- new GemFireException() {
- }));
+ assertEquals(
+ IOUtils.appendToPath(System.getProperty("java.home"), "bin",
+ "java" + LauncherLifecycleCommands.getExecutableSuffix()),
+ getLauncherLifecycleCommands().getJdkToolPathname(
+ "java" + LauncherLifecycleCommands.getExecutableSuffix(), new GemFireException() {}));
}
@Test(expected = NullPointerException.class)
public void testGetJdkToolPathnameWithNullPathnames() {
try {
- getLauncherLifecycleCommands().getJdkToolPathname((Stack<String>) null, new GemFireException() {
- });
+ getLauncherLifecycleCommands().getJdkToolPathname((Stack<String>) null,
+ new GemFireException() {});
} catch (NullPointerException expected) {
assertEquals("The JDK tool executable pathnames cannot be null!", expected.getMessage());
throw expected;
@@ -451,22 +466,23 @@ public class LauncherLifecycleCommandsJUnitTest {
try {
System.err.println(getLauncherLifecycleCommands().getJmxServiceUrlAsString("memberOne[]"));
} catch (IllegalArgumentException expected) {
- assertEquals(CliStrings.START_JCONSOLE__CONNECT_BY_MEMBER_NAME_ID_ERROR_MESSAGE, expected.getMessage());
+ assertEquals(CliStrings.START_JCONSOLE__CONNECT_BY_MEMBER_NAME_ID_ERROR_MESSAGE,
+ expected.getMessage());
throw expected;
}
}
@Test
public void testCreateServerCommandLine() throws Exception {
- ServerLauncher serverLauncher = new ServerLauncher.Builder().setCommand(
- ServerLauncher.Command.START).setDisableDefaultServer(true).setMemberName(
- "testCreateServerCommandLine").setRebalance(true)
- //.setServerBindAddress("localhost")
+ ServerLauncher serverLauncher = new ServerLauncher.Builder()
+ .setCommand(ServerLauncher.Command.START).setDisableDefaultServer(true)
+ .setMemberName("testCreateServerCommandLine").setRebalance(true)
+ // .setServerBindAddress("localhost")
.setServerPort(41214).setCriticalHeapPercentage(95.5f).setEvictionHeapPercentage(85.0f)
- .setSocketBufferSize(1024*1024).setMessageTimeToLive(93).build();
+ .setSocketBufferSize(1024 * 1024).setMessageTimeToLive(93).build();
- String[] commandLineElements = launcherCommands.createStartServerCommandLine(serverLauncher, null, null,
- new Properties(), null, false, new String[0], false, null, null);
+ String[] commandLineElements = launcherCommands.createStartServerCommandLine(serverLauncher,
+ null, null, new Properties(), null, false, new String[0], false, null, null);
assertNotNull(commandLineElements);
assertTrue(commandLineElements.length > 0);
@@ -477,14 +493,18 @@ public class LauncherLifecycleCommandsJUnitTest {
expectedCommandLineElements.add("--disable-default-server");
expectedCommandLineElements.add(serverLauncher.getMemberName().toLowerCase());
expectedCommandLineElements.add("--rebalance");
- //expectedCommandLineElements.add(String.format("--server-bind-address=%1$s", serverLauncher.getServerBindAddress().getHostName()));
- expectedCommandLineElements.add(String.format("--server-port=%1$d", serverLauncher.getServerPort()));
- expectedCommandLineElements.add(
- String.format("--critical-heap-percentage=%1$s", serverLauncher.getCriticalHeapPercentage()));
- expectedCommandLineElements.add(
- String.format("--eviction-heap-percentage=%1$s", serverLauncher.getEvictionHeapPercentage()));
- expectedCommandLineElements.add(String.format("--socket-buffer-size=%1$d", serverLauncher.getSocketBufferSize()));
- expectedCommandLineElements.add(String.format("--message-time-to-live=%1$d", serverLauncher.getMessageTimeToLive()));
+ // expectedCommandLineElements.add(String.format("--server-bind-address=%1$s",
+ // serverLauncher.getServerBindAddress().getHostName()));
+ expectedCommandLineElements
+ .add(String.format("--server-port=%1$d", serverLauncher.getServerPort()));
+ expectedCommandLineElements.add(String.format("--critical-heap-percentage=%1$s",
+ serverLauncher.getCriticalHeapPercentage()));
+ expectedCommandLineElements.add(String.format("--eviction-heap-percentage=%1$s",
+ serverLauncher.getEvictionHeapPercentage()));
+ expectedCommandLineElements
+ .add(String.format("--socket-buffer-size=%1$d", serverLauncher.getSocketBufferSize()));
+ expectedCommandLineElements
+ .add(String.format("--message-time-to-live=%1$d", serverLauncher.getMessageTimeToLive()));
for (String commandLineElement : commandLineElements) {
expectedCommandLineElements.remove(commandLineElement.toLowerCase());
@@ -496,20 +516,21 @@ public class LauncherLifecycleCommandsJUnitTest {
@Test
public void testCreateServerCommandLineWithRestAPI() throws Exception {
- ServerLauncher serverLauncher = new ServerLauncher.Builder().setCommand(
- ServerLauncher.Command.START).setDisableDefaultServer(true).setMemberName(
- "testCreateServerCommandLine").setRebalance(true)
- //.setServerBindAddress("localhost")
- .setServerPort(41214).setCriticalHeapPercentage(95.5f).setEvictionHeapPercentage(85.0f).build();
+ ServerLauncher serverLauncher = new ServerLauncher.Builder()
+ .setCommand(ServerLauncher.Command.START).setDisableDefaultServer(true)
+ .setMemberName("testCreateServerCommandLine").setRebalance(true)
+ // .setServerBindAddress("localhost")
+ .setServerPort(41214).setCriticalHeapPercentage(95.5f).setEvictionHeapPercentage(85.0f)
+ .build();
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty(START_DEV_REST_API, "true");
- gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8080");
- gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
+ gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8080");
+ gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
- String[] commandLineElements = launcherCommands.createStartServerCommandLine(serverLauncher, null, null,
- gemfireProperties, null, false, new String[0], false, null, null);
+ String[] commandLineElements = launcherCommands.createStartServerCommandLine(serverLauncher,
+ null, null, gemfireProperties, null, false, new String[0], false, null, null);
assertNotNull(commandLineElements);
assertTrue(commandLineElements.length > 0);
@@ -520,16 +541,21 @@ public class LauncherLifecycleCommandsJUnitTest {
expectedCommandLineElements.add("--disable-default-server");
expectedCommandLineElements.add(serverLauncher.getMemberName().toLowerCase());
expectedCommandLineElements.add("--rebalance");
- //expectedCommandLineElements.add(String.format("--server-bind-address=%1$s", serverLauncher.getServerBindAddress().getHostName()));
- expectedCommandLineElements.add(String.format("--server-port=%1$d", serverLauncher.getServerPort()));
- expectedCommandLineElements.add(
- String.format("--critical-heap-percentage=%1$s", serverLauncher.getCriticalHeapPercentage()));
- expectedCommandLineElements.add(
- String.format("--eviction-heap-percentage=%1$s", serverLauncher.getEvictionHeapPercentage()));
-
- expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + START_DEV_REST_API + "=" + "true");
- expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_PORT + "=" + "8080");
- expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_BIND_ADDRESS + "=" + "localhost");
+ // expectedCommandLineElements.add(String.format("--server-bind-address=%1$s",
+ // serverLauncher.getServerBindAddress().getHostName()));
+ expectedCommandLineElements
+ .add(String.format("--server-port=%1$d", serverLauncher.getServerPort()));
+ expectedCommandLineElements.add(String.format("--critical-heap-percentage=%1$s",
+ serverLauncher.getCriticalHeapPercentage()));
+ expectedCommandLineElements.add(String.format("--eviction-heap-percentage=%1$s",
+ serverLauncher.getEvictionHeapPercentage()));
+
+ expectedCommandLineElements
+ .add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + START_DEV_REST_API + "=" + "true");
+ expectedCommandLineElements
+ .add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_PORT + "=" + "8080");
+ expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + ""
+ + HTTP_SERVICE_BIND_ADDRESS + "=" + "localhost");
for (String commandLineElement : commandLineElements) {
@@ -537,14 +563,14 @@ public class LauncherLifecycleCommandsJUnitTest {
}
assertTrue(String.format("Expected ([]); but was (%1$s)", expectedCommandLineElements),
- expectedCommandLineElements.isEmpty());
+ expectedCommandLineElements.isEmpty());
}
@Test
public void testReadPidWithNonExistingFile() {
assertEquals(LauncherLifecycleCommands.INVALID_PID,
- getLauncherLifecycleCommands().readPid(new File("/path/to/non_existing/pid.file")));
+ getLauncherLifecycleCommands().readPid(new File("/path/to/non_existing/pid.file")));
}
private LauncherLifecycleCommands getLauncherLifecycleCommands() {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java
index 1b9f103..ec329d3 100644
--- a/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/management/internal/configuration/SharedConfigurationEndToEndDUnitTest.java
@@ -1,18 +1,16 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.configuration;
@@ -104,7 +102,7 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
@Override
public final void preTearDownCliCommandTestBase() throws Exception {
- //shutdown everything
+ // shutdown everything
shutdownAll();
serverNames.clear();
@@ -131,13 +129,15 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
verifyAsyncEventQueueCreation();
}
- private Set<String> startServers(final HeadlessGfsh gfsh, final String locatorString, final int numServers, final String serverNamePrefix, final int startNum) throws ClassNotFoundException, IOException {
+ private Set<String> startServers(final HeadlessGfsh gfsh, final String locatorString,
+ final int numServers, final String serverNamePrefix, final int startNum)
+ throws ClassNotFoundException, IOException {
Set<String> serverNames = new HashSet<>();
final int[] serverPorts = getRandomAvailableTCPPorts(numServers);
- for (int i=0; i<numServers; i++) {
+ for (int i = 0; i < numServers; i++) {
int port = serverPorts[i];
- String serverName = serverNamePrefix+ Integer.toString(i+startNum) + "-" + port;
+ String serverName = serverNamePrefix + Integer.toString(i + startNum) + "-" + port;
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.START_SERVER);
csb.addOption(CliStrings.START_SERVER__NAME, serverName);
@@ -154,8 +154,9 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
private void doCreateCommands() throws IOException {
createRegion(REGION1, REPLICATE, null);
createRegion(REGION2, PARTITION, null);
- createIndex(INDEX1 , "AAPL", REGION1, null);
- createAndDeployJar(this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "Deploy1.jar");
+ createIndex(INDEX1, "AAPL", REGION1, null);
+ createAndDeployJar(
+ this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "Deploy1.jar");
createAsyncEventQueue("q1");
final String autoCompact = "true";
final String allowForceCompaction = "true";
@@ -165,11 +166,12 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
final String maxOplogSize = "1000";
final String queueSize = "300";
final String timeInterval = "10";
- final String writeBufferSize="100";
+ final String writeBufferSize = "100";
final String diskStoreName = "ds1";
final String diskDirs = "ds1";
-
- createDiskStore(diskStoreName, diskDirs, autoCompact, allowForceCompaction, compactionThreshold, duCritical, duWarning, maxOplogSize, queueSize, timeInterval, writeBufferSize);
+
+ createDiskStore(diskStoreName, diskDirs, autoCompact, allowForceCompaction, compactionThreshold,
+ duCritical, duWarning, maxOplogSize, queueSize, timeInterval, writeBufferSize);
}
private void executeAndVerifyCommand(final String commandString) {
@@ -179,7 +181,8 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
assertFalse(cmdResult.failedToPersist());
}
- private void createRegion(final String regionName, final RegionShortcut regionShortCut, final String group) {
+ private void createRegion(final String regionName, final RegionShortcut regionShortCut,
+ final String group) {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_REGION);
csb.addOption(CliStrings.CREATE_REGION__REGION, regionName);
csb.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, regionShortCut.name());
@@ -204,17 +207,17 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
try {
ClassBuilder classBuilder = new ClassBuilder();
- byte[] jarBytes = classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener",
- "package com.qcdunit;" +
- "import java.util.List; import java.util.Properties;" +
- "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;" +
- "import org.apache.geode.cache.asyncqueue.AsyncEventListener;" +
- "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {" +
- "Properties props;" +
- "public boolean processEvents(List<AsyncEvent> events) { return true; }" +
- "public void close() {}" +
- "public void init(final Properties props) {this.props = props;}" +
- "public Properties getConfig() {return this.props;}}");
+ byte[] jarBytes =
+ classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener",
+ "package com.qcdunit;" + "import java.util.List; import java.util.Properties;"
+ + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;"
+ + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;"
+ + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {"
+ + "Properties props;"
+ + "public boolean processEvents(List<AsyncEvent> events) { return true; }"
+ + "public void close() {}"
+ + "public void init(final Properties props) {this.props = props;}"
+ + "public Properties getConfig() {return this.props;}}");
FileUtils.writeByteArrayToFile(jarFile, jarBytes);
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DEPLOY);
@@ -223,7 +226,8 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
csb = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, queueName);
- csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, "com.qcdunit.QueueCommandsDUnitTestListener");
+ csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER,
+ "com.qcdunit.QueueCommandsDUnitTestListener");
csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCH_SIZE, "100");
csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__BATCHTIMEINTERVAL, "200");
csb.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__DISPATCHERTHREADS, "4");
@@ -242,23 +246,18 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
}
}
- private void createDiskStore(final String diskStoreName,
- final String diskDirs,
- final String autoCompact,
- final String allowForceCompaction,
- final String compactionThreshold,
- final String duCritical,
- final String duWarning,
- final String maxOplogSize,
- final String queueSize,
- final String timeInterval,
- final String writeBufferSize) {
+ private void createDiskStore(final String diskStoreName, final String diskDirs,
+ final String autoCompact, final String allowForceCompaction, final String compactionThreshold,
+ final String duCritical, final String duWarning, final String maxOplogSize,
+ final String queueSize, final String timeInterval, final String writeBufferSize) {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
csb.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStoreName);
csb.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskDirs);
csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, autoCompact);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION, allowForceCompaction);
- csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD, compactionThreshold);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION,
+ allowForceCompaction);
+ csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD,
+ compactionThreshold);
csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_CRITICAL_PCT, duCritical);
csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__DISK_USAGE_WARNING_PCT, duWarning);
csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, maxOplogSize);
@@ -267,7 +266,7 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
csb.addOptionWithValueCheck(CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, writeBufferSize);
executeAndVerifyCommand(csb.getCommandString());
}
-
+
private void destroyDiskStore(final String diskStoreName, final String group) {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
csb.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStoreName);
@@ -275,7 +274,8 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
executeAndVerifyCommand(csb.toString());
}
- private void createIndex(final String indexName, final String expression, final String regionName, final String group) {
+ private void createIndex(final String indexName, final String expression, final String regionName,
+ final String group) {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CREATE_INDEX);
csb.addOption(CliStrings.CREATE_INDEX__NAME, indexName);
csb.addOption(CliStrings.CREATE_INDEX__EXPRESSION, expression);
@@ -317,11 +317,12 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
}
private Object[] setup() throws IOException {
- final int [] ports = getRandomAvailableTCPPorts(3);
+ final int[] ports = getRandomAvailableTCPPorts(3);
final int locator1Port = ports[0];
final String locator1Name = "locator1-" + locator1Port;
- final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator + "locator-" + locator1Port + ".log";
+ final String locatorLogPath = this.temporaryFolder.getRoot().getCanonicalPath() + File.separator
+ + "locator-" + locator1Port + ".log";
VM locatorAndMgr = getHost(0).getVM(3);
Object[] result = (Object[]) locatorAndMgr.invoke(new SerializableCallable() {
@@ -333,8 +334,7 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
try {
jmxHost = InetAddress.getLocalHost().getHostName();
- }
- catch (UnknownHostException ignore) {
+ } catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
@@ -356,13 +356,15 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port, locatorLogFile, null, locatorProps);
+ final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locator1Port,
+ locatorLogFile, null, locatorProps);
WaitCriterion wc = new WaitCriterion() {
@Override
public boolean done() {
return locator.isSharedConfigurationRunning();
}
+
@Override
public String description() {
return "Waiting for shared configuration to be started";
@@ -380,9 +382,9 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
});
HeadlessGfsh gfsh = getDefaultShell();
- String jmxHost = (String)result[1];
- int jmxPort = (Integer)result[2];
- int httpPort = (Integer)result[3];
+ String jmxHost = (String) result[1];
+ int jmxPort = (Integer) result[2];
+ int httpPort = (Integer) result[3];
connect(jmxHost, jmxPort, httpPort, gfsh);
@@ -393,7 +395,7 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
public Object call() {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
- localProps.setProperty(LOCATORS, "localhost[" + locator1Port+"]");
+ localProps.setProperty(LOCATORS, "localhost[" + locator1Port + "]");
localProps.setProperty(NAME, "DataMember");
getSystem(localProps);
Cache cache = getCache();
@@ -409,7 +411,7 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
locatorAndMgr.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
- GemFireCacheImpl cache = (GemFireCacheImpl)CacheFactory.getAnyInstance();
+ GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
ShutdownAllRequest.send(cache.getDistributedSystem().getDistributionManager(), -1);
return null;
}
@@ -417,7 +419,7 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
locatorAndMgr.invoke(SharedConfigurationTestUtils.cleanupLocator);
- //Clean up the directories
+ // Clean up the directories
if (!serverNames.isEmpty()) {
for (String serverName : serverNames) {
final File serverDir = new File(serverName);
@@ -437,7 +439,7 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
for (String serverName : serverNames) {
assertTrue(resultAsString.contains(serverName));
}
- }
+ }
private void verifyIndexCreationOnAllMembers(final String indexName) {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_INDEX);
@@ -448,12 +450,12 @@ public class SharedConfigurationEndToEndDUnitTest extends CliCommandTestBase {
assertTrue(resultAsString.contains(serverName));
}
}
-
+
private void verifyAsyncEventQueueCreation() {
CommandStringBuilder csb = new CommandStringBuilder(CliStrings.LIST_ASYNC_EVENT_QUEUES);
CommandResult cmdResult = executeCommand(csb.toString());
String resultAsString = commandResultToString(cmdResult);
-
+
for (String serverName : serverNames) {
assertTrue(resultAsString.contains(serverName));
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/GeodeRestClient.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/GeodeRestClient.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/GeodeRestClient.java
index c83cebb..4f92bfe 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/GeodeRestClient.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/GeodeRestClient.java
@@ -1,18 +1,16 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.rest.internal.web;
@@ -55,43 +53,50 @@ public class GeodeRestClient {
public final static String CONTEXT = "/geode/v1";
private int restPort = 0;
- public GeodeRestClient(int restPort){
+
+ public GeodeRestClient(int restPort) {
this.restPort = restPort;
}
- public HttpResponse doHEAD(String query, String username, String password) throws MalformedURLException {
+ public HttpResponse doHEAD(String query, String username, String password)
+ throws MalformedURLException {
HttpHead httpHead = new HttpHead(CONTEXT + query);
return doRequest(httpHead, username, password);
}
- public HttpResponse doPost(String query, String username, String password, String body) throws MalformedURLException {
+ public HttpResponse doPost(String query, String username, String password, String body)
+ throws MalformedURLException {
HttpPost httpPost = new HttpPost(CONTEXT + query);
httpPost.addHeader("content-type", "application/json");
httpPost.setEntity(new StringEntity(body, StandardCharsets.UTF_8));
return doRequest(httpPost, username, password);
}
- public HttpResponse doPut(String query, String username, String password, String body) throws MalformedURLException {
+ public HttpResponse doPut(String query, String username, String password, String body)
+ throws MalformedURLException {
HttpPut httpPut = new HttpPut(CONTEXT + query);
httpPut.addHeader("content-type", "application/json");
httpPut.setEntity(new StringEntity(body, StandardCharsets.UTF_8));
return doRequest(httpPut, username, password);
}
- public HttpResponse doGet(String uri, String username, String password) throws MalformedURLException {
+ public HttpResponse doGet(String uri, String username, String password)
+ throws MalformedURLException {
HttpGet getRequest = new HttpGet(CONTEXT + uri);
return doRequest(getRequest, username, password);
}
+
public HttpResponse doGet(String uri) throws MalformedURLException {
return doGet(uri, null, null);
}
- public HttpResponse doDelete(String uri, String username, String password) throws MalformedURLException {
+ public HttpResponse doDelete(String uri, String username, String password)
+ throws MalformedURLException {
HttpDelete httpDelete = new HttpDelete(CONTEXT + uri);
return doRequest(httpDelete, username, password);
}
- public static String getContentType(HttpResponse response){
+ public static String getContentType(HttpResponse response) {
return response.getEntity().getContentType().getValue();
}
@@ -118,14 +123,16 @@ public class GeodeRestClient {
return new JSONTokener(str.toString());
}
- private HttpResponse doRequest(HttpRequestBase request, String username, String password) throws MalformedURLException {
- HttpHost targetHost = new HttpHost(HOSTNAME,restPort, PROTOCOL);
+ private HttpResponse doRequest(HttpRequestBase request, String username, String password)
+ throws MalformedURLException {
+ HttpHost targetHost = new HttpHost(HOSTNAME, restPort, PROTOCOL);
CloseableHttpClient httpclient = HttpClients.custom().build();
HttpClientContext clientContext = HttpClientContext.create();
// if username is null, do not put in authentication
if (username != null) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
- credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(username, password));
+ credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
+ new UsernamePasswordCredentials(username, password));
httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
@@ -145,4 +152,4 @@ public class GeodeRestClient {
}
return null;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestFunctionTemplate.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestFunctionTemplate.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestFunctionTemplate.java
index b21f94c..eede038 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestFunctionTemplate.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestFunctionTemplate.java
@@ -1,18 +1,16 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.rest.internal.web;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestInterfaceJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestInterfaceJUnitTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestInterfaceJUnitTest.java
index 4e3269e..932119d 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestInterfaceJUnitTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestInterfaceJUnitTest.java
@@ -1,18 +1,16 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.rest.internal.web;
@@ -69,10 +67,11 @@ import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
/**
- * The GemFireRestInterfaceTest class is a test suite of test cases testing the contract and functionality of the
- * GemFire Developer REST API, mixing Java clients, this test GemFire's Cache Region API, along with
- * a REST-based client, also this test using Spring's RestTemplate, testing the proper interaction, especially
- * in the case of an application domain object type having a java.util.Date property.
+ * The GemFireRestInterfaceTest class is a test suite of test cases testing the contract and
+ * functionality of the GemFire Developer REST API, mixing Java clients, this test GemFire's Cache
+ * Region API, along with a REST-based client, also this test using Spring's RestTemplate, testing
+ * the proper interaction, especially in the case of an application domain object type having a
+ * java.util.Date property.
*
* @see org.junit.Test
* @see org.junit.runner.RunWith
@@ -83,15 +82,16 @@ import org.springframework.web.client.RestTemplate;
* @see org.apache.geode.pdx.ReflectionBasedAutoSerializer
* @since Geode 1.0.0
*/
-//@RunWith(SpringJUnit4ClassRunner.class)
-//@ContextConfiguration
+// @RunWith(SpringJUnit4ClassRunner.class)
+// @ContextConfiguration
@SuppressWarnings("unused")
@Category(IntegrationTest.class)
public class RestInterfaceJUnitTest {
protected static int DEFAULT_HTTP_SERVICE_PORT = 8189;
- protected static final String REST_API_SERVICE_ENDPOINT = "http://localhost:%1$d/gemfire-api/v1/%2$s/%3$s";
+ protected static final String REST_API_SERVICE_ENDPOINT =
+ "http://localhost:%1$d/gemfire-api/v1/%2$s/%3$s";
protected static final String UTF_8 = "UTF-8";
@Autowired
@@ -117,17 +117,15 @@ public class RestInterfaceJUnitTest {
gemfireProperties = (gemfireProperties != null ? gemfireProperties : new Properties());
gemfireCache = new CacheFactory()
- //.setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getPackage().getName().concat(".*")))
- .setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getName().replaceAll("\\$", ".")))
- .setPdxReadSerialized(true)
- .setPdxIgnoreUnreadFields(false)
- .set("name", getClass().getSimpleName())
- .set(MCAST_PORT, "0")
- .set(LOG_LEVEL, "config")
+ // .setPdxSerializer(new
+ // ReflectionBasedAutoSerializer(Person.class.getPackage().getName().concat(".*")))
+ .setPdxSerializer(
+ new ReflectionBasedAutoSerializer(Person.class.getName().replaceAll("\\$", ".")))
+ .setPdxReadSerialized(true).setPdxIgnoreUnreadFields(false)
+ .set("name", getClass().getSimpleName()).set(MCAST_PORT, "0").set(LOG_LEVEL, "config")
.set(HTTP_SERVICE_BIND_ADDRESS, "localhost")
.set(HTTP_SERVICE_PORT, String.valueOf(getHttpServicePort()))
- .set(START_DEV_REST_API, "true")
- .create();
+ .set(START_DEV_REST_API, "true").create();
RegionFactory<String, Object> peopleRegionFactory = gemfireCache.createRegionFactory();
@@ -146,9 +144,9 @@ public class RestInterfaceJUnitTest {
protected synchronized int getHttpServicePort() {
try {
- return Integer.parseInt(StringUtils.trimWhitespace(gemfireProperties.getProperty(HTTP_SERVICE_PORT)));
- }
- catch (NumberFormatException ignore) {
+ return Integer
+ .parseInt(StringUtils.trimWhitespace(gemfireProperties.getProperty(HTTP_SERVICE_PORT)));
+ } catch (NumberFormatException ignore) {
int httpServicePort = getHttpServicePort(DEFAULT_HTTP_SERVICE_PORT);
gemfireProperties.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpServicePort));
return httpServicePort;
@@ -157,18 +155,22 @@ public class RestInterfaceJUnitTest {
private int getHttpServicePort(final int defaultHttpServicePort) {
int httpServicePort = AvailablePortHelper.getRandomAvailableTCPPort();
- return (httpServicePort > 1024 && httpServicePort < 65536 ? httpServicePort : defaultHttpServicePort);
+ return (httpServicePort > 1024 && httpServicePort < 65536 ? httpServicePort
+ : defaultHttpServicePort);
}
protected ObjectMapper getObjectMapper() {
if (objectMapper == null) {
- Jackson2ObjectMapperFactoryBean objectMapperFactoryBean = new Jackson2ObjectMapperFactoryBean();
+ Jackson2ObjectMapperFactoryBean objectMapperFactoryBean =
+ new Jackson2ObjectMapperFactoryBean();
objectMapperFactoryBean.setFailOnEmptyBeans(true);
objectMapperFactoryBean.setFeaturesToEnable(Feature.ALLOW_COMMENTS);
objectMapperFactoryBean.setFeaturesToEnable(Feature.ALLOW_SINGLE_QUOTES);
- objectMapperFactoryBean.setFeaturesToEnable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
- objectMapperFactoryBean.setFeaturesToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ objectMapperFactoryBean
+ .setFeaturesToEnable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
+ objectMapperFactoryBean
+ .setFeaturesToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapperFactoryBean.setIndentOutput(true);
objectMapperFactoryBean.setSimpleDateFormat("MM/dd/yyyy");
objectMapperFactoryBean.afterPropertiesSet();
@@ -189,14 +191,16 @@ public class RestInterfaceJUnitTest {
}
protected String getAdhocQueryRestApiEndpoint(final int httpServicePort, final String query) {
- return String.format(REST_API_SERVICE_ENDPOINT, httpServicePort, "queries", String.format("adhoc?q=%1$s", query));
+ return String.format(REST_API_SERVICE_ENDPOINT, httpServicePort, "queries",
+ String.format("adhoc?q=%1$s", query));
}
protected String getRegionGetRestApiEndpoint(final Region<?, ?> region, final String key) {
return getRegionGetRestApiEndpoint(getHttpServicePort(), region, key);
}
- protected String getRegionGetRestApiEndpoint(final int httpServicePort, final Region<?, ?> region, final String key) {
+ protected String getRegionGetRestApiEndpoint(final int httpServicePort, final Region<?, ?> region,
+ final String key) {
return String.format(REST_API_SERVICE_ENDPOINT, httpServicePort, region.getName(), key);
}
@@ -213,17 +217,19 @@ public class RestInterfaceJUnitTest {
return createPerson(firstName, lastName, null);
}
- protected Person createPerson(final String firstName, final String lastName, final Date birthDate) {
+ protected Person createPerson(final String firstName, final String lastName,
+ final Date birthDate) {
return new Person(firstName, lastName, birthDate);
}
protected RestTemplate createRestTemplate() {
- MappingJackson2HttpMessageConverter httpMessageConverter = new MappingJackson2HttpMessageConverter();
+ MappingJackson2HttpMessageConverter httpMessageConverter =
+ new MappingJackson2HttpMessageConverter();
httpMessageConverter.setObjectMapper(getObjectMapper());
- return setErrorHandler(new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(
- httpMessageConverter)));
+ return setErrorHandler(
+ new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(httpMessageConverter)));
}
private RestTemplate setErrorHandler(final RestTemplate restTemplate) {
@@ -256,8 +262,7 @@ public class RestInterfaceJUnitTest {
@Override
public void handleError(final ClientHttpResponse response) throws IOException {
- System.err.printf("%1$d - %2$s%n", response.getRawStatusCode(),
- response.getStatusText());
+ System.err.printf("%1$d - %2$s%n", response.getRawStatusCode(), response.getStatusText());
System.err.println(readBody(response));
}
@@ -275,8 +280,7 @@ public class RestInterfaceJUnitTest {
}
return buffer.toString().trim();
- }
- finally {
+ } finally {
IOUtils.close(responseBodyReader);
}
}
@@ -308,20 +312,22 @@ public class RestInterfaceJUnitTest {
RestTemplate restTemplate = createRestTemplate();
- Person jonDoeResource = restTemplate.getForObject(getRegionGetRestApiEndpoint(getPeopleRegion(), key), Person.class);
+ Person jonDoeResource = restTemplate
+ .getForObject(getRegionGetRestApiEndpoint(getPeopleRegion(), key), Person.class);
assertNotNull(jonDoeResource);
assertNotSame(jonDoe, jonDoeResource);
assertEquals(jonDoe, jonDoeResource);
/*
- Object result = runQueryUsingApi(getPeopleRegion().getRegionService(), String.format("SELECT * FROM %1$s",
- getPeopleRegion().getFullPath()));
+ * Object result = runQueryUsingApi(getPeopleRegion().getRegionService(),
+ * String.format("SELECT * FROM %1$s", getPeopleRegion().getFullPath()));
+ *
+ * System.out.printf("(OQL Query using API) Person is (%1$s)%n", result);
+ */
- System.out.printf("(OQL Query using API) Person is (%1$s)%n", result);
- */
-
- String url = getAdhocQueryRestApiEndpoint(String.format("SELECT * FROM %1$s", getPeopleRegion().getFullPath()));
+ String url = getAdhocQueryRestApiEndpoint(
+ String.format("SELECT * FROM %1$s", getPeopleRegion().getFullPath()));
System.out.printf("URL (%1$s)%n", url);
@@ -338,13 +344,15 @@ public class RestInterfaceJUnitTest {
assertEquals(jonDoe, jonDoeResource);
}
- private Object runQueryUsingApi(final RegionService regionService, final String queryString) throws Exception {
+ private Object runQueryUsingApi(final RegionService regionService, final String queryString)
+ throws Exception {
return regionService.getQueryService().newQuery(queryString).execute();
}
- //@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
- //@JsonIgnoreProperties(ignoreUnknown = true)
- //@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@type")
+ // @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
+ // @JsonIgnoreProperties(ignoreUnknown = true)
+ // @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property =
+ // "@type")
public static class Person implements PdxSerializable {
protected static final String DEFAULT_BIRTH_DATE_FORMAT_PATTERN = "MM/dd/yyyy";
@@ -354,8 +362,7 @@ public class RestInterfaceJUnitTest {
private String firstName;
private String lastName;
- public Person() {
- }
+ public Person() {}
public Person(final String firstName, final String lastName) {
this(firstName, lastName, null);
@@ -373,7 +380,7 @@ public class RestInterfaceJUnitTest {
public void setBirthDate(final Date birthDate) {
Assert.isTrue(birthDate == null || birthDate.compareTo(Calendar.getInstance().getTime()) <= 0,
- "A Person's date of birth cannot be after today!");
+ "A Person's date of birth cannot be after today!");
this.birthDate = birthDate;
}
@@ -400,8 +407,9 @@ public class RestInterfaceJUnitTest {
}
protected String format(final Date dateTime, final String dateFormatPattern) {
- return (dateTime == null ? null : new SimpleDateFormat(StringUtils.hasText(dateFormatPattern) ? dateFormatPattern
- : DEFAULT_BIRTH_DATE_FORMAT_PATTERN).format(dateTime));
+ return (dateTime == null ? null
+ : new SimpleDateFormat(StringUtils.hasText(dateFormatPattern) ? dateFormatPattern
+ : DEFAULT_BIRTH_DATE_FORMAT_PATTERN).format(dateTime));
}
@Override
@@ -431,8 +439,8 @@ public class RestInterfaceJUnitTest {
Person that = (Person) obj;
return ObjectUtils.nullSafeEquals(this.getFirstName(), that.getFirstName())
- && ObjectUtils.nullSafeEquals(this.getLastName(), that.getLastName())
- && ObjectUtils.nullSafeEquals(this.getBirthDate(), that.getBirthDate());
+ && ObjectUtils.nullSafeEquals(this.getLastName(), that.getLastName())
+ && ObjectUtils.nullSafeEquals(this.getBirthDate(), that.getBirthDate());
}
@Override
@@ -447,7 +455,7 @@ public class RestInterfaceJUnitTest {
@Override
public String toString() {
return String.format("{ @type = %1$s, firstName = %2$s, lastName = %3$s, birthDate = %4$s }",
- getClass().getName(), getFirstName(), getLastName(), format(getBirthDate()));
+ getClass().getName(), getFirstName(), getLastName(), format(getBirthDate()));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
index 5f66f3b..fc9ae95 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/RestSecurityIntegrationTest.java
@@ -1,18 +1,16 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.rest.internal.web;
@@ -38,19 +36,22 @@ import org.apache.geode.test.junit.categories.IntegrationTest;
import org.apache.geode.test.junit.categories.SecurityTest;
-@Category({ IntegrationTest.class, SecurityTest.class })
+@Category({IntegrationTest.class, SecurityTest.class})
public class RestSecurityIntegrationTest {
protected static final String REGION_NAME = "AuthRegion";
private static int restPort = AvailablePortHelper.getRandomAvailableTCPPort();
- static Properties properties = new Properties() {{
- setProperty(SampleSecurityManager.SECURITY_JSON, "org/apache/geode/management/internal/security/clientServer.json");
- setProperty(SECURITY_MANAGER, SampleSecurityManager.class.getName());
- setProperty(START_DEV_REST_API, "true");
- setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
- setProperty(HTTP_SERVICE_PORT, restPort + "");
- }};
+ static Properties properties = new Properties() {
+ {
+ setProperty(SampleSecurityManager.SECURITY_JSON,
+ "org/apache/geode/management/internal/security/clientServer.json");
+ setProperty(SECURITY_MANAGER, SampleSecurityManager.class.getName());
+ setProperty(START_DEV_REST_API, "true");
+ setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
+ setProperty(HTTP_SERVICE_PORT, restPort + "");
+ }
+ };
@ClassRule
public static ServerStarter serverStarter = new ServerStarter(properties);
@@ -79,8 +80,10 @@ public class RestSecurityIntegrationTest {
assertEquals(401, restClient.getCode(response));
response = restClient.doPost("/functions/AddFreeItemsToOrder", "dataReader", "1234567", json);
assertEquals(403, restClient.getCode(response));
- response = restClient.doPost("/functions/AddFreeItemsToOrder?onRegion=" + REGION_NAME, "dataWriter", "1234567", json);
- // because we're only testing the security of the endpoint, not the endpoint functionality, a 500 is acceptable
+ response = restClient.doPost("/functions/AddFreeItemsToOrder?onRegion=" + REGION_NAME,
+ "dataWriter", "1234567", json);
+ // because we're only testing the security of the endpoint, not the endpoint functionality, a
+ // 500 is acceptable
assertEquals(500, restClient.getCode(response));
}
@@ -102,7 +105,8 @@ public class RestSecurityIntegrationTest {
response = restClient.doGet("/queries/adhoc?q=", "stranger", "1234567");
assertEquals(403, restClient.getCode(response));
response = restClient.doGet("/queries/adhoc?q=", "dataReader", "1234567");
- // because we're only testing the security of the endpoint, not the endpoint functionality, a 500 is acceptable
+ // because we're only testing the security of the endpoint, not the endpoint functionality, a
+ // 500 is acceptable
assertEquals(500, restClient.getCode(response));
}
@@ -113,24 +117,28 @@ public class RestSecurityIntegrationTest {
response = restClient.doPost("/queries?id=0&q=", "stranger", "1234567", "");
assertEquals(403, restClient.getCode(response));
response = restClient.doPost("/queries?id=0&q=", "dataReader", "1234567", "");
- // because we're only testing the security of the endpoint, not the endpoint functionality, a 500 is acceptable
+ // because we're only testing the security of the endpoint, not the endpoint functionality, a
+ // 500 is acceptable
assertEquals(500, restClient.getCode(response));
}
@Test
public void testPostQuery2() throws Exception {
- HttpResponse response = restClient.doPost("/queries/id", "unknown-user", "1234567", "{\"id\" : \"foo\"}");
+ HttpResponse response =
+ restClient.doPost("/queries/id", "unknown-user", "1234567", "{\"id\" : \"foo\"}");
assertEquals(401, restClient.getCode(response));
response = restClient.doPost("/queries/id", "stranger", "1234567", "{\"id\" : \"foo\"}");
assertEquals(403, restClient.getCode(response));
response = restClient.doPost("/queries/id", "dataReader", "1234567", "{\"id\" : \"foo\"}");
- // because we're only testing the security of the endpoint, not the endpoint functionality, a 500 is acceptable
+ // because we're only testing the security of the endpoint, not the endpoint functionality, a
+ // 500 is acceptable
assertEquals(500, restClient.getCode(response));
}
@Test
public void testPutQuery() throws Exception {
- HttpResponse response = restClient.doPut("/queries/id", "unknown-user", "1234567", "{\"id\" : \"foo\"}");
+ HttpResponse response =
+ restClient.doPut("/queries/id", "unknown-user", "1234567", "{\"id\" : \"foo\"}");
assertEquals(401, restClient.getCode(response));
response = restClient.doPut("/queries/id", "stranger", "1234567", "{\"id\" : \"foo\"}");
assertEquals(403, restClient.getCode(response));
@@ -162,8 +170,8 @@ public class RestSecurityIntegrationTest {
}
/**
- * This test should always return an OK, whether the user is known or unknown. A phishing script should not be
- * able to determine whether a user/password combination is good
+ * This test should always return an OK, whether the user is known or unknown. A phishing script
+ * should not be able to determine whether a user/password combination is good
*/
@Test
public void testPing() throws Exception {
@@ -290,7 +298,8 @@ public class RestSecurityIntegrationTest {
@Test
public void deleteRegionKey() throws Exception {
// Test an unknown user - 401 error
- HttpResponse response = restClient.doDelete("/" + REGION_NAME + "/key1", "unknown-user", "1234567");
+ HttpResponse response =
+ restClient.doDelete("/" + REGION_NAME + "/key1", "unknown-user", "1234567");
assertEquals(401, restClient.getCode(response));
// Test a user with insufficient rights - 403
@@ -308,15 +317,18 @@ public class RestSecurityIntegrationTest {
@Test
public void postRegionKey() throws Exception {
// Test an unknown user - 401 error
- HttpResponse response = restClient.doPost("/" + REGION_NAME + "?key9", "unknown", "1234567", "{ \"key9\" : \"foo\" }");
+ HttpResponse response = restClient.doPost("/" + REGION_NAME + "?key9", "unknown", "1234567",
+ "{ \"key9\" : \"foo\" }");
assertEquals(401, restClient.getCode(response));
// Test a user with insufficient rights - 403
- response = restClient.doPost("/" + REGION_NAME + "?key9", "dataReader", "1234567", "{ \"key9\" : \"foo\" }");
+ response = restClient.doPost("/" + REGION_NAME + "?key9", "dataReader", "1234567",
+ "{ \"key9\" : \"foo\" }");
assertEquals(403, restClient.getCode(response));
// Test an authorized user - 200
- response = restClient.doPost("/" + REGION_NAME + "?key9", "dataWriter", "1234567", "{ \"key9\" : \"foo\" }");
+ response = restClient.doPost("/" + REGION_NAME + "?key9", "dataWriter", "1234567",
+ "{ \"key9\" : \"foo\" }");
assertEquals(201, restClient.getCode(response));
}
@@ -326,30 +338,40 @@ public class RestSecurityIntegrationTest {
@Test
public void putRegionKey() throws Exception {
- String json = "{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1012,\"description\":\"Order for XYZ Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/20/2014\",\"contact\":\"Jelly Bean\",\"email\":\"jelly.bean@example.com\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":1,\"description\":\"Product-100\",\"quantity\":12,\"unitPrice\":5,\"totalPrice\":60}],\"totalPrice\":225}";
- String casJSON = "{\"@old\":{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1012,\"description\":\"Order for XYZ Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/20/2014\",\"contact\":\"Jelly Bean\",\"email\":\"jelly.bean@example.com\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":1,\"description\":\"Product-100\",\"quantity\":12,\"unitPrice\":5,\"totalPrice\":60}],\"totalPrice\":225},\"@new \":{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1013,\"description\":\"Order for New Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/25/2014\",\"contact\":\"Vanilla Bean\",\"email\":\"vanillabean@example.com\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":12345,\"description\":\"part 123\",\"quantity\":12,\"unitPrice\":29.99,\"totalPrice\":149.95}],\"totalPrice\":149.95}}";
+ String json =
+ "{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1012,\"description\":\"Order for XYZ Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/20/2014\",\"contact\":\"Jelly Bean\",\"email\":\"jelly.bean@example.com\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":1,\"description\":\"Product-100\",\"quantity\":12,\"unitPrice\":5,\"totalPrice\":60}],\"totalPrice\":225}";
+ String casJSON =
+ "{\"@old\":{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1012,\"description\":\"Order for XYZ Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/20/2014\",\"contact\":\"Jelly Bean\",\"email\":\"jelly.bean@example.com\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":1,\"description\":\"Product-100\",\"quantity\":12,\"unitPrice\":5,\"totalPrice\":60}],\"totalPrice\":225},\"@new \":{\"@type\":\"com.gemstone.gemfire.web.rest.domain.Order\",\"purchaseOrderNo\":1121,\"customerId\":1013,\"description\":\"Order for New Corp\",\"orderDate\":\"02/10/2014\",\"deliveryDate\":\"02/25/2014\",\"contact\":\"Vanilla Bean\",\"email\":\"vanillabean@example.com\",\"phone\":\"01-2048096\",\"items\":[{\"itemNo\":12345,\"description\":\"part 123\",\"quantity\":12,\"unitPrice\":29.99,\"totalPrice\":149.95}],\"totalPrice\":149.95}}";
// Test an unknown user - 401 error
- HttpResponse response = restClient.doPut("/" + REGION_NAME + "/key1?op=PUT", "unknown-user", "1234567", "{ \"key9\" : \"foo\" }");
+ HttpResponse response = restClient.doPut("/" + REGION_NAME + "/key1?op=PUT", "unknown-user",
+ "1234567", "{ \"key9\" : \"foo\" }");
assertEquals(401, restClient.getCode(response));
- response = restClient.doPut("/" + REGION_NAME + "/key1?op=CAS", "unknown-user", "1234567", "{ \"key9\" : \"foo\" }");
+ response = restClient.doPut("/" + REGION_NAME + "/key1?op=CAS", "unknown-user", "1234567",
+ "{ \"key9\" : \"foo\" }");
assertEquals(401, restClient.getCode(response));
- response = restClient.doPut("/" + REGION_NAME + "/key1?op=REPLACE", "unknown-user", "1234567", "{ \"@old\" : \"value1\", \"@new\" : \"CASvalue\" }");
+ response = restClient.doPut("/" + REGION_NAME + "/key1?op=REPLACE", "unknown-user", "1234567",
+ "{ \"@old\" : \"value1\", \"@new\" : \"CASvalue\" }");
assertEquals(401, restClient.getCode(response));
- response = restClient.doPut("/" + REGION_NAME + "/key1?op=PUT", "dataReader", "1234567", "{ \"key1\" : \"foo\" }");
+ response = restClient.doPut("/" + REGION_NAME + "/key1?op=PUT", "dataReader", "1234567",
+ "{ \"key1\" : \"foo\" }");
assertEquals(403, restClient.getCode(response));
- response = restClient.doPut("/" + REGION_NAME + "/key1?op=REPLACE", "dataReader", "1234567", "{ \"key1\" : \"foo\" }");
+ response = restClient.doPut("/" + REGION_NAME + "/key1?op=REPLACE", "dataReader", "1234567",
+ "{ \"key1\" : \"foo\" }");
assertEquals(403, restClient.getCode(response));
- response = restClient.doPut("/" + REGION_NAME + "/key1?op=CAS", "dataReader", "1234567", casJSON);
+ response =
+ restClient.doPut("/" + REGION_NAME + "/key1?op=CAS", "dataReader", "1234567", casJSON);
assertEquals(403, restClient.getCode(response));
- response = restClient.doPut("/" + REGION_NAME + "/key1?op=PUT", "key1User", "1234567", "{ \"key1\" : \"foo\" }");
+ response = restClient.doPut("/" + REGION_NAME + "/key1?op=PUT", "key1User", "1234567",
+ "{ \"key1\" : \"foo\" }");
assertEquals(200, restClient.getCode(response));
- response = restClient.doPut("/" + REGION_NAME + "/key1?op=REPLACE", "key1User", "1234567", json);
+ response =
+ restClient.doPut("/" + REGION_NAME + "/key1?op=REPLACE", "key1User", "1234567", json);
assertEquals(200, restClient.getCode(response));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8bf39571/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/AddFreeItemToOrders.java
----------------------------------------------------------------------
diff --git a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/AddFreeItemToOrders.java b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/AddFreeItemToOrders.java
index b2bb040..67714ec 100644
--- a/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/AddFreeItemToOrders.java
+++ b/geode-assembly/src/test/java/org/apache/geode/rest/internal/web/controllers/AddFreeItemToOrders.java
@@ -1,18 +1,16 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.rest.internal.web.controllers;
@@ -38,12 +36,12 @@ import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.pdx.PdxInstance;
/**
- * Gemfire function to add free items in the existing order
- * if the total price for that order is greater then the argument
+ * Gemfire function to add free items in the existing order if the total price for that order is
+ * greater then the argument
*/
-public class AddFreeItemToOrders implements Function {
-
+public class AddFreeItemToOrders implements Function {
+
public void execute(FunctionContext context) {
Cache c = null;
@@ -52,83 +50,91 @@ public class AddFreeItemToOrders implements Function {
List<Object> keys = new ArrayList<Object>();
List<Object> argsList = new ArrayList<Object>();
Object[] argsArray = null;
-
+
if (context.getArguments() instanceof Boolean) {
-
+
} else if (context.getArguments() instanceof String) {
String arg = (String) context.getArguments();
- }else if(context.getArguments() instanceof Vector ) {
-
- }else if (context.getArguments() instanceof Object[]) {
+ } else if (context.getArguments() instanceof Vector) {
+
+ } else if (context.getArguments() instanceof Object[]) {
argsArray = (Object[]) context.getArguments();
argsList = Arrays.asList(argsArray);
- }else {
+ } else {
System.out.println("AddFreeItemToOrders : Invalid Arguments");
}
-
+
try {
c = CacheFactory.getAnyInstance();
- ((GemFireCacheImpl)c).getCacheConfig().setPdxReadSerialized(true);
+ ((GemFireCacheImpl) c).getCacheConfig().setPdxReadSerialized(true);
r = c.getRegion("orders");
} catch (CacheClosedException ex) {
vals.add("NoCacheFoundResult");
context.getResultSender().lastResult(vals);
}
- String oql = "SELECT DISTINCT entry.key FROM /orders.entries entry WHERE entry.value.totalPrice > $1";
+ String oql =
+ "SELECT DISTINCT entry.key FROM /orders.entries entry WHERE entry.value.totalPrice > $1";
Object queryArgs[] = new Object[1];
queryArgs[0] = argsList.get(0);
-
+
final Query query = c.getQueryService().newQuery(oql);
SelectResults result = null;
try {
result = (SelectResults) query.execute(queryArgs);
int resultSize = result.size();
-
- if (result instanceof Collection<?>)
+
+ if (result instanceof Collection<?>)
for (Object item : result) {
keys.add(item);
}
} catch (FunctionDomainException e) {
- if(c != null)
- c.getLogger().info("Caught FunctionDomainException while executing function AddFreeItemToOrders: " + e.getMessage());
-
+ if (c != null)
+ c.getLogger()
+ .info("Caught FunctionDomainException while executing function AddFreeItemToOrders: "
+ + e.getMessage());
+
} catch (TypeMismatchException e) {
- if(c != null)
- c.getLogger().info("Caught TypeMismatchException while executing function AddFreeItemToOrders: " + e.getMessage());
+ if (c != null)
+ c.getLogger()
+ .info("Caught TypeMismatchException while executing function AddFreeItemToOrders: "
+ + e.getMessage());
} catch (NameResolutionException e) {
- if(c != null)
- c.getLogger().info("Caught NameResolutionException while executing function AddFreeItemToOrders: " + e.getMessage());
+ if (c != null)
+ c.getLogger()
+ .info("Caught NameResolutionException while executing function AddFreeItemToOrders: "
+ + e.getMessage());
} catch (QueryInvocationTargetException e) {
- if(c != null)
- c.getLogger().info("Caught QueryInvocationTargetException while executing function AddFreeItemToOrders" + e.getMessage());
+ if (c != null)
+ c.getLogger().info(
+ "Caught QueryInvocationTargetException while executing function AddFreeItemToOrders"
+ + e.getMessage());
}
-
- //class has to be in classpath.
+
+ // class has to be in classpath.
try {
- Item it = (Item)(argsList.get(1));
- for(Object key : keys)
- {
+ Item it = (Item) (argsList.get(1));
+ for (Object key : keys) {
Object obj = r.get(key);
- if(obj instanceof PdxInstance) {
- PdxInstance pi = (PdxInstance)obj;
- Order receivedOrder = (Order)pi.getObject();
+ if (obj instanceof PdxInstance) {
+ PdxInstance pi = (PdxInstance) obj;
+ Order receivedOrder = (Order) pi.getObject();
receivedOrder.addItem(it);
-
+
r.put(key, receivedOrder);
}
}
-
+
context.getResultSender().lastResult("success");
-
- }catch (ClassCastException e) {
-
+
+ } catch (ClassCastException e) {
+
context.getResultSender().lastResult("failure");
- }catch (Exception e) {
+ } catch (Exception e) {
context.getResultSender().lastResult("failure");
}
-
+
}
public String getId() {