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.onap.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.onap.appc.adapter.chef.ChefAdapter;
37 import org.onap.appc.exceptions.APPCException;
38 import com.att.cdp.exceptions.ZoneException;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
42 public class TestChefAdapterImpl {
43 private SvcLogicContext svcContext;
45 private ChefAdapter adapter;
47 private Map<String, String> params;
48 private String getAttribute;
52 adapter = new ChefAdapterFactory().create();
53 params = new HashMap<>();
55 "/src/test/resources/testclient.pem");
59 public void tearDown() {
65 @Test(expected=Exception.class)
66 public void testChefGetFail() throws IOException, IllegalStateException, IllegalArgumentException,
67 ZoneException, APPCException,SvcLogicException {
68 params.put("chefAction", "/nodes");
70 givenParams(params, "chefGet");
71 thenResponseShouldFail();
74 @Test(expected=Exception.class)
75 public void testChefPutFail() throws IOException, IllegalStateException, IllegalArgumentException,
76 ZoneException, APPCException,SvcLogicException {
77 params.put("chefAction", "/nodes/testnode");
78 params.put("runList", "recipe[commandtest]");
79 params.put("attributes", "");
80 params.put("chefRequestBody", "Test Body");
82 givenParams(params, "chefPut");
83 thenResponseShouldFail();
87 public void testTriggerFail() throws IOException, IllegalStateException, IllegalArgumentException,
88 ZoneException, APPCException,SvcLogicException {
91 givenParams(params, "trigger");
92 thenResponseShouldFail();
95 private void givenParams(Map<String, String> adapterParams, String method) throws SvcLogicException {
96 svcContext = new SvcLogicContext();
97 if (method == "chefGet"){
98 adapter.chefGet(adapterParams, svcContext);
99 getAttribute = "chefServerResult.code";
101 if (method == "chefPut"){
102 adapter.chefPut(adapterParams, svcContext);
103 getAttribute = "chefServerResult.code";
105 if (method == "trigger"){
106 adapter.trigger(adapterParams, svcContext);
107 getAttribute = "chefAgent.code";
111 private void thenResponseShouldFail(){
112 String status = svcContext.getAttribute(this.getAttribute);
113 assertEquals("500", status);