aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/main/java
diff options
context:
space:
mode:
authorpkaras <piotr.karas@nokia.com>2018-11-15 09:01:27 +0100
committerpkaras <piotr.karas@nokia.com>2018-11-15 09:01:27 +0100
commit828fc610ba0b70e44af91ef87a9093279b2c680b (patch)
tree5b97630a18a8dc9e259064a212bb496777ebb482 /prh-app-server/src/main/java
parentc1521dbf3b9012f090aa744cdd5420c1cd715489 (diff)
PrhAppConfigTest refactor
Change-Id: Iaa604d04139ca26fcb9a21e03484f72c56f15816 Issue-ID: DCAEGEN2-973 Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'prh-app-server/src/main/java')
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java14
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java53
2 files changed, 48 insertions, 19 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
index 9d199a14..fd7c8928 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java
@@ -20,6 +20,7 @@
package org.onap.dcaegen2.services.prh.configuration;
+import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
@@ -139,6 +140,9 @@ public class AppConfig extends PrhAppConfig {
@Override
public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
+ if (noFileConfiguration(dmaapConsumerConfiguration)) {
+ return null;
+ }
return new ImmutableDmaapConsumerConfiguration.Builder()
.dmaapUserPassword(
Optional.ofNullable(consumerDmaapUserPassword).filter(isEmpty.negate())
@@ -190,6 +194,9 @@ public class AppConfig extends PrhAppConfig {
@Override
public AaiClientConfiguration getAaiClientConfiguration() {
+ if (noFileConfiguration(aaiClientConfiguration)) {
+ return null;
+ }
return new ImmutableAaiClientConfiguration.Builder()
.aaiHost(Optional.ofNullable(aaiHost).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiHost()))
.aaiPort(
@@ -229,6 +236,9 @@ public class AppConfig extends PrhAppConfig {
@Override
public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
+ if (noFileConfiguration(dmaapPublisherConfiguration)) {
+ return null;
+ }
return new ImmutableDmaapPublisherConfiguration.Builder()
.dmaapContentType(
Optional.ofNullable(producerDmaapContentType).filter(isEmpty.negate())
@@ -268,4 +278,8 @@ public class AppConfig extends PrhAppConfig {
.orElse(dmaapPublisherConfiguration.enableDmaapCertAuth()))
.build();
}
+
+ private boolean noFileConfiguration(Object object) {
+ return Objects.isNull(object);
+ }
}
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 2b4b201a..f66924bc 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
@@ -95,29 +95,39 @@ public abstract class PrhAppConfig implements Config {
try (InputStream inputStream = resourceFile.getInputStream()) {
JsonElement rootElement = getJsonElement(parser, inputStream);
if (rootElement.isJsonObject()) {
- aaiClientConfiguration = deserializeType(gsonBuilder,
- concatenateJsonObjects(
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
- AaiClientConfiguration.class);
- dmaapConsumerConfiguration = deserializeType(gsonBuilder,
- concatenateJsonObjects(
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
- DmaapConsumerConfiguration.class);
- dmaapPublisherConfiguration = deserializeType(gsonBuilder,
- concatenateJsonObjects(
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
- DmaapPublisherConfiguration.class);
+ deserializeAaiConfiguration(gsonBuilder, rootElement);
+ deserializeDmaapConsumerConfiguration(gsonBuilder, rootElement);
+ deserializeDmaapPublisherConfiguration(gsonBuilder, rootElement);
}
- } catch (IOException e) {
+ }
+ catch (IOException e) {
LOGGER.warn("Problem with file loading, file ", e);
- } catch (JsonSyntaxException e) {
- LOGGER.warn("Problem with Json deserialization", e);
}
}
+ private void deserializeDmaapPublisherConfiguration(GsonBuilder gsonBuilder, JsonElement rootElement) {
+ dmaapPublisherConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP)
+ .getAsJsonObject(DMAAP_PRODUCER),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
+ DmaapPublisherConfiguration.class);
+ }
+
+ private void deserializeDmaapConsumerConfiguration(GsonBuilder gsonBuilder, JsonElement rootElement) {
+ dmaapConsumerConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(DMAAP)
+ .getAsJsonObject(DMAAP_CONSUMER),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
+ DmaapConsumerConfiguration.class);
+ }
+
+ private void deserializeAaiConfiguration(GsonBuilder gsonBuilder, JsonElement rootElement) {
+ aaiClientConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
+ AaiClientConfiguration.class);
+ }
+
JsonElement getJsonElement(JsonParser parser, InputStream inputStream) {
return parser.parse(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
}
@@ -130,7 +140,12 @@ public abstract class PrhAppConfig implements Config {
private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
@NotNull Class<T> type) {
- return gsonBuilder.create().fromJson(jsonObject, type);
+ try {
+ return gsonBuilder.create().fromJson(jsonObject, type);
+ } catch (JsonSyntaxException e) {
+ LOGGER.warn("Problem with Json deserialization", e);
+ return null;
+ }
}
void setResourceFile(Resource resourceFile) {