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>
diff --git a/prh-app-server/pom.xml b/prh-app-server/pom.xml
index 9ecf57b..b04c06b 100644
--- a/prh-app-server/pom.xml
+++ b/prh-app-server/pom.xml
@@ -19,8 +19,8 @@
   ~ ============LICENSE_END=========================================================
   -->
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <parent>
@@ -41,8 +41,7 @@
   <build>
     <resources>
       <resource>
-        <directory>config</directory>
-        <targetPath>${project.build.directory}/config</targetPath>
+        <directory>src/main/resources</directory>
       </resource>
     </resources>
 
@@ -71,16 +70,12 @@
               <include>${project.artifactId}.jar</include>
               <targetPath>/opt</targetPath>
             </resource>
-            <resource>
-              <directory>${project.build.directory}/config</directory>
-              <targetPath>/config</targetPath>
-            </resource>
           </resources>
           <exposes>
             <expose>8100</expose>
             <expose>8433</expose>
           </exposes>
-          <entryPoint>["java", "-jar", "/opt/${project.artifactId}.jar"]</entryPoint>
+          <cmd>["java", "-jar", "/opt/${project.artifactId}.jar"]</cmd>
         </configuration>
         <executions>
           <execution>
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java
index 10626a3..e598b4b 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java
@@ -89,7 +89,8 @@
         LOGGER.info("Received application configuration: {}", jsonObject);
         CloudConfigParser cloudConfigParser = new CloudConfigParser(jsonObject);
         dmaapPublisherCloudConfiguration = cloudConfigParser.getDmaapPublisherConfig();
-        aaiClientCloudConfiguration = cloudConfigParser.getAaiClientConfig();
+        aaiClientCloudConfiguration = ImmutableAaiClientConfiguration.copyOf(cloudConfigParser.getAaiClientConfig())
+            .withAaiHeaders(aaiClientConfiguration.aaiHeaders());
         dmaapConsumerCloudConfiguration = cloudConfigParser.getDmaapConsumerConfig();
     }
 
@@ -100,11 +101,10 @@
 
     @Override
     public AaiClientConfiguration getAaiClientConfiguration() {
-        return Optional.ofNullable(ImmutableAaiClientConfiguration.copyOf(aaiClientCloudConfiguration)
-            .withAaiHeaders(aaiClientConfiguration.aaiHeaders()))
-            .orElse(ImmutableAaiClientConfiguration.copyOf(super.getAaiClientConfiguration()));
+        return Optional.ofNullable(aaiClientCloudConfiguration).orElse(super.getAaiClientConfiguration());
     }
 
+
     @Override
     public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
         return Optional.ofNullable(dmaapConsumerCloudConfiguration).orElse(super.getDmaapConsumerConfiguration());
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
index 03d2438..882e4d7 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java
@@ -36,7 +36,6 @@
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
 import java.util.ServiceLoader;
-import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
 import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
@@ -44,9 +43,11 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.Resource;
 
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
@@ -71,9 +72,8 @@
 
     DmaapPublisherConfiguration dmaapPublisherConfiguration;
 
-    @NotEmpty
-    private String filepath;
-
+    @Value("classpath:prh_endpoints.json")
+    private Resource resourceFile;
 
     @Override
     public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
@@ -97,7 +97,8 @@
         ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
         JsonParser parser = new JsonParser();
         JsonObject jsonObject;
-        try (InputStream inputStream = getInputStream(filepath)) {
+
+        try (InputStream inputStream = resourceFile.getInputStream()) {
             JsonElement rootElement = getJsonElement(parser, inputStream);
             if (rootElement.isJsonObject()) {
                 jsonObject = rootElement.getAsJsonObject();
@@ -114,7 +115,7 @@
                     DmaapPublisherConfiguration.class);
             }
         } catch (IOException e) {
-            LOGGER.warn("Problem with file loading, file: {}", filepath, e);
+            LOGGER.warn("Problem with file loading, file ", e);
         } catch (JsonSyntaxException e) {
             LOGGER.warn("Problem with Json deserialization", e);
         }
@@ -129,18 +130,14 @@
         return gsonBuilder.create().fromJson(jsonObject, type);
     }
 
+    void setResourceFile(Resource resourceFile) {
+        this.resourceFile = resourceFile;
+    }
+
     InputStream getInputStream(@NotNull String filepath) throws IOException {
         return new BufferedInputStream(new FileInputStream(filepath));
     }
 
-    String getFilepath() {
-        return this.filepath;
-    }
-
-    public void setFilepath(String filepath) {
-        this.filepath = filepath;
-    }
-
     public void setXOnapRequestId(String xonaprequestid) {
         MDC.put(REQUEST_ID, xonaprequestid);
     }
