aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/java/org/onap/aai/cacher/common/CacheKeyConfigTest.java72
-rw-r--r--src/test/java/org/onap/aai/cacher/config/JettyPasswordDecoderTest.java52
-rw-r--r--src/test/resources/test/etc/initialcachekeyconfig.json41
3 files changed, 165 insertions, 0 deletions
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
index 0000000..e0d99ab
--- /dev/null
+++ b/src/test/java/org/onap/aai/cacher/common/CacheKeyConfigTest.java
@@ -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
index 0000000..f6ce311
--- /dev/null
+++ b/src/test/java/org/onap/aai/cacher/config/JettyPasswordDecoderTest.java
@@ -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
index 0000000..f1fdabe
--- /dev/null
+++ b/src/test/resources/test/etc/initialcachekeyconfig.json
@@ -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