Moving all files to root directory
[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  * 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.adapter.chef.impl;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28
29 import java.io.File;
30 import java.io.IOException;
31 import java.lang.reflect.Field;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Properties;
36 import java.util.Set;
37
38 import org.junit.Before;
39 import org.junit.BeforeClass;
40 import org.junit.Ignore;
41 import org.junit.Test;
42 import org.openecomp.appc.Constants;
43 import org.openecomp.appc.adapter.chef.ChefAdapter;
44 import org.openecomp.appc.adapter.chef.impl.ChefAdapterImpl;
45 import org.openecomp.appc.configuration.ConfigurationFactory;
46 import org.openecomp.appc.exceptions.APPCException;
47 import org.openecomp.appc.exceptions.UnknownProviderException;
48 import com.att.cdp.exceptions.ZoneException;
49 import com.att.cdp.zones.ComputeService;
50 import com.att.cdp.zones.Context;
51 import com.att.cdp.zones.ContextFactory;
52 import com.att.cdp.zones.model.Server;
53 import com.att.cdp.zones.model.Server.Status;
54 import org.openecomp.sdnc.sli.SvcLogicContext;
55 import org.slf4j.MDC;
56
57 @Ignore
58 public class TestChefAdapterImpl {
59
60
61     private ChefAdapterImpl adapter;
62
63     @SuppressWarnings("nls")
64     @BeforeClass
65     public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
66
67     }
68
69     @Before
70     public void setup() throws IllegalArgumentException, IllegalAccessException {
71
72         adapter = new ChefAdapterImpl(System.getProperty("user.dir")+"/src/main/resources/client.pem");
73     }
74     
75     @Test
76     public void testChefGet() throws IOException, IllegalStateException, IllegalArgumentException,
77       ZoneException, APPCException {
78
79             Map<String, String> params = new HashMap<>();
80             params.put("org.openecomp.appc.instance.chefAction", "/nodes");
81             
82             
83             SvcLogicContext svcContext = new SvcLogicContext();          
84             adapter.chefGet(params, svcContext);
85             String status=svcContext.getAttribute("org.openecomp.appc.chefServerResult.code");
86             assertEquals("200",status);
87
88     }
89
90     @Test
91     public void testChefPut() throws IOException, IllegalStateException, IllegalArgumentException,
92         ZoneException, APPCException {
93
94             Map<String, String> params = new HashMap<>();
95             params.put("org.openecomp.appc.instance.chefAction", "/nodes/testnode");
96             params.put("org.openecomp.appc.instance.runList", "recipe[commandtest]");
97             params.put("org.openecomp.appc.instance.attributes", "");
98             SvcLogicContext svcContext = new SvcLogicContext();          
99             adapter.chefPut(params, svcContext);
100             String status=svcContext.getAttribute("org.openecomp.appc.chefServerResult.code");
101             assertEquals("200",status);
102
103     }
104
105     @Test
106     public void testTrigger() throws IOException, IllegalStateException, IllegalArgumentException,
107     ZoneException, APPCException {
108
109             Map<String, String> params = new HashMap<>();
110             params.put("org.openecomp.appc.instance.ip", "http://example.com/test");
111             SvcLogicContext svcContext = new SvcLogicContext();          
112             adapter.trigger(params, svcContext);
113             String status=svcContext.getAttribute("org.openecomp.appc.chefAgent.code");
114             assertEquals("200",status);
115
116     }
117
118
119 }