CreateDataSourceInterceptor extends UsernamePasswordInterceptor { @Override public ResultModel preExecution(GfshParseResult parseResult) { String pooled = parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED); if (pooled != null && pooled.equalsIgnoreCase("false")) { String poolProperties = parseResult.getParamValueAsString(CreateDataSourceCommand.POOL_PROPERTIES); if (poolProperties != null && poolProperties.length() > 0) { return ResultModel.createError(POOL_PROPERTIES_ONLY_VALID_ON_POOLED_DATA_SOURCE); } String pooledDataSourceFactoryClass = parseResult .getParamValueAsString(CreateDataSourceCommand.POOLED_DATA_SOURCE_FACTORY_CLASS); if (pooledDataSourceFactoryClass != null && pooledDataSourceFactoryClass.length() > 0) { return ResultModel.createError( POOLED_DATA_SOURCE_FACTORY_CLASS_ONLY_VALID_ON_POOLED_DATA_SOURCE); } } return super.preExecution(parseResult); } CreateDataSourceInterceptor();   CreateDataSourceInterceptor(Gfsh gfsh); @Override ResultModel preExecution(GfshParseResult parseResult);  }
@Test public void defaultsAreOk() { ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.OK); }
@Test public void nonPooledIsOk() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("false"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.OK); }
@Test public void nonPooledWithEmptyPoolPropertiesIsOk() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("false"); when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOL_PROPERTIES)).thenReturn(""); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.OK); }
@Test public void nonPooledWithEmptyPoolFactoryIsOk() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("false"); when( parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED_DATA_SOURCE_FACTORY_CLASS)) .thenReturn(""); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.OK); }
@Test public void pooledIsOk() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("true"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.OK); }
@Test public void pooledWithPoolPropertiesIsOk() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("true"); when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOL_PROPERTIES)) .thenReturn("pool properties value"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.OK); }
@Test public void pooledWithPoolFactoryIsOk() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("true"); when( parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED_DATA_SOURCE_FACTORY_CLASS)) .thenReturn("pool factory value"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.OK); }
@Test public void nonPooledWithPoolPropertiesIsError() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("false"); when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOL_PROPERTIES)) .thenReturn("pool properties value"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.ERROR); assertThat(result.getInfoSection("info").getContent().get(0)) .contains(CreateDataSourceInterceptor.POOL_PROPERTIES_ONLY_VALID_ON_POOLED_DATA_SOURCE); }
@Test public void nonPooledWithPoolFactoryIsError() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("false"); when( parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED_DATA_SOURCE_FACTORY_CLASS)) .thenReturn("pool factory value"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.ERROR); assertThat(result.getInfoSection("info").getContent().get(0)) .contains( CreateDataSourceInterceptor.POOLED_DATA_SOURCE_FACTORY_CLASS_ONLY_VALID_ON_POOLED_DATA_SOURCE); }