summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-02-28 18:03:15 +0000
committerGerrit Code Review <gerrit@onap.org>2019-02-28 18:03:15 +0000
commit57a9709f076e97c2f837f42898c9dc3112cefe92 (patch)
treee8f7484f8c1d8dea4afbe03a338a0ae32ef90bc9 /main
parentadd76434556e3413075f1e60dda2c48d5254cfe2 (diff)
parentc3e2ced55c33946377454f2353dc24297e88584d (diff)
Merge "Use Coder class"
Diffstat (limited to 'main')
-rw-r--r--main/pom.xml4
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java20
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java12
3 files changed, 19 insertions, 17 deletions
diff --git a/main/pom.xml b/main/pom.xml
index f74e6eb9..63eb0ecc 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -39,10 +39,6 @@
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
- </dependency>
- <dependency>
<groupId>org.onap.policy.common</groupId>
<artifactId>common-parameters</artifactId>
<version>${policy.common.version}</version>
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java
index 08124bb3..489eb52d 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +21,12 @@
package org.onap.policy.pap.main.parameters;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import java.io.FileReader;
+import java.io.File;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.pap.main.PolicyPapException;
import org.onap.policy.pap.main.startstop.PapCommandLineArguments;
import org.slf4j.Logger;
@@ -40,6 +41,8 @@ public class PapParameterHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(PapParameterHandler.class);
+ private static final Coder CODER = new StandardCoder();
+
/**
* Read the parameters from the parameter file.
*
@@ -52,11 +55,10 @@ public class PapParameterHandler {
// Read the parameters
try {
- // Read the parameters from JSON using Gson
- final Gson gson = new GsonBuilder().create();
- papParameterGroup =
- gson.fromJson(new FileReader(arguments.getFullConfigurationFilePath()), PapParameterGroup.class);
- } catch (final Exception e) {
+ // Read the parameters from JSON
+ File file = new File(arguments.getFullConfigurationFilePath());
+ papParameterGroup = CODER.decode(file, PapParameterGroup.class);
+ } catch (final CoderException e) {
final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
+ "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
LOGGER.error(errorMessage, e);
diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
index cb14748d..b0f9521d 100644
--- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +25,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.FileNotFoundException;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.pap.main.PolicyPapException;
import org.onap.policy.pap.main.startstop.PapCommandLineArguments;
@@ -46,7 +49,8 @@ public class TestPapParameterHandler {
new PapParameterHandler().getParameters(noArguments);
fail("test should throw an exception here");
} catch (final Exception e) {
- assertTrue(e.getMessage().contains("FileNotFoundException"));
+ assertTrue(e.getCause() instanceof CoderException);
+ assertTrue(e.getCause().getCause() instanceof FileNotFoundException);
}
}
@@ -76,9 +80,9 @@ public class TestPapParameterHandler {
new PapParameterHandler().getParameters(invalidArguments);
fail("test should throw an exception here");
} catch (final Exception e) {
- assertEquals("error reading parameters from \"parameters/InvalidParameters.json\"\n"
- + "(JsonSyntaxException):java.lang.IllegalStateException: "
- + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ assertTrue(e.getMessage().startsWith(
+ "error reading parameters from \"parameters/InvalidParameters.json\""));
+ assertTrue(e.getCause() instanceof CoderException);
}
}