2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * 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=========================================================
21 package org.openecomp.modelloader.config;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
26 import java.io.FileInputStream;
27 import java.io.IOException;
28 import java.util.List;
29 import java.util.Properties;
31 import org.eclipse.jetty.util.security.Password;
32 import org.junit.Test;
33 import org.openecomp.modelloader.restclient.AaiRestClient;
35 import org.openecomp.sdc.utils.ArtifactTypeEnum;
37 public class ModelLoaderConfigTest {
40 public void testYangModelArtifactType() {
41 Properties props = new Properties();
42 props.setProperty("ml.distribution.ARTIFACT_TYPES",
43 "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
44 ModelLoaderConfig config = new ModelLoaderConfig(props);
46 List<String> types = config.getRelevantArtifactTypes();
48 System.out.println("ArtifactType: " + types.get(0));
50 types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
52 System.out.println("ArtifactType: " + types.get(1));
53 assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
55 System.out.println("ArtifactType: " + types.get(2));
56 assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
58 assertEquals(3, types.size());
62 public void testDecryptPassword() {
63 Properties props = new Properties();
64 String testPass = "youshallnotpass";
65 String encryptedTestPass = Password.obfuscate(testPass);
67 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
69 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);
70 ModelLoaderConfig config = new ModelLoaderConfig(props);
72 assertEquals(testPass, config.getPassword());
76 public void testDecryptKeystorePassword() {
77 Properties props = new Properties();
78 String testPass = "youshallnotpass";
79 String encryptedTestPass = Password.obfuscate(testPass);
81 System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
83 props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);
84 ModelLoaderConfig config = new ModelLoaderConfig(props);
86 assertEquals(testPass, config.getKeyStorePassword());
90 public void testDecryptAAIPassword() {
92 Properties props = new Properties();
93 String testPassword = "myvoiceismypassword";
94 String encryptedTestPassword = Password.obfuscate(testPassword);
96 props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);
97 ModelLoaderConfig config = new ModelLoaderConfig(props);
99 assertEquals(testPassword, config.getAaiAuthenticationPassword());
103 public void testNoAAIAuth() throws IOException {
105 Properties props = new Properties();
107 new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties"));
109 ModelLoaderConfig config = new ModelLoaderConfig(props);
110 AaiRestClient aaiClient = new AaiRestClient(config);
112 assertFalse("Empty AAI Password should result in no basic authentication",
113 aaiClient.useBasicAuth());
115 props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));
116 config = new ModelLoaderConfig(props);
117 aaiClient = new AaiRestClient(config);
119 assertFalse("No AAI Password should result in no basic authentication",
120 aaiClient.useBasicAuth());