Add missing tests 72/75672/3
authorbogumil_zebek <bogumil.zebek@nokia.com>
Fri, 11 Jan 2019 11:00:51 +0000 (12:00 +0100)
committerJames Forsyth <jf2512@att.com>
Mon, 18 Feb 2019 22:58:23 +0000 (22:58 +0000)
Issue-ID: AAI-2070
Change-Id: I141d4ba7609cb592dad8a1f32100a59442fe6326
Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Verify cache configuration processing

Issue-ID: AAI-2070
Change-Id: I235c779ccc7a33769465113e3cbf2d7b81ee3b82
Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Fix sonar violations

Change-Id: Ie724d74ca833a1ee16ff37203916a2231dba41ed
Issue-ID: AAI-2070
Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
src/test/java/org/onap/aai/cacher/common/CacheKeyConfigTest.java [new file with mode: 0644]
src/test/java/org/onap/aai/cacher/config/JettyPasswordDecoderTest.java [new file with mode: 0644]
src/test/resources/test/etc/initialcachekeyconfig.json [new file with mode: 0644]

diff --git a/src/test/java/org/onap/aai/cacher/common/CacheKeyConfigTest.java b/src/test/java/org/onap/aai/cacher/common/CacheKeyConfigTest.java
new file mode 100644 (file)
index 0000000..e0d99ab
--- /dev/null
@@ -0,0 +1,72 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.cacher.common;
+
+
+import com.google.common.collect.Lists;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+import org.onap.aai.cacher.model.CacheKey;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Bogumil Zebek
+ */
+public class CacheKeyConfigTest {
+
+    @Test
+    public void shouldProcessCacheConfigurationStoredInFile() throws IOException {
+
+        // given
+        String cacheKeyConfigJson = loadFile("test/etc/initialcachekeyconfig.json");
+        CacheKeyConfig cacheKeyConfig = new CacheKeyConfig(cacheKeyConfigJson);
+
+        // when
+        List<CacheKey> cacheKeys = cacheKeyConfig.populateCacheKeyList();
+
+        // then
+        assertThat(cacheKeys.size()).isEqualTo(4);
+        assertThat(
+                cacheKeys.stream().allMatch(
+                        it -> Lists.newArrayList("cloud-region", "complex", "pserver", "generic-vnf").contains(it.cacheKey)
+                )
+        ).isTrue();
+
+    }
+
+    private String loadFile(String pathToFile) throws IOException {
+        ClassLoader classLoader = getClass().getClassLoader();
+        URL resource = classLoader.getResource(pathToFile);
+        if (resource == null) {
+            throw new InvalidPathException("Missing file.", String.format("File '%s' not found.", pathToFile));
+        }
+        File file = new File(resource.getFile());
+        return new String(Files.readAllBytes(file.toPath()));
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/org/onap/aai/cacher/config/JettyPasswordDecoderTest.java b/src/test/java/org/onap/aai/cacher/config/JettyPasswordDecoderTest.java
new file mode 100644 (file)
index 0000000..f6ce311
--- /dev/null
@@ -0,0 +1,52 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.cacher.config;
+
+import org.eclipse.jetty.util.security.Password;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Bogumil Zebek
+ */
+public class JettyPasswordDecoderTest {
+
+    private JettyPasswordDecoder jettyPasswordDecoder;
+
+    @Before
+    public void setUp(){
+        this.jettyPasswordDecoder = new JettyPasswordDecoder();
+    }
+
+    @Test
+    public void shouldDecodeObfuscatedPassword(){
+        String encoded = Password.obfuscate("password");
+        assertEquals("password", jettyPasswordDecoder.decode(encoded));
+    }
+
+    @Test
+    public void shouldDecodeValueOfObfuscatedPassword(){
+        String encoded = "1v2j1uum1xtv1zej1zer1xtn1uvk1v1v";
+        assertEquals("password", jettyPasswordDecoder.decode(encoded));
+    }
+}
\ No newline at end of file
diff --git a/src/test/resources/test/etc/initialcachekeyconfig.json b/src/test/resources/test/etc/initialcachekeyconfig.json
new file mode 100644 (file)
index 0000000..f1fdabe
--- /dev/null
@@ -0,0 +1,41 @@
+{
+       "cachekeys": 
+       [
+               {
+                       "cacheKey": "cloud-region",
+                       "baseUrl": "https://AAI:AAI@localhost:8447",
+                       "module": "/aai/v13/",
+                       "URI": "cloud-infrastructure/cloud-regions?depth=0&resultIndex=1&resultSize=3",
+                       "timingIndicator": "onInit",
+                       "httpMethod": "GET",
+                       "parserStrategy": "aai-resource-get-all"
+               },
+               {
+                       "cacheKey": "complex",
+                       "baseUrl": "https://AAI:AAI@localhost:8447",
+                       "module": "/aai/v13/",
+                       "URI": "cloud-infrastructure/complexes?resultIndex=1&resultSize=3",
+                       "timingIndicator": "onInit",
+                       "httpMethod": "GET",
+                       "parserStrategy": "aai-resource-get-all"
+               },
+               {
+                       "cacheKey": "pserver",
+                       "baseUrl": "https://AAI:AAI@localhost:8447",
+                       "module": "/aai/v13/",
+                       "URI": "cloud-infrastructure/pservers?depth=5807c3c3-92cd-44d7-a508-8539cd36ecda&resultIndex=1&resultSize=3",
+                       "timingIndicator": "onInit",
+                       "httpMethod": "GET",
+                       "parserStrategy": "aai-resource-get-all"
+               },
+               {
+                       "cacheKey": "generic-vnf",
+                       "baseUrl": "https://AAI:AAI@localhost:8447",
+                       "module": "/aai/v13/",
+                       "URI": "network/generic-vnfs?depth=5807c3c3-92cd-44d7-a508-8539cd36ecda&resultIndex=1&resultSize=3",
+                       "timingIndicator": "onInit",
+                       "httpMethod": "GET",
+                       "parserStrategy": "aai-resource-get-all"
+               }
+       ]
+}
\ No newline at end of file