Ratpack + Spring boot unit testing.

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

Ratpack + Spring boot unit testing.

ankit8051
I have following unit test.

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class ApplicationTests {

       
        @Test
        public void contextLoads() {
               
        }

}

Getting bellow error::


java.lang.IllegalStateException: Failed to execute CommandLineRunner
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:807) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:788) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:775) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:366) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:98) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) [.cp/:na]
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) [.cp/:na]
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) [.cp/:na]
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) [.cp/:na]
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) [.cp/:na]
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) [.cp/:na]
Caused by: java.lang.IllegalArgumentException: port out of range:-1
        at java.net.InetSocketAddress.checkPort(Unknown Source) ~[na:1.8.0_65]
        at java.net.InetSocketAddress.<init>(Unknown Source) ~[na:1.8.0_65]
        at java.net.InetSocketAddress.<init>(Unknown Source) ~[na:1.8.0_65]
        at ratpack.server.internal.DefaultRatpackServer.buildSocketAddress(DefaultRatpackServer.java:400) ~[ratpack-core-1.1.1.jar:na]
        at ratpack.server.internal.DefaultRatpackServer.buildChannel(DefaultRatpackServer.java:258) ~[ratpack-core-1.1.1.jar:na]
        at ratpack.server.internal.DefaultRatpackServer.start(DefaultRatpackServer.java:116) ~[ratpack-core-1.1.1.jar:na]
        at ratpack.spring.config.RatpackConfiguration.run(RatpackConfiguration.java:51) ~[ratpack-spring-boot-1.1.1.jar:na]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        ... 32 common frames omitted

2016-02-16 14:34:22.259  INFO 8488 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with

Delegate.java:116) ~[spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        ... 25 common frames omitted
Caused by: java.lang.IllegalArgumentException: port out of range:-1
        at java.net.InetSocketAddress.checkPort(Unknown Source) ~[na:1.8.0_65]
        at java.net.InetSocketAddress.<init>(Unknown Source) ~[na:1.8.0_65]
        at java.net.InetSocketAddress.<init>(Unknown Source) ~[na:1.8.0_65]
        at ratpack.server.internal.DefaultRatpackServer.buildSocketAddress(DefaultRatpackServer.java:400) ~[ratpack-core-1.1.1.jar:na]
        at ratpack.server.internal.DefaultRatpackServer.buildChannel(DefaultRatpackServer.java:258) ~[ratpack-core-1.1.1.jar:na]
        at ratpack.server.internal.DefaultRatpackServer.start(DefaultRatpackServer.java:116) ~[ratpack-core-1.1.1.jar:na]
        at ratpack.spring.config.RatpackConfiguration.run(RatpackConfiguration.java:51) ~[ratpack-spring-boot-1.1.1.jar:na]
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
        ... 32 common frames omitted

rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack + Spring boot unit testing.

rus
Looks like a port issue.  Have you tried adding `@IntegrationTest("server.port=0")` to your test class?
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack + Spring boot unit testing.

ankit8051
rus,

Thanks for your help.

Is there any specific reason to add @IntegrationTest("server.port=0") on the test class?

rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack + Spring boot unit testing.

rus
Only to see if your test passes :)

I just glanced at the stacktrace and saw the port error and noticed you didn't have that set.  The example ratpack-spring ones do.