diff options
Diffstat (limited to 'aai-core/src')
35 files changed, 221 insertions, 139 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java index 2858ece3..d3addebb 100644 --- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java +++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSConsumer.java @@ -119,7 +119,7 @@ public class AAIDmaapEventJMSConsumer implements MessageListener { } metricLog.pre(eventName, aaiEvent, transactionId, serviceName); - HttpEntity httpEntity = new HttpEntity(aaiEvent, httpHeaders); + HttpEntity<String> httpEntity = new HttpEntity<String>(aaiEvent, httpHeaders); String transportType = environment.getProperty("dmaap.ribbon.transportType", "http"); String baseUrl = transportType + "://" + environment.getProperty("dmaap.ribbon.listOfServers"); diff --git a/aai-core/src/main/java/org/onap/aai/extensions/ExtensionController.java b/aai-core/src/main/java/org/onap/aai/extensions/ExtensionController.java index 612273d4..01e42f3d 100644 --- a/aai-core/src/main/java/org/onap/aai/extensions/ExtensionController.java +++ b/aai-core/src/main/java/org/onap/aai/extensions/ExtensionController.java @@ -63,7 +63,7 @@ public class ExtensionController { Method extension = clazz.getMethod(methodName, new Class[] {AAIExtensionMap.class}); if (extension != null) { - Object ret = extension.invoke(clazz.newInstance(), aaiExtMap); + Object ret = extension.invoke(clazz.getDeclaredConstructor().newInstance(), aaiExtMap); if (ret instanceof Integer) { Exception e = null; @@ -101,11 +101,12 @@ public class ExtensionController { } if (errorCallback != null) { - errorCallback.invoke(clazz.newInstance(), aaiExtMap); + errorCallback.invoke(clazz.getDeclaredConstructor().newInstance(), aaiExtMap); } else { Method defaultErrorCallbackExtension = clazz.getMethod(defaultErrorCallback, new Class[] {AAIExtensionMap.class}); - defaultErrorCallbackExtension.invoke(clazz.newInstance(), aaiExtMap); + defaultErrorCallbackExtension.invoke(clazz.getDeclaredConstructor().newInstance(), + aaiExtMap); } } } diff --git a/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java b/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java index c9e1f455..87983d8d 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/Introspector.java @@ -103,9 +103,10 @@ public abstract class Introspector implements Cloneable { Class<?> clazz = this.getClass(name); if (this.isListType(name) && result == null) { try { - this.set(convertedName, clazz.newInstance()); + this.set(convertedName, clazz.getDeclaredConstructor().newInstance()); result = this.get(convertedName); - } catch (DynamicException | InstantiationException | IllegalAccessException e) { + } catch (DynamicException | InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { LOGGER.warn(e.getMessage(), e); } } @@ -127,9 +128,10 @@ public abstract class Introspector implements Cloneable { Class<?> clazz = this.getClass(name); if (this.isListType(name) && value == null) { try { - this.set(convertedName, clazz.newInstance()); + this.set(convertedName, clazz.getDeclaredConstructor().newInstance()); value = this.get(convertedName); - } catch (DynamicException | InstantiationException | IllegalAccessException e) { + } catch (DynamicException | InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { LOGGER.warn(e.getMessage(), e); } } @@ -159,9 +161,10 @@ public abstract class Introspector implements Cloneable { Class<?> clazz = this.getClass(name); if (isListType && value == null) { try { - this.set(convertedName, clazz.newInstance()); + this.set(convertedName, clazz.getDeclaredConstructor().newInstance()); value = this.get(convertedName); - } catch (DynamicException | InstantiationException | IllegalAccessException e) { + } catch (DynamicException | InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException e) { LOGGER.warn(e.getMessage(), e); } } diff --git a/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java b/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java index 40352360..496c1e82 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/JSONStrategy.java @@ -21,6 +21,7 @@ package org.onap.aai.introspection; import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Map; import java.util.Set; @@ -150,7 +151,7 @@ public class JSONStrategy extends Introspector { Class<?> resultClass = null; Object resultObject = this.getValue(name); if (resultObject instanceof JSONArray) { - resultClass = ((List) resultObject).get(0).getClass(); + resultClass = ((List<?>) resultObject).get(0).getClass(); } return resultClass; @@ -159,8 +160,9 @@ public class JSONStrategy extends Introspector { @Override public Object newInstanceOfProperty(String name) { try { - return this.getClass(name).newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return this.getClass(name).getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) { return null; } } @@ -168,8 +170,9 @@ public class JSONStrategy extends Introspector { @Override public Object newInstanceOfNestedProperty(String name) { try { - return this.getGenericTypeClass(name).newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + return this.getGenericTypeClass(name).getDeclaredConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException e) { return null; } } diff --git a/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java b/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java index df8e9238..55980c3b 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java @@ -25,8 +25,15 @@ import com.google.common.base.Joiner; import java.io.StringWriter; import java.io.UnsupportedEncodingException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -170,12 +177,12 @@ public class MoxyStrategy extends Introspector { DatabaseMapping mapping = cd.getMappingForAttributeName(propName); Map<PropertyMetadata, String> result = new HashMap<>(); if (mapping != null) { - Set<Entry> entrySet = mapping.getProperties().entrySet(); - for (Entry<?, ?> entry : entrySet) { + Set<Map.Entry<String, String>> entrySet = mapping.getProperties().entrySet(); + for (Entry<String, String> entry : entrySet) { result.put( - PropertyMetadata.valueOf( - CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, (String) entry.getKey())), - (String) entry.getValue()); + PropertyMetadata + .valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, entry.getKey())), + entry.getValue()); } } diff --git a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/PrivateEdge.java b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/PrivateEdge.java index 9e32ef40..e58ff9bc 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/PrivateEdge.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/sideeffect/PrivateEdge.java @@ -25,8 +25,12 @@ import com.google.common.collect.Multimap; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import javax.ws.rs.core.MultivaluedMap; @@ -92,7 +96,7 @@ public class PrivateEdge extends SideEffect { List<Vertex> results = uriQuery.getQueryBuilder().toList(); if (results.size() == 1) { Vertex otherVertex = results.get(0); - VertexProperty otherVProperty = otherVertex.property("aai-node-type"); + VertexProperty<Object> otherVProperty = otherVertex.property("aai-node-type"); if (otherVProperty.isPresent()) { diff --git a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java index c66511f0..70e16e27 100644 --- a/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java +++ b/aai-core/src/main/java/org/onap/aai/prevalidation/ValidationService.java @@ -222,7 +222,7 @@ public class ValidationService { httpHeaders.put("Content-Type", "application/json"); List<String> violations = new ArrayList<>(); - ResponseEntity responseEntity; + ResponseEntity<String> responseEntity; try { responseEntity = validationRestClient.execute(VALIDATION_ENDPOINT, HttpMethod.POST, httpHeaders, body); @@ -267,7 +267,7 @@ public class ValidationService { return violations; } - boolean isSuccess(ResponseEntity responseEntity) { + boolean isSuccess(ResponseEntity<String> responseEntity) { return responseEntity != null && responseEntity.getStatusCode().is2xxSuccessful(); } diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java index 2517e2c0..3c5c4489 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/GraphTraversalBuilder.java @@ -23,7 +23,12 @@ package org.onap.aai.query.builder; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import org.apache.tinkerpop.gremlin.process.traversal.P; import org.apache.tinkerpop.gremlin.process.traversal.Path; @@ -288,7 +293,7 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { if (val != null) { // this is because the index is registered as an Integer if (val.getClass().equals(Long.class)) { - this.vertexHas(key, new Integer(val.toString())); + this.vertexHas(key, Integer.valueOf(val.toString())); } else { this.vertexHas(key, val); } @@ -321,7 +326,7 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { } // this is because the index is registered as an Integer if (val.getClass().equals(Long.class)) { - this.vertexHas(prop, new Integer(val.toString())); + this.vertexHas(prop, Integer.valueOf(val.toString())); } else { this.vertexHas(prop, val); } @@ -904,7 +909,7 @@ public abstract class GraphTraversalBuilder<E> extends QueryBuilder<E> { protected void executeQuery() { - Admin admin; + Admin<Vertex, Vertex> admin; if (start != null) { this.completeTraversal = traversal.asAdmin(); } else { diff --git a/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java b/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java index 423583f4..2bc90726 100644 --- a/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java +++ b/aai-core/src/main/java/org/onap/aai/query/builder/QueryBuilder.java @@ -634,7 +634,7 @@ public abstract class QueryBuilder<E> implements Iterator<E> { protected Object correctObjectType(Object obj) { if (obj != null && obj.getClass().equals(Long.class)) { - return new Integer(obj.toString()); + return Integer.valueOf(obj.toString()); } return obj; diff --git a/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java b/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java index 3666eb67..31805fd4 100644 --- a/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java +++ b/aai-core/src/main/java/org/onap/aai/restcore/RESTAPI.java @@ -341,7 +341,7 @@ public class RESTAPI { * @return the response */ public Response runner(String toe, String tba, String tdl, HttpHeaders headers, UriInfo info, HttpMethod httpMethod, - Callable c) { + Callable<Response> c) { Response response = null; Future<Response> handler = null; ExecutorService executor = null; diff --git a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java index dc478337..2192ff5e 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java @@ -575,7 +575,7 @@ public class DBSerializer { if (value != null) { if (!value.equals(oldValue)) { if (propertyType.toLowerCase().contains(".long")) { - v.property(dbProperty, new Integer(((Long) value).toString())); + v.property(dbProperty, Integer.valueOf(((Long) value).toString())); } else { v.property(dbProperty, value); } @@ -723,7 +723,7 @@ public class DBSerializer { throws IllegalArgumentException, SecurityException, UnsupportedEncodingException, AAIException { HashMap<String, Introspector> relatedVertices = new HashMap<>(); - VertexProperty aaiUriProperty = v.property(AAIProperties.AAI_URI); + VertexProperty<Object> aaiUriProperty = v.property(AAIProperties.AAI_URI); if (!aaiUriProperty.isPresent()) { if (LOGGER.isDebugEnabled()) { @@ -1232,7 +1232,7 @@ public class DBSerializer { throw new AAIException("AAI_6136", "query object mismatch: this object cannot hold multiple items." + obj.getDbName()); } else if (obj.isContainer()) { - final List getList; + final List<Object> getList; String listProperty = null; for (String property : obj.getProperties()) { if (obj.isListType(property) && obj.isComplexGenericType(property)) { @@ -1565,7 +1565,7 @@ public class DBSerializer { throws UnsupportedEncodingException, AAIException { List<Object> relationshipObjList = obj.getValue(RELATIONSHIP); - VertexProperty nodeTypeProperty = v.property(AAIProperties.NODE_TYPE); + VertexProperty<Object> nodeTypeProperty = v.property(AAIProperties.NODE_TYPE); if (!nodeTypeProperty.isPresent()) { LOGGER.warn("Not processing the vertex {} because its missing required property aai-node-type", v.id()); @@ -1651,7 +1651,7 @@ public class DBSerializer { private Object processEdgeRelationship(Introspector relationshipObj, Vertex cousin, String cleanUp, String edgeLabel, boolean isSkipRelatedTo) throws UnsupportedEncodingException, AAIUnknownObjectException { - VertexProperty aaiUriProperty = cousin.property("aai-uri"); + VertexProperty<Object> aaiUriProperty = cousin.property("aai-uri"); if (!aaiUriProperty.isPresent()) { return null; @@ -1670,7 +1670,7 @@ public class DBSerializer { return null; } - VertexProperty cousinVertexNodeType = cousin.property(AAIProperties.NODE_TYPE); + VertexProperty<Object> cousinVertexNodeType = cousin.property(AAIProperties.NODE_TYPE); if (cousinVertexNodeType.isPresent()) { String cousinType = cousinVertexNodeType.value().toString(); diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Aggregate.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Aggregate.java index 28362826..71f7bc78 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Aggregate.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Aggregate.java @@ -20,10 +20,19 @@ package org.onap.aai.serialization.queryformats; -import com.google.gson.*; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import java.io.UnsupportedEncodingException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -47,7 +56,6 @@ import org.slf4j.LoggerFactory; public class Aggregate extends MultiFormatMapper { private static final Logger LOGGER = LoggerFactory.getLogger(LifecycleFormat.class); - protected JsonParser parser = new JsonParser(); protected final DBSerializer serializer; protected final Loader loader; protected final UrlBuilder urlBuilder; @@ -99,7 +107,7 @@ public class Aggregate extends MultiFormatMapper { } final String json = obj.marshal(false); - return Optional.of(parser.parse(json).getAsJsonObject()); + return Optional.of(JsonParser.parseString(json).getAsJsonObject()); } catch (AAIUnknownObjectException e) { return Optional.empty(); } @@ -194,7 +202,8 @@ public class Aggregate extends MultiFormatMapper { return Optional.of(json); } - private Optional<JsonArray> processInput(Object input, Map properties) throws AAIFormatVertexException { + private Optional<JsonArray> processInput(Object input, Map<String, List<String>> properties) + throws AAIFormatVertexException { JsonArray json = new JsonArray(); for (Object l : (ArrayList) input) { if (l instanceof ArrayList) { diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java index fc3316d4..c0ba860f 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/GraphSON.java @@ -50,7 +50,6 @@ public class GraphSON implements FormatMapper { private final GraphSONMapper mapper = GraphSONMapper.build().addRegistry(JanusGraphIoRegistry.getInstance()).create(); private final GraphSONWriter writer = GraphSONWriter.build().mapper(mapper).create(); - protected JsonParser parser = new JsonParser(); @Override public Optional<JsonObject> formatObject(Object v) { @@ -64,7 +63,7 @@ public class GraphSON implements FormatMapper { logger.debug("GraphSON writeVertex error : {}", e.getMessage()); } - JsonObject jsonObject = parser.parse(result).getAsJsonObject(); + JsonObject jsonObject = JsonParser.parseString(result).getAsJsonObject(); if (jsonObject != null) { @@ -105,7 +104,7 @@ public class GraphSON implements FormatMapper { */ private void removePrivateEdges(JsonObject jsonObject, JsonObject edges, String edgeDirection) { - Iterator it = edges.entrySet().iterator(); + Iterator<Map.Entry<String, JsonElement>> it = edges.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, JsonElement> outEntry = (Map.Entry<String, JsonElement>) it.next(); JsonArray edgePropertiesArray = outEntry.getValue().getAsJsonArray(); diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/HistoryFormat.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/HistoryFormat.java index fccc17c6..02c4041f 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/HistoryFormat.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/HistoryFormat.java @@ -23,7 +23,6 @@ package org.onap.aai.serialization.queryformats; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import java.util.Iterator; import java.util.List; @@ -31,7 +30,11 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.tinkerpop.gremlin.structure.*; +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Property; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.onap.aai.db.props.AAIProperties; import org.onap.aai.introspection.Loader; import org.onap.aai.serialization.db.DBSerializer; @@ -61,7 +64,6 @@ public abstract class HistoryFormat extends MultiFormatMapper { protected static final String RELATED_TO = "related-to"; protected static final String NODE_ACTIONS = "node-actions"; - protected JsonParser parser = new JsonParser(); protected final DBSerializer serializer; protected final Loader loader; protected final UrlBuilder urlBuilder; @@ -90,10 +92,10 @@ public abstract class HistoryFormat extends MultiFormatMapper { protected JsonObject createMetaPropertiesObject(VertexProperty<Object> prop) { JsonObject json = new JsonObject(); - Iterator iter = prop.properties(); + Iterator<Property<Object>> iter = prop.properties(); while (iter.hasNext()) { - Property<Object> metaProp = (Property) iter.next(); + Property<Object> metaProp = iter.next(); mapPropertyValues(json, metaProp.key(), metaProp.value()); } diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/IdURL.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/IdURL.java index 10bba7f6..b9ba00eb 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/IdURL.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/IdURL.java @@ -45,18 +45,15 @@ import org.onap.aai.serialization.queryformats.utils.UrlBuilder; public class IdURL extends MultiFormatMapper { private final UrlBuilder urlBuilder; - private final JsonParser parser; private final Loader loader; public IdURL(Loader loader, UrlBuilder urlBuilder) throws AAIException { this.urlBuilder = urlBuilder; - this.parser = new JsonParser(); this.loader = loader; } public IdURL(Builder builder) throws AAIException { this.urlBuilder = builder.getUrlBuilder(); - this.parser = new JsonParser(); this.loader = builder.getLoader(); this.isTree = builder.isTree(); } @@ -77,7 +74,7 @@ public class IdURL extends MultiFormatMapper { final String json = searchResult.marshal(false); - return Optional.of(parser.parse(json).getAsJsonObject()); + return Optional.of(JsonParser.parseString(json).getAsJsonObject()); } catch (AAIUnknownObjectException e) { throw new RuntimeException("Fatal error - result-data object does not exist!"); diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/PathedURL.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/PathedURL.java index f052f778..0331925c 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/PathedURL.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/PathedURL.java @@ -45,19 +45,16 @@ import org.onap.aai.serialization.queryformats.utils.UrlBuilder; public final class PathedURL extends MultiFormatMapper { private final UrlBuilder urlBuilder; - private final JsonParser parser; private final Loader loader; private boolean includeUrl = false; public PathedURL(Loader loader, UrlBuilder urlBuilder) throws AAIException { this.urlBuilder = urlBuilder; - this.parser = new JsonParser(); this.loader = loader; } public PathedURL(Builder builder) { this.urlBuilder = builder.getUrlBuilder(); - this.parser = new JsonParser(); this.loader = builder.getLoader(); this.isTree = builder.isTree(); this.includeUrl = builder.isIncludeUrl(); @@ -82,7 +79,7 @@ public final class PathedURL extends MultiFormatMapper { searchResult.setValue("resource-version", v.value(AAIProperties.RESOURCE_VERSION)); final String json = searchResult.marshal(false); - return Optional.of(this.parser.parse(json).getAsJsonObject()); + return Optional.of(JsonParser.parseString(json).getAsJsonObject()); } catch (AAIUnknownObjectException e) { throw new RuntimeException("Fatal error - result-data does not exist!", e); diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java index bd858f4b..fe47a579 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/RawFormat.java @@ -23,7 +23,6 @@ package org.onap.aai.serialization.queryformats; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import java.util.Collections; import java.util.Iterator; @@ -47,7 +46,6 @@ import org.onap.aai.serialization.queryformats.params.NodesOnly; import org.onap.aai.serialization.queryformats.utils.UrlBuilder; public class RawFormat extends MultiFormatMapper { - protected JsonParser parser = new JsonParser(); protected final DBSerializer serializer; protected final Loader loader; protected final UrlBuilder urlBuilder; diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java index f4fd921f..1a69bed3 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/Resource.java @@ -56,7 +56,6 @@ public class Resource extends MultiFormatMapper { private final Loader loader; private final DBSerializer serializer; - private final JsonParser parser; private final UrlBuilder urlBuilder; private final boolean includeUrl; private final boolean nodesOnly; @@ -64,7 +63,6 @@ public class Resource extends MultiFormatMapper { private final boolean isSkipRelatedTo; public Resource(Builder builder) { - this.parser = new JsonParser(); this.loader = builder.getLoader(); this.serializer = builder.getSerializer(); this.urlBuilder = builder.getUrlBuilder(); @@ -190,7 +188,7 @@ public class Resource extends MultiFormatMapper { final String json = obj.marshal(false); - return Optional.of(getParser().parse(json).getAsJsonObject()); + return Optional.of(JsonParser.parseString(json).getAsJsonObject()); } catch (AAIUnknownObjectException e) { return Optional.empty(); } @@ -209,10 +207,6 @@ public class Resource extends MultiFormatMapper { return serializer; } - private JsonParser getParser() { - return parser; - } - public static class Builder implements NodesOnly<Builder>, Depth<Builder>, AsTree<Builder> { private final Loader loader; diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java index 076f665d..e81f6037 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/ResourceWithSoT.java @@ -21,7 +21,6 @@ package org.onap.aai.serialization.queryformats; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import java.util.List; import java.util.Map; @@ -39,7 +38,6 @@ import org.onap.aai.serialization.queryformats.utils.UrlBuilder; import org.onap.aai.util.AAIConfig; public class ResourceWithSoT extends MultiFormatMapper { - protected JsonParser parser = new JsonParser(); protected final DBSerializer serializer; protected final Loader loader; protected final UrlBuilder urlBuilder; diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/SimpleFormat.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/SimpleFormat.java index f1d1c26e..1caa7b50 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/SimpleFormat.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/SimpleFormat.java @@ -22,6 +22,7 @@ package org.onap.aai.serialization.queryformats; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import java.io.UnsupportedEncodingException; import java.util.ArrayList; @@ -67,7 +68,7 @@ public class SimpleFormat extends RawFormat { } final String json = obj.marshal(false); - return Optional.of(parser.parse(json).getAsJsonObject()); + return Optional.of(JsonParser.parseString(json).getAsJsonObject()); } catch (AAIUnknownObjectException e) { return Optional.empty(); } @@ -77,7 +78,7 @@ public class SimpleFormat extends RawFormat { @Override protected void addEdge(Edge e, Vertex v, JsonArray array) throws AAIFormatVertexException { - Property property = e.property("private"); + Property<Object> property = e.property("private"); if (property.isPresent()) { if ("true".equals(e.property("private").value().toString())) { diff --git a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/TreeFormat.java b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/TreeFormat.java index 2e1cbf6e..0da0ec55 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/queryformats/TreeFormat.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/queryformats/TreeFormat.java @@ -28,8 +28,11 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.io.UnsupportedEncodingException; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet; import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree; @@ -49,7 +52,6 @@ import org.onap.aai.serialization.queryformats.utils.UrlBuilder; public class TreeFormat extends MultiFormatMapper { private static final EELFLogger TREE_FORMAT_LOGGER = EELFManager.getInstance().getLogger(TreeFormat.class); - protected JsonParser parser = new JsonParser(); protected final DBSerializer serializer; protected final Loader loader; protected final UrlBuilder urlBuilder; @@ -181,9 +183,9 @@ public class TreeFormat extends MultiFormatMapper { // DSL Query if (o instanceof BulkSet) { - BulkSet bs = (BulkSet) o; - for (Object o1 : bs) { - Optional<JsonObject> obj = this.getJsonFromVertex((Vertex) o1); + BulkSet<Vertex> bs = (BulkSet<Vertex>) o; + for (Vertex o1 : bs) { + Optional<JsonObject> obj = this.getJsonFromVertex(o1); if (obj.isPresent()) { jsonObject = obj.get(); for (Map.Entry<String, JsonElement> mapEntry : jsonObject.entrySet()) { @@ -312,7 +314,7 @@ public class TreeFormat extends MultiFormatMapper { final String json = obj.marshal(false); - return Optional.of(getParser().parse(json).getAsJsonObject()); + return Optional.of(JsonParser.parseString(json).getAsJsonObject()); } catch (AAIUnknownObjectException e) { return Optional.empty(); } @@ -326,10 +328,6 @@ public class TreeFormat extends MultiFormatMapper { return serializer; } - private JsonParser getParser() { - return parser; - } - @Override protected Optional<JsonObject> getJsonFromVertex(Vertex input, Map<String, List<String>> properties) throws AAIFormatVertexException { diff --git a/aai-core/src/main/java/org/onap/aai/util/RestController.java b/aai-core/src/main/java/org/onap/aai/util/RestController.java index 6c57040d..1b050829 100644 --- a/aai-core/src/main/java/org/onap/aai/util/RestController.java +++ b/aai-core/src/main/java/org/onap/aai/util/RestController.java @@ -27,6 +27,7 @@ import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientResponse; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -256,7 +257,7 @@ public class RestController implements RestControllerInterface { * @return the list * @throws Exception the exception */ - private <T> List<T> mapJsonToObjectList(T typeDef, String json, Class clazz) throws Exception { + private <T> List<T> mapJsonToObjectList(T typeDef, String json, Class<?> clazz) throws Exception { List<T> list; ObjectMapper mapper = new ObjectMapper(); System.out.println(json); @@ -480,9 +481,14 @@ public class RestController implements RestControllerInterface { * @return single instance of RestController * @throws IllegalAccessException the illegal access exception * @throws InstantiationException the instantiation exception + * @throws SecurityException + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalArgumentException */ - public <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException { - return clazz.newInstance(); + public <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException, + IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { + return clazz.getDeclaredConstructor().newInstance(); } /** diff --git a/aai-core/src/main/java/org/onap/aai/util/RestControllerInterface.java b/aai-core/src/main/java/org/onap/aai/util/RestControllerInterface.java index 3304e9a5..6d20a010 100644 --- a/aai-core/src/main/java/org/onap/aai/util/RestControllerInterface.java +++ b/aai-core/src/main/java/org/onap/aai/util/RestControllerInterface.java @@ -20,6 +20,8 @@ package org.onap.aai.util; +import java.lang.reflect.InvocationTargetException; + import org.onap.aai.exceptions.AAIException; public interface RestControllerInterface { @@ -38,7 +40,8 @@ public interface RestControllerInterface { public void Delete(String sourceID, String transId, String path) throws AAIException; - public <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException; + public <T> T getInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException, + IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException; public <T> T DoesResourceExist(String resourcePath, String resourceClassName, String fromAppId, String transId); } 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/prevalidation/ValidationServiceTest.java b/aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java index 7f6e5610..d017408f 100644 --- a/aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java +++ b/aai-core/src/test/java/org/onap/aai/prevalidation/ValidationServiceTest.java @@ -115,7 +115,7 @@ public class ValidationServiceTest { String validationResponse = PayloadUtil.getResourcePayload("prevalidation/success-response-with-empty-violations.json"); - ResponseEntity responseEntity = Mockito.mock(ResponseEntity.class, Mockito.RETURNS_DEEP_STUBS); + ResponseEntity<String> responseEntity = Mockito.mock(ResponseEntity.class, Mockito.RETURNS_DEEP_STUBS); Mockito.when(restClient.execute(eq(ValidationService.VALIDATION_ENDPOINT), eq(HttpMethod.POST), any(), eq(pserverRequest))).thenReturn(responseEntity); 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/restcore/RESTAPITest.java b/aai-core/src/test/java/org/onap/aai/restcore/RESTAPITest.java index 3c099c75..4b73a7d7 100644 --- a/aai-core/src/test/java/org/onap/aai/restcore/RESTAPITest.java +++ b/aai-core/src/test/java/org/onap/aai/restcore/RESTAPITest.java @@ -27,7 +27,11 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; -import javax.ws.rs.core.*; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; import org.junit.Assert; import org.junit.BeforeClass; @@ -38,7 +42,7 @@ import org.onap.aai.exceptions.AAIException; public class RESTAPITest extends AAISetup { private static RESTAPI restapi; private static HttpHeaders httpHeaders; - private static Callable callable; + private static Callable<Response> callable; private static UriInfo info; private static Response response; diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java index 282f6457..f921a77c 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java @@ -21,14 +21,27 @@ package org.onap.aai.serialization.db; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; import org.apache.tinkerpop.gremlin.structure.Edge; @@ -37,7 +50,12 @@ import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; import org.janusgraph.core.JanusGraphFactory; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -987,7 +1005,7 @@ public class DbSerializerTest extends AAISetup { @Test public void cascadeL3NetworkPreventDeleteTest() throws AAIException, UnsupportedEncodingException { l3NetworkSetup(); - ArrayList expected_messages = new ArrayList<String>(); + ArrayList<String> expected_messages = new ArrayList<>(); expected_messages.add( "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list, l3-interface-ipv6-address-list]"); expected_messages.add( 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/ResourceFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java index 10178931..e26c56e2 100644 --- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java +++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java @@ -20,7 +20,9 @@ package org.onap.aai.serialization.queryformats; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -130,7 +132,7 @@ public class ResourceFormatTest extends AAISetup { FormatFactory ff = new FormatFactory(loader, serializer, schemaVersions, basePath, "https://localhost:8447/aai/"); - MultivaluedMap mvm = new MultivaluedHashMap(); + MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>(); mvm.add("depth", "0"); Formatter formatter = ff.get(Format.resource, mvm); 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..7634d22a 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; @@ -142,7 +142,7 @@ public class SimpleFormatTest extends AAISetup { FormatFactory ff = new FormatFactory(loader, serializer, schemaVersions, basePath, "https://localhost:8447/aai/"); - MultivaluedMap mvm = new MultivaluedHashMap(); + MultivaluedMap<String, String> mvm = new MultivaluedHashMap<>(); mvm.add("depth", "0"); Formatter formatter = ff.get(Format.simple, mvm); @@ -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 |