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.exceptions.APPCException;
37 import com.att.cdp.exceptions.ZoneException;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
41 public class TestChefAdapterImpl {
42 private SvcLogicContext svcContext;
44 private ChefAdapterImpl adapter;
46 private Map<String, String> params;
47 private String getAttribute;
51 adapter = new ChefAdapterImpl(Boolean.TRUE);
52 params = new HashMap<>();
54 "/src/test/resources/testclient.pem");
58 public void tearDown() {
64 @Test(expected=Exception.class)
65 public void testChefGetFail() throws IOException, IllegalStateException, IllegalArgumentException,
66 ZoneException, APPCException,SvcLogicException {
67 params.put("chefAction", "/nodes");
69 givenParams(params, "chefGet");
70 thenResponseShouldFail();
73 @Test(expected=Exception.class)
74 public void testChefPutFail() throws IOException, IllegalStateException, IllegalArgumentException,
75 ZoneException, APPCException,SvcLogicException {
76 params.put("chefAction", "/nodes/testnode");
77 params.put("runList", "recipe[commandtest]");
78 params.put("attributes", "");
79 params.put("chefRequestBody", "Test Body");
81 givenParams(params, "chefPut");
82 thenResponseShouldFail();
86 public void testTriggerFail() throws IOException, IllegalStateException, IllegalArgumentException,
87 ZoneException, APPCException,SvcLogicException {
90 givenParams(params, "trigger");
91 thenResponseShouldFail();
94 private void givenParams(Map<String, String> adapterParams, String method) throws SvcLogicException {
95 svcContext = new SvcLogicContext();
96 if (method == "chefGet"){
97 adapter.chefGet(adapterParams, svcContext);
98 getAttribute = "chefServerResult.code";
100 if (method == "chefPut"){
101 adapter.chefPut(adapterParams, svcContext);
102 getAttribute = "chefServerResult.code";
104 if (method == "trigger"){
105 adapter.trigger(adapterParams, svcContext);
106 getAttribute = "chefAgent.code";
110 private void thenResponseShouldFail(){
111 String status = svcContext.getAttribute(this.getAttribute);
112 assertEquals("500", status);