From 06a8e46e6beb8538d75b27b8cb7d82e3bcab0a2d Mon Sep 17 00:00:00 2001 From: "Wonnell, Skip (kw5258)" Date: Fri, 27 Apr 2018 14:14:01 -0500 Subject: Fixes for Chef Adapter bundle Programatically configure values for truststore and password when initializing the HttpClient. Update post and put methods to set entity Add organization into request URI Restore log messages to original values Issue-ID: APPC-868 Change-Id: Ia0fdf13fcb1e3ad91a4d2c5ce704523562191379 Signed-off-by: Wonnell, Skip (kw5258) --- .../chef/chefclient/ChefApiClientFactory.java | 44 ++++++++++++++++------ .../chef/chefclient/impl/ChefApiClientImpl.java | 30 ++++++++++----- .../chef/chefclient/impl/ChefApiHeaderFactory.java | 6 +-- .../chef/chefclient/impl/ChefRequestBuilder.java | 15 ++++---- .../appc/adapter/chef/impl/ChefAdapterImpl.java | 33 ++++++++-------- .../chefclient/impl/ChefApiClientImplTest.java | 5 ++- .../chef/impl/ChefAdapterImplJobPusherTest.java | 8 ++++ .../adapter/chef/impl/ChefAdapterImplTest.java | 7 ++-- .../impl/ChefAdapterImplVNFCOperationsTest.java | 30 ++++++++++++--- 9 files changed, 116 insertions(+), 62 deletions(-) (limited to 'appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src') diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java index 11d820d5d..c41142cc0 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/ChefApiClientFactory.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,30 +20,51 @@ */ package org.onap.appc.adapter.chef.chefclient; -import com.google.common.collect.ImmutableMap; +import java.io.File; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; import org.onap.appc.adapter.chef.chefclient.api.ChefApiClient; import org.onap.appc.adapter.chef.chefclient.impl.ChefApiClientImpl; import org.onap.appc.adapter.chef.chefclient.impl.ChefApiHeaderFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.collect.ImmutableMap; public class ChefApiClientFactory { - private HttpClient httpClient = HttpClients.createDefault(); + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefApiClientFactory.class); + + private HttpClient createChefHttpClient() { + String trustStoreFileName = "/opt/app/bvc/chef/chefServerSSL.jks"; + char[] trustStoreCreds = "adminadmin".toCharArray(); + try { + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + SSLContexts.custom().loadTrustMaterial(new File(trustStoreFileName), trustStoreCreds).build(), + SSLConnectionSocketFactory.getDefaultHostnameVerifier()); + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException + | IOException e) { + logger.error(e.getMessage(), e); + } + return null; + } + + private HttpClient httpClient = createChefHttpClient(); private ChefApiHeaderFactory chefApiHeaderFactory = new ChefApiHeaderFactory(); public ChefApiClient create(String endPoint, String organizations, String userId, String pemPath) { - return new ChefApiClientImpl( - httpClient, - endPoint, - (methodName, requestPath, body) -> chefApiHeaderFactory + return new ChefApiClientImpl(httpClient, endPoint, organizations, (methodName, requestPath, body) -> chefApiHeaderFactory .create(methodName, requestPath, body, userId, organizations, pemPath)); } - public ChefApiClient create(String endPoint) { - return new ChefApiClientImpl( - httpClient, - endPoint, - (methodName, requestPath, body) -> ImmutableMap.of()); + public ChefApiClient create(String endPoint, String organizations) { + return new ChefApiClientImpl(httpClient, endPoint, organizations, (methodName, requestPath, body) -> ImmutableMap.of()); } } diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImpl.java index 8edc2b566..f86b49033 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImpl.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -17,8 +17,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ @@ -26,6 +24,9 @@ package org.onap.appc.adapter.chef.chefclient.impl; import java.io.IOException; import java.net.URISyntaxException; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -39,11 +40,14 @@ public class ChefApiClientImpl implements ChefApiClient { private final HttpClient httpClient; private final String endpoint; + private final String organization; private final HttpHeaderFactory httpHeaderFactory; - - public ChefApiClientImpl(HttpClient httpClient, String endpoint, HttpHeaderFactory httpHeaderFactory) { + private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefApiClientImpl.class); + public ChefApiClientImpl(HttpClient httpClient, String endpoint, String organization, + HttpHeaderFactory httpHeaderFactory) { this.httpClient = httpClient; this.endpoint = endpoint; + this.organization = organization; this.httpHeaderFactory = httpHeaderFactory; } @@ -51,7 +55,7 @@ public class ChefApiClientImpl implements ChefApiClient { public ChefResponse get(String path) { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpGet() - .withPath(path) + .withPath(getPath(path)) .withHeaders(httpHeaderFactory.create("GET", path, "")); return execute(requestBuilder); } @@ -60,7 +64,7 @@ public class ChefApiClientImpl implements ChefApiClient { public ChefResponse delete(String path) { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpDelete() - .withPath(path) + .withPath(getPath(path)) .withHeaders(httpHeaderFactory.create("DELETE", path, "")); return execute(requestBuilder); } @@ -69,7 +73,7 @@ public class ChefApiClientImpl implements ChefApiClient { public ChefResponse post(String path, String body) { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpPost(body) - .withPath(path) + .withPath(getPath(path)) .withHeaders(httpHeaderFactory.create("POST", path, body)); return execute(requestBuilder); } @@ -78,13 +82,17 @@ public class ChefApiClientImpl implements ChefApiClient { public ChefResponse put(String path, String body) { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpPut(body) - .withPath(path) + .withPath(getPath(path)) .withHeaders(httpHeaderFactory.create("PUT", path, body)); + logger.info("request: PATH: "+path+ " body: "+body); return execute(requestBuilder); } private ChefResponse execute(OngoingRequestBuilder chefRequest) { try { + if (httpClient == null) { + return ChefResponse.create(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Could not create http client for chef"); + } HttpResponse response = httpClient.execute(chefRequest.build()); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity httpEntity = response.getEntity(); @@ -96,5 +104,9 @@ public class ChefApiClientImpl implements ChefApiClient { return ChefResponse.create(HttpStatus.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); } } + + private String getPath(String path) { + return "/organizations/" + organization + path; + } } diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiHeaderFactory.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiHeaderFactory.java index d045135c4..e40eee2a6 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiHeaderFactory.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiHeaderFactory.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +28,6 @@ public class ChefApiHeaderFactory { private FormattedTimestamp formattedTimestamp = new FormattedTimestamp(); - static { - System.setProperty("javax.net.ssl.trustStore", "/opt/onap/appc/chef/chefServerSSL.jks"); - System.setProperty("javax.net.ssl.trustStorePassword", "adminadmin"); - } - public ImmutableMap create(String methodName, String path, String body, String userId, String organizations, String pemPath) { diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefRequestBuilder.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefRequestBuilder.java index a2248438a..c2501e334 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefRequestBuilder.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/ChefRequestBuilder.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +34,7 @@ import org.apache.http.entity.StringEntity; final class ChefRequestBuilder { - private ChefRequestBuilder() { - } + private ChefRequestBuilder() {} static OngoingRequestBuilder newRequestTo(String endPoint) { return new OngoingRequestBuilder(endPoint); @@ -68,21 +68,22 @@ final class ChefRequestBuilder { public OngoingRequestBuilder httpPost(String body) { HttpPost httpPost = new HttpPost(); - toEntity(body); + httpPost.setEntity(toEntity(body)); httpRequestBase = httpPost; return this; } public OngoingRequestBuilder httpPut(String body) { HttpPut httpPut = new HttpPut(); - toEntity(body); + httpPut.setEntity(toEntity(body)); httpRequestBase = httpPut; return this; } - private void toEntity(String body) { + private StringEntity toEntity(String body) { StringEntity stringEntity = new StringEntity(body, "UTF-8"); stringEntity.setContentType("application/json"); + return stringEntity; } public OngoingRequestBuilder withHeaders(ImmutableMap headers) { @@ -93,13 +94,11 @@ final class ChefRequestBuilder { public HttpRequestBase build() throws URISyntaxException { setRequestUri(); setRequestHeaders(); - return httpRequestBase; } private void setRequestUri() throws URISyntaxException { - URI fullPath = new URIBuilder(endPoint) - .setPath(path).build(); + URI fullPath = new URIBuilder(endPoint).setPath(path).build(); httpRequestBase.setURI(fullPath); } diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java index 64aedcc24..bd367b035 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -17,8 +17,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ package org.onap.appc.adapter.chef.impl; @@ -146,8 +144,8 @@ public class ChefAdapterImpl implements ChefAdapter { doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage()); } catch (Exception e) { code = 401; - logger.error(POSTING_REQUEST_ERROR_STR, e); - doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage()); + logger.error(POSTING_REQUEST_ERROR_STR + "vnfcEnvironment", e); + doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + "vnfcEnvironment"+ e.getMessage()); } } else { code = 500; @@ -201,12 +199,12 @@ public class ChefAdapterImpl implements ChefAdapter { } } catch (JSONException e) { code = 401; - logger.error(POSTING_REQUEST_JSON_ERROR_STR, e); - doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage()); + logger.error(POSTING_REQUEST_JSON_ERROR_STR +"vnfcNodeobjects", e); + doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR +"vnfcNodeobjects" + e.getMessage()); } catch (Exception e) { code = 401; - logger.error(POSTING_REQUEST_ERROR_STR, e); - doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage()); + logger.error(POSTING_REQUEST_ERROR_STR +"vnfcNodeobjects", e); + doFailure(ctx, code, POSTING_REQUEST_ERROR_STR +"vnfcNodeobjects"+ e.getMessage()); } } @@ -250,8 +248,8 @@ public class ChefAdapterImpl implements ChefAdapter { } } catch (Exception e) { code = 401; - logger.error(POSTING_REQUEST_ERROR_STR, e); - doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage()); + logger.error(POSTING_REQUEST_ERROR_STR + "vnfcPushJob", e); + doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + "vnfcPushJob"+ e.getMessage()); } } @@ -321,12 +319,12 @@ public class ChefAdapterImpl implements ChefAdapter { } } catch (JSONException e) { code = 401; - logger.error(POSTING_REQUEST_JSON_ERROR_STR, e); - doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + e.getMessage()); + logger.error(POSTING_REQUEST_JSON_ERROR_STR + "fetchResults", e); + doFailure(ctx, code, POSTING_REQUEST_JSON_ERROR_STR + "fetchResults" + e.getMessage()); } catch (Exception e) { code = 401; - logger.error(POSTING_REQUEST_ERROR_STR , e); - doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + e.getMessage()); + logger.error(POSTING_REQUEST_ERROR_STR + "fetchResults" , e); + doFailure(ctx, code, POSTING_REQUEST_ERROR_STR + "fetchResults"+ e.getMessage()); } } @@ -382,7 +380,6 @@ public class ChefAdapterImpl implements ChefAdapter { String dgContext = params.get("dgContext"); JSONObject jsonConfig = new JSONObject(allConfigData); String contextData = fetchContextData(key, jsonConfig); - ctx.setAttribute(dgContext, contextData); } @@ -522,7 +519,7 @@ public class ChefAdapterImpl implements ChefAdapter { String tVmIp = params.get("ip"); try { - ChefResponse chefResponse = chefApiClientFactory.create(tVmIp).get(""); + ChefResponse chefResponse = chefApiClientFactory.create(tVmIp, organizations).get(""); chefClientResult(svcLogicContext, chefResponse.getStatusCode(), chefResponse.getBody()); svcLogicContext.setAttribute("chefAgent.code", "200"); } catch (Exception e) { @@ -655,4 +652,4 @@ public class ChefAdapterImpl implements ChefAdapter { throw new SvcLogicException("Chef Adapter error:" + cutMessage); } -} \ No newline at end of file +} diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java index ed39efb1b..f1e215aa4 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/impl/ChefApiClientImplTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -199,7 +200,7 @@ public class ChefApiClientImplTest { boolean headersMatch = checkIfHeadersMatch(httpRequestBase); try { return methodName.equals(httpRequestBase.getMethod()) - && new URI(END_POINT + REQUEST_PATH).equals(httpRequestBase.getURI()) + && new URI(END_POINT + "/organizations/" + ORGANIZATIONS_PATH + REQUEST_PATH).equals(httpRequestBase.getURI()) && headersMatch; } catch (URISyntaxException e) { e.printStackTrace(); @@ -215,4 +216,4 @@ public class ChefApiClientImplTest { .allMatch(p -> httpRequestBase.getFirstHeader(p.getKey()).getValue().equals(p.getValue())); } } -} \ No newline at end of file +} diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplJobPusherTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplJobPusherTest.java index f4d19e22b..9e83dd63d 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplJobPusherTest.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplJobPusherTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,6 +87,7 @@ public class ChefAdapterImplJobPusherTest { assertThat(svcLogicContext.getAttribute(JOB_ID)).isEqualTo("666"); } + @SuppressWarnings("unchecked") public void assertSuccessfulPostCallForStatus(int expectedHttpStatus) throws SvcLogicException { // GIVEN Map params = givenInputParams( @@ -106,6 +108,7 @@ public class ChefAdapterImplJobPusherTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(EXPECTED_RESPONSE_MSG); } + @SuppressWarnings("unchecked") @Test public void pushJob_shouldHandleAllOccurringExceptions_duringMethodExecution() { // GIVEN @@ -126,6 +129,7 @@ public class ChefAdapterImplJobPusherTest { assertThat(svcLogicContext.getAttribute(JOB_ID)).isBlank(); } + @SuppressWarnings("unchecked") @Test public void checkPushJob_shouldSetFailStatusAndMsgInContext_andThrowException_whenRetryTimesParamIsMissing() { // GIVEN @@ -137,6 +141,7 @@ public class ChefAdapterImplJobPusherTest { assertIfInputParamsAreValidated(params); } + @SuppressWarnings("unchecked") @Test public void checkPushJob_shouldSetFailStatusAndMsgInContext_andThrowException_whenRetryIntervalParamIsMissing() { // GIVEN @@ -148,6 +153,7 @@ public class ChefAdapterImplJobPusherTest { assertIfInputParamsAreValidated(params); } + @SuppressWarnings("unchecked") @Test public void checkPushJob_shouldSetFailStatusAndMsgInContext_andThrowException_whenJobIdParamIsMissing() { // GIVEN @@ -211,6 +217,7 @@ public class ChefAdapterImplJobPusherTest { ChefResponse.create(HttpStatus.SC_OK, "{status:running}")); } + @SuppressWarnings("unchecked") public void assertCheckJobStatusFor(String expectedHttpStatus, String expectedMessage, ChefResponse firstResponse, ChefResponse... nextResponses) throws SvcLogicException { @@ -233,6 +240,7 @@ public class ChefAdapterImplJobPusherTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedMessage); } + @SuppressWarnings("unchecked") private Map givenInputParams(Entry... entries) { Builder paramsBuilder = ImmutableMap.builder(); paramsBuilder.put("username", USERNAME) diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java index 62de292d9..3d4ee361b 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,7 +124,7 @@ public class ChefAdapterImplTest { // GIVEN Map params = ImmutableMap.of(IP_PARAM, ENDPOINT_IP); SvcLogicContext svcLogicContext = new SvcLogicContext(); - given(chefApiClientFactory.create(ENDPOINT_IP).get("")) + given(chefApiClientFactory.create(ENDPOINT_IP, "").get("")) .willReturn(ChefResponse.create(HttpStatus.SC_OK, EXPECTED_RESPONSE_MSG)); // WHEN @@ -141,7 +142,7 @@ public class ChefAdapterImplTest { // GIVEN Map params = ImmutableMap.of(IP_PARAM, ENDPOINT_IP); SvcLogicContext svcLogicContext = new SvcLogicContext(); - given(chefApiClientFactory.create(ENDPOINT_IP)).willThrow(new RuntimeException()); + given(chefApiClientFactory.create(ENDPOINT_IP, "")).willThrow(new RuntimeException()); // WHEN chefAdapterFactory.create().trigger(params, svcLogicContext); @@ -192,4 +193,4 @@ public class ChefAdapterImplTest { assertThat(svcLogicContext.getAttribute("chefServerResult.message")) .isEqualTo(expectedErrorMsg); } -} \ No newline at end of file +} diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java index 7f9c505ff..e79b72acb 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/ChefAdapterImplVNFCOperationsTest.java @@ -3,6 +3,7 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,6 +75,7 @@ public class ChefAdapterImplVNFCOperationsTest { svcLogicContext = new SvcLogicContext(); } + @SuppressWarnings("unchecked") @Test public void vnfcEnvironment_shouldSkipEnvironmentCreation_whenEnvParamIsEmpty() throws SvcLogicException { // GIVEN @@ -89,6 +91,7 @@ public class ChefAdapterImplVNFCOperationsTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo("Skip Environment block "); } + @SuppressWarnings("unchecked") @Test public void vnfcEnvironment_shouldCreateNewEnvironment_forEnvParam_whenRequestedEnvDoesNotExist() throws SvcLogicException { @@ -113,6 +116,7 @@ public class ChefAdapterImplVNFCOperationsTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage); } + @SuppressWarnings("unchecked") @Test public void vnfcEnvironment_shouldNotAttemptEnvCreation_andThrowException_whenPrivateKeyCheckFails() { // GIVEN @@ -132,6 +136,7 @@ public class ChefAdapterImplVNFCOperationsTest { .isEqualTo(expectedErrorMsg + CLIENT_PRIVATE_KEY_PATH); } + @SuppressWarnings("unchecked") @Test public void vnfcEnvironment_shouldNotAttemptEnvCreation_andHandleJSONException_whenJSONParamsAreMalformed() { // GIVEN @@ -151,6 +156,7 @@ public class ChefAdapterImplVNFCOperationsTest { .startsWith(expectedErrorMessage); } + @SuppressWarnings("unchecked") @Test public void vnfcEnvironment_shouldNotAttemptEnvCreation_andHandleException_whenExceptionOccursDuringExecution() { // GIVEN @@ -163,7 +169,7 @@ public class ChefAdapterImplVNFCOperationsTest { // WHEN // THEN assertThatExceptionOfType(SvcLogicException.class) .isThrownBy(() -> chefAdapterFactory.create().vnfcEnvironment(params, svcLogicContext)) - .withMessage(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage + "Null value encountered"); + .withMessage(CHEF_ADAPTER_ERROR_PREFIX + expectedErrorMessage + "vnfcEnvironmentNull value encountered"); assertThat(svcLogicContext.getStatus()).isEqualTo(FAILURE_STATUS); assertThat(svcLogicContext.getAttribute(RESULT_CODE_ATTR_KEY)) @@ -194,6 +200,7 @@ public class ChefAdapterImplVNFCOperationsTest { assertNodeObjectsAreUpdatedFor(firstNodeResponse, secondNodeResponse, expectedHttpStatus, expectedMessage); } + @SuppressWarnings("unchecked") public void assertNodeObjectsAreUpdatedFor(ChefResponse firstNodeResponse, ChefResponse secondNodeResponse, int expectedHttpStatus, String expectedMessage) throws SvcLogicException { // GIVEN @@ -220,6 +227,7 @@ public class ChefAdapterImplVNFCOperationsTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedMessage); } + @SuppressWarnings("unchecked") @Test public void vnfcNodeObjects_shouldThrowSvcLogicException_whenNodeListParamIsEmpty() { Map params = givenInputParams( @@ -228,6 +236,7 @@ public class ChefAdapterImplVNFCOperationsTest { checkMissingParamsAreValidated(params); } + @SuppressWarnings("unchecked") @Test public void vnfcNodeObjects_shouldThrowSvcLogicException_whenNodeParamIsEmpty() { Map params = givenInputParams( @@ -238,7 +247,7 @@ public class ChefAdapterImplVNFCOperationsTest { public void checkMissingParamsAreValidated(Map params) { // GIVEN - String expectedErrorMsg = "Missing Mandatory param(s) Node , NodeList "; + String expectedErrorMsg = "vnfcNodeobjectsMissing Mandatory param(s) Node , NodeList "; // WHEN // THEN assertThatExceptionOfType(SvcLogicException.class) @@ -252,6 +261,7 @@ public class ChefAdapterImplVNFCOperationsTest { .isEqualTo("Error posting request: " + expectedErrorMsg); } + @SuppressWarnings("unchecked") @Test public void vnfcNodeObjects_shouldNotUpdateNodes_andHandleJSONException_whenJSONParamsAreMalformed() { // GIVEN @@ -273,6 +283,7 @@ public class ChefAdapterImplVNFCOperationsTest { .startsWith(expectedErrorMessage); } + @SuppressWarnings("unchecked") @Test public void vnfcPushJob_shouldUpdateSvcContextWithJobId_whenPushJobWasSuccessfullyCreatedWithCallbackUrl() throws SvcLogicException { @@ -296,6 +307,7 @@ public class ChefAdapterImplVNFCOperationsTest { + "someURLForCallback" + "\"}," + "\"capture_output\": true" + "}"; } + @SuppressWarnings("unchecked") @Test public void vnfcPushJob_shouldUpdateSvcContextWithJobId_whenPushJobWasSuccessfullyCreatedWithoutCallbackUrl() throws SvcLogicException { @@ -334,10 +346,11 @@ public class ChefAdapterImplVNFCOperationsTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedResponseMessage); } + @SuppressWarnings("unchecked") @Test public void vnfcPushJob_shouldNotPushJob_andThrowException_whenNodeListParamIsEmpty() { // GIVEN - String expectedErrorMessage = "Error posting request: Missing Mandatory param(s) NodeList "; + String expectedErrorMessage = "Error posting request: vnfcPushJobMissing Mandatory param(s) NodeList "; Map params = givenInputParams(); // WHEN // THEN assertThatExceptionOfType(SvcLogicException.class) @@ -350,10 +363,11 @@ public class ChefAdapterImplVNFCOperationsTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage); } + @SuppressWarnings("unchecked") @Test public void fetchResults_shouldNotFetchResults_andThrowException_whenNodeListParamIsEmpty() { // GIVEN - String expectedErrorMessage = "Error posting request: Missing Mandatory param(s) NodeList "; + String expectedErrorMessage = "Error posting request: fetchResultsMissing Mandatory param(s) NodeList "; Map params = givenInputParams(); // WHEN // THEN assertThatExceptionOfType(SvcLogicException.class) @@ -366,13 +380,14 @@ public class ChefAdapterImplVNFCOperationsTest { assertThat(svcLogicContext.getAttribute(RESULT_MESSAGE_ATTR_KEY)).isEqualTo(expectedErrorMessage); } + @SuppressWarnings("unchecked") @Test public void fetchResults_shouldNotFetchResults_andThrowException_whenPrivateKeyCheckFails() { // GIVEN Map params = givenInputParams( immutableEntry("NodeList", "[\"test1.vnf_b.onap.com\", \"test2.vnf_b.onap.com\"]")); String expectedErrorMessage = - "Error posting request: " + "Error posting request: fetchResults" + CHEF_ADAPTER_ERROR_PREFIX + "Cannot find the private key in the APPC file system, please load the private key to " + CLIENT_PRIVATE_KEY_PATH; @@ -390,6 +405,7 @@ public class ChefAdapterImplVNFCOperationsTest { .isEqualTo(expectedErrorMessage); } + @SuppressWarnings("unchecked") @Test public void fetchResults_shouldUpdateSvcLogicContextWithJsonResponse_fromSuccessfulChefServerCall() throws SvcLogicException { @@ -414,6 +430,7 @@ public class ChefAdapterImplVNFCOperationsTest { .isEqualTo("{\"test1.vnf_b.onap.com\":{\"PushJobOutput\":\"ssh start/running, process 1090\"}}"); } + @SuppressWarnings("unchecked") @Test public void fetchResults_shouldUpdateSvcLogicContextWithFailedMessage_whenReturnedJSONMessageIsMissingAttribute() throws SvcLogicException { @@ -438,6 +455,7 @@ public class ChefAdapterImplVNFCOperationsTest { .isEqualTo("Cannot find PushJobOutput"); } + @SuppressWarnings("unchecked") private Map givenInputParams(Entry... entries) { Builder paramsBuilder = ImmutableMap.builder(); paramsBuilder.put("username", USERNAME) @@ -449,4 +467,4 @@ public class ChefAdapterImplVNFCOperationsTest { } return paramsBuilder.build(); } -} \ No newline at end of file +} -- cgit 1.2.3-korg