How to do integration test with AWS @EnableRdsInstance
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
add a comment |
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
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
add a comment |
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
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
java spring amazon-web-services spring-boot amazon-rds
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
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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