diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-11-10 09:21:49 +0000 |
---|---|---|
committer | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2022-11-10 09:31:12 +0000 |
commit | 5eb0e49534114edf8a76fef5b2a8e50c7bdaa812 (patch) | |
tree | b69c0e5d60fc48dd0c8084dfffb178b89566b83f /aai-core/src/test/java | |
parent | 8b504f6db32630ae4b6774efabc87ed76a950053 (diff) |
Replace deprecated methods in aai-common
Issue-ID: AAI-3589
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: I9e32b879ee0d143a6b66e06d425bed7412139e58
Diffstat (limited to 'aai-core/src/test/java')
8 files changed, 77 insertions, 44 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java index 9d406eb2..07764ecc 100644 --- a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java +++ b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java @@ -20,14 +20,26 @@ package org.onap.aai; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; import java.io.UnsupportedEncodingException; import java.net.URI; -import java.util.*; - -import javax.ws.rs.core.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; import org.javatuples.Pair; import org.mockito.Mockito; @@ -139,7 +151,7 @@ public class HttpTestUtil extends RESTAPI { when(uriInfo.getQueryParameters()).thenReturn(queryParameters); when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); - doReturn(null).when(queryParameters).remove(anyObject()); + doReturn(null).when(queryParameters).remove(any()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); try { diff --git a/aai-core/src/test/java/org/onap/aai/PayloadUtil.java b/aai-core/src/test/java/org/onap/aai/PayloadUtil.java index 7ee6c39c..d9448989 100644 --- a/aai-core/src/test/java/org/onap/aai/PayloadUtil.java +++ b/aai-core/src/test/java/org/onap/aai/PayloadUtil.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -44,7 +45,7 @@ public class PayloadUtil { String message = String.format("Unable to find the %s in src/test/resources", fileName); assertNotNull(message, inputStream); - String resource = IOUtils.toString(inputStream); + String resource = IOUtils.toString(inputStream, Charset.defaultCharset()); inputStream.close(); return resource; @@ -58,7 +59,7 @@ public class PayloadUtil { String message = String.format("Unable to find the %s in src/test/resources", fileName); assertNotNull(message, inputStream); - String resource = IOUtils.toString(inputStream); + String resource = IOUtils.toString(inputStream, Charset.defaultCharset()); inputStream.close(); return resource; @@ -77,7 +78,7 @@ public class PayloadUtil { if (cache.containsKey(fileName)) { resource = cache.get(fileName); } else { - resource = IOUtils.toString(inputStream); + resource = IOUtils.toString(inputStream, Charset.defaultCharset()); cache.put(fileName, resource); } diff --git a/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java b/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java index cafca63f..399ef7e0 100644 --- a/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java +++ b/aai-core/src/test/java/org/onap/aai/rest/NotificationDmaapEventTest.java @@ -20,7 +20,9 @@ package org.onap.aai.rest; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; @@ -29,7 +31,11 @@ import com.google.gson.JsonParser; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import javax.ws.rs.core.Response; @@ -848,11 +854,11 @@ public class NotificationDmaapEventTest extends AAISetup { UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions)); HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle); - JsonObject paylaods = new JsonParser().parse(PayloadUtil.getResourcePayload( - "customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json")) - .getAsJsonObject(); - String gvnfPaylaod = paylaods.get("generic-vnf").toString(); - String custPaylaod = paylaods.get("customer").toString(); + String json = PayloadUtil.getResourcePayload( + "customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json"); + JsonObject payloads = JsonParser.parseString(json).getAsJsonObject(); + String gvnfPaylaod = payloads.get("generic-vnf").toString(); + String custPaylaod = payloads.get("customer").toString(); String gvnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf"; String custUri = "/aai/v14/business/customers/customer/cust"; String vlanUri = "/aai/v14/network/generic-vnfs/generic-vnf/gvnf/l-interfaces/l-interface/lint/vlans/vlan/vlan"; @@ -909,10 +915,10 @@ public class NotificationDmaapEventTest extends AAISetup { UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions)); HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle, notification, AAIProperties.MAXIMUM_DEPTH); - JsonObject paylaods = new JsonParser() - .parse(PayloadUtil.getResourcePayload("complex_pserver_with_relation.json")).getAsJsonObject(); - String complexPaylaod = paylaods.get("complex").toString(); - String pserverPaylaod = paylaods.get("pserver").toString(); + JsonObject payloads = JsonParser + .parseString(PayloadUtil.getResourcePayload("complex_pserver_with_relation.json")).getAsJsonObject(); + String complexPaylaod = payloads.get("complex").toString(); + String pserverPaylaod = payloads.get("pserver").toString(); String complexUri = "/aai/v14/cloud-infrastructure/complexes/complex/complex-1"; String pserverUri = "/aai/v14/cloud-infrastructure/pservers/pserver/pserver-1"; @@ -955,11 +961,11 @@ public class NotificationDmaapEventTest extends AAISetup { UEBNotification notification = Mockito.spy(new UEBNotification(ModelType.MOXY, loaderFactory, schemaVersions)); HttpTestUtil httpTestUtil = new HttpTestUtil(queryStyle); - JsonObject paylaods = new JsonParser().parse(PayloadUtil.getResourcePayload( - "customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json")) - .getAsJsonObject(); - String gvnfPaylaod = paylaods.get("generic-vnf").toString(); - String custPaylaod = paylaods.get("customer").toString(); + String json = PayloadUtil.getResourcePayload( + "customer_with_children_and_generic-vnf_with_children_and_edge_between_service-instance_vlan.json"); + JsonObject payloads = JsonParser.parseString(json).getAsJsonObject(); + String gvnfPayload = payloads.get("generic-vnf").toString(); + String custPayload = payloads.get("customer").toString(); String custUri = "/aai/v14/business/customers/customer/cust"; String ssUri = custUri + "/service-subscriptions/service-subscription/ss"; String siUri = ssUri + "/service-instances/service-instance/si"; @@ -970,7 +976,7 @@ public class NotificationDmaapEventTest extends AAISetup { // Setup generic vnf Response response = httpTestUtil.doGet(gvnfUri); assertEquals("Expecting the generic-vnf to be not found", 404, response.getStatus()); - response = httpTestUtil.doPut(gvnfUri, gvnfPaylaod); + response = httpTestUtil.doPut(gvnfUri, gvnfPayload); assertEquals("Expecting the generic-vnf to be created", 201, response.getStatus()); response = httpTestUtil.doGet(gvnfUri, "all"); assertEquals("Expecting the generic-vnf to be found", 200, response.getStatus()); @@ -981,7 +987,7 @@ public class NotificationDmaapEventTest extends AAISetup { // Setup customer with service instance relation to vlan response = httpTestUtil.doGet(custUri); assertEquals("Expecting the customer to be not found", 404, response.getStatus()); - response = httpTestUtil.doPut(custUri, custPaylaod); + response = httpTestUtil.doPut(custUri, custPayload); assertEquals("Expecting the customer to be created", 201, response.getStatus()); response = httpTestUtil.doGet(custUri, "all"); assertEquals("Expecting the customer to be found", 200, response.getStatus()); diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java index 1462485d..2499defc 100644 --- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java +++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java @@ -24,7 +24,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; @@ -33,9 +33,21 @@ import com.google.gson.JsonParser; import java.io.UnsupportedEncodingException; import java.net.URI; -import java.util.*; - -import javax.ws.rs.core.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; import org.javatuples.Pair; import org.json.JSONArray; @@ -127,7 +139,7 @@ public class HttpEntryTest extends AAISetup { when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters); // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable - Mockito.doReturn(null).when(queryParameters).remove(anyObject()); + Mockito.doReturn(null).when(queryParameters).remove(any()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); } @@ -276,7 +288,7 @@ public class HttpEntryTest extends AAISetup { Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content); dbEngine.commit(); String msg = response.getEntity().toString(); - JsonObject jsonObj = new JsonParser().parse(msg).getAsJsonObject(); + JsonObject jsonObj = JsonParser.parseString(msg).getAsJsonObject(); String resourceVersion = ""; if (jsonObj.isJsonObject()) { resourceVersion = jsonObj.get("resource-version").getAsString(); @@ -298,7 +310,7 @@ public class HttpEntryTest extends AAISetup { Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content); dbEngine.commit(); String msg = response.getEntity().toString(); - JsonObject jsonObj = new JsonParser().parse(msg).getAsJsonObject(); + JsonObject jsonObj = JsonParser.parseString(msg).getAsJsonObject(); String resourceVersion = ""; if (jsonObj.isJsonObject()) { resourceVersion = jsonObj.get("resource-version").getAsString(); diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/ImpliedDeleteUnitTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/ImpliedDeleteUnitTest.java index 44f89746..27f52d1b 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/db/ImpliedDeleteUnitTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/db/ImpliedDeleteUnitTest.java @@ -198,7 +198,7 @@ public class ImpliedDeleteUnitTest { Mockito.when(mockQueryEngine.findDeletable(Mockito.anyList())).thenReturn(vertices); - Mockito.when(mockSerializer.getLatestVersionView(Mockito.anyObject())).thenReturn(mockIntrospector); + Mockito.when(mockSerializer.getLatestVersionView(Mockito.any())).thenReturn(mockIntrospector); Mockito.when(mockIntrospector.marshal(false)).thenReturn("{\"volume-id\":\"volume-1\"}") .thenReturn("{\"volume-id\":\"volume-2\"}").thenReturn("{\"volume-id\":\"volume-3\"}") @@ -284,7 +284,7 @@ public class ImpliedDeleteUnitTest { Mockito.when(mockQueryEngine.findDeletable(Mockito.anyList())).thenReturn(vertices); - Mockito.when(mockSerializer.getLatestVersionView(Mockito.anyObject())) + Mockito.when(mockSerializer.getLatestVersionView(Mockito.any())) .thenThrow(new RuntimeException("Unable to find node")); impliedDelete.execute(vserver.id(), "SDNC", "vserver", vertices); diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java index 1bfdf9c4..09a1d1b4 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java @@ -22,7 +22,9 @@ package org.onap.aai.serialization.queryformats; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -75,16 +77,16 @@ public class MultiFormatTest extends AAISetup { private Tree<?> resultTree; private Path resultPath; private SchemaVersion version; - private JsonObject expectedTreeIdFormat = new JsonParser().parse( + private JsonObject expectedTreeIdFormat = JsonParser.parseString( "{\"nodes\":[{\"resource-type\":\"generic-vnf\",\"nodes\":[{\"resource-type\":\"vserver\",\"nodes\":[{\"resource-type\":\"pserver\"}]},{\"resource-type\":\"pserver\",\"nodes\":[{\"resource-type\":\"complex\"}]}]}]}") .getAsJsonObject(); - private JsonObject expectedPathIdFormat = new JsonParser().parse( + private JsonObject expectedPathIdFormat = JsonParser.parseString( "{\"path\":[{\"resource-type\":\"generic-vnf\"},{\"resource-type\":\"vserver\"},{\"resource-type\":\"pserver\"},{\"resource-type\":\"complex\"}]}") .getAsJsonObject(); - private JsonObject expectedAsTreeWithResourceFormat = new JsonParser().parse( + private JsonObject expectedAsTreeWithResourceFormat = JsonParser.parseString( "{\"results\":[{\"generic-vnf\":{\"vnf-id\":\"vnf-id-1\",\"vnf-name\":\"vnf-name-1\",\"related-nodes\":[{\"vserver\":{\"vserver-id\":\"vserver-id-1\",\"vserver-name\":\"vserver-name-1\",\"related-nodes\":[{\"pserver\":{\"hostname\":\"hostname-1\"}}]}},{\"pserver\":{\"hostname\":\"hostname-2\",\"related-nodes\":[{\"complex\":{\"physical-location-id\":\"physical-location-id-2\",\"country\":\"US\"}}]}}]}}]}") .getAsJsonObject(); - private JsonObject expectedAsTreeWithSimpleFormat = new JsonParser().parse( + private JsonObject expectedAsTreeWithSimpleFormat = JsonParser.parseString( "{\"results\":[{\"id\":\"0\",\"node-type\":\"generic-vnf\",\"url\":null,\"properties\":{\"vnf-id\":\"vnf-id-1\",\"vnf-name\":\"vnf-name-1\"},\"related-to\":[{\"id\":\"1\",\"relationship-label\":\"tosca.relationships.HostedOn\",\"node-type\":\"vserver\",\"url\":null},{\"id\":\"5\",\"relationship-label\":\"tosca.relationships.HostedOn\",\"node-type\":\"pserver\",\"url\":null}],\"related-nodes\":[{\"id\":\"1\",\"node-type\":\"vserver\",\"url\":null,\"properties\":{\"vserver-id\":\"vserver-id-1\",\"vserver-name\":\"vserver-name-1\"},\"related-to\":[{\"id\":\"0\",\"relationship-label\":\"tosca.relationships.HostedOn\",\"node-type\":\"generic-vnf\",\"url\":null},{\"id\":\"2\",\"relationship-label\":\"tosca.relationships.HostedOn\",\"node-type\":\"pserver\",\"url\":null}],\"related-nodes\":[{\"id\":\"2\",\"node-type\":\"pserver\",\"url\":null,\"properties\":{\"hostname\":\"hostname-1\"},\"related-to\":[{\"id\":\"1\",\"relationship-label\":\"tosca.relationships.HostedOn\",\"node-type\":\"vserver\",\"url\":null},{\"id\":\"3\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\",\"node-type\":\"complex\",\"url\":null}]}]},{\"id\":\"5\",\"node-type\":\"pserver\",\"url\":null,\"properties\":{\"hostname\":\"hostname-2\"},\"related-to\":[{\"id\":\"0\",\"relationship-label\":\"tosca.relationships.HostedOn\",\"node-type\":\"generic-vnf\",\"url\":null},{\"id\":\"6\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\",\"node-type\":\"complex\",\"url\":null}],\"related-nodes\":[{\"id\":\"6\",\"node-type\":\"complex\",\"url\":null,\"properties\":{\"physical-location-id\":\"physical-location-id-2\",\"country\":\"US\"},\"related-to\":[{\"id\":\"5\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\",\"node-type\":\"pserver\",\"url\":null}]}]}]}]}") .getAsJsonObject(); diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java index 279c3e83..7aebe84d 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java @@ -23,9 +23,9 @@ package org.onap.aai.serialization.queryformats; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -160,7 +160,7 @@ public class SimpleFormatTest extends AAISetup { simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).build(); - when(serializer.dbToObject(anyObject(), anyObject(), anyInt(), anyBoolean(), anyString())) + when(serializer.dbToObject(any(), any(), anyInt(), anyBoolean(), anyString())) .thenThrow(new AAIException("Test Exception")); simpleFormat.createPropertiesObject(vfModule); diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java index c9e061c1..63671447 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java @@ -47,7 +47,7 @@ public class UrlBuilderTest extends AAISetup { private Vertex v; private static final String uri = "/test/uri"; - private static final Object vId = new Long(123); + private static final Object vId = Long.valueOf(123); private static final String protocolAndHost = "http://localhost/aai/"; @Before |