diff options
4 files changed, 42 insertions, 21 deletions
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 818d51694..1815266f3 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 @@ -31,11 +31,10 @@ public class ChefApiClientFactory { private ChefApiHeaderFactory chefApiHeaderFactory = new ChefApiHeaderFactory(); public ChefApiClient create(String endPoint, String organizations, String userId, String pemPath) { - return new ChefApiClientImpl(httpClient, - chefApiHeaderFactory, + return new ChefApiClientImpl( + httpClient, endPoint, - organizations, - userId, - pemPath); + (methodName, requestPath, body) -> chefApiHeaderFactory + .create(methodName, requestPath, body, userId, organizations, pemPath)); } } 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 b26f69a9e..8edc2b566 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 @@ -38,20 +38,13 @@ import org.onap.appc.adapter.chef.chefclient.impl.ChefRequestBuilder.OngoingRequ public class ChefApiClientImpl implements ChefApiClient { private final HttpClient httpClient; - private final ChefApiHeaderFactory chefApiHeaderFactory; - private String endpoint; - private String userId; - private String pemPath; - private String organizations; + private final String endpoint; + private final HttpHeaderFactory httpHeaderFactory; - public ChefApiClientImpl(HttpClient httpClient, ChefApiHeaderFactory chefApiHeaderFactory, - String endpoint, String organizations, String userId, String pemPath) { + public ChefApiClientImpl(HttpClient httpClient, String endpoint, HttpHeaderFactory httpHeaderFactory) { this.httpClient = httpClient; - this.chefApiHeaderFactory = chefApiHeaderFactory; this.endpoint = endpoint; - this.organizations = organizations; - this.userId = userId; - this.pemPath = pemPath; + this.httpHeaderFactory = httpHeaderFactory; } @Override @@ -59,7 +52,7 @@ public class ChefApiClientImpl implements ChefApiClient { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpGet() .withPath(path) - .withHeaders(chefApiHeaderFactory.create("GET", path, "", userId, organizations, pemPath)); + .withHeaders(httpHeaderFactory.create("GET", path, "")); return execute(requestBuilder); } @@ -68,7 +61,7 @@ public class ChefApiClientImpl implements ChefApiClient { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpDelete() .withPath(path) - .withHeaders(chefApiHeaderFactory.create("DELETE", path, "", userId, organizations, pemPath)); + .withHeaders(httpHeaderFactory.create("DELETE", path, "")); return execute(requestBuilder); } @@ -77,7 +70,7 @@ public class ChefApiClientImpl implements ChefApiClient { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpPost(body) .withPath(path) - .withHeaders(chefApiHeaderFactory.create("POST", path, body, userId, organizations, pemPath)); + .withHeaders(httpHeaderFactory.create("POST", path, body)); return execute(requestBuilder); } @@ -86,7 +79,7 @@ public class ChefApiClientImpl implements ChefApiClient { OngoingRequestBuilder requestBuilder = ChefRequestBuilder.newRequestTo(endpoint) .httpPut(body) .withPath(path) - .withHeaders(chefApiHeaderFactory.create("PUT", path, body, userId, organizations, pemPath)); + .withHeaders(httpHeaderFactory.create("PUT", path, body)); return execute(requestBuilder); } @@ -104,3 +97,4 @@ public class ChefApiClientImpl implements ChefApiClient { } } } + diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/HttpHeaderFactory.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/HttpHeaderFactory.java new file mode 100644 index 000000000..4a9d6c81e --- /dev/null +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/impl/HttpHeaderFactory.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 Nokia. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.appc.adapter.chef.chefclient.impl; + +import com.google.common.collect.ImmutableMap; + +@FunctionalInterface +public interface HttpHeaderFactory { + + ImmutableMap<String, String> create(String methodName, String requestPath, String body); +} 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 21e607de7..ed39efb1b 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 @@ -55,6 +55,7 @@ public class ChefApiClientImplTest { private static final String USER_ID = "testUser"; private static final String REQUEST_PATH = "/test/path"; private static final String BODY = "SOME BODY STRING"; + private static final String PEM_FILEPATH = "path/to/pemFile"; private static final ImmutableMap<String, String> HEADERS = ImmutableMap.<String, String>builder() .put("Content-type", "application/json") .put("Accept", "application/json") @@ -71,7 +72,6 @@ public class ChefApiClientImplTest { @InjectMocks private ChefApiClientFactory chefApiClientFactory; - private static final String PEM_FILEPATH = "path/to/pemFile"; private ChefApiClient chefApiClient; @Before |