Change getCanonicalName() to getName() in drools-pdp 16/90016/1
authorJim Hahn <jrh3@att.com>
Mon, 17 Jun 2019 14:42:41 +0000 (10:42 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 17 Jun 2019 14:42:41 +0000 (10:42 -0400)
Per javadocs, getName() should generally be used instead of
Class.getCanonicalName(). This change only applies to classes; it
does not apply to File objects.

Change-Id: I28df56b3dfd0382239960d7f0f6e1131d702b2ab
Issue-ID: POLICY-1646
Signed-off-by: Jim Hahn <jrh3@att.com>
feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java
policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java
policy-management/src/test/java/org/onap/policy/drools/protocol/coders/EventProtocolCoderTest.java
policy-management/src/test/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolsetTest.java
policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java

index 6b5dcfb..b156294 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * feature-healthcheck
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -257,7 +257,7 @@ class HealthCheckMonitor implements HealthCheck {
 
             for (HttpServletServer server : servers) {
                 if (server.isAaf()) {
-                    server.addFilterClass(null, AafHealthCheckFilter.class.getCanonicalName());
+                    server.addFilterClass(null, AafHealthCheckFilter.class.getName());
                 }
                 startServer(server);
             }
index 140d676..9731204 100644 (file)
@@ -374,21 +374,21 @@ public class MavenDroolsController implements DroolsController {
 
     @Override
     public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) {
-        if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), coderClass.getCanonicalName())) {
-            logger.error("{}{} cannot be retrieved. ", this, coderClass.getCanonicalName());
+        if (!ReflectionUtil.isClass(this.policyContainer.getClassLoader(), coderClass.getName())) {
+            logger.error("{}{} cannot be retrieved. ", this, coderClass.getName());
             return false;
         }
 
         if (modelHash == this.modelClassLoaderHash) {
             if (logger.isInfoEnabled()) {
-                logger.info(coderClass.getCanonicalName()
+                logger.info(coderClass.getName()
                         + this + " class loader matches original drools controller rules classloader "
                         + coderClass.getClassLoader());
             }
             return true;
         } else {
             if (logger.isWarnEnabled()) {
-                logger.warn(this + coderClass.getCanonicalName() + " class loaders don't match  "
+                logger.warn(this + coderClass.getName() + " class loaders don't match  "
                         + coderClass.getClassLoader() + " vs "
                         + this.policyContainer.getClassLoader());
             }
@@ -837,7 +837,7 @@ public class MavenDroolsController implements DroolsController {
 
     @Override
     public <T> List<T> facts(@NonNull String sessionName, @NonNull Class<T> clazz) {
-        return facts(sessionName, clazz.getCanonicalName(), false)
+        return facts(sessionName, clazz.getName(), false)
             .stream()
             .filter(clazz::isInstance)
             .map(clazz::cast)
index 3595f91..4b38e72 100644 (file)
@@ -214,6 +214,6 @@ public class NullDroolsController implements DroolsController {
     }
 
     private String makeInvokeMsg() {
-        return this.getClass().getCanonicalName() + " invoked";
+        return this.getClass().getName() + " invoked";
     }
 }
index 56eadad..1297ff8 100644 (file)
@@ -920,7 +920,7 @@ abstract class GenericEventProtocolCoder {
             throw new IllegalArgumentException("Invalid topic");
         }
 
-        String reverseKey = this.reverseCodersKey(topic, event.getClass().getCanonicalName());
+        String reverseKey = this.reverseCodersKey(topic, event.getClass().getName());
         if (!this.reverseCoders.containsKey(reverseKey)) {
             throw new IllegalArgumentException("no reverse coder has been found");
         }
@@ -996,7 +996,7 @@ abstract class GenericEventProtocolCoder {
 
         List<DroolsController> droolsControllers = new ArrayList<>();
 
-        String reverseKey = this.reverseCodersKey(topic, encodedClass.getClass().getCanonicalName());
+        String reverseKey = this.reverseCodersKey(topic, encodedClass.getClass().getName());
         if (!this.reverseCoders.containsKey(reverseKey)) {
             logger.warn("{}: no reverse mapping for {}", this, reverseKey);
             return droolsControllers;
@@ -1016,7 +1016,7 @@ abstract class GenericEventProtocolCoder {
                     "No Encoders toolsets available for topic "
                             + topic
                             + " encoder "
-                            + encodedClass.getClass().getCanonicalName());
+                            + encodedClass.getClass().getName());
         }
 
         for (ProtocolCoderToolset encoderSet : toolsets) {
@@ -1025,7 +1025,7 @@ abstract class GenericEventProtocolCoder {
             String artifactId = encoderSet.getArtifactId();
             List<CoderFilters> coderFilters = encoderSet.getCoders();
             for (CoderFilters coder : coderFilters) {
-                if (coder.getCodedClass().equals(encodedClass.getClass().getCanonicalName())) {
+                if (coder.getCodedClass().equals(encodedClass.getClass().getName())) {
                     DroolsController droolsController = DroolsController.factory.get(groupId, artifactId, "");
                     if (droolsController.ownsCoder(
                             encodedClass.getClass(), coder.getModelClassLoaderHash())) {
@@ -1040,7 +1040,7 @@ abstract class GenericEventProtocolCoder {
                     "No Encoders toolsets available for "
                             + topic
                             + ":"
-                            + encodedClass.getClass().getCanonicalName());
+                            + encodedClass.getClass().getName());
         }
 
         return droolsControllers;
@@ -1235,7 +1235,7 @@ abstract class GenericEventProtocolCoder {
                     this,
                     droolsControllers,
                     topic,
-                    fact.getClass().getCanonicalName());
+                    fact.getClass().getName());
             // continue
         }
         return droolsControllers.get(0);
@@ -1266,7 +1266,7 @@ abstract class GenericEventProtocolCoder {
                     this,
                     droolsControllers,
                     topic,
-                    fact.getClass().getCanonicalName());
+                    fact.getClass().getName());
             // continue
         }
         return droolsControllers;
index 86655ff..963aced 100644 (file)
@@ -521,7 +521,7 @@ class PolicyEngineManager implements PolicyEngine {
             this.httpServers = getServletFactory().build(properties);
             for (HttpServletServer server : this.httpServers) {
                 if (server.isAaf()) {
-                    server.addFilterClass(null, AafTelemetryAuthFilter.class.getCanonicalName());
+                    server.addFilterClass(null, AafTelemetryAuthFilter.class.getName());
                 }
             }
         } catch (final IllegalArgumentException e) {
index 77da1c1..4b0c438 100644 (file)
@@ -116,7 +116,7 @@ public class NullDroolsControllerTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void fetchModelClass() {
-        new NullDroolsController().fetchModelClass(this.getClass().getCanonicalName());
+        new NullDroolsController().fetchModelClass(this.getClass().getName());
     }
 
     @Test
@@ -153,4 +153,4 @@ public class NullDroolsControllerTest {
     public void factQuery() {
         Assert.assertTrue(new NullDroolsController().factQuery(null, null, null, false).isEmpty());
     }
-}
\ No newline at end of file
+}
index 682d280..40646b1 100644 (file)
@@ -86,7 +86,7 @@ public class EventProtocolCoderTest {
 
         EventProtocolCoder.manager.addEncoder(
                 EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
-                        .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName())
+                        .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getName())
                         .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
                         .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));
 
index b7d72f3..c6209a5 100644 (file)
@@ -102,7 +102,7 @@ public class ProtocolCoderToolsetTest {
                 EventProtocolParams.builder().topic(JUNIT_PROTOCOL_CODER_TOPIC)
                         .groupId(this.releaseId.getGroupId())
                         .artifactId(this.releaseId.getArtifactId())
-                        .eventClass(Triple.class.getCanonicalName())
+                        .eventClass(Triple.class.getName())
                         .protocolFilter(protocolFilter)
                         .customGsonCoder(null)
                         .modelClassLoaderHash(12345678), CONTROLLER_ID);
@@ -113,7 +113,7 @@ public class ProtocolCoderToolsetTest {
         testToolset(protocolFilter, gsonToolset);
 
         Triple<String, String, String> triple = createTriple();
-        gsonToolset.setCustomCoder(new CustomGsonCoder(this.getClass().getCanonicalName(), "customCoder"));
+        gsonToolset.setCustomCoder(new CustomGsonCoder(this.getClass().getName(), "customCoder"));
         String tripleEncoded = encode(gsonToolset, triple);
         decode(protocolFilter, gsonToolset, triple, tripleEncoded);
     }
@@ -131,7 +131,7 @@ public class ProtocolCoderToolsetTest {
         addRemoveCoder(coderToolset);
 
         /* restore original filters */
-        coderToolset.addCoder(Triple.class.getCanonicalName(), protocolFilter, 654321);
+        coderToolset.addCoder(Triple.class.getName(), protocolFilter, 654321);
 
         Triple<String, String, String> triple = createTriple();
 
@@ -152,8 +152,8 @@ public class ProtocolCoderToolsetTest {
             logger.trace("Junit expected exception - decode does not pass filtering", e);
         }
 
-        CoderFilters coderFilters = coderToolset.getCoder(Triple.class.getCanonicalName());
-        Assert.assertTrue(coderFilters.getCodedClass() == Triple.class.getCanonicalName());
+        CoderFilters coderFilters = coderToolset.getCoder(Triple.class.getName());
+        Assert.assertTrue(coderFilters.getCodedClass() == Triple.class.getName());
         Assert.assertTrue(coderFilters.getFilter() == protocolFilter);
         Assert.assertTrue(coderFilters.getFilter().getRule() != null);
 
@@ -184,26 +184,26 @@ public class ProtocolCoderToolsetTest {
     }
 
     private void addRemoveCoder(ProtocolCoderToolset coderToolset) {
-        coderToolset.addCoder(this.getClass().getCanonicalName(),
+        coderToolset.addCoder(this.getClass().getName(),
                 new JsonProtocolFilter("[?($.second =~ /.*/)]"), 654321);
         Assert.assertTrue(coderToolset.getCoders().size() == 2);
 
-        coderToolset.removeCoders(this.getClass().getCanonicalName());
+        coderToolset.removeCoders(this.getClass().getName());
         Assert.assertTrue(coderToolset.getCoders().size() == 1);
     }
 
     private void updateCoderFilterRule(ProtocolCoderToolset coderToolset) {
-        coderToolset.addCoder(Triple.class.getCanonicalName(), new JsonProtocolFilter("[?($.third =~ /.*/)]"), 654321);
+        coderToolset.addCoder(Triple.class.getName(), new JsonProtocolFilter("[?($.third =~ /.*/)]"), 654321);
 
         Assert.assertTrue(coderToolset.getCoders().size() == 1);
 
-        Assert.assertTrue(coderToolset.getCoder(Triple.class.getCanonicalName()).getModelClassLoaderHash() == 654321);
+        Assert.assertTrue(coderToolset.getCoder(Triple.class.getName()).getModelClassLoaderHash() == 654321);
 
         Assert.assertTrue(
                 coderToolset.getCoder(
-                        Triple.class.getCanonicalName()).getFilter().getRule() != null);
+                        Triple.class.getName()).getFilter().getRule() != null);
 
-        Assert.assertTrue("[?($.third =~ /.*/)]".equals(coderToolset.getCoder(Triple.class.getCanonicalName())
+        Assert.assertTrue("[?($.third =~ /.*/)]".equals(coderToolset.getCoder(Triple.class.getName())
                 .getFilter().getRule()));
     }
 
@@ -218,7 +218,7 @@ public class ProtocolCoderToolsetTest {
         CoderFilters coderFilters = coderToolset.getCoder(CONTROLLER_ID);
         Assert.assertTrue(coderFilters == null);
 
-        coderFilters = coderToolset.getCoder(Triple.class.getCanonicalName());
+        coderFilters = coderToolset.getCoder(Triple.class.getName());
         Assert.assertNotNull(coderFilters);
 
         Assert.assertEquals(coderFilters.getFilter(), protocolFilter);
@@ -238,7 +238,7 @@ public class ProtocolCoderToolsetTest {
         droolsControllerConfig.put(DroolsProperties.RULES_ARTIFACTID, releaseId.getArtifactId());
         droolsControllerConfig.put(DroolsProperties.RULES_VERSION, releaseId.getVersion());
         droolsControllerConfig.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS + "." + JUNIT_PROTOCOL_CODER_TOPIC
-                + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX, Triple.class.getCanonicalName());
+                + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX, Triple.class.getName());
 
         DroolsController.factory.build(droolsControllerConfig, null, noopTopics);
     }
index 64af6d4..a586e77 100644 (file)
@@ -213,7 +213,7 @@ public class PolicyEngineTest {
 
         EventProtocolCoder.manager.addEncoder(
                 EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
-                        .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getCanonicalName())
+                        .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getName())
                         .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
                         .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()));