Implement support for v10 model entities.
[aai/model-loader.git] / src / test / java / org / openecomp / modelloader / config / ModelLoaderConfigTest.java
1 /**\r
2  * ============LICENSE_START=======================================================\r
3  * Model Loader\r
4  * ================================================================================\r
5  * Copyright © 2017 AT&T Intellectual Property.\r
6  * Copyright © 2017 Amdocs\r
7  * All rights reserved.\r
8  * ================================================================================\r
9  * Licensed under the Apache License, Version 2.0 (the "License");\r
10  * you may not use this file except in compliance with the License.\r
11  * You may obtain a copy of the License at\r
12  * http://www.apache.org/licenses/LICENSE-2.0\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  *\r
20  * ECOMP and OpenECOMP are trademarks\r
21  * and service marks of AT&T Intellectual Property.\r
22  */\r
23 package org.openecomp.modelloader.config;\r
24 \r
25 import static org.junit.Assert.assertEquals;\r
26 import static org.junit.Assert.assertFalse;\r
27 \r
28 import java.io.FileInputStream;\r
29 import java.io.IOException;\r
30 import java.util.List;\r
31 import java.util.Properties;\r
32 \r
33 import org.eclipse.jetty.util.security.Password;\r
34 import org.junit.Test;\r
35 import org.openecomp.modelloader.restclient.AaiRestClient;\r
36 \r
37 import org.openecomp.sdc.utils.ArtifactTypeEnum;\r
38 \r
39 public class ModelLoaderConfigTest {\r
40 \r
41   @Test\r
42   public void testYangModelArtifactType() {\r
43     Properties props = new Properties();\r
44     props.setProperty("ml.distribution.ARTIFACT_TYPES",\r
45         "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");\r
46     ModelLoaderConfig config = new ModelLoaderConfig(props, null);\r
47 \r
48     List<String> types = config.getRelevantArtifactTypes();\r
49 \r
50     System.out.println("ArtifactType: " + types.get(0));\r
51     assertEquals(0,\r
52         types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));\r
53 \r
54     System.out.println("ArtifactType: " + types.get(1));\r
55     assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));\r
56 \r
57     System.out.println("ArtifactType: " + types.get(2));\r
58     assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));\r
59 \r
60     assertEquals(3, types.size());\r
61   }\r
62 \r
63   @Test\r
64   public void testDecryptPassword() {\r
65     Properties props = new Properties();\r
66     String testPass = "youshallnotpass";\r
67     String encryptedTestPass = Password.obfuscate(testPass);\r
68 \r
69     System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);\r
70 \r
71     props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);\r
72     ModelLoaderConfig config = new ModelLoaderConfig(props, null);\r
73 \r
74     assertEquals(testPass, config.getPassword());\r
75   }\r
76 \r
77   @Test\r
78   public void testDecryptKeystorePassword() {\r
79     Properties props = new Properties();\r
80     String testPass = "youshallnotpass";\r
81     String encryptedTestPass = Password.obfuscate(testPass);\r
82 \r
83     System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);\r
84 \r
85     props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);\r
86     ModelLoaderConfig config = new ModelLoaderConfig(props, null);\r
87 \r
88     assertEquals(testPass, config.getKeyStorePassword());\r
89   }\r
90 \r
91   @Test\r
92   public void testDecryptAAIPassword() {\r
93 \r
94     Properties props = new Properties();\r
95     String testPassword = "myvoiceismypassword";\r
96     String encryptedTestPassword = Password.obfuscate(testPassword);\r
97 \r
98     props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);\r
99     ModelLoaderConfig config = new ModelLoaderConfig(props, null);\r
100 \r
101     assertEquals(testPassword, config.getAaiAuthenticationPassword());\r
102   }\r
103 \r
104   @Test\r
105   public void testNoAAIAuth() throws IOException {\r
106 \r
107     Properties props = new Properties();\r
108     props.load(\r
109         new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties"));\r
110 \r
111     ModelLoaderConfig config = new ModelLoaderConfig(props, null);\r
112     AaiRestClient aaiClient = new AaiRestClient(config);\r
113 \r
114     assertFalse("Empty AAI Password should result in no basic authentication",\r
115         aaiClient.useBasicAuth());\r
116 \r
117     props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));\r
118     config = new ModelLoaderConfig(props, null);\r
119     aaiClient = new AaiRestClient(config);\r
120 \r
121     assertFalse("No AAI Password should result in no basic authentication",\r
122         aaiClient.useBasicAuth());\r
123   }\r
124   \r
125 }\r