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