From dc478d6c91264f483c6dfb79cf1ff80a12eb1be2 Mon Sep 17 00:00:00 2001 From: luna Date: Mon, 25 Feb 2019 11:13:26 +0800 Subject: api custom header Issue-ID: DCAEGEN2-897 Change-Id: Iaff1a8f71a0ab1be997fbea654d6032eee91009b Signed-off-by: luna --- .../header/CustomHeaderUtilsTest.java | 75 ++++++++++++++++++++++ .../src/test/resources/api_version_config.json | 7 ++ 2 files changed, 82 insertions(+) create mode 100644 standardization/api-custom-header/src/test/java/org/onap/dcaegen2/services/sdk/standardization/header/CustomHeaderUtilsTest.java create mode 100644 standardization/api-custom-header/src/test/resources/api_version_config.json (limited to 'standardization/api-custom-header/src/test') 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 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 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 rspHeaders = util.getRspCustomHeader(); + Assertions.assertTrue("3".equals(rspHeaders.get("X-MinorVersion"))); + } + + private CustomHeaderUtils getHeaderUtil(String minorVer) { + Map reqHeaderMap = new HashMap(); + 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 -- cgit 1.2.3-korg