GEODE-3056: fix the message for invalid partition-resolver
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/d8a11d1e Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/d8a11d1e Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/d8a11d1e Branch: refs/heads/feature/GEODE-2804v3 Commit: d8a11d1e4a4ccc78ddc3f86db172edf0dddf7215 Parents: d8160d6 Author: Jinmei Liao <jil...@pivotal.io> Authored: Mon Jun 19 09:53:39 2017 -0700 Committer: Jinmei Liao <jil...@pivotal.io> Committed: Mon Jun 19 17:09:30 2017 -0700 ---------------------------------------------------------------------- .../CreateAlterDestroyRegionCommands.java | 13 ++-- .../CreateAlterDestroyRegionCommandsTest.java | 65 ++++++++++++++++++++ 2 files changed, 73 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/d8a11d1e/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java index bf22854..b762396 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommands.java @@ -612,14 +612,17 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { } } - private void validateRegionFunctionArgs(InternalCache cache, - RegionFunctionArgs regionFunctionArgs) { + DistributedSystemMXBean getDSMBean(InternalCache cache) { + ManagementService managementService = ManagementService.getExistingManagementService(cache); + return managementService.getDistributedSystemMXBean(); + } + + void validateRegionFunctionArgs(InternalCache cache, RegionFunctionArgs regionFunctionArgs) { if (regionFunctionArgs.getRegionPath() == null) { throw new IllegalArgumentException(CliStrings.CREATE_REGION__MSG__SPECIFY_VALID_REGION_PATH); } - ManagementService managementService = ManagementService.getExistingManagementService(cache); - DistributedSystemMXBean dsMBean = managementService.getDistributedSystemMXBean(); + DistributedSystemMXBean dsMBean = getDSMBean(cache); String useAttributesFrom = regionFunctionArgs.getUseAttributesFrom(); if (useAttributesFrom != null && !useAttributesFrom.isEmpty() @@ -840,7 +843,7 @@ public class CreateAlterDestroyRegionCommands implements GfshCommand { } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new IllegalArgumentException( CliStrings.format(CliStrings.CREATE_REGION__MSG__INVALID_PARTITION_RESOLVER, - new Object[] {regionFunctionArgs.getCompressor()}), + new Object[] {regionFunctionArgs.getPartitionResolver()}), e); } } http://git-wip-us.apache.org/repos/asf/geode/blob/d8a11d1e/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java new file mode 100644 index 0000000..155b1ad --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/CreateAlterDestroyRegionCommandsTest.java @@ -0,0 +1,65 @@ +/* + * 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.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.mockito.ArgumentCaptor; + +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.management.DistributedSystemMXBean; +import org.apache.geode.management.internal.cli.functions.RegionFunctionArgs; +import org.apache.geode.test.dunit.rules.GfshParserRule; +import org.apache.geode.test.junit.categories.IntegrationTest; + +@Category(IntegrationTest.class) +public class CreateAlterDestroyRegionCommandsTest { + + @Rule + public GfshParserRule parser = new GfshParserRule(); + + @Test + public void testCreateRegionWithInvalidPartitionResolver() throws Exception { + InternalCache cache = mock(InternalCache.class); + DistributedSystemMXBean dsMBean = mock(DistributedSystemMXBean.class); + CreateAlterDestroyRegionCommands spy = + parser.spyCommand("create region --name=region3 --type=PARTITION --partition-resolver=Foo"); + doReturn(cache).when(spy).getCache(); + doReturn(dsMBean).when(spy).getDSMBean(cache); + + parser.executeLastCommandWithInstance(spy); + + ArgumentCaptor<RegionFunctionArgs> argsCaptor = + ArgumentCaptor.forClass(RegionFunctionArgs.class); + + verify(spy).validateRegionFunctionArgs(any(), argsCaptor.capture()); + + RegionFunctionArgs args = argsCaptor.getValue(); + assertThat(args.getPartitionResolver()).isEqualTo("Foo"); + + assertThatThrownBy(() -> spy.validateRegionFunctionArgs(cache, args)) + .hasMessageContaining("Foo is an invalid Partition Resolver"); + } +}