[AAI-3] Remove dependency on SDC
[aai/model-loader.git] / src / test / java / org / openecomp / modelloader / config / ModelLoaderConfigTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Model Loader
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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=========================================================
19  *
20  * ECOMP and OpenECOMP are trademarks
21  * and service marks of AT&T Intellectual Property.
22  */
23 package org.openecomp.modelloader.config;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.util.List;
31 import java.util.Properties;
32
33 import org.eclipse.jetty.util.security.Password;
34 import org.junit.Test;
35 import org.openecomp.modelloader.restclient.AaiRestClient;
36
37 import org.openecomp.sdc.utils.ArtifactTypeEnum;
38
39 public class ModelLoaderConfigTest {
40
41   @Test
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);
47
48     List<String> types = config.getRelevantArtifactTypes();
49
50     System.out.println("ArtifactType: " + types.get(0));
51     assertEquals(0,
52         types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
53
54     System.out.println("ArtifactType: " + types.get(1));
55     assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
56
57     System.out.println("ArtifactType: " + types.get(2));
58     assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
59
60     assertEquals(3, types.size());
61   }
62
63   @Test
64   public void testDecryptPassword() {
65     Properties props = new Properties();
66     String testPass = "youshallnotpass";
67     String encryptedTestPass = Password.obfuscate(testPass);
68
69     System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
70
71     props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);
72     ModelLoaderConfig config = new ModelLoaderConfig(props, null);
73
74     assertEquals(testPass, config.getPassword());
75   }
76
77   @Test
78   public void testDecryptKeystorePassword() {
79     Properties props = new Properties();
80     String testPass = "youshallnotpass";
81     String encryptedTestPass = Password.obfuscate(testPass);
82
83     System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
84
85     props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);
86     ModelLoaderConfig config = new ModelLoaderConfig(props, null);
87
88     assertEquals(testPass, config.getKeyStorePassword());
89   }
90
91   @Test
92   public void testDecryptAAIPassword() {
93
94     Properties props = new Properties();
95     String testPassword = "myvoiceismypassword";
96     String encryptedTestPassword = Password.obfuscate(testPassword);
97
98     props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);
99     ModelLoaderConfig config = new ModelLoaderConfig(props, null);
100
101     assertEquals(testPassword, config.getAaiAuthenticationPassword());
102   }
103
104   @Test
105   public void testNoAAIAuth() throws IOException {
106
107     Properties props = new Properties();
108     props.load(
109         new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties"));
110
111     ModelLoaderConfig config = new ModelLoaderConfig(props, null);
112     AaiRestClient aaiClient = new AaiRestClient(config);
113
114     assertFalse("Empty AAI Password should result in no basic authentication",
115         aaiClient.useBasicAuth());
116
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);
120
121     assertFalse("No AAI Password should result in no basic authentication",
122         aaiClient.useBasicAuth());
123   }
124   
125   @Test
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);
131
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"));
134   }
135 }