aboutsummaryrefslogtreecommitdiffstats
path: root/standardization/api-custom-header/src/test
diff options
context:
space:
mode:
authorluna <nil@vmware.com>2019-02-25 11:13:26 +0800
committerni lu <nil@vmware.com>2019-03-15 02:53:45 +0000
commitdc478d6c91264f483c6dfb79cf1ff80a12eb1be2 (patch)
tree5f06e63474295992d4ec7cfc026e1a763ce0352a /standardization/api-custom-header/src/test
parentc852448b1e6ca5e28e0b0dab26c2af3d5af3f390 (diff)
api custom header
Issue-ID: DCAEGEN2-897 Change-Id: Iaff1a8f71a0ab1be997fbea654d6032eee91009b Signed-off-by: luna <nil@vmware.com>
Diffstat (limited to 'standardization/api-custom-header/src/test')
-rw-r--r--standardization/api-custom-header/src/test/java/org/onap/dcaegen2/services/sdk/standardization/header/CustomHeaderUtilsTest.java75
-rw-r--r--standardization/api-custom-header/src/test/resources/api_version_config.json7
2 files changed, 82 insertions, 0 deletions
diff --git a/standardization/api-custom-header/src/test/java/org/onap/dcaegen2/services/sdk/standardization/header/CustomHeaderUtilsTest.java b/standardization/api-custom-header/src/test/java/org/onap/dcaegen2/services/sdk/standardization/header/CustomHeaderUtilsTest.java
new file mode 100644
index 00000000..73fcec1a
--- /dev/null
+++ b/standardization/api-custom-header/src/test/java/org/onap/dcaegen2/services/sdk/standardization/header/CustomHeaderUtilsTest.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.services.sdk
+ * ================================================================================
+ * Copyright (C) 2019 vmware. 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.dcaegen2.services.sdk.standardization.header;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class CustomHeaderUtilsTest {
+ private String filePath = getClass().getClassLoader().getResource("api_version_config.json").getPath();
+
+ /**
+ * not send minor version when client requests
+ */
+ @Test
+ void testRequestNoMinorVer() {
+ CustomHeaderUtils util = getHeaderUtil(null);
+ util.isOkCustomHeaders();
+
+ Map<String, String> rspHeaders = util.getRspCustomHeader();
+ Assertions.assertTrue("3".equals(rspHeaders.get("X-MinorVersion")));
+ }
+
+ /**
+ * minor version not exist which client request
+ */
+ @Test
+ void testRequestWithWrongMinorVer() {
+ CustomHeaderUtils util = getHeaderUtil("2");
+
+ // check request header
+ util.isOkCustomHeaders();
+
+ Assertions.assertFalse(util.isOkCustomHeaders());
+
+ Map<String, String> rspHeaders = util.getRspCustomHeader();
+ Assertions.assertTrue("4".equals(rspHeaders.get("X-MinorVersion")));
+ }
+
+ /**
+ * minor version exists which client request
+ */
+ @Test
+ void testRequestWithMinorVerOk() {
+ CustomHeaderUtils util = getHeaderUtil("3");
+ Assertions.assertFalse(!util.isOkCustomHeaders());
+
+ Map<String, String> rspHeaders = util.getRspCustomHeader();
+ Assertions.assertTrue("3".equals(rspHeaders.get("X-MinorVersion")));
+ }
+
+ private CustomHeaderUtils getHeaderUtil(String minorVer) {
+ Map<String, String> reqHeaderMap = new HashMap<String, String>();
+ reqHeaderMap.put("X-MinorVersion", minorVer);
+ return new CustomHeaderUtils("5", reqHeaderMap, filePath, "eventListener");
+ }
+} \ No newline at end of file
diff --git a/standardization/api-custom-header/src/test/resources/api_version_config.json b/standardization/api-custom-header/src/test/resources/api_version_config.json
new file mode 100644
index 00000000..81468ac4
--- /dev/null
+++ b/standardization/api-custom-header/src/test/resources/api_version_config.json
@@ -0,0 +1,7 @@
+{
+ "apiVersion":
+ {
+ "eventListener": ["4.7.2","5.3.2","5.4.1","7.0.1"],
+ "xxxxxx": ["1.0.2","1.1.2","2.0.1"]
+ }
+} \ No newline at end of file