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