From commits-return-29761-archive-asf-public=cust-asf.ponee.io@geode.apache.org Sat Dec 1 01:43:56 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id CF77E180671 for ; Sat, 1 Dec 2018 01:43:55 +0100 (CET) Received: (qmail 10916 invoked by uid 500); 1 Dec 2018 00:43:54 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 10907 invoked by uid 99); 1 Dec 2018 00:43:54 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Dec 2018 00:43:54 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 44CC382912; Sat, 1 Dec 2018 00:43:54 +0000 (UTC) Date: Sat, 01 Dec 2018 00:43:53 +0000 To: "commits@geode.apache.org" Subject: [geode] branch develop updated: GEODE-6029: Added test for describe jndi-binding (#2828) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <154362503242.25829.16213575298799123452@gitbox.apache.org> From: dschneider@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: geode X-Git-Refname: refs/heads/develop X-Git-Reftype: branch X-Git-Oldrev: b06045146cdcc2d6d178cd23fe468154eb245d07 X-Git-Newrev: 3c37923697f9254d643fb318ba935dc3329b5e70 X-Git-Rev: 3c37923697f9254d643fb318ba935dc3329b5e70 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 AuthorDate: Fri Nov 30 16:43:43 2018 -0800 GEODE-6029: Added test for describe jndi-binding (#2828) Co-authored-by: Ben Ross Co-authored-by: Jianxia Chen --- .../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 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"); + } + +}