aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/templates/template.demo
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2017-08-28 22:16:36 +0000
committerGerrit Code Review <gerrit@onap.org>2017-08-28 22:16:36 +0000
commit5d7908a75107dcd18e7dd2f8a2d3e6528f5f830d (patch)
tree48f3fd34db7bf8ca5714474773d2a86cedce3a95 /controlloop/templates/template.demo
parent98d04b5c4e9aa3f7dd40cd40cbd1b00689b0bc22 (diff)
parent11e0afc41aa47b9b5fe36c6c654c5b7493e4ba46 (diff)
Merge "Removal of sys.out/err with logger messages"
Diffstat (limited to 'controlloop/templates/template.demo')
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java57
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java5
2 files changed, 33 insertions, 29 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java
index 18c0a2098..1fce83d2c 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java
@@ -78,6 +78,8 @@ import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.drools.impl.PolicyEngineJUnitImpl;
import org.onap.policy.guard.PolicyGuard;
import org.onap.policy.guard.PolicyGuardYamlToXacml;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.att.research.xacml.api.pdp.PDPEngine;
import com.att.research.xacml.api.pdp.PDPEngineFactory;
import com.att.research.xacml.util.FactoryException;
@@ -87,7 +89,7 @@ import com.att.research.xacml.util.XACMLProperties;
public class ControlLoopXacmlGuardTest {
-
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopXacmlGuardTest.class);
@Test
public void test() {
@@ -129,9 +131,9 @@ public class ControlLoopXacmlGuardTest {
- System.out.println("============");
- System.out.println(URLEncoder.encode(pair.b, "UTF-8"));
- System.out.println("============");
+ logger.debug("============");
+ logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug("============");
kieSession.addEventListener(new RuleRuntimeEventListener() {
@@ -152,7 +154,7 @@ public class ControlLoopXacmlGuardTest {
@Override
public void matchCreated(MatchCreatedEvent event) {
- //System.out.println("matchCreated: " + event.getMatch().getRule());
+ //logger.debug("matchCreated: " + event.getMatch().getRule());
}
@Override
@@ -161,7 +163,7 @@ public class ControlLoopXacmlGuardTest {
@Override
public void beforeMatchFired(BeforeMatchFiredEvent event) {
- //System.out.println("beforeMatchFired: " + event.getMatch().getRule() + event.getMatch().getObjects());
+ //logger.debug("beforeMatchFired: " + event.getMatch().getRule() + event.getMatch().getObjects());
}
@Override
@@ -222,7 +224,6 @@ public class ControlLoopXacmlGuardTest {
//
// Insert our globals
//
- final ControlLoopLogger logger = new ControlLoopLoggerStdOutImpl();
kieSession.setGlobal("Logger", logger);
final PolicyEngineJUnitImpl engine = new PolicyEngineJUnitImpl();
kieSession.setGlobal("Engine", engine);
@@ -283,8 +284,8 @@ public class ControlLoopXacmlGuardTest {
// "About to query Guard" notification (Querying about Restart)
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
- System.out.println("\n\n####################### GOING TO QUERY GUARD about Restart!!!!!!");
- System.out.println("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
+ logger.debug("\n\n####################### GOING TO QUERY GUARD about Restart!!!!!!");
+ logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
@@ -292,7 +293,7 @@ public class ControlLoopXacmlGuardTest {
// "Response from Guard" notification
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
- System.out.println("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
+ logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
@@ -302,8 +303,8 @@ public class ControlLoopXacmlGuardTest {
// "About to query Guard" notification (Querying about Rebuild)
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
- System.out.println("\n\n####################### GOING TO QUERY GUARD about Rebuild!!!!!!");
- System.out.println("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
+ logger.debug("\n\n####################### GOING TO QUERY GUARD about Rebuild!!!!!!");
+ logger.debug("Rule: {} Message", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
@@ -312,7 +313,7 @@ public class ControlLoopXacmlGuardTest {
// "Response from Guard" notification
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
- System.out.println("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
+ logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
@@ -322,8 +323,8 @@ public class ControlLoopXacmlGuardTest {
// "About to query Guard" notification (Querying about Migrate)
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
- System.out.println("\n\n####################### GOING TO QUERY GUARD!!!!!!");
- System.out.println("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
+ logger.debug("\n\n####################### GOING TO QUERY GUARD!!!!!!");
+ logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
@@ -332,7 +333,7 @@ public class ControlLoopXacmlGuardTest {
// "Response from Guard" notification
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
- System.out.println("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
+ logger.debug("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
@@ -351,7 +352,7 @@ public class ControlLoopXacmlGuardTest {
if(true == ((VirtualControlLoopNotification)obj).message.contains("Guard result: Permit")){
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
- System.out.println("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
+ logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
@@ -362,7 +363,7 @@ public class ControlLoopXacmlGuardTest {
assertTrue(obj instanceof Request);
assertTrue(((Request)obj).CommonHeader.SubRequestID.equals("1"));
- System.out.println("\n============ APP-C Got request!!! ===========\n");
+ logger.debug("\n============ APP-C Got request!!! ===========\n");
//
// Ok - let's simulate ACCEPT
//
@@ -402,12 +403,12 @@ public class ControlLoopXacmlGuardTest {
} catch (InterruptedException e) {
- System.err.println("Test thread got InterruptedException " + e.getLocalizedMessage());
+ logger.error("Test thread got InterruptedException ", e.getLocalizedMessage());
} catch (AssertionError e) {
- System.err.println("Test thread got AssertionError " + e.getLocalizedMessage());
+ logger.error("Test thread got AssertionError ", e.getLocalizedMessage());
e.printStackTrace();
} catch (Exception e) {
- System.err.println("Test thread got Exception " + e.getLocalizedMessage());
+ logger.error("Test thread got Exception ", e.getLocalizedMessage());
e.printStackTrace();
}
kieSession.halt();
@@ -437,9 +438,9 @@ public class ControlLoopXacmlGuardTest {
public static void dumpFacts(KieSession kieSession) {
- System.out.println("Fact Count: " + kieSession.getFactCount());
+ logger.debug("Fact Count: {}", kieSession.getFactCount());
for (FactHandle handle : kieSession.getFactHandles()) {
- System.out.println("FACT: " + handle);
+ logger.debug("FACT: {}", handle);
}
}
@@ -559,7 +560,7 @@ public class ControlLoopXacmlGuardTest {
p = Pattern.compile("\\$\\{controlLoopYaml\\}");
m = p.matcher(ruleContents);
ruleContents = m.replaceAll(controlLoopYaml);
- System.out.println(ruleContents);
+ logger.debug(ruleContents);
return ruleContents;
}
@@ -572,7 +573,7 @@ public class ControlLoopXacmlGuardTest {
KieModuleModel kModule = ks.newKieModuleModel();
- System.out.println("KMODULE:" + System.lineSeparator() + kModule.toXML());
+ logger.debug("KMODULE: {} {}", System.lineSeparator(), kModule.toXML());
//
// Generate our drools rule from our template
@@ -599,18 +600,18 @@ public class ControlLoopXacmlGuardTest {
Results results = builder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
for (Message msg : results.getMessages()) {
- System.err.println(msg.toString());
+ logger.error("{}", msg);
}
throw new RuntimeException("Drools Rule has Errors");
}
for (Message msg : results.getMessages()) {
- System.out.println(msg.toString());
+ logger.debug("{}", msg);
}
//
// Create our kie Session and container
//
ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
- System.out.println(releaseId);
+ logger.debug("{}", releaseId);
KieContainer kContainer = ks.newKieContainer(releaseId);
return kContainer.newKieSession();
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
index 2793f9aa2..62e7341a5 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java
@@ -35,9 +35,12 @@ import org.yaml.snakeyaml.constructor.Constructor;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class Util {
+ private static final Logger logger = LoggerFactory.getLogger(Util.class);
public static class Pair<A, B> {
public final A a;
public final B b;
@@ -58,7 +61,7 @@ public final class Util {
Object obj = yaml.load(contents);
//String ttt = ((ControlLoopPolicy)obj).policies.getFirst().payload.get("asdas");
- System.out.println(contents);
+ logger.debug(contents);
//for(Policy policy : ((ControlLoopPolicy)obj).policies){
return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);