Return List<Artifact> in ArtifactDownloadManager
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / config / TestModelLoaderConfig.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.modelloader.config;
22
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24
25 import java.io.File;
26 import java.util.List;
27 import java.util.Properties;
28 import org.eclipse.jetty.util.security.Password;
29 import org.junit.jupiter.api.Test;
30 import org.onap.sdc.utils.ArtifactTypeEnum;
31
32 /**
33  * Tests for ModelLoaderConfig class.
34  *
35  */
36 public class TestModelLoaderConfig {
37
38     @Test
39     public void testYangModelArtifactType() {
40         Properties props = new Properties();
41         props.setProperty("ml.distribution.ARTIFACT_TYPES", "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
42         ModelLoaderConfig config = new ModelLoaderConfig(props, null);
43
44         List<String> types = config.getRelevantArtifactTypes();
45
46         System.out.println("ArtifactType: " + types.get(0));
47         assertEquals(0, types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
48
49         System.out.println("ArtifactType: " + types.get(1));
50         assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
51
52         System.out.println("ArtifactType: " + types.get(2));
53         assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
54
55         assertEquals(3, types.size());
56     }
57
58     @Test
59     public void testDecryptPassword() {
60         String password = "youshallnotpass";
61         ModelLoaderConfig config =
62                 createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password);
63         assertEquals(password, config.getPassword());
64         
65         config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password);
66         assertEquals(password, config.getPassword());
67     }
68
69     @Test
70     public void testDecryptKeystorePassword() {
71         String password = "youshallnotpass";
72         ModelLoaderConfig config =
73                 createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password);
74         assertEquals(password, config.getKeyStorePassword());
75         
76         config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password);
77         assertEquals(password, config.getKeyStorePassword());
78     }
79
80     @Test
81     public void testDecryptAaiAuthenticationPassword() {
82         String password = "myvoiceismypassword";
83         ModelLoaderConfig config =
84                 createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password);
85         assertEquals(password, config.getAaiAuthenticationPassword());
86         
87         config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password);
88         assertEquals(password, config.getAaiAuthenticationPassword());
89     }
90
91     @Test
92     public void testDecryptAaiKeystorePassword() {
93         String password = "myvoiceismypassword";
94         ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password);
95         assertEquals(password, config.getAaiKeyStorePassword());
96         
97         config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password);
98         assertEquals(password, config.getAaiKeyStorePassword());
99     }
100
101     @Test
102     public void testAaiBaseUrl() {
103         String url = "http://localhost:1234/";
104         Properties props = new Properties();
105         props.put(ModelLoaderConfig.PROP_AAI_BASE_URL, url);
106         ModelLoaderConfig config = new ModelLoaderConfig(props, null);
107         assertEquals(url, config.getAaiBaseUrl());
108     }
109
110     @Test
111     public void testDecryptBabelKeystorePassword() {
112         String password = "babelpassword";
113         ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password);
114         assertEquals(password, config.getBabelKeyStorePassword());
115         
116         config = createUnobfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password);
117         assertEquals(password, config.getBabelKeyStorePassword());
118     }
119
120     @Test
121     public void testBabelKeystorePath() {
122         String root = "path_to_keystore";
123         String path = "relative_keystore_path";
124         Properties props = new Properties();
125         props.put(ModelLoaderConfig.PROP_BABEL_KEYSTORE_FILE, path);
126         ModelLoaderConfig config = new ModelLoaderConfig(props, root);
127         assertEquals(root + File.separator + path, config.getBabelKeyStorePath());
128     }
129
130     @Test
131     public void testBabelBaseUrl() {
132         String url = "http://localhost/";
133         Properties props = new Properties();
134         props.put(ModelLoaderConfig.PROP_BABEL_BASE_URL, url);
135         ModelLoaderConfig config = new ModelLoaderConfig(props, null);
136         assertEquals(url, config.getBabelBaseUrl());
137     }
138
139     @Test
140     public void testBabelGenerateArtifactsUrl() {
141         String url = "/path/to/the/resource";
142         Properties props = new Properties();
143         props.put(ModelLoaderConfig.PROP_BABEL_GENERATE_RESOURCE_URL, url);
144         ModelLoaderConfig config = new ModelLoaderConfig(props, null);
145         assertEquals(url, config.getBabelGenerateArtifactsUrl());
146     }
147
148     @Test
149     public void testGetUrls() {
150         Properties props = new Properties();
151         props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/");
152         props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL,
153                 "/aai/v*/service-design-and-creation/named-queries/named-query/");
154         ModelLoaderConfig config = new ModelLoaderConfig(props, null);
155
156         assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9"));
157         assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/",
158                 config.getAaiNamedQueryUrl("v10"));
159     }
160
161
162     /**
163      * Create a Model Loader Configuration object from the supplied Property.
164      * 
165      * @param propertyName property key
166      * @param propertyValue value of the property
167      * @return a new ModelLoaderConfig object containing a single obfuscated property value
168      */
169     private ModelLoaderConfig createObfuscatedTestConfig(String propertyName, String propertyValue) {
170         Properties props = new Properties();
171         props.put(propertyName, Password.obfuscate(propertyValue));
172         return new ModelLoaderConfig(props, null);
173     }
174     
175     private ModelLoaderConfig createUnobfuscatedTestConfig(String propertyName, String propertyValue) {
176         Properties props = new Properties();
177         props.put(propertyName, propertyValue);
178         return new ModelLoaderConfig(props, null);
179     }
180 }