diff --git a/prh-app-server/src/main/resources/application.properties b/prh-app-server/src/main/resources/application.properties
deleted file mode 100644
index e343a36..0000000
--- a/prh-app-server/src/main/resources/application.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-spring.profiles.active=prod
-server.port=8433
-server.ssl.key-store-type=PKCS12
-server.ssl.key-store-password=nokiapnf
-server.ssl.key-store=classpath:keystore.jks
-server.ssl.key-password=nokiapnf
-server.ssl.key-alias=tomcat-localhost
-logging.level.root=ERROR
-logging.level.org.springframework=ERROR
-logging.level.org.springframework.data=ERROR
-logging.level.org.onap.dcaegen2.services.prh=INFO
-logging.level.org.springframework.web.reactive=WARN
-logging.level.reactor.ipc.netty.http.client=WARN
-app.filepath=config/prh_endpoints.json
-app.xonaprequestid=requestID
-app.xinvocationid=invocationID
-
diff --git a/prh-app-server/config/application.yaml b/prh-app-server/src/main/resources/application.yaml
similarity index 83%
rename from prh-app-server/config/application.yaml
rename to prh-app-server/src/main/resources/application.yaml
index 2e6f54d..88d1e40 100644
--- a/prh-app-server/config/application.yaml
+++ b/prh-app-server/src/main/resources/application.yaml
@@ -6,7 +6,7 @@
   ssl:
     key-store-type: PKCS12
     key-store-password: nokiapnf
-    key-store: classpath:keystore.jks
+    key-store: classpath:keystore-local
     key-password: nokiapnf
     keyAlias: tomcat-localhost
 logging:
@@ -17,5 +17,3 @@
     org.springframework: ERROR
     org.springframework.data: ERROR
     org.springframework.web.reactive: WARN
-app:
-  filepath: config/prh_endpoints.json
\ No newline at end of file
diff --git a/prh-app-server/src/main/resources/keystore.jks b/prh-app-server/src/main/resources/keystore-local
similarity index 100%
rename from prh-app-server/src/main/resources/keystore.jks
rename to prh-app-server/src/main/resources/keystore-local
Binary files differ
diff --git a/prh-app-server/config/keystore b/prh-app-server/src/main/resources/keystore-onap
similarity index 100%
rename from prh-app-server/config/keystore
rename to prh-app-server/src/main/resources/keystore-onap
Binary files differ
diff --git a/prh-app-server/src/main/resources/keystore.jks.old b/prh-app-server/src/main/resources/keystore.jks.old
deleted file mode 100644
index 8a2b4f9..0000000
--- a/prh-app-server/src/main/resources/keystore.jks.old
+++ /dev/null
Binary files differ
diff --git a/prh-app-server/config/prh_endpoints.json b/prh-app-server/src/main/resources/prh_endpoints.json
similarity index 100%
rename from prh-app-server/config/prh_endpoints.json
rename to prh-app-server/src/main/resources/prh_endpoints.json
diff --git a/prh-app-server/src/main/resources/scheduled-context.xml b/prh-app-server/src/main/resources/scheduled-context.xml
deleted file mode 100644
index 82067c1..0000000
--- a/prh-app-server/src/main/resources/scheduled-context.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns:context="http://www.springframework.org/schema/context"
-  xmlns:task="http://www.springframework.org/schema/task"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xmlns="http://www.springframework.org/schema/beans"
-  xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
-		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
-
-  <context:component-scan
-    base-package="org.onap.dcaegen2.services.prh"/>
-  <task:scheduled-tasks>
-    <task:scheduled fixed-rate="1000" method="startTasks"
-      ref="scheduleController"/>
-  </task:scheduled-tasks>
-</beans>
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 8ad2a94..0186630 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.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 @@
     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 @@
     }
 
     @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 @@
         //
         // 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 @@
         //
         // Then
         //
-        verify(prhAppConfig, times(1)).setFilepath(anyString());
         verify(prhAppConfig, times(1)).initFileStreamReader();
         Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration());
         Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
@@ -136,12 +143,15 @@
     }
 
     @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 @@
         //
         // Then
         //
-        verify(prhAppConfig, times(1)).setFilepath(anyString());
         verify(prhAppConfig, times(1)).initFileStreamReader();
         Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
         Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());
@@ -167,14 +176,13 @@
         //
         // 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 @@
         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 @@
         appConfig.aaiClientConfiguration = prhAppConfig.getAaiClientConfiguration();
 
         // Then
-        verify(prhAppConfig, times(1)).setFilepath(anyString());
         verify(prhAppConfig, times(1)).initFileStreamReader();
         Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
         Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());