2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.appc.listener.CL.impl;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.fail;
28 import java.util.Properties;
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;
38 public class TestProviderOperations {
40 private String ACTIVE_ENDPOINT;
44 Properties props = ConfigurationFactory.getConfiguration().getProperties();
45 ACTIVE_ENDPOINT = props.getProperty("appc.ClosedLoop.provider.url");
46 assertNotNull(ACTIVE_ENDPOINT);
47 ProviderOperations.setUrl(ACTIVE_ENDPOINT);
49 props.getProperty("test.vm_url");
50 assertNotNull("VM_URL");
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");
63 ProviderOperations.topologyDG(null);
64 fail("Topology Operation with null input should fail");
65 } catch (APPCException e) {
66 assertNotNull(e.getMessage());
70 msg.setUrl("some bad url here");
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());
79 // Will be tested in worker
80 // msg.setUrl(VM_URL);
81 // System.out.println("Rebooting real VM. Test can take up to 90s");
83 // assertTrue(ProviderOperations.topologyDG(msg));
84 // } catch (APPCException e) {
85 // fail("Topology Operation with good url should succeed. Check url in gui first");
91 public void testConfigurationOperation() {
93 ProviderOperations.topologyDG(null);
94 fail("Configuration Operation should throw execption. Not yet supported");
95 } catch (APPCException e) {
96 assertNotNull(e.getMessage());
101 public void testBasicAuthFormating() {
102 String user = "user";
103 String pass = "pass";
105 String result = ProviderOperations.setAuthentication(user, pass);
107 assertNotNull(result);
108 String decode = new String(Base64.decode(result.getBytes()));
109 assertEquals(user + ":" + pass, decode);
113 public void testGetSet() {
114 // Every test URL will get reset
115 assertEquals(ACTIVE_ENDPOINT, ProviderOperations.getUrl());
117 String newUrl = "http://example.com";
118 ProviderOperations.setUrl(newUrl);
119 assertEquals(newUrl, ProviderOperations.getUrl());