diff options
Diffstat (limited to 'eaaf-springboot-utils/src/test')
4 files changed, 130 insertions, 0 deletions
diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/SimpleSpringBootStarterTest.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/SimpleSpringBootStarterTest.java new file mode 100644 index 00000000..3313d36e --- /dev/null +++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/SimpleSpringBootStarterTest.java @@ -0,0 +1,62 @@ +package at.gv.egiz.eaaf.utils.springboot.test; + +import java.io.IOException; + +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.ExitCodeGenerator; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.context.ConfigurableApplicationContext; + +import at.gv.egiz.eaaf.utils.springboot.test.dummy.DummySpringBootApp; + +public class SimpleSpringBootStarterTest { + + @Test + public void Test() throws ClientProtocolException, IOException { + + DummySpringBootApp.main(new String[] { + "--spring.config.location=classpath:/jUnit_application.properties"}); + + ConfigurableApplicationContext ctx = DummySpringBootApp.getCtx(); + Assert.assertNotNull("SpringBootContext", ctx); + + //check if AJP Connector config was set + TomcatServletWebServerFactory ajp = ctx.getBean(TomcatServletWebServerFactory.class); + Assert.assertNotNull("No AJP connector", ajp); + + //check simple http calls + testSimpleHttpCall(); + + + + SpringApplication.exit(ctx, new ExitCodeGenerator() { + @Override + public int getExitCode() { + // TODO Auto-generated method stub + return 0; + } + }); + } + + private void testSimpleHttpCall() throws ClientProtocolException, IOException { + // check if authentication works on actuator end-point + final HttpClientBuilder builder = HttpClients.custom(); + final CloseableHttpClient client = builder.build(); + Assert.assertNotNull("httpClient", client); + + final HttpUriRequest httpGet1 = new HttpGet("http://localhost:8080/junit"); + final CloseableHttpResponse httpResp1 = client.execute(httpGet1); + Assert.assertEquals("http statusCode", 200, httpResp1.getStatusLine().getStatusCode()); + + } + +} diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/dummy/DummyController.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/dummy/DummyController.java new file mode 100644 index 00000000..65dcf5c1 --- /dev/null +++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/dummy/DummyController.java @@ -0,0 +1,23 @@ +package at.gv.egiz.eaaf.utils.springboot.test.dummy; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + + +@Controller +public class DummyController { + + @RequestMapping(value = {"/junit"}, + method = { RequestMethod.POST, RequestMethod.GET }) + public void performGenericAuthenticationProcess(HttpServletRequest req, HttpServletResponse resp) + throws IOException { + resp.setStatus(200); + + } +} diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/dummy/DummySpringBootApp.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/dummy/DummySpringBootApp.java new file mode 100644 index 00000000..bc742371 --- /dev/null +++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/dummy/DummySpringBootApp.java @@ -0,0 +1,26 @@ +package at.gv.egiz.eaaf.utils.springboot.test.dummy; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; + +import lombok.Getter; + +@ComponentScan(basePackages = {"at.gv.egiz.eaaf.utils.springboot"}) +@EnableAutoConfiguration +@SpringBootApplication +public class DummySpringBootApp { + + @Getter + private static ConfigurableApplicationContext ctx; + + public static void main(String[] args) { + + final SpringApplication springApp = new SpringApplication(DummySpringBootApp.class); + ctx = springApp.run(args); + + } + +} diff --git a/eaaf-springboot-utils/src/test/resources/jUnit_application.properties b/eaaf-springboot-utils/src/test/resources/jUnit_application.properties new file mode 100644 index 00000000..dd7a77c1 --- /dev/null +++ b/eaaf-springboot-utils/src/test/resources/jUnit_application.properties @@ -0,0 +1,19 @@ +## embbeded Tomcat +tomcat.workingdir=./target/work +tomcat.ajp.enabled=true +tomcat.ajp.port=8009 +tomcat.ajp.networkAddress=127.0.0.1 +tomcat.ajp.additionalAttributes.secretrequired=true +tomcat.ajp.additionalAttributes.secret=junit + +############################################################################# +## Embedded Tomcat Logging +logging.accesslog.enabled=true +logging.mdc.enabled=true +logging.mdc.headers[0]=header1 +logging.mdc.headers[1]=header2 +logging.mdc.cookies[0]=cookie1 +logging.mdc.cookies[1]=cookie2 +logging.mdc.sessionAttributes[0]=attr1 +logging.mdc.sessionAttributes[1]=attr2 +logging.mdc.nullvalue=null
\ No newline at end of file |