aboutsummaryrefslogtreecommitdiff
path: root/ms_specific_connector/src/test/java/at/asitplus/eidas/specific/connector/test/MainClassExecutableModeTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ms_specific_connector/src/test/java/at/asitplus/eidas/specific/connector/test/MainClassExecutableModeTest.java')
-rw-r--r--ms_specific_connector/src/test/java/at/asitplus/eidas/specific/connector/test/MainClassExecutableModeTest.java119
1 files changed, 119 insertions, 0 deletions
diff --git a/ms_specific_connector/src/test/java/at/asitplus/eidas/specific/connector/test/MainClassExecutableModeTest.java b/ms_specific_connector/src/test/java/at/asitplus/eidas/specific/connector/test/MainClassExecutableModeTest.java
new file mode 100644
index 00000000..708560b2
--- /dev/null
+++ b/ms_specific_connector/src/test/java/at/asitplus/eidas/specific/connector/test/MainClassExecutableModeTest.java
@@ -0,0 +1,119 @@
+package at.asitplus.eidas.specific.connector.test;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+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.apache.ignite.Ignition;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+
+import at.asitplus.eidas.specific.connector.SpringBootApplicationInitializer;
+import at.gv.egiz.eaaf.core.impl.logging.DummyStatusMessager;
+import at.gv.egiz.eaaf.core.impl.logging.LogMessageProviderFactory;
+import eu.eidas.auth.cache.IgniteInstanceInitializerSpecificCommunication;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@RunWith(BlockJUnit4ClassRunner.class)
+public class MainClassExecutableModeTest {
+
+ /**
+ * jUnit class initializer.
+ * @throws InterruptedException In case of an error
+ *
+ */
+ @BeforeClass
+ public static void classInitializer() throws InterruptedException {
+ final String current = new java.io.File(".").toURI().toString();
+ System.clearProperty("eidas.ms.configuration");
+
+ //eIDAS Ref. Impl. properties
+ System.setProperty("EIDAS_CONFIG_REPOSITORY", current.substring("file:".length())
+ + "../basicConfig/eIDAS/");
+ System.setProperty("SPECIFIC_CONNECTOR_CONFIG_REPOSITORY", current.substring("file:".length())
+ + "../basicConfig/eIDAS/");
+ System.setProperty("SPECIFIC_PROXY_SERVICE_CONFIG_REPOSITORY", current.substring("file:".length())
+ + "../basicConfig/eIDAS/");
+
+ }
+
+ /**
+ * Initializer.
+ * @throws Exception In case of an error
+ *
+ */
+ @AfterClass
+ public static void closeIgniteNode() throws Exception {
+ System.out.println("Closing Ignite Node ... ");
+
+ log.info("Stopping already running Apache Ignite nodes ... ");
+ Ignition.stopAll(true);
+ Thread.sleep(1000);
+
+ //set Ignite-node holder to 'null' because static holders are shared between different tests
+ final Field field = IgniteInstanceInitializerSpecificCommunication.class.getDeclaredField("instance");
+ field.setAccessible(true);
+ field.set(null, null);
+
+ }
+
+ /**
+ * Test reseter.
+ *
+ */
+ @After
+ public void cleanJvmState() throws NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException {
+ final Field field = LogMessageProviderFactory.class.getDeclaredField("internalMessager");
+ field.setAccessible(true);
+ field.set(null, new DummyStatusMessager());
+
+ System.clearProperty("eidas.ms.configuration");
+ SpringBootApplicationInitializer.exit();
+
+ }
+
+
+ @Test
+ public void validConfigLocation() throws Throwable {
+ SpringBootApplicationInitializer
+ .main(new String[] {
+ "--spring.config.location=src/test/resources/config/junit_config_2_springboot.properties,classpath:/application.properties",
+ "--spring.profiles.active=jUnitTestMode" });
+
+ System.out.println("Is started!");
+
+ // test Spring-Actuator http Basic-Auth
+ testSpringActuatorSecurity();
+
+ }
+
+ private void testSpringActuatorSecurity() 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 httpGetInfo = new HttpGet("http://localhost:8080/ms_connector/actuator/info");
+ final CloseableHttpResponse httpRespInfo = client.execute(httpGetInfo);
+ Assert.assertEquals("http statusCode", 200, httpRespInfo.getStatusLine().getStatusCode());
+
+ final HttpUriRequest httpGetHealth = new HttpGet("http://localhost:8080/ms_connector/actuator/health");
+ final CloseableHttpResponse httpRespHealth = client.execute(httpGetHealth);
+ Assert.assertEquals("http statusCode", 503, httpRespHealth.getStatusLine().getStatusCode());
+
+ }
+
+}