DescribeMappingCommand extends GfshCommand { private CacheConfig getCacheConfig(ConfigurationPersistenceService configService, String group) throws PreconditionException { return MappingCommandUtils.getCacheConfig(configService, group); }  @CliCommand(value = DESCRIBE_MAPPING, help = DESCRIBE_MAPPING__HELP) @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel describeMapping(@CliOption(key = DESCRIBE_MAPPING__REGION_NAME,
      mandatory = true, help = DESCRIBE_MAPPING__REGION_NAME__HELP) String regionName,
      @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
          optionContext = ConverterHint.MEMBERGROUP,
          help = DESCRIBE_MAPPING__GROUPS_NAME__HELP) String[] groups); @CliAvailabilityIndicator({DESCRIBE_MAPPING}) boolean commandAvailable(); static final String RESULT_SECTION_NAME; }
@Test public void commandFailureWhenClusterConfigServiceEnabledAndCacheConfigNotFound() { RegionMapping regionMapping = new RegionMapping(); regionMapping.setRegionName("region1"); regionMapping.setPdxName("class1"); regionMapping.setTableName("table1"); regionMapping.setDataSourceName("name1"); regionMapping.setIds("myId"); regionMapping.setSpecifiedIds(true); regionMapping.setCatalog("myCatalog"); regionMapping.setSchema("mySchema"); ArrayList<CacheElement> elements = new ArrayList<>(); elements.add(regionMapping); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(null); gfsh.executeAndAssertThat(command, COMMAND).statusIsError() .containsOutput("Cache Configuration not found."); }
@Test public void commandFailureWhenClusterConfigServiceEnabledAndCacheConfigNotFoundWithGroup() { RegionMapping regionMapping = new RegionMapping(); regionMapping.setRegionName("region1"); regionMapping.setPdxName("class1"); regionMapping.setTableName("table1"); regionMapping.setDataSourceName("name1"); regionMapping.setIds("myId"); regionMapping.setSpecifiedIds(true); regionMapping.setCatalog("myCatalog"); regionMapping.setSchema("mySchema"); ArrayList<CacheElement> elements = new ArrayList<>(); elements.add(regionMapping); when(configurationPersistenceService.getCacheConfig("group1")).thenReturn(null); gfsh.executeAndAssertThat(command, COMMAND + " --group=group1").statusIsError() .containsOutput("Cache Configuration not found for group group1."); }
@Test public void commandFailureWhenCacheConfigFoundAndRegionConfigNotFoundWithGroup() { RegionMapping regionMapping = new RegionMapping(); regionMapping.setRegionName("region1"); regionMapping.setPdxName("class1"); regionMapping.setTableName("table1"); regionMapping.setDataSourceName("name1"); regionMapping.setIds("myId"); regionMapping.setSpecifiedIds(true); regionMapping.setCatalog("myCatalog"); regionMapping.setSchema("mySchema"); when(clusterConfig.getRegions()).thenReturn(new ArrayList<>()); when(configurationPersistenceService.getCacheConfig("group1")).thenReturn(clusterConfig); gfsh.executeAndAssertThat(command, COMMAND + " --groups=group1").statusIsError() .containsOutput("A region named region1 must already exist for group group1."); }
@Test public void whenMemberExistsForGroup() { RegionMapping regionMapping = new RegionMapping(); regionMapping.setRegionName("region1"); regionMapping.setPdxName("class1"); regionMapping.setTableName("table1"); regionMapping.setDataSourceName("name1"); regionMapping.setIds("myId"); regionMapping.setSpecifiedIds(false); regionMapping.setCatalog("myCatalog"); regionMapping.setSchema("mySchema"); ArrayList<CacheElement> elements = new ArrayList<>(); elements.add(regionMapping); when(regionConfig.getCustomRegionElements()).thenReturn(elements); when(regionConfig.getRegionAttributes().getDataPolicy()) .thenReturn(RegionAttributesDataPolicy.REPLICATE); when(configurationPersistenceService.getCacheConfig("group1")).thenReturn(clusterConfig); gfsh.executeAndAssertThat(command, COMMAND + " --groups=group1").statusIsSuccess() .hasDataSection() .hasContent() .containsEntry(REGION_NAME, "region1") .containsEntry(DATA_SOURCE_NAME, "name1").containsEntry(TABLE_NAME, "table1") .containsEntry(PDX_NAME, "class1").containsEntry(ID_NAME, "myId") .containsEntry(SPECIFIED_ID_NAME, "false") .containsEntry(SCHEMA_NAME, "mySchema").containsEntry(CATALOG_NAME, "myCatalog") .containsEntry(SYNCHRONOUS_NAME, "true"); }