DestroyRegionCommand extends GfshCommand { void checkForJDBCMapping(String regionPath) { String regionName = regionPath; if (regionPath.startsWith(SEPARATOR)) { regionName = regionPath.substring(1); } InternalConfigurationPersistenceService ccService = getConfigurationPersistenceService(); if (ccService == null) { return; } Set<String> groupNames = new HashSet<>(ccService.getGroups()); groupNames.add("cluster"); for (String groupName : groupNames) { CacheConfig cacheConfig = ccService.getCacheConfig(groupName); if (cacheConfig != null) { RegionConfig regionConfig = find(cacheConfig.getRegions(), regionName); if (regionConfig != null) { Identifiable<?> element = find(regionConfig.getCustomRegionElements(), "jdbc-mapping"); if (element != null) { throw new IllegalStateException("Cannot destroy region \"" + regionName + "\" because JDBC mapping exists. Use \"destroy jdbc-mapping\" first."); } } } } }  @CliCommand(value = {CliStrings.DESTROY_REGION}, help = CliStrings.DESTROY_REGION__HELP) @CliMetaData(relatedTopic = CliStrings.TOPIC_GEODE_REGION) @ResourceOperation(resource = ResourcePermission.Resource.DATA, operation = ResourcePermission.Operation.MANAGE) ResultModel destroyRegion(
      @CliOption(key = CliStrings.DESTROY_REGION__REGION, optionContext = ConverterHint.REGION_PATH,
          mandatory = true, help = CliStrings.DESTROY_REGION__REGION__HELP) String regionPath,
      @CliOption(key = CliStrings.IFEXISTS, help = CliStrings.IFEXISTS_HELP,
          specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean ifExists);  }
@Test(expected = IllegalStateException.class) public void checkForJDBCMappingWithRegionPathThrowsIllegalStateException() { setupJDBCMappingOnRegion("regionName"); command.checkForJDBCMapping(SEPARATOR + "regionName"); }
@Test(expected = IllegalStateException.class) public void checkForJDBCMappingWithRegionNameThrowsIllegalStateException() { setupJDBCMappingOnRegion("regionName"); command.checkForJDBCMapping("regionName"); }
@Test(expected = IllegalStateException.class) public void checkForJDBCMappingWithRegionNameThrowsIllegalStateExceptionForGroup() { Set<String> groups = new HashSet<>(); groups.add("Group1"); doReturn(groups).when(ccService).getGroups(); setupJDBCMappingOnRegion("regionName"); doReturn(cacheConfig).when(ccService).getCacheConfig("Group1"); command.checkForJDBCMapping("regionName"); }
@Test public void checkForJDBCMappingWithNoClusterConfigDoesNotThrowException() { setupJDBCMappingOnRegion("regionName"); doReturn(null).when(command).getConfigurationPersistenceService(); command.checkForJDBCMapping("regionName"); }
@Test public void checkForJDBCMappingWithNoCacheConfigDoesNotThrowException() { setupJDBCMappingOnRegion("regionName"); doReturn(null).when(ccService).getCacheConfig("cluster"); command.checkForJDBCMapping("regionName"); }
@Test public void checkForJDBCMappingWithNoRegionConfigDoesNotThrowException() { setupJDBCMappingOnRegion("regionName"); doReturn(Collections.emptyList()).when(cacheConfig).getRegions(); command.checkForJDBCMapping("regionName"); }
@Test public void checkForJDBCMappingWithNoJDBCMappingDoesNotThrowException() { setupJDBCMappingOnRegion("regionName"); doReturn("something").when(cacheElement).getId(); command.checkForJDBCMapping("regionName"); }