diff options
author | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-02-11 10:00:02 +0100 |
---|---|---|
committer | Piotr Borelowski <p.borelowski@partner.samsung.com> | 2020-02-13 15:29:31 +0000 |
commit | 361511c01e4e51dddb6e3bfe11b6728a76dbbfd0 (patch) | |
tree | a6fade70552eece7d8a6df74a104cc8108044cdb /adapters/mso-ve-vnfm-adapter | |
parent | e4f76347e6eac071e5a3ff4666763b68b9075183 (diff) |
Fixed, simplified and tested AuthorizationHeadersProvider
(+small changes in poms)
Ve-Vnfm (SOL002) Adapter project
Issue-ID: SO-2574
Signed-off-by: Piotr Borelowski <p.borelowski@partner.samsung.com>
Change-Id: I480ac1d5b46aae5a9d4db8249d98c186b59fd12f
Diffstat (limited to 'adapters/mso-ve-vnfm-adapter')
4 files changed, 62 insertions, 18 deletions
diff --git a/adapters/mso-ve-vnfm-adapter/pom.xml b/adapters/mso-ve-vnfm-adapter/pom.xml index 3518445b45..4472956eb7 100644 --- a/adapters/mso-ve-vnfm-adapter/pom.xml +++ b/adapters/mso-ve-vnfm-adapter/pom.xml @@ -59,10 +59,21 @@ </dependencies> <build> + <finalName>${project.artifactId}-${project.version}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <mainClass>org.onap.so.adapters.vevnfm.Application</mainClass> + </configuration> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> </plugin> </plugins> </build> diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProvider.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProvider.java index eca5240cb5..251e0c426b 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProvider.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProvider.java @@ -20,29 +20,15 @@ package org.onap.so.adapters.vevnfm.provider; -import java.util.List; -import org.apache.logging.log4j.util.Strings; import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.springframework.http.HttpHeaders; public class AuthorizationHeadersProvider extends BasicHttpHeadersProvider { - private List<String> previousAuthorization; - public void addAuthorization(final String authorization) { - final HttpHeaders headers = getHttpHeaders(); - previousAuthorization = headers.get(AUTHORIZATION_HEADER); - headers.set(AUTHORIZATION_HEADER, authorization); - } - - public void resetPrevious() { - if (!isPreviousAuthorizationBlank()) { - getHttpHeaders().addAll(AUTHORIZATION_HEADER, previousAuthorization); - } + getHttpHeaders().set(AUTHORIZATION_HEADER, authorization); } - private boolean isPreviousAuthorizationBlank() { - return previousAuthorization == null || previousAuthorization.isEmpty() - || Strings.isBlank(previousAuthorization.get(0)); + public void removeAuthorization() { + getHttpHeaders().remove(AUTHORIZATION_HEADER); } } diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java index 0e77ce4073..eefd9ba93b 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/SubscriberService.java @@ -68,7 +68,7 @@ public class SubscriberService { final LccnSubscriptionRequest request = createRequest(); return sender.send(info, request); } finally { - headersProvider.resetPrevious(); + headersProvider.removeAuthorization(); } } diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java new file mode 100644 index 0000000000..64503ddfc2 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * SO + * ================================================================================ + * Copyright (C) 2020 Samsung. 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.so.adapters.vevnfm.provider; + +import static org.junit.Assert.*; +import static org.onap.so.configuration.rest.BasicHttpHeadersProvider.AUTHORIZATION_HEADER; +import org.junit.Test; +import org.springframework.http.HttpHeaders; + +public class AuthorizationHeadersProviderTest { + + private static final String AUTHORIZATION_EXAMPLE = "authorization"; + + private final AuthorizationHeadersProvider provider = new AuthorizationHeadersProvider(); + + @Test + public void testSuccessValidAuthorizationAndRemoval() { + final HttpHeaders headers = provider.getHttpHeaders(); + final int size = headers.size(); + + provider.addAuthorization(AUTHORIZATION_EXAMPLE); + assertEquals(size + 1, headers.size()); + assertTrue(headers.containsKey(AUTHORIZATION_HEADER)); + + provider.removeAuthorization(); + assertEquals(size, headers.size()); + assertFalse(headers.containsKey(AUTHORIZATION_HEADER)); + } +} |