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.jupiter.api.Assertions.assertEquals;
26 import java.util.List;
27 import java.util.Properties;
28 import org.eclipse.jetty.util.security.Password;
29 import org.junit.jupiter.api.Test;
30 import org.onap.sdc.utils.ArtifactTypeEnum;
33 * Tests for ModelLoaderConfig class.
36 public class TestModelLoaderConfig {
39 public void testYangModelArtifactType() {
40 Properties props = new Properties();
41 props.setProperty("ml.distribution.ARTIFACT_TYPES", "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
42 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
44 List<String> types = config.getRelevantArtifactTypes();
46 System.out.println("ArtifactType: " + types.get(0));
47 assertEquals(0, types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
49 System.out.println("ArtifactType: " + types.get(1));
50 assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
52 System.out.println("ArtifactType: " + types.get(2));
53 assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
55 assertEquals(3, types.size());
59 public void testDecryptPassword() {
60 String password = "youshallnotpass";
61 ModelLoaderConfig config =
62 createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password);
63 assertEquals(password, config.getPassword());
65 config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password);
66 assertEquals(password, config.getPassword());
70 public void testDecryptKeystorePassword() {
71 String password = "youshallnotpass";
72 ModelLoaderConfig config =
73 createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password);
74 assertEquals(password, config.getKeyStorePassword());
76 config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password);
77 assertEquals(password, config.getKeyStorePassword());
81 public void testDecryptAaiAuthenticationPassword() {
82 String password = "myvoiceismypassword";
83 ModelLoaderConfig config =
84 createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password);
85 assertEquals(password, config.getAaiAuthenticationPassword());
87 config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password);
88 assertEquals(password, config.getAaiAuthenticationPassword());
92 public void testDecryptAaiKeystorePassword() {
93 String password = "myvoiceismypassword";
94 ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password);
95 assertEquals(password, config.getAaiKeyStorePassword());
97 config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password);
98 assertEquals(password, config.getAaiKeyStorePassword());
102 public void testAaiBaseUrl() {
103 String url = "http://localhost:1234/";
104 Properties props = new Properties();
105 props.put(ModelLoaderConfig.PROP_AAI_BASE_URL, url);
106 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
107 assertEquals(url, config.getAaiBaseUrl());
111 public void testDecryptBabelKeystorePassword() {
112 String password = "babelpassword";
113 ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password);
114 assertEquals(password, config.getBabelKeyStorePassword());
116 config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password);
117 assertEquals(password, config.getBabelKeyStorePassword());
121 public void testBabelKeystorePath() {
122 String root = "path_to_keystore";
123 String path = "relative_keystore_path";
124 Properties props = new Properties();
125 props.put(ModelLoaderConfig.PROP_BABEL_KEYSTORE_FILE, path);
126 ModelLoaderConfig config = new ModelLoaderConfig(props, root);
127 assertEquals(root + File.separator + path, config.getBabelKeyStorePath());
131 public void testBabelBaseUrl() {
132 String url = "http://localhost/";
133 Properties props = new Properties();
134 props.put(ModelLoaderConfig.PROP_BABEL_BASE_URL, url);
135 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
136 assertEquals(url, config.getBabelBaseUrl());
140 public void testBabelGenerateArtifactsUrl() {
141 String url = "/path/to/the/resource";
142 Properties props = new Properties();
143 props.put(ModelLoaderConfig.PROP_BABEL_GENERATE_RESOURCE_URL, url);
144 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
145 assertEquals(url, config.getBabelGenerateArtifactsUrl());
149 public void testGetUrls() {
150 Properties props = new Properties();
151 props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/");
152 props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL,
153 "/aai/v*/service-design-and-creation/named-queries/named-query/");
154 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
156 assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9"));
157 assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/",
158 config.getAaiNamedQueryUrl("v10"));
163 * Create a Model Loader Configuration object from the supplied Property.
165 * @param propertyName property key
166 * @param propertyValue value of the property
167 * @return a new ModelLoaderConfig object containing a single obfuscated property value
169 private ModelLoaderConfig createObfuscatedTestConfig(String propertyName, String propertyValue) {
170 Properties props = new Properties();
171 props.put(propertyName, Password.obfuscate(propertyValue));
172 return new ModelLoaderConfig(props, null);
175 private ModelLoaderConfig createUnobfuscatedTestConfig(String propertyName, String propertyValue) {
176 Properties props = new Properties();
177 props.put(propertyName, propertyValue);
178 return new ModelLoaderConfig(props, null);