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