diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-12-25 21:03:24 +0100 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2020-12-25 21:03:24 +0100 |
commit | 7b83b319fce24faf12a3d69db9ccce87d0dde4f6 (patch) | |
tree | a1772907af9e12feff748bc68062d0e89e1cea97 /eaaf-springboot-utils/src/test/java/at/gv/egiz | |
parent | a378db97e9f14bfa81bd490186c065d77f5806c7 (diff) | |
parent | a3b7c488300b9b231959663bbd2dd96a4a452ec0 (diff) | |
download | EAAF-Components-7b83b319fce24faf12a3d69db9ccce87d0dde4f6.tar.gz EAAF-Components-7b83b319fce24faf12a3d69db9ccce87d0dde4f6.tar.bz2 EAAF-Components-7b83b319fce24faf12a3d69db9ccce87d0dde4f6.zip |
Merge branch 'feature/add_springboot_commons' into 'nightlyBuild'
Feature/add springboot commons
See merge request egiz/eaaf_components!8
Diffstat (limited to 'eaaf-springboot-utils/src/test/java/at/gv/egiz')
3 files changed, 111 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); + + } + +} |