2 * ============LICENSE_START==========================================
\r
4 * ===================================================================
\r
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017-2018 Amdocs
\r
7 * ===================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END============================================
\r
21 package org.onap.aai.modelloader.config;
\r
23 import static org.junit.Assert.assertEquals;
\r
24 import static org.junit.Assert.assertFalse;
\r
26 import java.io.File;
\r
27 import java.io.FileInputStream;
\r
28 import java.io.IOException;
\r
29 import java.util.List;
\r
30 import java.util.Properties;
\r
32 import org.eclipse.jetty.util.security.Password;
\r
33 import org.junit.Test;
\r
34 import org.onap.aai.modelloader.restclient.AaiRestClient;
\r
35 import org.openecomp.sdc.utils.ArtifactTypeEnum;
\r
38 * Tests for ModelLoaderConfig class
\r
41 public class ModelLoaderConfigTest {
\r
44 public void testYangModelArtifactType() {
\r
45 Properties props = new Properties();
\r
46 props.setProperty("ml.distribution.ARTIFACT_TYPES", "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
\r
47 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
49 List<String> types = config.getRelevantArtifactTypes();
\r
51 System.out.println("ArtifactType: " + types.get(0));
\r
52 assertEquals(0, types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
\r
54 System.out.println("ArtifactType: " + types.get(1));
\r
55 assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
\r
57 System.out.println("ArtifactType: " + types.get(2));
\r
58 assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
\r
60 assertEquals(3, types.size());
\r
64 public void testMsgBusAddrs() {
\r
65 Properties props = new Properties();
\r
66 props.setProperty("ml.distribution.MSG_BUS_ADDRESSES", "host1.onap.com:3904,host2.onap.com:3904");
\r
67 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
69 List<String> addrs = config.getMsgBusAddress();
\r
71 assertEquals(2, addrs.size());
\r
72 assertEquals(0, addrs.get(0).compareToIgnoreCase("host1.onap.com:3904"));
\r
73 assertEquals(0, addrs.get(1).compareToIgnoreCase("host2.onap.com:3904"));
\r
77 public void testDecryptPassword() {
\r
78 String password = "youshallnotpass";
\r
79 ModelLoaderConfig config =
\r
80 createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password);
\r
81 assertEquals(password, config.getPassword());
\r
85 public void testDecryptKeystorePassword() {
\r
86 String password = "youshallnotpass";
\r
87 ModelLoaderConfig config =
\r
88 createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password);
\r
89 assertEquals(password, config.getKeyStorePassword());
\r
93 public void testDecryptAAIAuthenticationPassword() {
\r
94 String password = "myvoiceismypassword";
\r
95 ModelLoaderConfig config =
\r
96 createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password);
\r
97 assertEquals(password, config.getAaiAuthenticationPassword());
\r
101 public void testDecryptAAIKeystorePassword() {
\r
102 String password = "myvoiceismypassword";
\r
103 ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password);
\r
104 assertEquals(password, config.getAaiKeyStorePassword());
\r
108 public void testAaiBaseUrl() {
\r
109 String url = "http://localhost:1234/";
\r
110 Properties props = new Properties();
\r
111 props.put(ModelLoaderConfig.PROP_AAI_BASE_URL, url);
\r
112 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
113 assertEquals(url, config.getAaiBaseUrl());
\r
117 public void testDecryptBabelKeystorePassword() {
\r
118 String password = "babelpassword";
\r
119 ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password);
\r
120 assertEquals(password, config.getBabelKeyStorePassword());
\r
124 public void testBabelKeystorePath() {
\r
125 String root = "path_to_keystore";
\r
126 String path = "relative_keystore_path";
\r
127 Properties props = new Properties();
\r
128 props.put(ModelLoaderConfig.PROP_BABEL_KEYSTORE_FILE, path);
\r
129 ModelLoaderConfig config = new ModelLoaderConfig(props, root);
\r
130 assertEquals(root + File.separator + path, config.getBabelKeyStorePath());
\r
134 public void testBabelBaseUrl() {
\r
135 String url = "http://localhost/";
\r
136 Properties props = new Properties();
\r
137 props.put(ModelLoaderConfig.PROP_BABEL_BASE_URL, url);
\r
138 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
139 assertEquals(url, config.getBabelBaseUrl());
\r
143 public void testBabelGenerateArtifactsUrl() {
\r
144 String url = "/path/to/the/resource";
\r
145 Properties props = new Properties();
\r
146 props.put(ModelLoaderConfig.PROP_BABEL_GENERATE_RESOURCE_URL, url);
\r
147 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
148 assertEquals(url, config.getBabelGenerateArtifactsUrl());
\r
152 public void testNoAAIAuth() throws IOException {
\r
154 Properties props = new Properties();
\r
155 props.load(new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties"));
\r
157 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
158 AaiRestClient aaiClient = new AaiRestClient(config);
\r
160 assertFalse("Empty AAI Password should result in no basic authentication", aaiClient.useBasicAuth());
\r
162 props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));
\r
163 config = new ModelLoaderConfig(props, null);
\r
164 aaiClient = new AaiRestClient(config);
\r
166 assertFalse("No AAI Password should result in no basic authentication", aaiClient.useBasicAuth());
\r
170 public void testGetUrls() {
\r
171 Properties props = new Properties();
\r
172 props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/");
\r
173 props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL,
\r
174 "/aai/v*/service-design-and-creation/named-queries/named-query/");
\r
175 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
\r
177 assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9"));
\r
178 assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/",
\r
179 config.getAaiNamedQueryUrl("v10"));
\r
184 * @param propertyName
\r
185 * @param propertyValue
\r
186 * @return a new ModelLoaderConfig object containing a single obfuscated property value
\r
188 private ModelLoaderConfig createObfuscatedTestConfig(String propertyName, String propertyValue) {
\r
189 Properties props = new Properties();
\r
190 props.put(propertyName, Password.obfuscate(propertyValue));
\r
191 return new ModelLoaderConfig(props, null);
\r