summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-11-16 13:17:29 +0100
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-11-16 13:42:47 +0100
commit677d218e4c337de6faca915723d47390ef4290d0 (patch)
treeb1b8ce87f45d78a59a7567f9e3900ddeb48a11b9 /src
parent78c8b0e7fc7e6d707190202cac4b8f2ad03828dc (diff)
Rework the CldsUserJson
Rework the CldsUserJson and associated Unit tests Change-Id: I0be23ef8c6a44bc7cec7f7011b08a32d2662c56f Issue-ID: CLAMP-74 Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java16
-rw-r--r--src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java24
2 files changed, 18 insertions, 22 deletions
diff --git a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
index ecfb4aa1..15d06b9a 100644
--- a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
+++ b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
@@ -28,23 +28,29 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
+import org.onap.clamp.clds.exception.CldsUsersException;
import org.onap.clamp.clds.service.CldsUser;
public class CldsUserJsonDecoder {
-
/**
* This method decodes the JSON file provided to a CldsUser Array. The
* stream is closed after this call, this is not possible to reuse it.
*
+ * @param cldsUsersFile
+ * The inputStream containing the users json file
* @return CldsUser[] Array containing a list of the user defined in the
* JSON file
*/
- public static CldsUser[] decodeJson(InputStream cldsUsersFile) throws IOException {
- // the ObjectMapper readValue method closes the stream no need to do it
- return new ObjectMapper().readValue(cldsUsersFile, CldsUser[].class);
+ public static CldsUser[] decodeJson(InputStream cldsUsersFile) {
+ try {
+ // the ObjectMapper readValue method closes the stream no need to do
+ // it
+ return new ObjectMapper().readValue(cldsUsersFile, CldsUser[].class);
+ } catch (IOException e) {
+ throw new CldsUsersException("Exception occurred during the decoding of the clds-users.json", e);
+ }
}
private CldsUserJsonDecoder() {
-
}
}
diff --git a/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java b/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
index b3d52172..5f73ac16 100644
--- a/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
+++ b/src/test/java/org/onap/clamp/clds/config/CldsUserJsonDecoderTest.java
@@ -30,41 +30,33 @@ import org.junit.Test;
import org.onap.clamp.clds.service.CldsUser;
public class CldsUserJsonDecoderTest {
-
private String user1 = "admin1";
private String user2 = "admin2";
-
private String password = "5f4dcc3b5aa765d61d8327deb882cf99";
private String[] normalPermissionsArray = { "permission-type-cl|dev|read", "permission-type-cl|dev|update",
- "permission-type-cl-manage|dev|*", "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
- "permission-type-template|dev|update" };
-
+ "permission-type-cl-manage|dev|*", "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
+ "permission-type-template|dev|update" };
private String[] incompletePermissionsArray = { "permission-type-cl|dev|*", "permission-type-cl|dev|*",
- "permission-type-cl-manage|dev|*", "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
- "permission-type-template|dev|update" };
+ "permission-type-cl-manage|dev|*", "permission-type-filter-vf|dev|*", "permission-type-template|dev|read",
+ "permission-type-template|dev|update" };
@Test
- public void testDecodingDoubleUsers() throws Exception {
+ public void testDecodingDoubleUsers() {
CldsUser[] usersArray = CldsUserJsonDecoder
.decodeJson(CldsUserJsonDecoderTest.class.getResourceAsStream("/clds/clds-users-two-users.json"));
-
assertEquals(usersArray.length, 2);
-
assertEquals(usersArray[0].getUser(), user1);
assertEquals(usersArray[1].getUser(), user2);
-
assertEquals(usersArray[0].getPassword(), password);
assertEquals(usersArray[1].getPassword(), password);
-
assertArrayEquals(usersArray[0].getPermissionsString(), normalPermissionsArray);
assertArrayEquals(usersArray[1].getPermissionsString(), normalPermissionsArray);
}
@Test
- public void testDecodingNoPermission() throws Exception {
+ public void testDecodingNoPermission() {
CldsUser[] usersArray = CldsUserJsonDecoder
.decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-no-permission.json"));
-
assertEquals(usersArray.length, 1);
assertEquals(usersArray[0].getUser(), user1);
assertEquals(usersArray[0].getPassword(), null);
@@ -72,14 +64,12 @@ public class CldsUserJsonDecoderTest {
}
@Test
- public void testDecodingIncompletePermissions() throws Exception {
+ public void testDecodingIncompletePermissions() {
CldsUser[] usersArray = CldsUserJsonDecoder
.decodeJson(this.getClass().getResourceAsStream("/clds/clds-users-incomplete-permissions.json"));
-
assertEquals(usersArray.length, 1);
assertEquals(usersArray[0].getUser(), user1);
assertEquals(usersArray[0].getPassword(), password);
assertArrayEquals(usersArray[0].getPermissionsString(), incompletePermissionsArray);
}
-
}