CreateMappingCommand extends SingleGfshCommand { @CliCommand(value = CREATE_MAPPING, help = CREATE_MAPPING__HELP) @CliMetaData( interceptor = "org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand$Interceptor", relatedTopic = {CliStrings.DEFAULT_TOPIC_GEODE}) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) public ResultModel createMapping( @CliOption(key = CREATE_MAPPING__REGION_NAME, mandatory = true, help = CREATE_MAPPING__REGION_NAME__HELP) String regionName, @CliOption(key = CREATE_MAPPING__DATA_SOURCE_NAME, mandatory = true, help = CREATE_MAPPING__DATA_SOURCE_NAME__HELP) String dataSourceName, @CliOption(key = CREATE_MAPPING__TABLE_NAME, help = CREATE_MAPPING__TABLE_NAME__HELP) String table, @CliOption(key = CREATE_MAPPING__PDX_NAME, mandatory = true, help = CREATE_MAPPING__PDX_NAME__HELP) String pdxName, @CliOption(key = CREATE_MAPPING__PDX_CLASS_FILE, help = CREATE_MAPPING__PDX_CLASS_FILE__HELP) String pdxClassFile, @CliOption(key = CREATE_MAPPING__SYNCHRONOUS_NAME, help = CREATE_MAPPING__SYNCHRONOUS_NAME__HELP, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean synchronous, @CliOption(key = CREATE_MAPPING__ID_NAME, help = CREATE_MAPPING__ID_NAME__HELP) String id, @CliOption(key = CREATE_MAPPING__CATALOG_NAME, help = CREATE_MAPPING__CATALOG_NAME__HELP) String catalog, @CliOption(key = CREATE_MAPPING__SCHEMA_NAME, help = CREATE_MAPPING__SCHEMA_NAME__HELP) String schema, @CliOption(key = CliStrings.IFNOTEXISTS, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false", help = CREATE_MAPPING__IFNOTEXISTS__HELP) boolean ifNotExists, @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS}, optionContext = ConverterHint.MEMBERGROUP, help = CREATE_MAPPING__GROUPS_NAME__HELP) String[] groups) throws IOException { if (regionName.startsWith(SEPARATOR)) { regionName = regionName.substring(1); } String tempPdxClassFilePath = null; String remoteInputStreamName = null; RemoteInputStream remoteInputStream = null; if (pdxClassFile != null) { List<String> pdxClassFilePaths = getFilePathFromShell(); if (pdxClassFilePaths.size() != 1) { throw new IllegalStateException( "Expected only one element in the list returned by getFilePathFromShell, but it returned: " + pdxClassFilePaths); } tempPdxClassFilePath = pdxClassFilePaths.get(0); } Set<DistributedMember> targetMembers = findMembers(groups, null); RegionMapping mapping = new RegionMapping(regionName, pdxName, table, dataSourceName, id, catalog, schema); try { ConfigurationPersistenceService configurationPersistenceService = checkForClusterConfiguration(); if (groups == null) { groups = new String[] {ConfigurationPersistenceService.CLUSTER_CONFIG}; } for (String group : groups) { CacheConfig cacheConfig = MappingCommandUtils.getCacheConfig(configurationPersistenceService, group); RegionConfig regionConfig = checkForRegion(regionName, cacheConfig, group); checkForExistingMapping(regionName, regionConfig); checkForCacheLoader(regionName, regionConfig); checkForCacheWriter(regionName, synchronous, regionConfig); checkForAsyncQueue(regionName, synchronous, cacheConfig); checkForAEQIdForAccessor(regionName, synchronous, regionConfig); } } catch (PreconditionException ex) { if (ifNotExists) { return ResultModel .createInfo(IF_NOT_EXISTS_SKIPPING_EXCEPTION_MESSAGE + ex.getMessage()); } else { return ResultModel.createError(ex.getMessage()); } } if (pdxClassFile != null) { ManagementAgent agent = ((SystemManagementService) getManagementService()).getManagementAgent(); RemoteStreamExporter exporter = agent.getRemoteStreamExporter(); remoteInputStreamName = FilenameUtils.getName(tempPdxClassFilePath); remoteInputStream = exporter.export(createSimpleRemoteInputStream(tempPdxClassFilePath)); } CliFunctionResult preconditionCheckResult; try { preconditionCheckResult = executeFunctionAndGetFunctionResult(new CreateMappingPreconditionCheckFunction(), new Object[] {mapping, remoteInputStreamName, remoteInputStream}, targetMembers.iterator().next()); } finally { if (remoteInputStream != null) { try { remoteInputStream.close(true); } catch (IOException ex) { } } } if (preconditionCheckResult.isSuccessful()) { Object[] preconditionOutput = (Object[]) preconditionCheckResult.getResultObject(); String computedIds = (String) preconditionOutput[0]; if (computedIds != null) { mapping.setIds(computedIds); } @SuppressWarnings("unchecked") ArrayList<FieldMapping> fieldMappings = (ArrayList<FieldMapping>) preconditionOutput[1]; for (FieldMapping fieldMapping : fieldMappings) { mapping.addFieldMapping(fieldMapping); } } else { String message = preconditionCheckResult.getStatusMessage(); return ResultModel.createError(message); } Object[] arguments = new Object[] {mapping, synchronous}; List<CliFunctionResult> results = executeAndGetFunctionResult(new CreateMappingFunction(), arguments, targetMembers); ResultModel result = ResultModel.createMemberStatusResult(results, EXPERIMENTAL, null, false, true); result.setConfigObject(arguments); return result; }  @CliCommand(value = CREATE_MAPPING, help = CREATE_MAPPING__HELP) @CliMetaData( interceptor = "org.apache.geode.connectors.jdbc.internal.cli.CreateMappingCommand$Interceptor", relatedTopic = {CliStrings.DEFAULT_TOPIC_GEODE}) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel createMapping(
      @CliOption(key = CREATE_MAPPING__REGION_NAME, mandatory = true,
          help = CREATE_MAPPING__REGION_NAME__HELP) String regionName,
      @CliOption(key = CREATE_MAPPING__DATA_SOURCE_NAME, mandatory = true,
          help = CREATE_MAPPING__DATA_SOURCE_NAME__HELP) String dataSourceName,
      @CliOption(key = CREATE_MAPPING__TABLE_NAME,
          help = CREATE_MAPPING__TABLE_NAME__HELP) String table,
      @CliOption(key = CREATE_MAPPING__PDX_NAME, mandatory = true,
          help = CREATE_MAPPING__PDX_NAME__HELP) String pdxName,
      @CliOption(key = CREATE_MAPPING__PDX_CLASS_FILE,
          help = CREATE_MAPPING__PDX_CLASS_FILE__HELP) String pdxClassFile,
      @CliOption(key = CREATE_MAPPING__SYNCHRONOUS_NAME,
          help = CREATE_MAPPING__SYNCHRONOUS_NAME__HELP,
          specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean synchronous,
      @CliOption(key = CREATE_MAPPING__ID_NAME, help = CREATE_MAPPING__ID_NAME__HELP) String id,
      @CliOption(key = CREATE_MAPPING__CATALOG_NAME,
          help = CREATE_MAPPING__CATALOG_NAME__HELP) String catalog,
      @CliOption(key = CREATE_MAPPING__SCHEMA_NAME,
          help = CREATE_MAPPING__SCHEMA_NAME__HELP) String schema,
      @CliOption(key = CliStrings.IFNOTEXISTS,
          specifiedDefaultValue = "true", unspecifiedDefaultValue = "false",
          help = CREATE_MAPPING__IFNOTEXISTS__HELP) boolean ifNotExists,
      @CliOption(key = {CliStrings.GROUP, CliStrings.GROUPS},
          optionContext = ConverterHint.MEMBERGROUP,
          help = CREATE_MAPPING__GROUPS_NAME__HELP) String[] groups); @Override boolean updateConfigForGroup(String group, CacheConfig cacheConfig, Object element); @CliAvailabilityIndicator({CREATE_MAPPING}) @SuppressWarnings("unused") boolean commandAvailable(); static final String CREATE_MAPPING__IFNOTEXISTS__HELP; }
@Test public void createsMappingReturnsStatusOKWhenFunctionResultSuccess() throws IOException { setupRequiredPreconditions(); results.add(successFunctionResult); String ids = "ids"; String catalog = "catalog"; String schema = "schema"; ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, ids, catalog, schema, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); Object[] results = (Object[]) result.getConfigObject(); RegionMapping regionMapping = (RegionMapping) results[0]; boolean synchronous = (boolean) results[1]; assertThat(regionMapping).isNotNull(); assertThat(regionMapping.getRegionName()).isEqualTo(regionName); assertThat(regionMapping.getDataSourceName()).isEqualTo(dataSourceName); assertThat(regionMapping.getTableName()).isEqualTo(tableName); assertThat(regionMapping.getPdxName()).isEqualTo(pdxClass); assertThat(regionMapping.getIds()).isEqualTo(ids); assertThat(regionMapping.getCatalog()).isEqualTo(catalog); assertThat(regionMapping.getSchema()).isEqualTo(schema); assertThat(synchronous).isFalse(); }
@Test public void createsMappingReturnsStatusOKWhenFunctionResultSuccessWithGroups() throws IOException { setupRequiredPreconditionsForGroup(); results.add(successFunctionResult); String ids = "ids"; String catalog = "catalog"; String schema = "schema"; String[] groups = {group1Name, group2Name}; ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, ids, catalog, schema, false, groups); assertThat(result.getStatus()).isSameAs(Result.Status.OK); Object[] results = (Object[]) result.getConfigObject(); RegionMapping regionMapping = (RegionMapping) results[0]; boolean synchronous = (boolean) results[1]; assertThat(regionMapping).isNotNull(); assertThat(regionMapping.getRegionName()).isEqualTo(regionName); assertThat(regionMapping.getDataSourceName()).isEqualTo(dataSourceName); assertThat(regionMapping.getTableName()).isEqualTo(tableName); assertThat(regionMapping.getPdxName()).isEqualTo(pdxClass); assertThat(regionMapping.getIds()).isEqualTo(ids); assertThat(regionMapping.getCatalog()).isEqualTo(catalog); assertThat(regionMapping.getSchema()).isEqualTo(schema); assertThat(regionMapping.getFieldMappings()).isEmpty(); assertThat(synchronous).isFalse(); }
@Test public void createsMappingReturnsCorrectFieldMappings() throws IOException { setupRequiredPreconditions(); results.add(successFunctionResult); String ids = "ids"; String catalog = "catalog"; String schema = "schema"; this.fieldMappings.add(new FieldMapping("pdx1", "pdx1type", "jdbc1", "jdbc1type", false)); this.fieldMappings.add(new FieldMapping("pdx2", "pdx2type", "jdbc2", "jdbc2type", false)); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, ids, catalog, schema, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); Object[] results = (Object[]) result.getConfigObject(); RegionMapping regionMapping = (RegionMapping) results[0]; assertThat(regionMapping.getFieldMappings()).isEqualTo(this.fieldMappings); }
@Test public void createsMappingWithPdxClassFileReturnsCorrectFieldMappings() throws IOException { RemoteInputStream remoteInputStream = setupPdxClassFile(); setupRequiredPreconditions(); results.add(successFunctionResult); String ids = "ids"; String catalog = "catalog"; String schema = "schema"; this.fieldMappings.add(new FieldMapping("pdx1", "pdx1type", "jdbc1", "jdbc1type", false)); this.fieldMappings.add(new FieldMapping("pdx2", "pdx2type", "jdbc2", "jdbc2type", false)); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, ids, catalog, schema, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); Object[] results = (Object[]) result.getConfigObject(); RegionMapping regionMapping = (RegionMapping) results[0]; assertThat(regionMapping.getFieldMappings()).isEqualTo(this.fieldMappings); ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class); verify(createRegionMappingCommand).executeFunctionAndGetFunctionResult(any(), argumentCaptor.capture(), any()); Object[] args = argumentCaptor.getValue(); assertThat(args).hasSize(3); assertThat(args[0]).isEqualTo(regionMapping); assertThat(args[1]).isEqualTo("myPdxClassFilePath"); assertThat(args[2]).isSameAs(remoteInputStream); }
@Test public void createsMappingReturnsRegionMappingWithComputedIds() throws IOException { setupRequiredPreconditions(); results.add(successFunctionResult); String ids = "does not matter"; String catalog = "catalog"; String schema = "schema"; String computedIds = "id1,id2"; preconditionOutput[0] = computedIds; ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, ids, catalog, schema, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); Object[] results = (Object[]) result.getConfigObject(); RegionMapping regionMapping = (RegionMapping) results[0]; assertThat(regionMapping.getIds()).isEqualTo(computedIds); }
@Test public void createsMappingReturnsErrorIfPreconditionCheckErrors() throws IOException { setupRequiredPreconditions(); results.add(successFunctionResult); String ids = "ids"; String catalog = "catalog"; String schema = "schema"; when(preconditionCheckResults.isSuccessful()).thenReturn(false); when(preconditionCheckResults.getStatusMessage()).thenReturn("precondition check failed"); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, ids, catalog, schema, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("precondition check failed"); }
@Test public void createsMappingWithRegionPathCreatesMappingWithSlashRemoved() throws IOException { setupRequiredPreconditions(); results.add(successFunctionResult); ResultModel result = createRegionMappingCommand.createMapping(SEPARATOR + regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); Object[] results = (Object[]) result.getConfigObject(); RegionMapping regionMapping = (RegionMapping) results[0]; assertThat(regionMapping).isNotNull(); assertThat(regionMapping.getRegionName()).isEqualTo(regionName); }
@Test public void createsMappingReturnsStatusERRORWhenFunctionResultIsEmpty() throws IOException { setupRequiredPreconditions(); results.clear(); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); }
@Test public void createsMappingReturnsStatusERRORWhenClusterConfigIsDisabled() throws IOException { results.add(successFunctionResult); doReturn(null).when(createRegionMappingCommand).getConfigurationPersistenceService(); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("Cluster Configuration must be enabled."); }
@Test public void createsMappingReturnsStatusERRORWhenClusterConfigDoesNotContainRegion() throws IOException { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(cacheConfig); when(cacheConfig.getRegions()).thenReturn(Collections.emptyList()); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()) .contains("A region named " + regionName + " must already exist."); }
@Test public void createsMappingReturnsStatusERRORWhenRegionMappingExists() throws IOException { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); DeclarableType loaderDeclarable = mock(DeclarableType.class); when(loaderDeclarable.getClassName()).thenReturn(null); when(loaderAttribute.getCacheLoader()).thenReturn(loaderDeclarable); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); List<CacheElement> customList = new ArrayList<>(); RegionMapping existingMapping = mock(RegionMapping.class); customList.add(existingMapping); when(matchingRegion.getCustomRegionElements()).thenReturn(customList); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("A JDBC mapping for " + regionName + " already exists."); }
@Test public void createsMappingIsSkippedWhenRegionMappingExistsWithIfNotExistsTrue() throws IOException { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); DeclarableType loaderDeclarable = mock(DeclarableType.class); when(loaderDeclarable.getClassName()).thenReturn(null); when(loaderAttribute.getCacheLoader()).thenReturn(loaderDeclarable); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); List<CacheElement> customList = new ArrayList<>(); RegionMapping existingMapping = mock(RegionMapping.class); customList.add(existingMapping); when(matchingRegion.getCustomRegionElements()).thenReturn(customList); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, true, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); assertThat(result.toString()) .contains("Skipping: A JDBC mapping for " + regionName + " already exists."); }
@Test public void createsMappingReturnsStatusERRORWhenClusterConfigRegionHasLoader() throws IOException { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); DeclarableType loaderDeclarable = mock(DeclarableType.class); when(loaderDeclarable.getClassName()).thenReturn("MyCacheLoaderClass"); when(loaderAttribute.getCacheLoader()).thenReturn(loaderDeclarable); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("The existing region " + regionName + " must not already have a cache-loader, but it has MyCacheLoaderClass"); }
@Test public void createMappingWithSynchronousReturnsStatusERRORWhenClusterConfigRegionHasWriter() throws IOException { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType writerAttribute = mock(RegionAttributesType.class); DeclarableType writerDeclarable = mock(DeclarableType.class); when(writerDeclarable.getClassName()).thenReturn("MyCacheWriterClass"); when(writerAttribute.getCacheWriter()).thenReturn(writerDeclarable); when(matchingRegion.getRegionAttributes()).thenReturn(writerAttribute); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, true, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("The existing region " + regionName + " must not already have a cache-writer, but it has MyCacheWriterClass"); }
@Test public void createMappingWithSynchronousReturnsStatusOKWhenAsycnEventQueueAlreadyExists() throws IOException { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); when(loaderAttribute.getCacheLoader()).thenReturn(null); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); List<AsyncEventQueue> asyncEventQueues = new ArrayList<>(); AsyncEventQueue matchingQueue = mock(AsyncEventQueue.class); String queueName = MappingCommandUtils.createAsyncEventQueueName(regionName); when(matchingQueue.getId()).thenReturn(queueName); asyncEventQueues.add(matchingQueue); when(cacheConfig.getAsyncEventQueues()).thenReturn(asyncEventQueues); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, true, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.OK); }
@Test public void createsMappingReturnsStatusERRORWhenAsycnEventQueueAlreadyExists() throws IOException { results.add(successFunctionResult); ConfigurationPersistenceService configurationPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(configurationPersistenceService).when(createRegionMappingCommand) .getConfigurationPersistenceService(); when(configurationPersistenceService .getCacheConfig(ConfigurationPersistenceService.CLUSTER_CONFIG)).thenReturn(cacheConfig); List<RegionConfig> list = new ArrayList<>(); list.add(matchingRegion); when(cacheConfig.getRegions()).thenReturn(list); RegionAttributesType loaderAttribute = mock(RegionAttributesType.class); when(loaderAttribute.getCacheLoader()).thenReturn(null); when(matchingRegion.getRegionAttributes()).thenReturn(loaderAttribute); List<AsyncEventQueue> asyncEventQueues = new ArrayList<>(); AsyncEventQueue matchingQueue = mock(AsyncEventQueue.class); String queueName = MappingCommandUtils.createAsyncEventQueueName(regionName); when(matchingQueue.getId()).thenReturn(queueName); asyncEventQueues.add(matchingQueue); when(cacheConfig.getAsyncEventQueues()).thenReturn(asyncEventQueues); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, pdxClassFile, false, null, null, null, false, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()) .contains("An async-event-queue named " + queueName + " must not already exist."); }