From 361511c01e4e51dddb6e3bfe11b6728a76dbbfd0 Mon Sep 17 00:00:00 2001
From: Piotr Borelowski
Date: Tue, 11 Feb 2020 10:00:02 +0100
Subject: Fixed, simplified and tested AuthorizationHeadersProvider (+small
changes in poms)
Ve-Vnfm (SOL002) Adapter project
Issue-ID: SO-2574
Signed-off-by: Piotr Borelowski
Change-Id: I480ac1d5b46aae5a9d4db8249d98c186b59fd12f
---
.../provider/AuthorizationHeadersProvider.java | 20 ++-------
.../adapters/vevnfm/service/SubscriberService.java | 2 +-
.../provider/AuthorizationHeadersProviderTest.java | 47 ++++++++++++++++++++++
3 files changed, 51 insertions(+), 18 deletions(-)
create mode 100644 adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/provider/AuthorizationHeadersProviderTest.java
(limited to 'adapters/mso-ve-vnfm-adapter/src')
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 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));
+ }
+}
--
cgit 1.2.3-korg