How to do integration test with AWS @EnableRdsInstance












0















I am new to Spring Boot and Spring AWS Cloud. I am trying to complete this tutorial http://www.briansjavablog.com/2016/05/spring-boot-angular-amazon-web-services.html. Although the tutorial is really good, it turns out it hasn't any test.



I would like to execute some integration tests with RDS in AWS, to check the connection is OK.
I am using next class as a AWS Resource Config:



@Configuration
@ImportResource("classpath:/aws-config.xml")
@EnableRdsInstance(databaseName = "${rds.name}",
dbInstanceIdentifier = "${rds.instance}",
password = "${rds.password}",
username = "${rds.username}")
public class AwsResourceConfig {
}


I am building tests like this one:



@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles({"test"})
public class EmployeeControllerTest {

@Autowired
private MockMvc mvc;

@MockBean
private EmployeeRepository employeeRepository;

@Test
public void whenGetEmployees_thenEmployeesAreReturned() throws Exception {

// given
Employee employee = givenEmployee();
when(employeeRepository.findAll()).thenReturn(new ArrayList<>(Arrays.asList(employee)));

// when
MvcResult result = mvc.perform(get("/employees"))
.andReturn();

// then
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getResponse().getContentAsString()).isNotEmpty();
}


But when I am runnning those tests, it seems Spring is looking for those placeholders to be created. I tried to add them in several places, but with no luck. The error I got is:




Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '${rds.instance}': Invocation of init
method failed; nested exception is
com.amazonaws.services.rds.model.AmazonRDSException: Invalid database
identifier: ${rds.instance} (Service: AmazonRDS; Status Code: 400;
Error Code: InvalidParameterValue; Request ID:
e83246b2-bba4-4b5f-87ec-13851f0dd711)




When I run this application in local, it is working as expected, only failing when running the tests. Do you know why?
Please feel free to ask for any other resource in case you need it.



Thank you!










share|improve this question

























  • Hi, from your question, seems like you have set up an application.yml file containing the instance information(name,password,etc...). You will need to do the same for your test directory as well. copying the same information to the resources folder in your test directory and also setting up another Config class for your test

    – JWiryo
    Nov 26 '18 at 8:35


















0















I am new to Spring Boot and Spring AWS Cloud. I am trying to complete this tutorial http://www.briansjavablog.com/2016/05/spring-boot-angular-amazon-web-services.html. Although the tutorial is really good, it turns out it hasn't any test.



I would like to execute some integration tests with RDS in AWS, to check the connection is OK.
I am using next class as a AWS Resource Config:



@Configuration
@ImportResource("classpath:/aws-config.xml")
@EnableRdsInstance(databaseName = "${rds.name}",
dbInstanceIdentifier = "${rds.instance}",
password = "${rds.password}",
username = "${rds.username}")
public class AwsResourceConfig {
}


I am building tests like this one:



@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles({"test"})
public class EmployeeControllerTest {

@Autowired
private MockMvc mvc;

@MockBean
private EmployeeRepository employeeRepository;

@Test
public void whenGetEmployees_thenEmployeesAreReturned() throws Exception {

// given
Employee employee = givenEmployee();
when(employeeRepository.findAll()).thenReturn(new ArrayList<>(Arrays.asList(employee)));

// when
MvcResult result = mvc.perform(get("/employees"))
.andReturn();

// then
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getResponse().getContentAsString()).isNotEmpty();
}


But when I am runnning those tests, it seems Spring is looking for those placeholders to be created. I tried to add them in several places, but with no luck. The error I got is:




Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '${rds.instance}': Invocation of init
method failed; nested exception is
com.amazonaws.services.rds.model.AmazonRDSException: Invalid database
identifier: ${rds.instance} (Service: AmazonRDS; Status Code: 400;
Error Code: InvalidParameterValue; Request ID:
e83246b2-bba4-4b5f-87ec-13851f0dd711)




When I run this application in local, it is working as expected, only failing when running the tests. Do you know why?
Please feel free to ask for any other resource in case you need it.



Thank you!










share|improve this question

























  • Hi, from your question, seems like you have set up an application.yml file containing the instance information(name,password,etc...). You will need to do the same for your test directory as well. copying the same information to the resources folder in your test directory and also setting up another Config class for your test

    – JWiryo
    Nov 26 '18 at 8:35
















0












0








0








I am new to Spring Boot and Spring AWS Cloud. I am trying to complete this tutorial http://www.briansjavablog.com/2016/05/spring-boot-angular-amazon-web-services.html. Although the tutorial is really good, it turns out it hasn't any test.



I would like to execute some integration tests with RDS in AWS, to check the connection is OK.
I am using next class as a AWS Resource Config:



