summaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-09-04 09:50:05 +0200
committerpwielebs <piotr.wielebski@nokia.com>2018-09-04 09:50:05 +0200
commitbe3127220aed103d1c1bb495080d62593d61b835 (patch)
treed18321c21dd28859e5f6e7eed3553ea0fff38a3c /prh-app-server/src/test/java
parenta4c979b6de8c1c76f0f12ae2b8dd0e60c3084830 (diff)
Maven resources refactoring
Added resurces to java spring classpath directly Change-Id: I194748706f63cff1966111bbdb52538bd5a83855 Issue-ID: DCAEGEN2-606 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-app-server/src/test/java')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java39
1 files changed, 23 insertions, 16 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
index 8ad2a94f..01866309 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java
@@ -41,6 +41,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.core.io.Resource;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
@@ -78,8 +80,16 @@ class PrhAppConfigTest {
private static PrhAppConfig prhAppConfig;
private static AppConfig appConfig;
- private static String filePath = Objects
- .requireNonNull(PrhAppConfigTest.class.getClassLoader().getResource(PRH_ENDPOINTS)).getFile();
+ private static InputStream inputStream;
+
+ static {
+ try {
+ inputStream = Objects
+ .requireNonNull(PrhAppConfigTest.class.getClassLoader().getResource(PRH_ENDPOINTS)).openStream();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
@BeforeEach
void setUp() {
@@ -88,17 +98,15 @@ class PrhAppConfigTest {
}
@Test
- void whenApplicationWasStarted_FilePathIsSet() {
+ void whenApplicationWasStarted_FilePathIsSet() throws IOException {
//
// When
//
- prhAppConfig.setFilepath(filePath);
+ doReturn(inputStream).when(prhAppConfig).getInputStream(anyString());
//
// Then
//
- verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(0)).initFileStreamReader();
- Assertions.assertEquals(filePath, prhAppConfig.getFilepath());
}
@Test
@@ -112,7 +120,7 @@ class PrhAppConfigTest {
//
// When
//
- prhAppConfig.setFilepath(filePath);
+ prhAppConfig.setResourceFile(new InputStreamResource(inputStream));
doReturn(inputStream).when(prhAppConfig).getInputStream(any());
prhAppConfig.initFileStreamReader();
appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration();
@@ -121,7 +129,6 @@ class PrhAppConfigTest {
//
// Then
//
- verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
@@ -136,12 +143,15 @@ class PrhAppConfigTest {
}
@Test
- void whenFileIsNotExist_ThrowIoException() {
+ void whenFileIsNotExist_ThrowIoException() throws IOException {
//
// Given
+ InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
+ StandardCharsets.UTF_8)));
+ Resource resource = spy(new InputStreamResource(inputStream));
//
- filePath = "/temp.json";
- prhAppConfig.setFilepath(filePath);
+ when(resource.getInputStream()).thenThrow(new IOException());
+ prhAppConfig.setResourceFile(resource);
//
// When
//
@@ -149,7 +159,6 @@ class PrhAppConfigTest {
//
// Then
//
- verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());
@@ -167,14 +176,13 @@ class PrhAppConfigTest {
//
// When
//
- prhAppConfig.setFilepath(filePath);
+ prhAppConfig.setResourceFile(new InputStreamResource(inputStream));
doReturn(inputStream).when(prhAppConfig).getInputStream(any());
prhAppConfig.initFileStreamReader();
//
// Then
//
- verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
@@ -190,7 +198,7 @@ class PrhAppConfigTest {
InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
StandardCharsets.UTF_8)));
// When
- prhAppConfig.setFilepath(filePath);
+ prhAppConfig.setResourceFile(new InputStreamResource(inputStream));
doReturn(inputStream).when(prhAppConfig).getInputStream(any());
JsonElement jsonElement = mock(JsonElement.class);
when(jsonElement.isJsonObject()).thenReturn(false);
@@ -201,7 +209,6 @@ class PrhAppConfigTest {
appConfig.aaiClientConfiguration = prhAppConfig.getAaiClientConfiguration();
// Then
- verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());