2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 * ECOMP and OpenECOMP are trademarks
21 * and service marks of AT&T Intellectual Property.
23 package org.openecomp.modelloader.config;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.util.List;
31 import java.util.Properties;
33 import org.eclipse.jetty.util.security.Password;
34 import org.junit.Test;
35 import org.openecomp.modelloader.restclient.AaiRestClient;
37 import org.openecomp.sdc.utils.ArtifactTypeEnum;
39 public class ModelLoaderConfigTest {
42 public void testYangModelArtifactType() {
43 Properties props = new Properties();
44 props.setProperty("ml.distribution.ARTIFACT_TYPES",
45 "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));
52 types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
54 System.out.println("ArtifactType: " + types.get(1));
55 assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
57 System.out.println("ArtifactType: " + types.get(2));
58 assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
60 assertEquals(3, types.size());
64 public void testDecryptPassword() {
65 Properties props = new Properties();
66 String testPass = "youshallnotpass";
67 String encryptedTestPass = Password.obfuscate(testPass);
69 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
71 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);
72 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
74 assertEquals(testPass, config.getPassword());
78 public void testDecryptKeystorePassword() {
79 Properties props = new Properties();
80 String testPass = "youshallnotpass";
81 String encryptedTestPass = Password.obfuscate(testPass);
83 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
85 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);
86 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
88 assertEquals(testPass, config.getKeyStorePassword());
92 public void testDecryptAAIPassword() {
94 Properties props = new Properties();
95 String testPassword = "myvoiceismypassword";
96 String encryptedTestPassword = Password.obfuscate(testPassword);
98 props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);
99 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
101 assertEquals(testPassword, config.getAaiAuthenticationPassword());
105 public void testNoAAIAuth() throws IOException {
107 Properties props = new Properties();
109 new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties"));
111 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
112 AaiRestClient aaiClient = new AaiRestClient(config);
114 assertFalse("Empty AAI Password should result in no basic authentication",
115 aaiClient.useBasicAuth());
117 props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));
118 config = new ModelLoaderConfig(props, null);
119 aaiClient = new AaiRestClient(config);
121 assertFalse("No AAI Password should result in no basic authentication",
122 aaiClient.useBasicAuth());
126 public void testGetUrls() {
127 Properties props = new Properties();
128 props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/");
129 props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL, "/aai/v*/service-design-and-creation/named-queries/named-query/");
130 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
132 assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9"));
133 assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/", config.getAaiNamedQueryUrl("v10"));