summaryrefslogtreecommitdiff
path: root/eaaf-springboot-utils/src/test/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf-springboot-utils/src/test/java/at/gv/egiz')
-rw-r--r--eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/SimpleSpringBootStarterTest.java2
-rw-r--r--eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckNoKeyStoreFactoryTest.java38
-rw-r--r--eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckTest.java96
3 files changed, 135 insertions, 1 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
index 3313d36e..611cc3aa 100644
--- 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
@@ -24,7 +24,7 @@ public class SimpleSpringBootStarterTest {
public void Test() throws ClientProtocolException, IOException {
DummySpringBootApp.main(new String[] {
- "--spring.config.location=classpath:/jUnit_application.properties"});
+ "--spring.config.location=classpath:/config/jUnit_application.properties"});
ConfigurableApplicationContext ctx = DummySpringBootApp.getCtx();
Assert.assertNotNull("SpringBootContext", ctx);
diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckNoKeyStoreFactoryTest.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckNoKeyStoreFactoryTest.java
new file mode 100644
index 00000000..92c88544
--- /dev/null
+++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckNoKeyStoreFactoryTest.java
@@ -0,0 +1,38 @@
+package at.gv.egiz.eaaf.utils.springboot.test.actuator;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.boot.actuate.health.Status;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import at.gv.egiz.eaaf.core.impl.credential.EaafKeyStoreFactory;
+import at.gv.egiz.eaaf.utils.springboot.actuator.HsmFacadeProviderHealthCheck;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/spring/test_spring_actuator.xml")
+public class HsmFacadeProviderHealthCheckNoKeyStoreFactoryTest {
+
+ @Mock
+ private EaafKeyStoreFactory keyStoreFactory;
+
+ @InjectMocks
+ @Autowired
+ private HsmFacadeProviderHealthCheck check;
+
+ @Test
+ public void noEaafKeyStoreFactoryBean() {
+ //get current status
+ Health status = check.health();
+
+ //validate result
+ Assert.assertEquals("wrong statusCode", Status.UNKNOWN.getCode(), status.getStatus().getCode());
+
+ }
+
+}
diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckTest.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckTest.java
new file mode 100644
index 00000000..29feee5e
--- /dev/null
+++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/actuator/HsmFacadeProviderHealthCheckTest.java
@@ -0,0 +1,96 @@
+package at.gv.egiz.eaaf.utils.springboot.test.actuator;
+
+import static org.mockito.Mockito.when;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.boot.actuate.health.Status;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import at.gv.egiz.eaaf.core.impl.credential.EaafKeyStoreFactory;
+import at.gv.egiz.eaaf.core.impl.credential.EaafKeyStoreFactory.HsmFacadeStatus;
+import at.gv.egiz.eaaf.utils.springboot.actuator.HsmFacadeProviderHealthCheck;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/spring/test_spring_actuator.xml")
+public class HsmFacadeProviderHealthCheckTest {
+
+ @Mock
+ private EaafKeyStoreFactory keyStoreFactory = Mockito.mock(EaafKeyStoreFactory.class);
+
+ @InjectMocks
+ @Autowired
+ private HsmFacadeProviderHealthCheck check;
+
+ @Before
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+
+ }
+
+ @Test
+ public void hsmFacadeStatusUnknown() {
+ //set-up test result
+ when(keyStoreFactory.isHsmFacadeInitialized()).thenReturn(false);
+
+ //get current status
+ Health status = check.health();
+
+ //validate result
+ Assert.assertEquals("wrong statusCode", Status.UNKNOWN.getCode(), status.getStatus().getCode());
+
+ }
+
+ @Test
+ public void statusUp() throws Exception {
+ //set-up test result
+ when(keyStoreFactory.isHsmFacadeInitialized()).thenReturn(true);
+ when(keyStoreFactory.checkHsmFacadeStatus()).thenReturn(HsmFacadeStatus.UP);
+
+ //get current status
+ Health status = check.health();
+
+ //validate result
+ Assert.assertEquals("wrong statusCode", Status.UP.getCode(), status.getStatus().getCode());
+
+ }
+
+ @Test
+ public void statusDown() throws Exception {
+ //set-up test result
+ when(keyStoreFactory.isHsmFacadeInitialized()).thenReturn(true);
+ when(keyStoreFactory.checkHsmFacadeStatus()).thenReturn(HsmFacadeStatus.DOWN);
+
+ //get current status
+ Health status = check.health();
+
+ //validate result
+ Assert.assertEquals("wrong statusCode", Status.DOWN.getCode(), status.getStatus().getCode());
+
+ }
+
+ @Test
+ public void statusUnknown() throws Exception {
+ //set-up test result
+ when(keyStoreFactory.isHsmFacadeInitialized()).thenReturn(true);
+ when(keyStoreFactory.checkHsmFacadeStatus()).thenReturn(HsmFacadeStatus.UNKNOWN);
+
+ //get current status
+ Health status = check.health();
+
+ //validate result
+ Assert.assertEquals("wrong statusCode", Status.UNKNOWN.getCode(), status.getStatus().getCode());
+
+ }
+
+
+}