This is an automated email from the ASF dual-hosted git repository.
dschneider pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 3c37923 GEODE-6029: Added test for describe jndi-binding (#2828)
3c37923 is described below
commit 3c37923697f9254d643fb318ba935dc3329b5e70
Author: Jianxia Chen <[email protected]>
AuthorDate: Fri Nov 30 16:43:43 2018 -0800
GEODE-6029: Added test for describe jndi-binding (#2828)
Co-authored-by: Ben Ross <[email protected]>
Co-authored-by: Jianxia Chen <[email protected]>
---
.../cli/commands/DescribeJndiBindingCommand.java | 11 +--
.../cli/commands/CreateJndiBindingCommandTest.java | 10 +--
.../commands/DescribeJndiBindingCommandTest.java | 87 ++++++++++++++++++++++
3 files changed, 91 insertions(+), 17 deletions(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
index 0f83ad9..cda960d 100644
---
a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
+++
b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommand.java
@@ -17,18 +17,14 @@ package org.apache.geode.management.internal.cli.commands;
import java.util.List;
-import org.apache.logging.log4j.Logger;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.apache.geode.cache.configuration.CacheConfig;
import org.apache.geode.cache.configuration.JndiBindingsType;
-import org.apache.geode.cache.execute.Function;
-import
org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
-import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.distributed.ConfigurationPersistenceService;
import org.apache.geode.management.cli.CliMetaData;
import org.apache.geode.management.cli.GfshCommand;
-import
org.apache.geode.management.internal.cli.functions.ListJndiBindingFunction;
import org.apache.geode.management.internal.cli.result.model.ResultModel;
import
org.apache.geode.management.internal.cli.result.model.TabularResultModel;
import org.apache.geode.management.internal.security.ResourceOperation;
@@ -36,11 +32,9 @@ import org.apache.geode.security.ResourcePermission;
public class DescribeJndiBindingCommand extends GfshCommand {
public static final String JNDI_PROPERTIES_SECTION = "jndi-properties";
- private static final Logger logger = LogService.getLogger();
static final String DESCRIBE_JNDI_BINDING = "describe jndi-binding";
private static final String DESCRIBE_JNDIBINDING__HELP =
"Describe the configuration of the given jndi binding.";
- private static final Function LIST_BINDING_FUNCTION = new
ListJndiBindingFunction();
@CliCommand(value = DESCRIBE_JNDI_BINDING, help = DESCRIBE_JNDIBINDING__HELP)
@CliMetaData
@@ -52,8 +46,7 @@ public class DescribeJndiBindingCommand extends GfshCommand {
ResultModel crm = new ResultModel();
TabularResultModel tabularData = crm.addTable(JNDI_PROPERTIES_SECTION);
- InternalConfigurationPersistenceService ccService =
- (InternalConfigurationPersistenceService)
getConfigurationPersistenceService();
+ ConfigurationPersistenceService ccService =
getConfigurationPersistenceService();
if (ccService != null) {
CacheConfig cacheConfig = ccService.getCacheConfig("cluster");
if (cacheConfig == null) {
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
index 4bdff14..378466d 100644
---
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateJndiBindingCommandTest.java
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -33,13 +32,10 @@ import java.util.List;
import java.util.Set;
import java.util.function.UnaryOperator;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
-import org.xml.sax.SAXException;
import org.apache.geode.cache.configuration.CacheConfig;
import org.apache.geode.cache.configuration.JndiBindingsType;
@@ -122,8 +118,7 @@ public class CreateJndiBindingCommandTest {
}
@Test
- public void returnsErrorIfBindingAlreadyExistsAndIfUnspecified()
- throws ParserConfigurationException, SAXException, IOException {
+ public void returnsErrorIfBindingAlreadyExistsAndIfUnspecified() {
InternalConfigurationPersistenceService clusterConfigService =
mock(InternalConfigurationPersistenceService.class);
CacheConfig cacheConfig = mock(CacheConfig.class);
@@ -139,8 +134,7 @@ public class CreateJndiBindingCommandTest {
}
@Test
- public void skipsIfBindingAlreadyExistsAndIfSpecified()
- throws ParserConfigurationException, SAXException, IOException {
+ public void skipsIfBindingAlreadyExistsAndIfSpecified() {
InternalConfigurationPersistenceService clusterConfigService =
mock(InternalConfigurationPersistenceService.class);
CacheConfig cacheConfig = mock(CacheConfig.class);
diff --git
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandTest.java
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandTest.java
new file mode 100644
index 0000000..bae159e
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeJndiBindingCommandTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+package org.apache.geode.management.internal.cli.commands;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import org.apache.geode.cache.configuration.CacheConfig;
+import org.apache.geode.cache.configuration.JndiBindingsType;
+import
org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
+import org.apache.geode.test.junit.rules.GfshParserRule;
+
+public class DescribeJndiBindingCommandTest {
+ @ClassRule
+ public static GfshParserRule gfsh = new GfshParserRule();
+
+ InternalConfigurationPersistenceService ccService;
+ CacheConfig cacheConfig;
+
+ private DescribeJndiBindingCommand command;
+ JndiBindingsType.JndiBinding binding;
+ List<JndiBindingsType.JndiBinding> bindings;
+
+ private static String COMMAND = "describe jndi-binding ";
+
+ @Before
+ public void setUp() throws Exception {
+ binding = new JndiBindingsType.JndiBinding();
+ binding.setJndiName("jndi-name");
+ binding.setType("SIMPLE");
+ binding.setJdbcDriverClass("org.postgresql.Driver");
+ binding.setConnectionUrl("jdbc:postgresql://localhost:5432/my_db");
+ binding.setUserName("MyUser");
+ bindings = new ArrayList<>();
+
+ command = spy(DescribeJndiBindingCommand.class);
+ ccService = mock(InternalConfigurationPersistenceService.class);
+ cacheConfig = mock(CacheConfig.class);
+ doReturn(ccService).when(command).getConfigurationPersistenceService();
+ when(ccService.getCacheConfig("cluster")).thenReturn(cacheConfig);
+ when(cacheConfig.getJndiBindings()).thenReturn(bindings);
+ }
+
+ @Test
+ public void describeJndiBinding() {
+ bindings.add(binding);
+ gfsh.executeAndAssertThat(command, COMMAND + "
--name=jndi-name").statusIsSuccess()
+ .containsOutput(
+
"\"SIMPLE\",\"jndi-name\",\"org.postgresql.Driver\",\"MyUser\",\"jdbc:postgresql://localhost:5432/my_db\",\"\",\"\",\"\",\"\",\"\"");
+ }
+
+ @Test
+ public void bindingEmpty() {
+ bindings.clear();
+ gfsh.executeAndAssertThat(command, COMMAND + "
--name=jndi-name").statusIsError()
+ .containsOutput("jndi-name not found");
+ }
+
+ @Test
+ public void bindingNotFound() {
+ bindings.add(binding);
+ gfsh.executeAndAssertThat(command, COMMAND + "
--name=bad-name").statusIsError()
+ .containsOutput("bad-name not found");
+ }
+
+}