05fc9e3938399e1efb11d85de925b06b4bdff628
[sdc.git] /
1 /*
2  * Copyright © 2019 iconectiv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.core.externaltesting.impl;
18
19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.onap.sdc.tosca.services.YamlUtil;
23 import org.openecomp.core.externaltesting.api.ClientConfiguration;
24 import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.InputStream;
29
30 public class ConfigurationTests {
31
32   @Test
33   public void testClientConfig() {
34     // a brain dead test of the setter and getter.
35     // future tests for more complex config to come.
36     ClientConfiguration cc = new ClientConfiguration();
37     cc.setEnabled(true);
38     Assert.assertTrue("client configuration setter", cc.isEnabled());
39     cc.setEnabled(false);
40     Assert.assertFalse("client configuration setter", cc.isEnabled());
41   }
42
43   @Test
44   public void testConfig() throws Exception {
45     try (InputStream fileInput = new FileInputStream(new File("src/test/data/externaltesting-configuration.yaml"))) {
46       YamlUtil yamlUtil = new YamlUtil();
47       Object raw = yamlUtil.yamlToMap(fileInput);
48       TestingAccessConfig accessConfig = new ObjectMapper().convertValue(raw, TestingAccessConfig.class);
49       Assert.assertNotNull("client config available", accessConfig.getClient());
50     }
51   }
52
53   @Test
54   public void testEndpointDefinition() {
55     RemoteTestingEndpointDefinition def = new RemoteTestingEndpointDefinition();
56     def.setId("vtp");
57     def.setEnabled(true);
58     def.setTitle("VTP");
59     def.setApiKey("FOOBARBAZ");
60     def.setUrl("http://example.com/vtptesting");
61     def.setScenarioFilter("c.*");
62
63     RemoteTestingEndpointDefinition def2 = new RemoteTestingEndpointDefinition();
64     def2.setId("vtp");
65     def2.setEnabled(true);
66     def2.setTitle("VTP");
67     def2.setUrl("http://example.com/vtptesting");
68     def2.setApiKey("FOOBARBAZ");
69     def2.setScenarioFilter("c.*");
70
71     Assert.assertEquals("code", "VTP", def.getTitle());
72     Assert.assertEquals("API keys equals", def.getApiKey(), def2.getApiKey());
73     Assert.assertEquals("code equals", def.getTitle(), def2.getTitle());
74     Assert.assertEquals("url equals", def.getUrl(), def2.getUrl());
75
76     boolean matches = def.getScenarioFilterPattern().matcher("certification").matches();
77     Assert.assertTrue("pattern", matches);
78
79   }
80 }