/** * This method tests the blank proxy details */ @Test public void testEmrAwsDtoBlankProxy() throws Exception { // Set the proxy as blank too to get the EMR client without proxy AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDto(); awsParamsDto.setHttpProxyHost(""); emrDao.getEmrClient(awsParamsDto); }
/** * Constructs awsParamsDto with AWS parameters. * * @return the AWS params DTO object. */ public AwsParamsDto getAwsParamsDto() { // Get HTTP proxy configuration settings. String httpProxyHost = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST); Integer httpProxyPort = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class); // Get AWS region name. String awsRegionName = configurationHelper.getProperty(ConfigurationValue.AWS_REGION_NAME); // Create an AWS parameters DTO. AwsParamsDto awsParamsDto = new AwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); awsParamsDto.setAwsRegionName(awsRegionName); return awsParamsDto; }
/** * Constructs awsParamsDto with AWS parameters. * * @return the AWS params DTO object. */ public AwsParamsDto getAwsParamsDto() { // Get HTTP proxy configuration settings. String httpProxyHost = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST); Integer httpProxyPort = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class); // Get AWS region name. String awsRegionName = configurationHelper.getProperty(ConfigurationValue.AWS_REGION_NAME); // Create an AWS parameters DTO. AwsParamsDto awsParamsDto = new AwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); awsParamsDto.setAwsRegionName(awsRegionName); return awsParamsDto; }
@Test public void testEquals() throws Exception { AwsParamsDto dto1 = new AwsParamsDto(); dto1.setHttpProxyHost("localhost1"); dto1.setHttpProxyPort(8080); AwsParamsDto dto2 = new AwsParamsDto(); dto2.setHttpProxyHost("localhost2"); dto2.setHttpProxyPort(8080); AwsParamsDto dto3 = new AwsParamsDto(); dto3.setHttpProxyHost("localhost1"); dto3.setHttpProxyPort(8080); assertTrue(!dto1.equals(dto2)); assertTrue(dto1.equals(dto3)); }
@Test public void testGetEc2Client() throws Exception { // Get the EMR client with proxy configuration. AwsParamsDto awsParamsDto = awsHelper.getAwsParamsDto(); awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); // Set the proxy host as blank to get the EMR client without proxy. awsParamsDto.setHttpProxyHost(BLANK_TEXT); awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); // Set the proxy port as null to get the EMR client without proxy. awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); awsParamsDto.setHttpProxyPort(null); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); // Set the proxy host as blank and proxy port as null to get the EMR client without proxy. awsParamsDto.setHttpProxyHost(BLANK_TEXT); awsParamsDto.setHttpProxyPort(null); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); }
@Test public void testDecrypt() { // Decrypt the test ciphertext. AwsParamsDto testAwsParamsDto = new AwsParamsDto(); testAwsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); testAwsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT); // Decrypt the test ciphertext. String resultPlainText = kmsDao.decrypt(testAwsParamsDto, MockKmsOperationsImpl.MOCK_CIPHER_TEXT); // Validate the results. assertEquals(MockKmsOperationsImpl.MOCK_PLAIN_TEXT, resultPlainText); }
@Test public void testHashCode() throws Exception { AwsParamsDto dto1 = new AwsParamsDto(); dto1.setHttpProxyHost("localhost1"); dto1.setHttpProxyPort(8080); AwsParamsDto dto2 = new AwsParamsDto(); dto2.setHttpProxyHost("localhost2"); dto2.setHttpProxyPort(8080); AwsParamsDto dto3 = new AwsParamsDto(); dto3.setHttpProxyHost("localhost1"); dto3.setHttpProxyPort(8080); assertTrue(dto1.hashCode() != dto2.hashCode()); assertTrue(dto1.hashCode() == dto3.hashCode()); } }
@Test public void testGetClientConfiguration() throws Exception { // Try to get AWS parameters using all possible permutations of HTTP proxy settings. for (String testHttpProxyHost : Arrays.asList(STRING_VALUE, BLANK_TEXT, null)) { for (Integer testHttpProxyPort : Arrays.asList(INTEGER_VALUE, null)) { // Create AWS parameters DTO. AwsParamsDto testAwsParamsDto = awsHelper.getAwsParamsDto(); testAwsParamsDto.setHttpProxyHost(testHttpProxyHost); testAwsParamsDto.setHttpProxyPort(testHttpProxyPort); // Get client configuration. ClientConfiguration resultClientConfiguration = awsHelper.getClientConfiguration(testAwsParamsDto); // Validate the results. assertNotNull(resultClientConfiguration); // The proxy settings are set only when both host and port are specified in the AWS parameters DTO. if (STRING_VALUE.equals(testHttpProxyHost) && INTEGER_VALUE.equals(testHttpProxyPort)) { assertEquals(testHttpProxyHost, resultClientConfiguration.getProxyHost()); assertEquals(testHttpProxyPort, Integer.valueOf(resultClientConfiguration.getProxyPort())); } else { assertNull(resultClientConfiguration.getProxyHost()); assertEquals(-1, resultClientConfiguration.getProxyPort()); } } } }
@Test public void getEmrClientAssertClientConfigurationSet() throws Exception { String httpProxyHost = "httpProxyHost"; Integer httpProxyPort = 1234; AwsParamsDto awsParamsDto = getAwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration"); assertNotNull(clientConfiguration); assertEquals(httpProxyHost, clientConfiguration.getProxyHost()); assertEquals(httpProxyPort.intValue(), clientConfiguration.getProxyPort()); }
awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT);
@Test public void getEmrClientAssertClientConfigurationNotSetWhenProxyPortIsNull() throws Exception { String httpProxyHost = "httpProxyHost"; Integer httpProxyPort = null; AwsParamsDto awsParamsDto = getAwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration"); assertNotNull(clientConfiguration); assertNull(clientConfiguration.getProxyHost()); }
@Test public void getEmrClientAssertClientConfigurationNotSetWhenProxyHostIsBlank() throws Exception { String httpProxyHost = ""; Integer httpProxyPort = 1234; AwsParamsDto awsParamsDto = getAwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration"); assertNotNull(clientConfiguration); assertNull(clientConfiguration.getProxyHost()); }
sourceHttpProxyHost = this.getHttpProxyHost(); String copyHttpProxyHost = ((String) strategy.copy(LocatorUtils.property(locator, "httpProxyHost", sourceHttpProxyHost), sourceHttpProxyHost, (this.httpProxyHost!= null))); copy.setHttpProxyHost(copyHttpProxyHost); } else { if (httpProxyHostShouldBeCopiedAndSet == Boolean.FALSE) {