Spring Cloud Config

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Spring Cloud Config

hlopez
Hello,

I have an application that is using spring-cloud-config to get come configuration properties it needs to start up. So the application is not holding the required fields it needs to have for startup, but getting them from the spring-cloud-config-server.
Can I use Citrus to HTTP server to mimic the response of the spring-cloud-config-server?

I'm trying the following way using the Java DSL:

- In my @Configuration
    @Bean
    public HttpServer httpServer() {
        return CitrusEndpoints.http().server().port(8888).build();
    }

- In my @CitrusTest which's class extends TestNGCitrusTestRunner
        http(new BuilderSupport<HttpActionBuilder>() {
            @Override
            public void configure(HttpActionBuilder httpActionBuilder) {
                httpActionBuilder
                        .server(httpServer)
                        .receive()
                        .get("/abc")
                        .payload("")
                        .contentType("text/html")
                        .accept("text/html, */*")
                        .timeout(5000)
                        .build();
            }
        });

The main problem I have is where do I start my application because the HTTPServer should be running first to receive the get("/abc"), I don't see an option to FORK the server so it will wait and timeout after 5 seconds.
Reply | Threaded
Open this post in threaded view
|

Re: Spring Cloud Config

hlopez
I found the following way to test my code:
@ContextConfiguration(classes = {AppConfig.class})
@TestPropertySource(properties = {"host.address=localhost", "application.name=TEST"})
public class AbcAppIT extends TestNGCitrusTestRunner {

This will let my application start correctly without needing the spring-cloud-config-server to be started up first. It makes it a bit more unit like testing.

Is there a way I can pass a TestNg Assert to Citrus Assert? If now I do some test (not messaging test), how can I make sure that Citrus will fail if my assert fails?
Currently, my TestNG Assertion is failing but Citrus is finishing with 1 successful test.
Reply | Threaded
Open this post in threaded view
|

Re: Spring Cloud Config

Christoph Deppisch
Administrator
You need to put your assertion into a Citrus test action. Possible errors will then fail the action and Citrus is able to handle this error, too. By the way in next version 2.7.3 we have improved the reporting so Citrus is also able to handle Java exceptions that were thrown outside of the test action scope. Here is an example how to add your assertion to a anonymous test action:

run(new AbstractTestAction() {
    public void doExecute(TestContext context) {
        Assert.assertFalse(true, "This will fail with error");
    } 
});
Reply | Threaded
Open this post in threaded view
|

Re: Spring Cloud Config

hlopez
Thanks, I'll upgrade to the 2.7.3 as soon as it is released to the public maven repositories.
The AbstractTestAction seems to do the trick.
Reply | Threaded
Open this post in threaded view
|

Re: Spring Cloud Config

Christoph Deppisch
Administrator
Citrus 2.7.3 has been released!