From a15713911c1e05a2e73074a2f3bcdb5d3674a803 Mon Sep 17 00:00:00 2001 From: Justin Pfifer Date: Tue, 29 Jan 2019 18:53:54 -0800 Subject: [PATCH] Set the region for test runs (#488) The AWS SDK depends on being able to find which region it should operate in. In many cases this is either explicitly set or retrieved from a variety of sources. For these test cases we don't actually care what the region. To ensure that the tests operate as expected the region is set before the test runs, and reset upon completion. --- .../MultiLangDaemonConfigurationTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java index 868d6d49..59d99930 100644 --- a/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java +++ b/amazon-kinesis-client-multilang/src/test/java/software/amazon/kinesis/multilang/config/MultiLangDaemonConfigurationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Amazon Software License (the "License"). * You may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import static org.junit.Assert.assertThat; import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.ConvertUtilsBean; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -37,8 +38,11 @@ import software.amazon.kinesis.retrieval.polling.PollingConfig; @RunWith(MockitoJUnitRunner.class) public class MultiLangDaemonConfigurationTest { + private static final String AWS_REGION_PROPERTY_NAME = "aws.region"; + private BeanUtilsBean utilsBean; private ConvertUtilsBean convertUtilsBean; + private String originalRegionValue; @Mock private ShardRecordProcessorFactory shardRecordProcessorFactory; @@ -48,10 +52,22 @@ public class MultiLangDaemonConfigurationTest { @Before public void setup() { + originalRegionValue = System.getProperty(AWS_REGION_PROPERTY_NAME); + System.setProperty(AWS_REGION_PROPERTY_NAME, "us-east-1"); convertUtilsBean = new ConvertUtilsBean(); utilsBean = new BeanUtilsBean(convertUtilsBean); } + @After + public void after() { + if (originalRegionValue != null) { + System.setProperty(AWS_REGION_PROPERTY_NAME, originalRegionValue); + } else { + System.clearProperty(AWS_REGION_PROPERTY_NAME); + } + } + + public MultiLangDaemonConfiguration baseConfiguration() { MultiLangDaemonConfiguration configuration = new MultiLangDaemonConfiguration(utilsBean, convertUtilsBean); configuration.setApplicationName("Test");