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
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.openecomp.modelloader.config;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.util.List;
32 import java.util.Properties;
34 import org.eclipse.jetty.util.security.Password;
35 import org.junit.Test;
36 import org.openecomp.modelloader.restclient.AaiRestClient;
38 import org.openecomp.sdc.utils.ArtifactTypeEnum;
40 public class ModelLoaderConfigTest {
43 public void testYangModelArtifactType() {
44 Properties props = new Properties();
45 props.setProperty("ml.distribution.ARTIFACT_TYPES",
46 "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
47 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
49 List<String> types = config.getRelevantArtifactTypes();
51 System.out.println("ArtifactType: " + types.get(0));
53 types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
55 System.out.println("ArtifactType: " + types.get(1));
56 assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
58 System.out.println("ArtifactType: " + types.get(2));
59 assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
61 assertEquals(3, types.size());
65 public void testDecryptPassword() {
66 Properties props = new Properties();
67 String testPass = "youshallnotpass";
68 String encryptedTestPass = Password.obfuscate(testPass);
70 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
72 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);
73 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
75 assertEquals(testPass, config.getPassword());
79 public void testDecryptKeystorePassword() {
80 Properties props = new Properties();
81 String testPass = "youshallnotpass";
82 String encryptedTestPass = Password.obfuscate(testPass);
84 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
86 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);
87 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
89 assertEquals(testPass, config.getKeyStorePassword());
93 public void testDecryptAAIPassword() {
95 Properties props = new Properties();
96 String testPassword = "myvoiceismypassword";
97 String encryptedTestPassword = Password.obfuscate(testPassword);
99 props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);
100 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
102 assertEquals(testPassword, config.getAaiAuthenticationPassword());
106 public void testNoAAIAuth() throws IOException {
108 Properties props = new Properties();
110 new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties"));
112 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
113 AaiRestClient aaiClient = new AaiRestClient(config);
115 assertFalse("Empty AAI Password should result in no basic authentication",
116 aaiClient.useBasicAuth());
118 props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));
119 config = new ModelLoaderConfig(props, null);
120 aaiClient = new AaiRestClient(config);
122 assertFalse("No AAI Password should result in no basic authentication",
123 aaiClient.useBasicAuth());
127 public void testGetUrls() {
128 Properties props = new Properties();
129 props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/");
130 props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL, "/aai/v*/service-design-and-creation/named-queries/named-query/");
131 ModelLoaderConfig config = new ModelLoaderConfig(props, null);
133 assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9"));
134 assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/", config.getAaiNamedQueryUrl("v10"));