Fixed checkstyle issues that were subsequently reported.
Also fixed a few eclipse warnings.
Also fixed some of the sonar issues in the files that were touched:
- use "{}" in logger calls
- camelcase method names
- use "<?>" instead of generics
- add serialization ID
Issue-ID: POLICY-2188
Change-Id: I5c94a2e26dd74a61a0a919e1c3da17ab02a5bc9d
Signed-off-by: Jim Hahn <jrh3@att.com>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
assertNotNull(HttpClient.getBody(response, clazz));
}
- private <T> void empty(Response response, Class<T> clazz) {
- assertNull(HttpClient.getBody(response, clazz));
- }
-
@NotNull
private Response checkResponse(int statusCode, Response response) {
assertEquals(statusCode, response.getStatus());
============LICENSE_START=======================================================
drools-pdp-apps
================================================================================
- Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
Modifications Copyright (C) 2020 Bell Canada.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
- <version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
package org.onap.policy.m2.adapters;
import java.io.Serializable;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopNotification;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
-
import org.onap.policy.m2.base.OnsetAdapter;
public class VirtualOnsetAdapter extends OnsetAdapter implements Serializable {
@Override
public ControlLoopNotification createNotification(ControlLoopEvent event) {
if (event instanceof VirtualControlLoopEvent) {
- return new VirtualControlLoopNotification((VirtualControlLoopEvent)event);
+ return new VirtualControlLoopNotification((VirtualControlLoopEvent) event);
}
// Right now, the onset event from the transaction is used to locate
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import org.junit.Test;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopNotification;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
// we want an exact class match, so 'instanceOf' is not being used
assertEquals(VirtualControlLoopNotification.class, notification.getClass());
- ControlLoopEvent controlLoopEvent = new ControlLoopEvent() {};
+ ControlLoopEvent controlLoopEvent = new ControlLoopEvent() {
+ private static final long serialVersionUID = 1L;
+ };
notification = virtualOnsetAdapter.createNotification(controlLoopEvent);
assertNotNull(notification);
}
package org.onap.policy.m2.appclcm;
import java.io.Serializable;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.policy.Policy;
-
import org.onap.policy.m2.adapters.VirtualOnsetAdapter;
import org.onap.policy.m2.base.Actor;
import org.onap.policy.m2.base.Operation;
import java.util.HashMap;
import java.util.Map;
-
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.appclcm.AppcLcmOutput;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.guard.PolicyGuardResponse;
import org.onap.policy.m2.appclcm.model.AppcLcmResponseCode;
import org.onap.policy.m2.base.Transaction;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* the appc lcm response json payload
* @return the string that contains the state of the vnf
*/
+ @SuppressWarnings("unchecked")
private String getVnfHealthState(String jsonPayload) {
HashMap<String, Object> healthCheckPayloadMap;
try {
// The rest of this method is mostly copied from
// 'ControlLoopOperationManager.onResponse'.
- AppcLcmOutput response = ((AppcLcmDmaapWrapper)object).getBody().getOutput();
+ AppcLcmOutput response = ((AppcLcmDmaapWrapper) object).getBody().getOutput();
//
// Determine which subrequestID (ie. attempt)
package org.onap.policy.m2.appclcm;
import com.google.common.collect.ImmutableList;
-
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
-
import org.onap.policy.appclcm.AppcLcmBody;
import org.onap.policy.appclcm.AppcLcmCommonHeader;
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.m2.base.GuardAdjunct;
import org.onap.policy.m2.base.Operation;
import org.onap.policy.m2.base.Transaction;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return;
}
- this.onset = (VirtualControlLoopEvent)onset;
+ this.onset = (VirtualControlLoopEvent) onset;
// fetch or create the guard adjunct -- note that 'guard' operations are
// only performed if a 'GuardContext' is present, and the adjunct was
public void incomingMessage(Object object) {
if (! (object instanceof AppcLcmDmaapWrapper)) {
if (object instanceof PolicyGuardResponse) {
- incomingGuardMessage((PolicyGuardResponse)object);
+ incomingGuardMessage((PolicyGuardResponse) object);
} else if (object instanceof ControlLoopEvent) {
incomingAbatedEvent((ControlLoopEvent) object);
}
// The rest of this method is mostly copied from
// 'ControlLoopOperationManager.onResponse'.
- AppcLcmOutput response = ((AppcLcmDmaapWrapper)object).getBody().getOutput();
+ AppcLcmOutput response = ((AppcLcmDmaapWrapper) object).getBody().getOutput();
//
// Determine which subrequestID (ie. attempt)
import java.util.Properties;
import java.util.UUID;
-
import org.drools.core.WorkingMemory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.onap.policy.m2.appclcm.AppcLcmHealthCheckOperation;
import org.onap.policy.m2.appclcm.AppcLcmOperation;
import org.onap.policy.m2.base.Transaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class AppcLcmActorTest {
- private static Logger logger = LoggerFactory.getLogger(AppcLcmActorTest.class);
-
public static Policy policy;
public static VirtualControlLoopEvent event;
public static Transaction transaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
import static org.mockito.Mockito.mock;
import java.util.Properties;
import java.util.UUID;
-
import org.drools.core.WorkingMemory;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.appclcm.AppcLcmInput;
import org.onap.policy.appclcm.util.Serialization;
import java.util.HashMap;
import java.util.Properties;
import java.util.UUID;
-
import org.drools.core.WorkingMemory;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.appclcm.AppcLcmInput;
import org.onap.policy.appclcm.util.Serialization;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.m2.appclcm.AppcLcmOperation;
import org.onap.policy.m2.base.Transaction;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertNull;
import org.junit.Test;
-
import org.onap.policy.m2.appclcm.model.AppcLcmResponseCode;
package org.onap.policy.m2.base;
import java.io.Serializable;
-
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.guard.GuardContext;
package org.onap.policy.m2.base;
import java.io.Serializable;
-
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopNotification;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static Logger logger = LoggerFactory.getLogger(OnsetAdapter.class);
// table mapping onset message class to 'OnsetAdapter' instance
- private static Map<Class,OnsetAdapter> map = new ConcurrentHashMap<>();
+ private static Map<Class<?>, OnsetAdapter> map = new ConcurrentHashMap<>();
/**
* This method is called to add an entry to the table.
* @param value an instance of 'OnsetAdapter' that should be
* associated with 'clazz'
*/
- public static void register(Class clazz, OnsetAdapter value) {
+ public static void register(Class<?> clazz, OnsetAdapter value) {
// only create an entry if one doesn't already exist
map.putIfAbsent(clazz, value);
}
// one will be chosen "at random".
// we need to look for the best match of 'clazz'
- HashSet<Class> matches = new HashSet<>();
- Class chosenMatch = null;
+ HashSet<Class<?>> matches = new HashSet<>();
+ Class<?> chosenMatch = null;
synchronized (map) {
for (Class<?> possibleMatch : map.keySet()) {
if (possibleMatch.isAssignableFrom(clazz)) {
// we have a match -- see if it is the best match
boolean add = true;
- for (Class<?> match : new ArrayList<Class>(matches)) {
+ for (Class<?> match : new ArrayList<Class<?>>(matches)) {
if (match.isAssignableFrom(possibleMatch)) {
// 'possibleMatch' is a better match than 'match'
matches.remove(match);
// the new 'ControlLoopNotification' is abstract
public static class BaseControlLoopNotification extends ControlLoopNotification {
+ private static final long serialVersionUID = 1L;
+
BaseControlLoopNotification(ControlLoopEvent event) {
super(event);
}
package org.onap.policy.m2.base;
import java.io.Serializable;
-
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.policy.Policy;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.UUID;
-
import lombok.Getter;
import org.drools.core.WorkingMemory;
import org.kie.api.runtime.rule.FactHandle;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopNotification;
import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// This table maps 'actor' names to objects implementing the
// 'Actor' interface. 'ServiceLoader' is used to locate and create
// these objects, and populate the table.
- private static Map<String,Actor> nameToActor = new HashMap<>();
+ private static Map<String, Actor> nameToActor = new HashMap<>();
static {
// use 'ServiceLoader' to locate all of the 'Actor' implementations
break;
case FAILURE:
- nextPolicy = processResult_Failure();
+ nextPolicy = processResultFailure();
break;
case FAILURE_TIMEOUT:
}
// returns the next policy if the current operation fails
- private String processResult_Failure() {
+ private String processResultFailure() {
String nextPolicy = null;
int attempt = currentOperation.getAttempt();
if (attempt <= currentPolicy.getRetry()) {
Actor actor = nameToActor.get(currentPolicy.getActor());
if (actor != null) {
attempt += 1;
- logger.debug("found Actor, attempt " + attempt);
+ logger.debug("found Actor, attempt {}", attempt);
currentOperation =
actor.createOperation(this, currentPolicy, onset, attempt);
createHistEntry();
} else {
- logger.error("'Transaction' can't find actor "
- + currentPolicy.getActor());
+ logger.error("'Transaction' can't find actor {}", currentPolicy.getActor());
}
} else {
// operation failed, and no retries (or no retries left)
nextPolicy = (attempt == 1
? currentPolicy.getFailure()
: currentPolicy.getFailure_retries());
- logger.debug("moving to policy " + nextPolicy);
+ logger.debug("moving to policy {}", nextPolicy);
}
return nextPolicy;
}
actor.createOperation(this, currentPolicy, onset, 1);
createHistEntry();
} else {
- logger.error("'Transaction' can't find actor "
- + currentPolicy.getActor());
+ logger.error("'Transaction' can't find actor {}", currentPolicy.getActor());
}
} else {
- logger.error("Transaction' can't find policy " + id);
+ logger.error("Transaction' can't find policy {}", id);
}
if (currentOperation == null) {
T adjunct = null;
try {
// create the adjunct (may trigger an exception)
- adjunct = clazz.newInstance();
+ adjunct = clazz.getDeclaredConstructor().newInstance();
// initialize the adjunct (may also trigger an exception */
adjunct.init(Transaction.this);
import static org.junit.Assert.assertNull;
import org.junit.Test;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.Policy;
public static final String STATE = "COMPLETE";
public static class TestOperation implements Operation {
+ private static final long serialVersionUID = 1L;
@Override
public Object getRequest() throws ControlLoopException {
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import java.time.Instant;
import java.util.UUID;
-
import org.junit.BeforeClass;
import org.junit.Test;
-
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.guard.GuardContext;
public class GuardAdjunctTest {
private static final String ADJUNCT_CONTEXT_FIELD = "context";
- private static final String ADJUNCT_TRANSACTION_FIELD = "transaction";
private static GuardAdjunct adjunct;
private static Transaction transaction;
assertTrue(adjunct.asyncQuery(policy, "testTarget", UUID.randomUUID().toString()));
GuardContext savedContext = Whitebox.getInternalState(adjunct, ADJUNCT_CONTEXT_FIELD);
- Whitebox.setInternalState(adjunct, ADJUNCT_CONTEXT_FIELD, (GuardContext)null);
+ Whitebox.setInternalState(adjunct, ADJUNCT_CONTEXT_FIELD, (GuardContext) null);
try {
assertFalse(adjunct.asyncQuery(policy, "testTarget", UUID.randomUUID().toString()));
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.anyObject;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.Instant;
import java.util.LinkedList;
import java.util.UUID;
-
import org.drools.core.WorkingMemory;
import org.drools.core.impl.StatefulKnowledgeSessionImpl;
import org.junit.BeforeClass;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.m2.base.GuardAdjunct;
public class TransactionTest {
public static void setUpBeforeClass() {
mockWorkingMemory = mock(WorkingMemory.class);
FactHandle factHandle = mock(FactHandle.class);
- when(mockWorkingMemory.getFactHandle(anyObject())).thenReturn(factHandle);
+ when(mockWorkingMemory.getFactHandle(any())).thenReturn(factHandle);
}
@Test
Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
ControlLoopNotification notification = transaction.processError();
assertNull(notification);
-
+
VirtualControlLoopEvent onset =
createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
transaction.setControlLoopEvent(onset);
import org.drools.core.WorkingMemory;
import org.onap.policy.drools.core.PolicyContainer;
import org.onap.policy.drools.core.PolicySession;
-import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.system.PolicyControllerConstants;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.util.DroolsSessionCommonSerializable;
// 'EntityManagerFactory' does not exist yet -- create one
// copy database properties to a 'HashMap'
- HashMap<Object,Object> propertiesMap = new HashMap<>(dbProperties);
+ HashMap<Object, Object> propertiesMap = new HashMap<>(dbProperties);
// use 'ClassLoader' from Drools session
propertiesMap.put("eclipselink.classloader",
import java.util.UUID;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-
import org.drools.core.WorkingMemory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
package org.onap.policy.drools.m2.lock;
import java.io.Serializable;
-
import org.onap.policy.drools.core.lock.Lock;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.system.PolicyEngineConstants;
import java.util.Properties;
import java.util.UUID;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-
import org.onap.policy.drools.core.lock.Lock;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.m2.base.Transaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
public class LockAdjunctTest {
- private static Logger logger = LoggerFactory.getLogger(LockAdjunctTest.class);
-
public class TestOwner implements LockCallback {
@Override
"${notificationTopic}", "NOTIFICATION-APPCLCM-TOPIC",
"${operationTopic}", "APPC-REQUEST-APPCLCM-TOPIC",
"${policyName}", "appclcm",
- "${policyScope}", "service=vUSP;resource=vCTS;type=operational" ,
+ "${policyScope}", "service=vUSP;resource=vCTS;type=operational",
"${policyVersion}",
"org.onap.policy.m2.test:appclcm:" + projectVersion,
"${unique}", "2");
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static Logger logger = LoggerFactory.getLogger(SimDmaap.class);
// maps topic name to 'Topic' instance
- static Map<String,Topic> topicTable = new ConcurrentHashMap<>();
+ static Map<String, Topic> topicTable = new ConcurrentHashMap<>();
/**
* Each instance of this class corresponds to a DMAAP or UEB topic.
String topic;
// maps group name into group instance
- Map<String,Group> groupTable = new ConcurrentHashMap<>();
+ Map<String, Group> groupTable = new ConcurrentHashMap<>();
/**
* Create or get a Topic.
// no more messages
break;
}
- String[] prefix = data.substring(cur,leftBrace).split("\\.");
+ String[] prefix = data.substring(cur, leftBrace).split("\\.");
if (prefix.length == 3) {
try {
// determine length of message, and advance current position
builder.append("[\"").append(message);
// add up to '<limit>-1' more messages
- for (int i = 1 ; i < limit ; i += 1) {
+ for (int i = 1; i < limit; i += 1) {
// fetch the next message -- don't wait if it isn't currently there
message = messages.poll();
if (message == null) {
package org.onap.policy.m2.test;
import com.google.gson.JsonObject;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
-
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder;
import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
import com.att.nsa.cambria.client.CambriaConsumer;
-
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.UUID;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
public static String openAndReplace(String fileName, String... args)
throws IOException, FileNotFoundException {
String text = fileToString(new File(fileName));
- for (int i = 0 ; i < args.length ; i += 2) {
+ for (int i = 0; i < args.length; i += 2) {
text = text.replace(args[i], args[i + 1]);
}
return text;
*/
public static JsonObject json(Object... data) {
JsonObject obj = new JsonObject();
- for (int i = 0 ; i < data.length ; i += 2) {
+ for (int i = 0; i < data.length; i += 2) {
obj.add(data[i].toString(), toJsonElement(data[i + 1]));
}
return obj;
package org.onap.policy.util;
-import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.HashMap;
-
import org.onap.policy.drools.core.PolicySession;
/**
session.setAdjunct(Adjunct.class, adjunct);
} else {
// found the adjunct -- return it
- adjunct = (Adjunct)adj;
+ adjunct = (Adjunct) adj;
//adjunct = Adjunct.class.cast(adj);
}
}
* warnings.
*/
private static class Adjunct extends HashMap<String, Object> {
+ private static final long serialVersionUID = 1L;
}
}
import org.junit.Test;
import org.junit.runner.RunWith;
-
import org.mockito.Mockito;
-
import org.onap.policy.drools.core.PolicySession;
-
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
<parent>
<groupId>org.onap.policy.parent</groupId>
<artifactId>integration</artifactId>
- <version>3.1.3</version>
+ <version>3.2.0-SNAPSHOT</version>
<relativePath />
</parent>