Remove commented methods/fields in APPC
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / test / java / org / openecomp / appc / listener / CL / impl / TestProviderOperations.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
22 package org.openecomp.appc.listener.CL.impl;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.fail;
27
28 import java.util.Properties;
29
30 import org.eclipse.osgi.internal.signedcontent.Base64;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.openecomp.appc.configuration.ConfigurationFactory;
34 import org.openecomp.appc.exceptions.APPCException;
35 import org.openecomp.appc.listener.CL.impl.ProviderOperations;
36 import org.openecomp.appc.listener.CL.model.IncomingMessage;
37
38 public class TestProviderOperations {
39
40     private String ACTIVE_ENDPOINT;
41     
42     @Before
43     public void setup() {
44         Properties props = ConfigurationFactory.getConfiguration().getProperties();
45         ACTIVE_ENDPOINT = props.getProperty("appc.ClosedLoop.provider.url");
46         assertNotNull(ACTIVE_ENDPOINT);
47         ProviderOperations.setUrl(ACTIVE_ENDPOINT);
48
49         props.getProperty("test.vm_url");
50         assertNotNull("VM_URL");
51     }
52
53     @Test
54     public void testTopologyOperation() {
55         IncomingMessage msg = new IncomingMessage();
56         // Client and Time are for ID
57         msg.setRequestClient("APPC");
58         msg.setRequestTime("TEST");
59         msg.setRequest("Restart");
60
61         // Null Input
62         try {
63             ProviderOperations.topologyDG(null);
64             fail("Topology Operation with null input should fail");
65         } catch (APPCException e) {
66             assertNotNull(e.getMessage());
67         }
68
69         // Bad URL
70         msg.setUrl("some bad url here");
71         try {
72             ProviderOperations.topologyDG(msg);
73             // Could also be issue in IaaS Adapter
74             fail("Topology Operation with bad url should fail");
75         } catch (APPCException e) {
76             assertNotNull(e.getMessage());
77         }
78
79         // Will be tested in worker
80         // msg.setUrl(VM_URL);
81         // System.out.println("Rebooting real VM. Test can take up to 90s");
82         // try {
83         // assertTrue(ProviderOperations.topologyDG(msg));
84         // } catch (APPCException e) {
85         // fail("Topology Operation with good url should succeed. Check url in gui first");
86         // }
87
88     }
89
90     @Test
91     public void testConfigurationOperation() {
92         try {
93             ProviderOperations.topologyDG(null);
94             fail("Configuration Operation should throw execption. Not yet supported");
95         } catch (APPCException e) {
96             assertNotNull(e.getMessage());
97         }
98     }
99
100     @Test
101     public void testBasicAuthFormating() {
102         String user = "user";
103         String pass = "pass";
104
105         String result = ProviderOperations.setAuthentication(user, pass);
106
107         assertNotNull(result);
108         String decode = new String(Base64.decode(result.getBytes()));
109         assertEquals(user + ":" + pass, decode);
110     }
111
112     @Test
113     public void testGetSet() {
114         // Every test URL will get reset
115         assertEquals(ACTIVE_ENDPOINT, ProviderOperations.getUrl());
116
117         String newUrl = "http://example.com";
118         ProviderOperations.setUrl(newUrl);
119         assertEquals(newUrl, ProviderOperations.getUrl());
120     }
121
122 }