2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.adapter.chef.impl;
27 import static org.junit.Assert.assertEquals;
29 import java.io.IOException;
30 import java.util.HashMap;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.openecomp.appc.exceptions.APPCException;
37 import com.att.cdp.exceptions.ZoneException;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 public class TestChefAdapterImpl {
41 private SvcLogicContext svcContext;
43 private ChefAdapterImpl adapter;
45 private Map<String, String> params;
46 private String getAttribute;
50 adapter = new ChefAdapterImpl(Boolean.TRUE);
51 params = new HashMap<>();
52 params.put("org.openecomp.appc.instance.pemPath",
53 "/src/test/resources/testclient.pem");
57 public void tearDown() {
64 public void testChefGetFail() throws IOException, IllegalStateException, IllegalArgumentException,
65 ZoneException, APPCException {
66 params.put("org.openecomp.appc.instance.chefAction", "/nodes");
68 givenParams(params, "chefGet");
69 thenResponseShouldFail();
73 public void testChefPutFail() throws IOException, IllegalStateException, IllegalArgumentException,
74 ZoneException, APPCException {
75 params.put("org.openecomp.appc.instance.chefAction", "/nodes/testnode");
76 params.put("org.openecomp.appc.instance.runList", "recipe[commandtest]");
77 params.put("org.openecomp.appc.instance.attributes", "");
78 params.put("org.openecomp.appc.instance.chefRequestBody", "Test Body");
80 givenParams(params, "chefPut");
81 thenResponseShouldFail();
85 public void testTriggerFail() throws IOException, IllegalStateException, IllegalArgumentException,
86 ZoneException, APPCException {
87 params.put("org.openecomp.appc.instance.ip", "");
89 givenParams(params, "trigger");
90 thenResponseShouldFail();
93 private void givenParams(Map<String, String> adapterParams, String method) {
94 svcContext = new SvcLogicContext();
95 if (method == "chefGet"){
96 adapter.chefGet(adapterParams, svcContext);
97 getAttribute = "org.openecomp.appc.chefServerResult.code";
99 if (method == "chefPut"){
100 adapter.chefPut(adapterParams, svcContext);
101 getAttribute = "org.openecomp.appc.chefServerResult.code";
103 if (method == "trigger"){
104 adapter.trigger(adapterParams, svcContext);
105 getAttribute = "org.openecomp.appc.chefAgent.code";
109 private void thenResponseShouldFail(){
110 String status = svcContext.getAttribute(this.getAttribute);
111 assertEquals("500", status);