AlterQueryServiceCommand extends SingleGfshCommand { QueryConfigService getQueryConfigService() { ConfigurationPersistenceService configService = getConfigurationPersistenceService(); if (configService != null) { CacheConfig cacheConfig = configService.getCacheConfig(null); if (cacheConfig != null) { QueryConfigService queryConfigService = cacheConfig .findCustomCacheElement(QueryConfigService.ELEMENT_ID, QueryConfigService.class); if (queryConfigService != null) { return queryConfigService; } } } return new QueryConfigService(); }  @CliCommand(value = COMMAND_NAME, help = COMMAND_HELP) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel execute(
      @CliOption(key = AUTHORIZER_NAME, help = METHOD_AUTHORIZER_NAME_HELP,
          mandatory = true) String methodAuthorizerName,
      @CliOption(key = AUTHORIZER_PARAMETERS, help = AUTHORIZER_PARAMETERS_HELP,
          optionContext = "splittingRegex=" + SPLITTING_REGEX) String[] authorizerParameters,
      @CliOption(key = FORCE_UPDATE, help = FORCE_UPDATE_HELP, specifiedDefaultValue = "true",
          unspecifiedDefaultValue = "false") boolean forceUpdate); @Override boolean updateConfigForGroup(String group, CacheConfig config, Object configObject); static final String PARTIAL_FAILURE_MESSAGE; }
@Test public void getQueryConfigurationServiceReturnsExistingQueryConfigService() { CacheConfig mockCacheConfig = mock(CacheConfig.class); QueryConfigService mockQueryConfigService = mock(QueryConfigService.class); ConfigurationPersistenceService mockConfigPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(mockConfigPersistenceService).when(command).getConfigurationPersistenceService(); when(mockConfigPersistenceService.getCacheConfig(null)).thenReturn(mockCacheConfig); when(mockCacheConfig.findCustomCacheElement(QueryConfigService.ELEMENT_ID, QueryConfigService.class)).thenReturn(mockQueryConfigService); assertThat(command.getQueryConfigService()).isSameAs(mockQueryConfigService); }
@Test public void getQueryConfigurationServiceReturnsNewQueryConfigServiceWhenNoExistingServiceIsFound() { CacheConfig mockCacheConfig = mock(CacheConfig.class); ConfigurationPersistenceService mockConfigPersistenceService = mock(ConfigurationPersistenceService.class); doReturn(mockConfigPersistenceService).when(command).getConfigurationPersistenceService(); when(mockConfigPersistenceService.getCacheConfig(null)).thenReturn(mockCacheConfig); when(mockCacheConfig.findCustomCacheElement(QueryConfigService.ELEMENT_ID, QueryConfigService.class)).thenReturn(null); assertThat(command.getQueryConfigService()).isInstanceOf(QueryConfigService.class); }