Change to CCSDK and ODL Carbon
[appc.git] / appc-adapters / appc-chef-adapter / appc-chef-adapter-bundle / src / test / java / org / openecomp / appc / adapter / chef / impl / TestChefAdapterImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.adapter.chef.impl;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
31
32 import java.io.File;
33 import java.io.IOException;
34 import java.lang.reflect.Field;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Properties;
39 import java.util.Set;
40
41 import org.junit.Before;
42 import org.junit.BeforeClass;
43 import org.junit.Ignore;
44 import org.junit.Test;
45 import org.openecomp.appc.Constants;
46 import org.openecomp.appc.adapter.chef.ChefAdapter;
47 import org.openecomp.appc.adapter.chef.impl.ChefAdapterImpl;
48 import org.openecomp.appc.configuration.ConfigurationFactory;
49 import org.openecomp.appc.exceptions.APPCException;
50 import org.openecomp.appc.exceptions.UnknownProviderException;
51 import com.att.cdp.exceptions.ZoneException;
52 import com.att.cdp.zones.ComputeService;
53 import com.att.cdp.zones.Context;
54 import com.att.cdp.zones.ContextFactory;
55 import com.att.cdp.zones.model.Server;
56 import com.att.cdp.zones.model.Server.Status;
57 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
58 import org.slf4j.MDC;
59
60 @Ignore
61 public class TestChefAdapterImpl {
62
63
64     private ChefAdapterImpl adapter;
65
66     @SuppressWarnings("nls")
67     @BeforeClass
68     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
69
70     }
71
72     @Before
73     public void setup() throws IllegalArgumentException, IllegalAccessException {
74
75         adapter = new ChefAdapterImpl(System.getProperty("user.dir")+"/src/main/resources/client.pem");
76     }
77
78     @Test
79     public void testChefGet() throws IOException, IllegalStateException, IllegalArgumentException,
80       ZoneException, APPCException {
81
82             Map<String, String> params = new HashMap<>();
83             params.put("org.openecomp.appc.instance.chefAction", "/nodes");
84
85             SvcLogicContext svcContext = new SvcLogicContext();
86             adapter.chefGet(params, svcContext);
87             String status=svcContext.getAttribute("org.openecomp.appc.chefServerResult.code");
88             assertEquals("200",status);
89
90     }
91
92     @Test
93     public void testChefPut() throws IOException, IllegalStateException, IllegalArgumentException,
94         ZoneException, APPCException {
95
96             Map<String, String> params = new HashMap<>();
97             params.put("org.openecomp.appc.instance.chefAction", "/nodes/testnode");
98             params.put("org.openecomp.appc.instance.runList", "recipe[commandtest]");
99             params.put("org.openecomp.appc.instance.attributes", "");
100             SvcLogicContext svcContext = new SvcLogicContext();
101             adapter.chefPut(params, svcContext);
102             String status=svcContext.getAttribute("org.openecomp.appc.chefServerResult.code");
103             assertEquals("200",status);
104
105     }
106
107     @Test
108     public void testTrigger() throws IOException, IllegalStateException, IllegalArgumentException,
109     ZoneException, APPCException {
110
111             Map<String, String> params = new HashMap<>();
112             params.put("org.openecomp.appc.instance.ip", "http://example.com/test");
113             SvcLogicContext svcContext = new SvcLogicContext();
114             adapter.trigger(params, svcContext);
115             String status=svcContext.getAttribute("org.openecomp.appc.chefAgent.code");
116             assertEquals("200",status);
117
118     }
119
120
121 }