Correct object provider for jersey 96/103896/1
authorBenjamin, Max <max.benjamin@att.com>
Wed, 18 Mar 2020 17:05:11 +0000 (13:05 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Wed, 18 Mar 2020 17:05:12 +0000 (13:05 -0400)
Initial setup of aai test for unknown property error
updated mapper provider in AAI Client
added back support for cxf clients
updated aai-schema version to a release version
formatted file that was missed
moved provider register calls together

Issue-ID: SO-2750
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I0bf694f39bbab9bcbabd85bb30fb9dbf23f00520

common/src/main/java/org/onap/so/client/RestClient.java
common/src/main/java/org/onap/so/client/aai/AAIVersion.java
common/src/main/java/org/onap/so/client/policy/CommonObjectMapperProvider.java
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/AAIDeserializeTest.java [new file with mode: 0644]
mso-api-handlers/mso-api-handler-infra/src/test/resources/MsoRequestTest/AAI.json [new file with mode: 0644]
mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/aai/UnknownProperty.json [new file with mode: 0644]

index 077ba24..30389de 100644 (file)
@@ -188,8 +188,7 @@ public abstract class RestClient {
             client.register(new PayloadLoggingClientFilter(this.getMaxPayloadSize()));
         }
         CommonObjectMapperProvider provider = this.getCommonObjectMapperProvider();
-        client.register(new JacksonJsonProvider(provider.getMapper()));
-
+        client.register(provider).register(new JacksonJsonProvider(provider.getMapper()));
         metricLogClientFilter = new SOMetricLogClientFilter();
         mdcSetup.setTargetEntity(getTargetEntity());
         client.register(metricLogClientFilter);
index 4f06b78..4288788 100644 (file)
@@ -23,7 +23,16 @@ package org.onap.so.client.aai;
 import org.onap.so.client.graphinventory.GraphInventoryVersion;
 
 public enum AAIVersion implements GraphInventoryVersion {
-    V13("v13"), V14("v14"), V15("v15"), V16("v16"), V17("v17"), V18("v18"), V19("v19");
+    V10("V10"),
+    V11("V11"),
+    V12("V12"),
+    V13("v13"),
+    V14("v14"),
+    V15("v15"),
+    V16("v16"),
+    V17("v17"),
+    V18("v18"),
+    V19("v19");
 
     public static final AAIVersion LATEST = AAIVersion.values()[AAIVersion.values().length - 1];
     private final String value;
index c55370f..334e0f7 100644 (file)
 
 package org.onap.so.client.policy;
 
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.MapperFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 
-public class CommonObjectMapperProvider {
+@Provider
+public class CommonObjectMapperProvider implements ContextResolver<ObjectMapper> {
 
     protected ObjectMapper mapper;
 
@@ -43,4 +46,10 @@ public class CommonObjectMapperProvider {
     public ObjectMapper getMapper() {
         return mapper;
     }
+
+    @Override
+    public ObjectMapper getContext(Class<?> type) {
+
+        return mapper;
+    }
 }
index 0afc272..168f82b 100644 (file)
@@ -23,9 +23,7 @@ package org.onap.so.apihandlerinfra;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import javax.annotation.PostConstruct;
-import javax.servlet.ServletConfig;
 import javax.ws.rs.ApplicationPath;
-import javax.ws.rs.core.Context;
 import org.glassfish.jersey.server.ResourceConfig;
 import org.glassfish.jersey.servlet.ServletProperties;
 import org.onap.logging.filter.base.Constants;
@@ -96,6 +94,7 @@ public class JerseyConfiguration extends ResourceConfig {
         // this registration seems to be needed to get predictable
         // execution behavior for the above JSON Exception Mappers
         register(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.class);
+
         register(ModelDistributionRequest.class);
         property(ServletProperties.FILTER_FORWARD_ON_404, true);
 
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/AAIDeserializeTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/AAIDeserializeTest.java
new file mode 100644 (file)
index 0000000..e6409fa
--- /dev/null
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.apihandlerinfra;
+
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static org.junit.Assert.assertEquals;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import javax.ws.rs.core.MediaType;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.domain.yang.Tenant;
+import org.onap.so.client.aai.AAIVersion;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpHeaders;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class AAIDeserializeTest extends BaseTest {
+
+    private final ObjectMapper mapper = new ObjectMapper();
+
+    @Autowired
+    private MsoRequest msoReq;
+
+    @Value("${wiremock.server.port}")
+    private String wiremockPort;
+
+    @Before
+    public void beforeClass() {
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+    }
+
+    public String inputStream(String JsonInput) throws IOException {
+        JsonInput = "src/test/resources/MsoRequestTest" + JsonInput;
+        return new String(Files.readAllBytes(Paths.get(JsonInput)));
+    }
+
+    @Test
+    public void doNotFailOnUnknownPropertiesTest() throws JsonParseException, JsonMappingException, IOException {
+        wireMockServer.stubFor(get(("/aai/" + AAIVersion.LATEST
+                + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/mdt1/tenants/tenant/88a6ca3ee0394ade9403f075db23167e"))
+                        .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+                                .withBodyFile("aai/UnknownProperty.json")
+                                .withStatus(org.apache.http.HttpStatus.SC_OK)));
+        ServiceInstancesRequest sir = mapper.readValue(inputStream("/AAI.json"), ServiceInstancesRequest.class);
+        String tenantId = "88a6ca3ee0394ade9403f075db23167e";
+        String tenantNameFromAAI = "testTenantName";
+        String cloudOwner = "cloudOwner";
+        sir.getRequestDetails().getCloudConfiguration().setCloudOwner(cloudOwner);
+        Tenant tenant = new Tenant();
+        tenant.setTenantId(tenantId);
+        tenant.setTenantName(tenantNameFromAAI);
+        String tenantName = msoReq.getTenantNameFromAAI(sir);
+        assertEquals(tenantNameFromAAI, tenantName);
+    }
+
+}
+
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/MsoRequestTest/AAI.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/MsoRequestTest/AAI.json
new file mode 100644 (file)
index 0000000..455d73a
--- /dev/null
@@ -0,0 +1,132 @@
+{ 
+  "requestDetails": { 
+    "modelInfo": { 
+      "modelType": "service", 
+      "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", 
+      "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", 
+      "modelName": "model-name", 
+      "modelVersion": "10" 
+    }, 
+    "cloudConfiguration": { 
+      "lcpCloudRegionId": "mdt1", 
+      "tenantId": "88a6ca3ee0394ade9403f075db23167e" 
+    }, 
+    "owningEntity": { 
+      "owningEntityId": "038d99af-0427-42c2-9d15-971b99b9b489", 
+      "owningEntityName": "PACKET CORE" 
+    }, 
+    "project": { 
+      "projectName": "{some project name}" 
+    }, 
+    "subscriberInfo": { 
+      "globalSubscriberId": "{some subscriber id}" 
+    }, 
+    "requestInfo": { 
+      "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", 
+      "source": "VID", 
+      "suppressRollback": true, 
+      "requestorId": "xxxxxx" 
+    }, 
+    "requestParameters": { 
+      "subscriptionServiceType": "type", 
+      "aLaCarte": false, 
+      "userParams": [ 
+        { 
+          "service": { 
+            "modelInfo": { 
+              "modelType": "service", 
+          "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", 
+          "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", 
+          "modelName": "model-name", 
+          "modelVersion": "10" 
+            }, 
+            "instanceParams": [], 
+            "resources": { 
+              "vnfs": [ 
+                { 
+                  "modelInfo": { 
+                    "modelCustomizationName": "model-name 0", 
+                    "modelName": "model-name", 
+                    "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a",
+                    "modelCustomizationId": "ab153b6e-c364-44c0-bef6-1f2982117f04" 
+                  }, 
+          "cloudConfiguration": {
+              "lcpCloudRegionId": "mdt1",
+              "tenantId": "88a6ca3ee0394ade9403f075db23167e"
+              },
+          "platform": { 
+            "platformName": "someValue" 
+          }, 
+          "lineOfBusiness": { 
+            "lineOfBusinessName": "someValue" 
+          }, 
+          "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",  
+                  "instanceParams": [ 
+          { 
+           "instanceName": "someVnfInstanceName"  
+                    } 
+                  ], 
+                  "vfModules": [ 
+                    { 
+                      "modelInfo": { 
+                        "modelName": "name._base__BV..module-0",
+                        "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", 
+                        "modelCustomizationId": "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f" 
+                      }, 
+                      "instanceParams": [ 
+                        { 
+                          "vmx_int_net_len": "24",
+                          "asn": "someValue" 
+                        } 
+                      ] 
+                    }, 
+                    { 
+                      "modelInfo": { 
+                        "modelName": "name._vRE_BV..module-1",
+                        "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", 
+                        "modelCustomizationId": "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", 
+                        "modelType": "vfModule" 
+                      }, 
+                      "instanceParams": [ 
+                        { 
+                          "availability_zone_0": "mtpocdv-kvm-az01", 
+                          "vre_a_volume_size_0": "100" 
+                        } 
+                      ] 
+                    }, 
+                    { 
+                      "modelInfo": { 
+                        "modelName": "name._vRE_BV..module-1",
+                        "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", 
+                        "modelCustomizationId": "72d9d1cd-f46d-447a-abdb-451d6fb05fa8" 
+                      }, 
+                      "instanceParams": [ 
+                        { 
+                          "availability_zone_0": "mtpocdv-kvm-az01", 
+                          "vre_a_volume_size_0": "50" 
+                        } 
+                      ] 
+                    }, 
+                    { 
+                      "modelInfo": { 
+                        "modelName": "name.BV..module-2",
+                        "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", 
+                        "modelCustomizationId": "da4d4327-fb7d-4311-ac7a-be7ba60cf969" 
+                      }, 
+                      "instanceParams": [ 
+                        { 
+                          "availability_zone_0": "mtpocdv-kvm-az01", 
+                          "vmx_vpfe_int_ip_0": "192.168.0.16" 
+                        } 
+                      ] 
+                    } 
+                  ] 
+                } 
+              ] 
+            } 
+          } 
+        } 
+      ] 
+    } 
+  } 
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/aai/UnknownProperty.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/aai/UnknownProperty.json
new file mode 100644 (file)
index 0000000..e606f8a
--- /dev/null
@@ -0,0 +1 @@
+{"tenant-id":"78491aac74be4fab9873db114774b475","tenant-name":"testTenantName", "test":"test", "parent-id": "25239", "tenant-context":"Development","resource-version":"1581690782612"}
\ No newline at end of file