ListMappingCommand extends GfshCommand { private CacheConfig getCacheConfig(ConfigurationPersistenceService configService, String group) throws PreconditionException { CacheConfig result = configService.getCacheConfig(group); if (result == null) { throw new PreconditionException( "Cache Configuration not found" + ((group.equals(ConfigurationPersistenceService.CLUSTER_CONFIG)) ? "." : " for group " + group + ".")); } return result; }  @CliCommand(value = LIST_MAPPING, help = LIST_MAPPING__HELP) @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel listMapping(@CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
      optionContext = ConverterHint.MEMBERGROUP,
      help = LIST_MAPPING__GROUPS_NAME__HELP) String[] groups); @CliAvailabilityIndicator({LIST_MAPPING}) boolean commandAvailable(); static final String JDBC_MAPPINGS_SECTION; }
@Test public void whenNoCacheConfig() { when(configService.getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)) .thenReturn(null); gfsh.executeAndAssertThat(command, COMMAND).statusIsError() .containsOutput("Cache Configuration not found."); }
@Test public void whenNoMappingExists() { when(configService.getCacheConfig(eq(ConfigurationPersistenceService.CLUSTER_CONFIG))) .thenReturn(cacheConfig); gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess().containsOutput(NO_MAPPINGS_FOUND); }
@SuppressWarnings("unchecked") @Test public void whenMappingExists() { when(configService.getCacheConfig(eq(ConfigurationPersistenceService.CLUSTER_CONFIG))) .thenReturn(cacheConfig); List<RegionConfig> regions = new ArrayList<>(); regions.add(region1Config); regions.add(region2Config); when(region1Config.getName()).thenReturn("region1"); when(region2Config.getName()).thenReturn("region2"); when(cacheConfig.getRegions()).thenReturn(regions); RegionMapping mapping1 = new RegionMapping("region1", "class1", "table1", "name1", null, null, null); RegionMapping mapping2 = new RegionMapping("region2", "class2", "table2", "name2", null, null, null); List<CacheElement> mappingList1 = new ArrayList<>(); mappingList1.add(mapping1); List<CacheElement> mappingList2 = new ArrayList<>(); mappingList2.add(mapping2); when(region1Config.getCustomRegionElements()).thenReturn(mappingList1); when(region2Config.getCustomRegionElements()).thenReturn(mappingList2); ResultCollector<CliFunctionResult, List<CliFunctionResult>> rc = mock(ResultCollector.class); doReturn(rc).when(command).executeFunction(any(), any(), any(Set.class)); when(rc.getResult()).thenReturn(Collections.singletonList(new CliFunctionResult("server-1", Stream.of(mapping1, mapping2).collect(toSet()), "success"))); gfsh.executeAndAssertThat(command, COMMAND).statusIsSuccess().containsOutput("region1", "region2"); }
@SuppressWarnings("unchecked") @Test public void whenMappingExistsForServerGroup() { when(configService.getCacheConfig(TEST_GROUP1)).thenReturn(cacheConfig); List<RegionConfig> regions = new ArrayList<>(); regions.add(region1Config); regions.add(region2Config); when(region1Config.getName()).thenReturn("region1"); when(region2Config.getName()).thenReturn("region2"); when(cacheConfig.getRegions()).thenReturn(regions); RegionMapping mapping1 = new RegionMapping("region1", "class1", "table1", "name1", null, null, null); RegionMapping mapping2 = new RegionMapping("region2", "class2", "table2", "name2", null, null, null); List<CacheElement> mappingList1 = new ArrayList<>(); mappingList1.add(mapping1); List<CacheElement> mappingList2 = new ArrayList<>(); mappingList2.add(mapping2); when(region1Config.getCustomRegionElements()).thenReturn(mappingList1); when(region2Config.getCustomRegionElements()).thenReturn(mappingList2); ResultCollector<CliFunctionResult, List<CliFunctionResult>> rc = mock(ResultCollector.class); doReturn(rc).when(command).executeFunction(any(), any(), any(Set.class)); when(rc.getResult()).thenReturn(Collections.singletonList(new CliFunctionResult("server-1", Stream.of(mapping1, mapping2).collect(toSet()), "success"))); gfsh.executeAndAssertThat(command, COMMAND_FOR_GROUP).statusIsSuccess().containsOutput( "region1", "region2"); }