summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-02-12 20:55:54 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-02-23 11:44:45 +0100
commitb17042b955489d8a023d09abad5436ff9b900dc3 (patch)
tree1e4392ac04a2fb1ed8d17075d504cf6594acaf16 /nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
parentd4982f7b1777e9cdae9a4cc7d0d104263889ac69 (diff)
Updating Nokia driver
Change-Id: I950afe6acbdb359cd67a448024f006a45e8fc293 Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java')
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
new file mode 100644
index 00000000..eeb79be8
--- /dev/null
+++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestSwaggerDefinitionConsistency.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016-2017, Nokia Corporation
+ *
+ * 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.
+ */
+
+package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Sets;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil.loadFile;
+
+public class TestSwaggerDefinitionConsistency extends TestBase {
+
+ public static final HashSet<Class<?>> CLASSES = Sets.newHashSet(LcmApi.class, LcnApi.class, SwaggerApi.class, ConverterApi.class);
+
+ @Test
+ public void test() throws Exception {
+ JsonObject root = new JsonParser().parse(new String(loadFile("self.swagger.json"))).getAsJsonObject();
+ String basePath = root.get("basePath").getAsString();
+ HashMultimap<String, RequestMethod> expectedPaths = HashMultimap.create();
+ for (String pathName : child(root, "paths").keySet()) {
+ JsonObject path = child(child(root, "paths"), pathName);
+ for (String method : path.keySet()) {
+ locate(basePath + pathName);
+ expectedPaths.put(basePath + pathName, RequestMethod.valueOf(method.toUpperCase()));
+ }
+ }
+
+ for (Class<?> clazz : CLASSES) {
+ RequestMapping currentBasePath = clazz.getAnnotation(RequestMapping.class);
+ for (Method method : clazz.getMethods()) {
+ RequestMapping methodMapping = method.getAnnotation(RequestMapping.class);
+ if (methodMapping != null) {
+ String fPath = currentBasePath.value()[0] + methodMapping.value()[0];
+ RequestMethod restMethod = methodMapping.method()[0];
+ Set<RequestMethod> currentMethods = expectedPaths.get(fPath);
+ if (!currentMethods.contains(restMethod)) {
+ TestCase.fail("Not documented REST API" + fPath + " " + restMethod + " current " + currentMethods);
+ }
+ }
+ }
+ }
+ }
+
+ private void locate(String path) {
+ for (Class<?> clazz : CLASSES) {
+ RequestMapping basePath = clazz.getAnnotation(RequestMapping.class);
+ for (Method method : clazz.getMethods()) {
+ RequestMapping methodMapping = method.getAnnotation(RequestMapping.class);
+ if (methodMapping != null && path.equals(basePath.value()[0] + methodMapping.value()[0])) {
+ return;
+ }
+ }
+ }
+ throw new NoSuchElementException(path);
+ }
+}