@Configuration
@ImportResource("classpath:/aws-config.xml")
@EnableRdsInstance(databaseName = "${rds.name}",
dbInstanceIdentifier = "${rds.instance}",
password = "${rds.password}",
username = "${rds.username}")
public class AwsResourceConfig {
}


I am building tests like this one:



@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles({"test"})
public class EmployeeControllerTest {

@Autowired
private MockMvc mvc;

@MockBean
private EmployeeRepository employeeRepository;

@Test
public void whenGetEmployees_thenEmployeesAreReturned() throws Exception {

// given
Employee employee = givenEmployee();
when(employeeRepository.findAll()).thenReturn(new ArrayList<>(Arrays.asList(employee)));

// when
MvcResult result = mvc.perform(get("/employees"))
.andReturn();

// then
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getResponse().getContentAsString()).isNotEmpty();
}


But when I am runnning those tests, it seems Spring is looking for those placeholders to be created. I tried to add them in several places, but with no luck. The error I got is:




Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '${rds.instance}': Invocation of init
method failed; nested exception is
com.amazonaws.services.rds.model.AmazonRDSException: Invalid database
identifier: ${rds.instance} (Service: AmazonRDS; Status Code: 400;
Error Code: InvalidParameterValue; Request ID:
e83246b2-bba4-4b5f-87ec-13851f0dd711)




When I run this application in local, it is working as expected, only failing when running the tests. Do you know why?
Please feel free to ask for any other resource in case you need it.



Thank you!










share|improve this question
















I am new to Spring Boot and Spring AWS Cloud. I am trying to complete this tutorial http://www.briansjavablog.com/2016/05/spring-boot-angular-amazon-web-services.html. Although the tutorial is really good, it turns out it hasn't any test.



I would like to execute some integration tests with RDS in AWS, to check the connection is OK.
I am using next class as a AWS Resource Config:



@Configuration
@ImportResource("classpath:/aws-config.xml")
@EnableRdsInstance(databaseName = "${rds.name}",
dbInstanceIdentifier = "${rds.instance}",
password = "${rds.password}",
username = "${rds.username}")
public class AwsResourceConfig {
}


I am building tests like this one:



@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles({"test"})
public class EmployeeControllerTest {

@Autowired
private MockMvc mvc;

@MockBean
private EmployeeRepository employeeRepository;

@Test
public void whenGetEmployees_thenEmployeesAreReturned() throws Exception {

// given
Employee employee = givenEmployee();
when(employeeRepository.findAll()).thenReturn(new ArrayList<>(Arrays.asList(employee)));

// when
MvcResult result = mvc.perform(get("/employees"))
.andReturn();

// then
assertThat(result.getResponse().getStatus()).isEqualTo(HttpStatus.OK.value());
assertThat(result.getResponse().getContentAsString()).isNotEmpty();
}


But when I am runnning those tests, it seems Spring is looking for those placeholders to be created. I tried to add them in several places, but with no luck. The error I got is:




Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '${rds.instance}': Invocation of init
method failed; nested exception is
com.amazonaws.services.rds.model.AmazonRDSException: Invalid database
identifier: ${rds.instance} (Service: AmazonRDS; Status Code: 400;
Error Code: InvalidParameterValue; Request ID:
e83246b2-bba4-4b5f-87ec-13851f0dd711)




When I run this application in local, it is working as expected, only failing when running the tests. Do you know why?
Please feel free to ask for any other resource in case you need it.



Thank you!







java spring amazon-web-services spring-boot amazon-rds






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 8:27







alonso_50

















asked Nov 25 '18 at 14:25









alonso_50alonso_50

636713




636713













  • Hi, from your question, seems like you have set up an application.yml file containing the instance information(name,password,etc...). You will need to do the same for your test directory as well. copying the same information to the resources folder in your test directory and also setting up another Config class for your test

    – JWiryo
    Nov 26 '18 at 8:35





















  • Hi, from your question, seems like you have set up an application.yml file containing the instance information(name,password,etc...). You will need to do the same for your test directory as well. copying the same information to the resources folder in your test directory and also setting up another Config class for your test

    – JWiryo
    Nov 26 '18 at 8:35



















Hi, from your question, seems like you have set up an application.yml file containing the instance information(name,password,etc...). You will need to do the same for your test directory as well. copying the same information to the resources folder in your test directory and also setting up another Config class for your test

– JWiryo
Nov 26 '18 at 8:35







Hi, from your question, seems like you have set up an application.yml file containing the instance information(name,password,etc...). You will need to do the same for your test directory as well. copying the same information to the resources folder in your test directory and also setting up another Config class for your test

– JWiryo
Nov 26 '18 at 8:35














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468459%2fhow-to-do-integration-test-with-aws-enablerdsinstance%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53468459%2fhow-to-do-integration-test-with-aws-enablerdsinstance%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'