diff options
Diffstat (limited to 'context/context-test-utils/src')
24 files changed, 217 insertions, 200 deletions
diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextBooleanItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextBooleanItem.java index 3afd5c89d..436624b7d 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextBooleanItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextBooleanItem.java @@ -96,10 +96,7 @@ public class TestContextBooleanItem implements Serializable { return false; } final TestContextBooleanItem other = (TestContextBooleanItem) obj; - if (flag != other.flag) { - return false; - } - return true; + return flag == other.flag; } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextByteItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextByteItem.java index 2b107b492..eec5d2b47 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextByteItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextByteItem.java @@ -94,10 +94,7 @@ public class TestContextByteItem implements Serializable { return false; } final TestContextByteItem other = (TestContextByteItem) obj; - if (byteValue != other.byteValue) { - return false; - } - return true; + return byteValue == other.byteValue; } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java index f7c849023..188b69c05 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java @@ -239,10 +239,7 @@ public class TestContextDateItem implements Serializable { if (time != other.time) { return false; } - if (year != other.year) { - return false; - } - return true; + return year == other.year; } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java index efad26052..4712074a2 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java @@ -241,10 +241,7 @@ public class TestContextDateLocaleItem implements Serializable { } else if (!timeZoneString.equals(other.timeZoneString)) { return false; } - if (utcOffset != other.utcOffset) { - return false; - } - return true; + return utcOffset == other.utcOffset; } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDoubleItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDoubleItem.java index ac4f5069f..26d98cdf4 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDoubleItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDoubleItem.java @@ -97,10 +97,7 @@ public class TestContextDoubleItem implements Serializable { return false; } final TestContextDoubleItem other = (TestContextDoubleItem) obj; - if (Double.doubleToLongBits(doubleValue) != Double.doubleToLongBits(other.doubleValue)) { - return false; - } - return true; + return Double.doubleToLongBits(doubleValue) == Double.doubleToLongBits(other.doubleValue); } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextFloatItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextFloatItem.java index cd8165251..294cf5b55 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextFloatItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextFloatItem.java @@ -94,10 +94,7 @@ public class TestContextFloatItem implements Serializable { return false; } final TestContextFloatItem other = (TestContextFloatItem) obj; - if (Float.floatToIntBits(floatValue) != Float.floatToIntBits(other.floatValue)) { - return false; - } - return true; + return Float.floatToIntBits(floatValue) == Float.floatToIntBits(other.floatValue); } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextIntItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextIntItem.java index 898302716..24cfebbc5 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextIntItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextIntItem.java @@ -103,10 +103,7 @@ public class TestContextIntItem implements Serializable { return false; } final TestContextIntItem other = (TestContextIntItem) obj; - if (intValue != other.intValue) { - return false; - } - return true; + return intValue == other.intValue; } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongItem.java index be3ee60f8..025cde657 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongItem.java @@ -95,10 +95,7 @@ public class TestContextLongItem implements Serializable { return false; } final TestContextLongItem other = (TestContextLongItem) obj; - if (longValue != other.longValue) { - return false; - } - return true; + return longValue == other.longValue; } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongObjectItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongObjectItem.java index 215868d11..9027bfcbf 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongObjectItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextLongObjectItem.java @@ -30,7 +30,7 @@ public class TestContextLongObjectItem implements Serializable { private static final int HASH_PRIME_1 = 31; - private Long longValue = new Long(0); + private Long longValue = 0L; /** * The Constructor. diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeMapItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeMapItem.java index eed0c1a2f..538a5433e 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeMapItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeMapItem.java @@ -32,7 +32,7 @@ public class TestContextTreeMapItem implements Serializable { private static final int HASH_PRIME_1 = 31; - private Map<String, String> mapValue = new TreeMap<String, String>(); + private Map<String, String> mapValue = new TreeMap<>(); /** * The Constructor. @@ -55,7 +55,7 @@ public class TestContextTreeMapItem implements Serializable { */ public Map<String, String> getMapValue() { if (mapValue == null) { - mapValue = new TreeMap<String, String>(); + mapValue = new TreeMap<>(); } return mapValue; } diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeSetItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeSetItem.java index fe47c1af0..e38d9c640 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeSetItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextTreeSetItem.java @@ -22,6 +22,7 @@ package org.onap.policy.apex.context.test.concepts; import java.io.Serializable; import java.util.Set; +import java.util.SortedSet; import java.util.TreeSet; /** @@ -32,7 +33,7 @@ public class TestContextTreeSetItem implements Serializable { private static final int HASH_PRIME_1 = 31; - private TreeSet<String> setValue = new TreeSet<String>(); + private SortedSet<String> setValue = new TreeSet<>(); /** * The Constructor. @@ -51,7 +52,7 @@ public class TestContextTreeSetItem implements Serializable { * * @param setValue the set value */ - public TestContextTreeSetItem(final TreeSet<String> setValue) { + public TestContextTreeSetItem(final SortedSet<String> setValue) { this.setValue = setValue; } @@ -62,7 +63,7 @@ public class TestContextTreeSetItem implements Serializable { */ public Set<String> getSetValue() { if (setValue == null) { - setValue = new TreeSet<String>(); + setValue = new TreeSet<>(); } return setValue; } @@ -72,7 +73,7 @@ public class TestContextTreeSetItem implements Serializable { * * @param setValue the sets the value */ - public void setSetValue(final TreeSet<String> setValue) { + public void setSetValue(final SortedSet<String> setValue) { this.setValue = setValue; } diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java index 189208fd5..0d2528791 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdate.java @@ -54,7 +54,7 @@ public class ContextAlbumUpdate { * @throws IOException the IO exception * @throws ApexException the apex exception */ - public void testContextAlbumUpdate() throws ApexModelException, IOException, ApexException { + public void testContextAlbumUpdate() throws IOException, ApexException { LOGGER.debug("Running TestContextAlbumUpdate test . . ."); final AxArtifactKey distributorKey = new AxArtifactKey(APEX_DISTRIBUTOR, VERSION); diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java index 75c615898..17c98a12d 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextInstantiation.java @@ -94,6 +94,17 @@ public class ContextInstantiation { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextInstantiation.class); + // Recurring string constants + private static final String TEST_POLICY_CONTEXT_ITEM000 = "TestPolicyContextItem000"; + private static final String TEST_POLICY_CONTEXT_ITEM005 = "TestPolicyContextItem005"; + private static final String TEST_POLICY_CONTEXT_ITEM004 = "TestPolicyContextItem004"; + private static final String TEST_POLICY_CONTEXT_ITEM003 = "TestPolicyContextItem003"; + private static final String TEST_POLICY_CONTEXT_ITEM002 = "TestPolicyContextItem002"; + private static final String TEST_POLICY_CONTEXT_ITEM001 = "TestPolicyContextItem001"; + private static final String NORMAL_TEST_EXCEPTION = "normal test exception"; + private static final String NULL_VALUES_ILLEGAL_TAG = + "album \"ExternalContextAlbum:0.0.1\" null values are illegal on key "; + private static final TreeSet<String> TEST_TREE_SET = new TreeSet<>(); private static final Map<String, String> TEST_HASH_MAP = new HashMap<>(); @@ -124,8 +135,8 @@ public class ContextInstantiation { try { - final ContextAlbum policyContextAlbum = - contextDistributor.createContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION)); + final ContextAlbum policyContextAlbum = contextDistributor + .createContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION)); assertNotNull(policyContextAlbum); policyContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray()); @@ -142,8 +153,8 @@ public class ContextInstantiation { policyContextAlbum.putAll(valueMap0); - final TestPolicyContextItem contextItem = - (TestPolicyContextItem) policyContextAlbum.get(TEST_POLICY_CONTEXT_ITEM); + final TestPolicyContextItem contextItem = (TestPolicyContextItem) policyContextAlbum + .get(TEST_POLICY_CONTEXT_ITEM); assertEquals(STRING_VAL, contextItem.getTestPolicyContextItem000().getStringValue()); assertEquals(LONG_VAL, contextItem.getTestPolicyContextItem001().getLongValue()); @@ -152,8 +163,8 @@ public class ContextInstantiation { assertEquals(contextItem.getTestPolicyContextItem004().getLongValue(), testDate.getTime()); assertEquals(TEST_HASH_MAP, contextItem.getTestPolicyContextItem005().getMapValue()); - final TestGlobalContextItem globalContext = - getTestGlobalContextItem(contextDistributor, testDate, tci9, tciA); + final TestGlobalContextItem globalContext = getTestGlobalContextItem(contextDistributor, testDate, tci9, + tciA); final Map<String, Object> valueMap1 = new HashMap<>(); valueMap1.put(GLOBAL_CONTEXT_KEY, globalContext); @@ -162,8 +173,8 @@ public class ContextInstantiation { globalContextAlbum.putAll(valueMap1); - final TestGlobalContextItem globalContextItem = - (TestGlobalContextItem) globalContextAlbum.get(GLOBAL_CONTEXT_KEY); + final TestGlobalContextItem globalContextItem = (TestGlobalContextItem) globalContextAlbum + .get(GLOBAL_CONTEXT_KEY); assertFalse(globalContextItem.getTestGlobalContextItem000().getFlag()); @@ -176,13 +187,13 @@ public class ContextInstantiation { assertDouble(PI_VAL, globalContextItem.getTestGlobalContextItem005().getDoubleValue()); assertEquals(STRING_GLOBAL_VAL, globalContextItem.getTestGlobalContextItem006().getStringValue()); - assertEquals(new Long(testDate.getTime()), globalContextItem.getTestGlobalContextItem007().getLongValue()); + assertEquals((Long) testDate.getTime(), globalContextItem.getTestGlobalContextItem007().getLongValue()); assertEquals(testDate, globalContextItem.getTestGlobalContextItem008().getDateValue()); assertEquals(tci9.getDateValue().getTime(), - globalContextItem.getTestGlobalContextItem009().getDateValue().getTime()); + globalContextItem.getTestGlobalContextItem009().getDateValue().getTime()); assertEquals(tciA.getDateValue().getTime(), - globalContextItem.getTestGlobalContextItem00A().getDateValue().getTime()); + globalContextItem.getTestGlobalContextItem00A().getDateValue().getTime()); assertEquals(TEST_TREE_SET, globalContextItem.getTestGlobalContextItem00B().getSetValue()); assertEquals(TEST_HASH_MAP, globalContextItem.getTestGlobalContextItem00C().getMapValue()); @@ -190,8 +201,8 @@ public class ContextInstantiation { final AxContextModel externalContextModel = TestContextAlbumFactory.createExternalContextModel(); final TestContextDateTzItem tci9A = new TestContextDateTzItem(tci9); - final TestContextDateLocaleItem tciA_A = new TestContextDateLocaleItem(tciA); - final TestExternalContextItem externalContext = getTestExternalContextItem(testDate, tci9A, tciA_A); + final TestContextDateLocaleItem tciAa = new TestContextDateLocaleItem(tciA); + final TestExternalContextItem externalContext = getTestExternalContextItem(testDate, tci9A, tciAa); final Map<String, Object> valueMap2 = new HashMap<>(); valueMap2.put(EXTERNAL_CONTEXT, externalContext); @@ -208,8 +219,8 @@ public class ContextInstantiation { externalContextAlbum.putAll(valueMap2); externalContextAlbum.getAlbumDefinition().setWritable(false); - TestExternalContextItem externalContextItem = - (TestExternalContextItem) externalContextAlbum.get(EXTERNAL_CONTEXT); + TestExternalContextItem externalContextItem = (TestExternalContextItem) externalContextAlbum + .get(EXTERNAL_CONTEXT); assertFalse(externalContextItem.getTestExternalContextItem000().getFlag()); assertEquals(BYTE_VAL, externalContextItem.getTestExternalContextItem001().getByteValue()); @@ -220,14 +231,13 @@ public class ContextInstantiation { assertDouble(PI_VAL, externalContextItem.getTestExternalContextItem005().getDoubleValue()); assertEquals(STRING_EXT_VAL, externalContextItem.getTestExternalContextItem006().getStringValue()); - assertEquals(new Long(testDate.getTime()), - externalContextItem.getTestExternalContextItem007().getLongValue()); + assertEquals((Long) testDate.getTime(), externalContextItem.getTestExternalContextItem007().getLongValue()); assertEquals(testDate, externalContextItem.getTestExternalContextItem008().getDateValue()); assertEquals(tci9A.getDateValue().getTime(), - externalContextItem.getTestExternalContextItem009().getDateValue().getTime()); + externalContextItem.getTestExternalContextItem009().getDateValue().getTime()); - assertEquals(tciA_A.getDateValue().getTime(), - externalContextItem.getTestExternalContextItem00A().getDateValue().getTime()); + assertEquals(tciAa.getDateValue().getTime(), + externalContextItem.getTestExternalContextItem00A().getDateValue().getTime()); assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue()); assertEquals(TEST_HASH_MAP, externalContextItem.getTestExternalContextItem00C().getMapValue()); @@ -240,7 +250,8 @@ public class ContextInstantiation { fail(EXCEPTION_MESSAGE); } catch (final ContextRuntimeException e) { assertEquals("album \"ExternalContextAlbum:0.0.1\" clear() not allowed on read only albums", - e.getMessage()); + e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertEquals(1, externalContextAlbum.size()); @@ -254,8 +265,8 @@ public class ContextInstantiation { externalContextAlbum.get(null); } catch (final ContextRuntimeException e) { assertEquals("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for get()", - e.getMessage()); - + e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } final Object aObject = externalContextAlbum.get(EXTERNAL_CONTEXT); @@ -266,16 +277,17 @@ public class ContextInstantiation { externalContextAlbum.put(null, null); } catch (final ContextRuntimeException e) { assertEquals("album \"ExternalContextAlbum:0.0.1\" null keys are illegal on keys for put()", - e.getMessage()); + e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } try { externalContextAlbum.put("TestExternalContextItem00A", null); } catch (final ContextRuntimeException e) { - assertEquals("album \"ExternalContextAlbum:0.0.1\" null values are illegal on key " - + "\"TestExternalContextItem00A\" for put()", e.getMessage()); + assertEquals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItem00A\" for put()", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } - assertEquals(tciA_A, externalContextItem.getTestExternalContextItem00A()); + assertEquals(tciAa, externalContextItem.getTestExternalContextItem00A()); // Should return the hash set assertEquals(TEST_TREE_SET, externalContextItem.getTestExternalContextItem00B().getSetValue()); @@ -300,24 +312,24 @@ public class ContextInstantiation { try { externalContextAlbum.put("TestExternalContextItem00A", null); } catch (final ContextRuntimeException e) { - assert (e.getMessage().equals("album \"ExternalContextAlbum:0.0.1\" null values are illegal on key " - + "\"TestExternalContextItem00A\" for put()")); + assert (e.getMessage().equals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItem00A\" for put()")); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertTrue(externalContextAlbum.get(EXTERNAL_CONTEXT).equals(externalContext)); try { externalContextAlbum.put("TestExternalContextItemFFF", null); } catch (final ContextRuntimeException e) { - assert (e.getMessage().equals("album \"ExternalContextAlbum:0.0.1\" null values are illegal on key " - + "\"TestExternalContextItemFFF\" for put()")); + assert (e.getMessage().equals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItemFFF\" for put()")); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertEquals(1, externalContextAlbum.size()); try { externalContextAlbum.put("TestExternalContextItemFFF", null); } catch (final ContextRuntimeException e) { - assertEquals("album \"ExternalContextAlbum:0.0.1\" null values are illegal on key " - + "\"TestExternalContextItemFFF\" for put()", e.getMessage()); + assertEquals(NULL_VALUES_ILLEGAL_TAG + "\"TestExternalContextItemFFF\" for put()", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertEquals(1, externalContextAlbum.size()); @@ -336,11 +348,12 @@ public class ContextInstantiation { } private void assertContextAlbumContains(final TestExternalContextItem externalContext, - final ContextAlbum externalContextAlbum) { + final ContextAlbum externalContextAlbum) { try { externalContextAlbum.containsKey(null); } catch (final ContextRuntimeException e) { assertEquals("null values are illegal on method parameter \"key\"", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertTrue(externalContextAlbum.containsKey(EXTERNAL_CONTEXT)); @@ -350,6 +363,7 @@ public class ContextInstantiation { externalContextAlbum.containsValue(null); } catch (final ContextRuntimeException e) { assertEquals("null values are illegal on method parameter \"value\"", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertTrue(externalContextAlbum.containsValue(externalContext)); @@ -357,15 +371,15 @@ public class ContextInstantiation { } private ContextAlbum getContextAlbum(final Distributor contextDistributor) throws ContextException { - final ContextAlbum globalContextAlbum = - contextDistributor.createContextAlbum(new AxArtifactKey(GLOBAL_CONTEXT_ALBUM, VERSION)); + final ContextAlbum globalContextAlbum = contextDistributor + .createContextAlbum(new AxArtifactKey(GLOBAL_CONTEXT_ALBUM, VERSION)); assertNotNull(globalContextAlbum); globalContextAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray()); return globalContextAlbum; } private TestGlobalContextItem getTestGlobalContextItem(final Distributor contextDistributor, final Date testDate, - final TestContextDateTzItem tci9, final TestContextDateLocaleItem tciA) throws ContextException { + final TestContextDateTzItem tci9, final TestContextDateLocaleItem tciA) throws ContextException { final AxContextModel globalContextModel = TestContextAlbumFactory.createGlobalContextModel(); final TestGlobalContextItem globalContext = getTestGlobalContextItem(testDate, tci9, tciA); contextDistributor.registerModel(globalContextModel); @@ -373,14 +387,14 @@ public class ContextInstantiation { } private TestGlobalContextItem getTestGlobalContextItem(final Date testDate, final TestContextDateTzItem tci9, - final TestContextDateLocaleItem tciA) { + final TestContextDateLocaleItem tciA) { final TestGlobalContextItem globalContext = new TestGlobalContextItem(); final TestContextBooleanItem testGlobalContextItem000 = new TestContextBooleanItem(false); final TestContextByteItem testGlobalContextItem001 = new TestContextByteItem(BYTE_VAL); final TestContextIntItem testGlobalContextItem002 = new TestContextIntItem(INT_VAL); final TestContextLongItem testGlobalContextItem003 = new TestContextLongItem(LONG_VAL); - final TestContextFloatItem testGlobalContextItem004 = new TestContextFloatItem(new Float(FLOAT_VAL)); + final TestContextFloatItem testGlobalContextItem004 = new TestContextFloatItem(FLOAT_VAL); final TestContextDoubleItem testGlobalContextItem005 = new TestContextDoubleItem(PI_VAL); final TestContextStringItem testGlobalContextItem006 = new TestContextStringItem(STRING_GLOBAL_VAL); final TestContextLongObjectItem testGlobalContextItem007 = new TestContextLongObjectItem(testDate.getTime()); @@ -389,7 +403,6 @@ public class ContextInstantiation { final TestContextTreeSetItem testGlobalContextItem00B = new TestContextTreeSetItem(TEST_TREE_SET); final TestContextTreeMapItem testGlobalContextItem00C = new TestContextTreeMapItem(TEST_HASH_MAP); - globalContext.setTestGlobalContextItem000(testGlobalContextItem000); globalContext.setTestGlobalContextItem001(testGlobalContextItem001); globalContext.setTestGlobalContextItem002(testGlobalContextItem002); @@ -415,12 +428,12 @@ public class ContextInstantiation { final TestContextTreeMapItem contextTreeMapItem = new TestContextTreeMapItem(TEST_HASH_MAP); final Map<String, Object> valueMapA = new LinkedHashMap<>(); - valueMapA.put("TestPolicyContextItem001", contextLongItem); - valueMapA.put("TestPolicyContextItem002", contextDoubleItem); - valueMapA.put("TestPolicyContextItem003", contextBooleanItem); - valueMapA.put("TestPolicyContextItem004", contextLongItem2); - valueMapA.put("TestPolicyContextItem005", contextTreeMapItem); - valueMapA.put("TestPolicyContextItem000", contextStringItem); + valueMapA.put(TEST_POLICY_CONTEXT_ITEM001, contextLongItem); + valueMapA.put(TEST_POLICY_CONTEXT_ITEM002, contextDoubleItem); + valueMapA.put(TEST_POLICY_CONTEXT_ITEM003, contextBooleanItem); + valueMapA.put(TEST_POLICY_CONTEXT_ITEM004, contextLongItem2); + valueMapA.put(TEST_POLICY_CONTEXT_ITEM005, contextTreeMapItem); + valueMapA.put(TEST_POLICY_CONTEXT_ITEM000, contextStringItem); assertPutMethods(policyContextAlbum, contextStringItem, valueMapA); @@ -438,23 +451,24 @@ public class ContextInstantiation { } private void assertPutMethods(final ContextAlbum policyContextAlbum, final TestContextStringItem contextStringItem, - final Map<String, Object> valueMapA) { + final Map<String, Object> valueMapA) { try { - policyContextAlbum.put("TestPolicyContextItem000", contextStringItem); + policyContextAlbum.put(TEST_POLICY_CONTEXT_ITEM000, contextStringItem); fail(EXCEPTION_MESSAGE); } catch (final ContextRuntimeException e) { - assertEquals( - getMessage("TestPolicyContextItem000", "TestContextItem006", + assertEquals(getMessage(TEST_POLICY_CONTEXT_ITEM000, "TestContextItem006", TestContextStringItem.class.getCanonicalName(), "stringValue=" + STRING_VAL), - e.getMessage()); + e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } try { policyContextAlbum.putAll(valueMapA); fail(EXCEPTION_MESSAGE); } catch (final ContextRuntimeException e) { - assertEquals(getMessage("TestPolicyContextItem001", "TestContextItem003", - TestContextLongItem.class.getCanonicalName(), "longValue=" + INT_VAL_3), e.getMessage()); + assertEquals(getMessage(TEST_POLICY_CONTEXT_ITEM001, "TestContextItem003", + TestContextLongItem.class.getCanonicalName(), "longValue=" + INT_VAL_3), e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } } @@ -487,7 +501,7 @@ public class ContextInstantiation { } private TestExternalContextItem getTestExternalContextItem(final Date testDate, final TestContextDateTzItem tci9A, - final TestContextDateLocaleItem tciAa) { + final TestContextDateLocaleItem tciAa) { final TestExternalContextItem externalContext = new TestExternalContextItem(); final TestContextBooleanItem testExternalContextItem000 = new TestContextBooleanItem(false); @@ -502,7 +516,6 @@ public class ContextInstantiation { final TestContextTreeSetItem testExternalContextItem00B = new TestContextTreeSetItem(TEST_TREE_SET); final TestContextTreeMapItem testExternalContextItem00C = new TestContextTreeMapItem(TEST_HASH_MAP); - externalContext.setTestExternalContextItem000(testExternalContextItem000); externalContext.setTestExternalContextItem001(testExternalContextItem001); externalContext.setTestExternalContextItem002(testExternalContextItem002); @@ -524,10 +537,10 @@ public class ContextInstantiation { } private String getMessage(final String key, final String objName, final String clazzName, final String valString, - final String compatibleClazzName) { + final String compatibleClazzName) { return "Failed to set context value for key \"" + key + "\" in album \"PolicyContextAlbum:0.0.1\": " - + "PolicyContextAlbum:0.0.1: object \"" + objName + " [" + valString + "]\" " + "of class \"" - + clazzName + "\"" + " not compatible with class \"" + compatibleClazzName + "\""; + + "PolicyContextAlbum:0.0.1: object \"" + objName + " [" + valString + "]\" " + "of class \"" + + clazzName + "\"" + " not compatible with class \"" + compatibleClazzName + "\""; } private void assertFloat(final float actual, final float expected) { @@ -538,7 +551,6 @@ public class ContextInstantiation { assertTrue(Double.compare(actual, expected) == 0); } - private Distributor getDistributor() throws ContextException { final AxArtifactKey distributorKey = new AxArtifactKey("ApexDistributorInit", VERSION); final Distributor distributor = new DistributorFactory().getDistributor(distributorKey); diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java index 95d14324c..d6a55effb 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/ContextUpdate.java @@ -62,8 +62,11 @@ import org.slf4j.ext.XLoggerFactory; * @author Sergey Sachkov (sergey.sachkov@ericsson.com) */ public class ContextUpdate { + // Recurring string constants. + private static final String NORMAL_TEST_EXCEPTION = "normal test exception"; + private static final String ZERO = "zero"; - private static final String _0 = "0"; + private static final String NUMBER_ZERO = "0"; // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextUpdate.class); @@ -74,7 +77,7 @@ public class ContextUpdate { * @throws IOException the IO exception * @throws ApexException the apex exception */ - public void testContextUpdate() throws ApexModelException, IOException, ApexException { + public void testContextUpdate() throws IOException, ApexException { LOGGER.debug("Running TestContextUpdate test . . ."); final Distributor contextDistributor = getDistributor(); @@ -86,35 +89,38 @@ public class ContextUpdate { final TestContextDateLocaleItem tciA = getTestContextDateLocaleItem(); final TestContextTreeMapItem tciC = getTestContextTreeMapItem(); - longContextAlbum.put(_0, (long) 0); - longContextAlbum.put(_0, 0); - longContextAlbum.put(_0, _0); + longContextAlbum.put(NUMBER_ZERO, (long) 0); + longContextAlbum.put(NUMBER_ZERO, 0); + longContextAlbum.put(NUMBER_ZERO, NUMBER_ZERO); try { - longContextAlbum.put(_0, ZERO); + longContextAlbum.put(NUMBER_ZERO, ZERO); fail(EXCEPTION_MESSAGE); } catch (final ContextRuntimeException e) { assertEquals("Failed to set context value for key \"0\" in album \"LongContextAlbum:0.0.1\":" + " LongContextAlbum:0.0.1: object \"zero\" of class \"java.lang.String\" not compatible with" + " class \"java.lang.Long\"", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } try { - longContextAlbum.put(_0, ""); + longContextAlbum.put(NUMBER_ZERO, ""); fail(EXCEPTION_MESSAGE); } catch (final ContextRuntimeException e) { assertEquals( "Failed to set context value for key \"0\" in album \"LongContextAlbum:0.0.1\": LongContextAlbum" + ":0.0.1: object \"\" of class \"java.lang.String\" not compatible with class \"java.lang.Long\"", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } try { - longContextAlbum.put(_0, null); + longContextAlbum.put(NUMBER_ZERO, null); fail(EXCEPTION_MESSAGE); } catch (final ContextRuntimeException e) { assertEquals("album \"LongContextAlbum:0.0.1\" null values are illegal on key \"0\" for put()", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } try { @@ -122,6 +128,7 @@ public class ContextUpdate { fail(EXCEPTION_MESSAGE); } catch (final ContextRuntimeException e) { assertEquals("album \"LongContextAlbum:0.0.1\" null keys are illegal on keys for put()", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertNull(dateContextAlbum.put("date0", tciA)); @@ -136,14 +143,13 @@ public class ContextUpdate { private TestContextTreeMapItem getTestContextTreeMapItem() { final Map<String, String> testHashMap = new HashMap<>(); - testHashMap.put(_0, ZERO); + testHashMap.put(NUMBER_ZERO, ZERO); testHashMap.put("1", "one"); testHashMap.put("2", "two"); testHashMap.put("3", "three"); testHashMap.put("4", "four"); - final TestContextTreeMapItem tciC = new TestContextTreeMapItem(testHashMap); - return tciC; + return new TestContextTreeMapItem(testHashMap); } private TestContextDateLocaleItem getTestContextDateLocaleItem() { diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java index 244bd7d24..293ef9205 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java @@ -67,19 +67,31 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; - - /** * The Class SequentialContextInstantiation checks sequential initiation of context. * * @author Sergey Sachkov (sergey.sachkov@ericsson.com) */ public class SequentialContextInstantiation { - private static final String DV1 = "dv1"; - private static final String DV0 = "dv0"; // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(SequentialContextInstantiation.class); + // Recurring string constants. + private static final String TEST_AB = "TestAB"; + private static final String TEST_AA = "TestAA"; + private static final String ITEM_NULL = "ItemNull"; + private static final String ITEM06 = "Item06"; + private static final String ITEM05 = "Item05"; + private static final String ITEM03 = "Item03"; + private static final String ITEM02 = "Item02"; + private static final String ITEM01 = "Item01"; + private static final String ITEM00_2 = "Item00_2"; + + // Recurring string constants. + private static final String NORMAL_TEST_EXCEPTION = "normal test exception"; + private static final String DV1 = "dv1"; + private static final String DV0 = "dv0"; + /** * Test sequential context instantiation. * @@ -107,8 +119,10 @@ public class SequentialContextInstantiation { dateAlbum.put("tci9", tci9); } catch (final Exception e) { final String message = "class \"" + TestContextDateTzItem.class.getCanonicalName() - + "\" not compatible with class \"" + TestContextDateLocaleItem.class.getCanonicalName() + "\""; + + "\" not compatible with class \"" + TestContextDateLocaleItem.class.getCanonicalName() + + "\""; assertTrue(e.getMessage().contains(message)); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } final TestContextDateLocaleItem tciA01 = new TestContextDateLocaleItem(tciA00); @@ -116,15 +130,15 @@ public class SequentialContextInstantiation { final TestContextDateLocaleItem tciA03 = new TestContextDateLocaleItem(tciA00); final Map<String, Object> valueMap0 = new HashMap<>(); - valueMap0.put("Item01", tciA01); - valueMap0.put("Item02", tciA02); - valueMap0.put("Item03", tciA03); + valueMap0.put(ITEM01, tciA01); + valueMap0.put(ITEM02, tciA02); + valueMap0.put(ITEM03, tciA03); dateAlbum.putAll(valueMap0); assertEquals(5, dateAlbum.size()); - assertEquals(tciA01, dateAlbum.get("Item01")); - assertEquals(tciA02, dateAlbum.get("Item02")); - assertEquals(tciA03, dateAlbum.get("Item03")); + assertEquals(tciA01, dateAlbum.get(ITEM01)); + assertEquals(tciA02, dateAlbum.get(ITEM02)); + assertEquals(tciA03, dateAlbum.get(ITEM03)); final Map<String, Object> valueMap1 = getMap(testDate, tciA00, tci9); @@ -135,31 +149,32 @@ public class SequentialContextInstantiation { dateAlbum1.putAll(valueMap1); fail(EXCEPTION_MESSAGE); } catch (final Exception e) { - assertTrue(e.getMessage().endsWith( - "not compatible with class \"" + TestContextDateLocaleItem.class.getCanonicalName() + "\"")); + assertTrue(e.getMessage().endsWith("not compatible with class \"" + + TestContextDateLocaleItem.class.getCanonicalName() + "\"")); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertEquals(5, dateAlbum1.size()); valueMap1.clear(); - valueMap1.put("Item00_2", tciA00); + valueMap1.put(ITEM00_2, tciA00); dateAlbum1.putAll(valueMap1); assertEquals(6, dateAlbum1.size()); - assertEquals(tciA00, dateAlbum1.get("Item00_2")); - dateAlbum.remove("Item00_2"); + assertEquals(tciA00, dateAlbum1.get(ITEM00_2)); + dateAlbum.remove(ITEM00_2); assertEquals(5, dateAlbum1.size()); final ContextAlbum dateAlbumCopy = getContextAlbum(DATE_CONTEXT_ALBUM, contextDistributor); final Map<String, Object> valueMap2 = new HashMap<>(); valueMap2.put("Item04", tciA01); - valueMap2.put("Item05", tciA02); - valueMap2.put("Item06", tciA03); + valueMap2.put(ITEM05, tciA02); + valueMap2.put(ITEM06, tciA03); dateAlbumCopy.putAll(valueMap2); assertEquals(8, dateAlbumCopy.size()); - assertEquals(tciA03, dateAlbumCopy.get("Item06")); + assertEquals(tciA03, dateAlbumCopy.get(ITEM06)); final Collection<Object> mapValues = dateAlbum.values(); assertTrue(dateAlbumCopy.values().containsAll(mapValues)); @@ -168,18 +183,17 @@ public class SequentialContextInstantiation { dateAlbum1.clear(); assertTrue(dateAlbum1.isEmpty()); - dateAlbum.put("Item00", tciA00); final Map<String, Object> valueMap3 = new HashMap<>(); - valueMap3.put("Item01", tciA01); - valueMap3.put("Item02", tciA02); - valueMap3.put("Item03", tciA03); + valueMap3.put(ITEM01, tciA01); + valueMap3.put(ITEM02, tciA02); + valueMap3.put(ITEM03, tciA03); dateAlbum.putAll(valueMap3); final Map<String, Object> valueMap4 = new HashMap<>(); valueMap4.put("Item04", tciA01); - valueMap4.put("Item05", tciA02); - valueMap4.put("Item06", tciA03); + valueMap4.put(ITEM05, tciA02); + valueMap4.put(ITEM06, tciA03); dateAlbumCopy.putAll(valueMap4); @@ -191,9 +205,9 @@ public class SequentialContextInstantiation { assertAlbumGetAndPutMethods(dateAlbum, tciA03, tciA00); // Should do removes - dateAlbum.remove("TestAA"); - dateAlbum.remove("TestAB"); - dateAlbum.remove("ItemNull"); + dateAlbum.remove(TEST_AA); + dateAlbum.remove(TEST_AB); + dateAlbum.remove(ITEM_NULL); assertEquals(7, entrySet.size()); assertTrue(dateAlbumCopy.values().containsAll(mapValues)); // CHECKSTYLE:ON: checkstyle:magicNumber @@ -208,16 +222,17 @@ public class SequentialContextInstantiation { fail(EXCEPTION_MESSAGE); } catch (final Exception e) { assertEquals("null values are illegal on method parameter \"key\"", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } - assertTrue(dateAlbum.containsKey("Item05")); + assertTrue(dateAlbum.containsKey(ITEM05)); assertTrue(!dateAlbum.containsKey("Item07")); try { dateAlbum.containsValue(null); } catch (final Exception e) { assertEquals("null values are illegal on method parameter \"value\"", e.getMessage()); - + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertTrue(dateAlbum.containsValue(tciA01)); @@ -225,75 +240,81 @@ public class SequentialContextInstantiation { } private void assertAlbumGetAndPutMethods(final ContextAlbum dateAlbum, final TestContextDateLocaleItem tciA03, - final TestContextDateLocaleItem tciA00) { + final TestContextDateLocaleItem tciA00) { try { dateAlbum.get(null); fail(EXCEPTION_MESSAGE); } catch (final Exception e) { assertEquals("album \"DateContextAlbum:0.0.1\" null keys are illegal on keys for get()", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } - final Object aObject = dateAlbum.get("Item03"); + final Object aObject = dateAlbum.get(ITEM03); assertEquals(tciA03, aObject); try { dateAlbum.put(null, null); fail(EXCEPTION_MESSAGE); } catch (final Exception e) { assertEquals("album \"DateContextAlbum:0.0.1\" null keys are illegal on keys for put()", e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } // Put null ContextItem should work (return null) try { - dateAlbum.put("ItemNull", null); + dateAlbum.put(ITEM_NULL, null); } catch (final Exception e) { assertEquals("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"ItemNull\" for put()", - e.getMessage()); + e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } // Should return null - assertNull(dateAlbum.get("ItemNull")); + assertNull(dateAlbum.get(ITEM_NULL)); // Put should return the previous contextItem tciA00.setDst(false); - final TestContextDateLocaleItem tciA03_clone = new TestContextDateLocaleItem(tciA03); - tciA03_clone.setDst(true); - TestContextDateLocaleItem retItem = (TestContextDateLocaleItem) dateAlbum.put("Item03", tciA03_clone); + final TestContextDateLocaleItem tciA03Clone = new TestContextDateLocaleItem(tciA03); + tciA03Clone.setDst(true); + TestContextDateLocaleItem retItem = (TestContextDateLocaleItem) dateAlbum.put(ITEM03, tciA03Clone); assertEquals(tciA03, retItem); - retItem = (TestContextDateLocaleItem) dateAlbum.put("Item03", tciA03); - assertEquals(tciA03_clone, retItem); + retItem = (TestContextDateLocaleItem) dateAlbum.put(ITEM03, tciA03); + assertEquals(tciA03Clone, retItem); try { - dateAlbum.put("ItemNull", null); + dateAlbum.put(ITEM_NULL, null); fail(EXCEPTION_MESSAGE); } catch (final Exception e) { - assert (e.getMessage() - .equals("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"ItemNull\" for put()")); + assert ("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"ItemNull\" for put()" + .equals(e.getMessage())); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } - dateAlbum.put("TestAA", tciA00); - assertEquals(tciA00, dateAlbum.get("TestAA")); + dateAlbum.put(TEST_AA, tciA00); + assertEquals(tciA00, dateAlbum.get(TEST_AA)); // Should print warning try { - dateAlbum.put("TestAA", null); + dateAlbum.put(TEST_AA, null); fail(EXCEPTION_MESSAGE); } catch (final Exception e) { assertEquals("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"TestAA\" for put()", - e.getMessage()); + e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertEquals(8, dateAlbum.size()); try { - dateAlbum.put("TestAB", null); + dateAlbum.put(TEST_AB, null); fail(EXCEPTION_MESSAGE); } catch (final Exception e) { assertEquals("album \"DateContextAlbum:0.0.1\" null values are illegal on key \"TestAB\" for put()", - e.getMessage()); + e.getMessage()); + LOGGER.trace(NORMAL_TEST_EXCEPTION, e); } assertEquals(8, dateAlbum.size()); } private Map<String, Object> getMap(final Date testDate, final TestContextDateLocaleItem tciA00, - final TestContextDateTzItem tci9) { + final TestContextDateTzItem tci9) { final TestContextBooleanItem testBadItem000 = new TestContextBooleanItem(); final TestContextByteItem testBadItem001 = new TestContextByteItem(); final TestContextIntItem testBadItem002 = new TestContextIntItem(); @@ -325,7 +346,7 @@ public class SequentialContextInstantiation { values.put("TestBadItem007", testBadItem007); values.put("TestBadItem008", testBadItem008); values.put("TestBadItem009", tci9); - values.put("Item00_2", tciA00); + values.put(ITEM00_2, tciA00); return values; } @@ -348,7 +369,7 @@ public class SequentialContextInstantiation { } private ContextAlbum getContextAlbum(final String albumName, final Distributor contextDistributor) - throws ContextException { + throws ContextException { final ContextAlbum dateAlbum = contextDistributor.createContextAlbum(new AxArtifactKey(albumName, VERSION)); assertNotNull(dateAlbum); dateAlbum.setUserArtifactStack(Constants.getAxArtifactKeyArray()); diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/factory/TestContextAlbumFactory.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/factory/TestContextAlbumFactory.java index 3003344b3..9689acb3d 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/factory/TestContextAlbumFactory.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/factory/TestContextAlbumFactory.java @@ -48,7 +48,10 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; * @author Liam Fallon (liam.fallon@ericsson.com) */ public final class TestContextAlbumFactory { - + // Recurring string constants. + private static final String CONTEXT = "context"; + private static final String SCHEMAS2 = "Schemas"; + private static final String KEY_INFO_MAP_KEY = "KeyInfoMapKey"; private static final String APPLICATION = "APPLICATION"; private static final String JAVA_LONG = Long.class.getCanonicalName(); private static final String JAVA_FLAVOUR = "Java"; @@ -69,12 +72,12 @@ public final class TestContextAlbumFactory { final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(POLICY_CONTEXT_ALBUM, VERSION), APPLICATION, true, policySchema.getKey()); - final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("Schemas", VERSION)); + final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION)); schemas.getSchemasMap().put(policySchema.getKey(), policySchema); - final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", VERSION)); + final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION)); albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition); - final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", VERSION)); + final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION)); final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("PolicyContextModel", VERSION), schemas, albums, keyInformation); contextModel.setKeyInformation(keyInformation); @@ -94,12 +97,12 @@ public final class TestContextAlbumFactory { final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(GLOBAL_CONTEXT_ALBUM, VERSION), "GLOBAL", true, globalSchema.getKey()); - final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("Schemas", VERSION)); + final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION)); schemas.getSchemasMap().put(globalSchema.getKey(), globalSchema); - final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", VERSION)); + final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION)); albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition); - final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", VERSION)); + final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION)); final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("GlobalContextModel", VERSION), schemas, albums, keyInformation); contextModel.setKeyInformation(keyInformation); @@ -119,12 +122,12 @@ public final class TestContextAlbumFactory { final AxContextAlbum albumDefinition = new AxContextAlbum(new AxArtifactKey(EXTERNAL_CONTEXT_ALBUM, VERSION), "EXTERNAL", true, externalSchema.getKey()); - final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("Schemas", VERSION)); + final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION)); schemas.getSchemasMap().put(externalSchema.getKey(), externalSchema); - final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", VERSION)); + final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION)); albums.getAlbumsMap().put(albumDefinition.getKey(), albumDefinition); - final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", VERSION)); + final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION)); final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("ExternalContextModel", VERSION), schemas, albums, keyInformation); contextModel.setKeyInformation(keyInformation); @@ -150,13 +153,13 @@ public final class TestContextAlbumFactory { final AxContextAlbum albumDefinition2 = new AxContextAlbum(longContextAlbumKey2, APPLICATION, true, longSchema.getKey()); - final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("Schemas", VERSION)); + final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION)); schemas.getSchemasMap().put(longSchema.getKey(), longSchema); - final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", VERSION)); + final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION)); albums.getAlbumsMap().put(albumDefinition1.getKey(), albumDefinition1); albums.getAlbumsMap().put(albumDefinition2.getKey(), albumDefinition2); - final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", VERSION)); + final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION)); final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("LongContextModel", VERSION), schemas, albums, keyInformation); contextModel.setKeyInformation(keyInformation); @@ -180,7 +183,7 @@ public final class TestContextAlbumFactory { final AxContextSchema mapSchema = new AxContextSchema(new AxArtifactKey("MapSchema", VERSION), JAVA_FLAVOUR, TestContextTreeMapItem.class.getCanonicalName()); - final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("Schemas", VERSION)); + final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey(SCHEMAS2, VERSION)); schemas.getSchemasMap().put(longSchema.getKey(), longSchema); schemas.getSchemasMap().put(lTypeSchema.getKey(), lTypeSchema); schemas.getSchemasMap().put(dateSchema.getKey(), dateSchema); @@ -195,13 +198,13 @@ public final class TestContextAlbumFactory { final AxContextAlbum mapAlbumDefinition = new AxContextAlbum(new AxArtifactKey(MAP_CONTEXT_ALBUM, VERSION), APPLICATION, true, mapSchema.getKey()); - final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", VERSION)); + final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey(CONTEXT, VERSION)); albums.getAlbumsMap().put(longAlbumDefinition.getKey(), longAlbumDefinition); albums.getAlbumsMap().put(lTypeAlbumDefinition.getKey(), lTypeAlbumDefinition); albums.getAlbumsMap().put(dateAlbumDefinition.getKey(), dateAlbumDefinition); albums.getAlbumsMap().put(mapAlbumDefinition.getKey(), mapAlbumDefinition); - final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", VERSION)); + final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey(KEY_INFO_MAP_KEY, VERSION)); final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("MultiAlbumsContextModel", VERSION), schemas, albums, keyInformation); contextModel.setKeyInformation(keyInformation); diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/AlbumModifier.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/AlbumModifier.java index 1253d2234..d1127ffa3 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/AlbumModifier.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/AlbumModifier.java @@ -26,6 +26,7 @@ import org.onap.policy.apex.context.ContextException; /** * The Interface AlbumModifier defines the interface to allow context albums be modified during context tests. */ +@FunctionalInterface public interface AlbumModifier { /** diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/LockType.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/LockType.java index 82de5b4a7..c4e6ac43a 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/LockType.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/lock/modifier/LockType.java @@ -64,7 +64,7 @@ public enum LockType { * * @param value the value */ - private LockType(final int value) { + LockType(final int value) { this.value = value; } diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java index 88cdccc88..87ffa3b40 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContext.java @@ -67,7 +67,7 @@ public class ConcurrentContext { * @throws ApexException the Apex exception occurs in handling Apex */ public Map<String, TestContextLongItem> testConcurrentContext() - throws ApexModelException, IOException, ApexException { + throws IOException, ApexException { try { setupAndVerifyContext(); @@ -140,7 +140,7 @@ public class ConcurrentContext { * * @throws ContextException the context exception */ - private void setupAndVerifyContext() throws ContextException { + private void setupAndVerifyContext() { contextDistributor = configrationProvider.getDistributor(); ltypeAlbum = configrationProvider.getContextAlbum(contextDistributor); final Map<String, Object> initValues = configrationProvider.getContextAlbumInitValues(); diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java index 7d7548569..b8e052947 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvm.java @@ -119,7 +119,7 @@ public final class ConcurrentContextJvm { public static void main(final String[] args) throws Exception { configure(); - System.out.println("JVM Arguments: " + Arrays.toString(args)); + LOGGER.info("JVM Arguments: " + Arrays.toString(args)); // CHECKSTYLE:OFF: checkstyle:magicNumber // An even number of arguments greater than 3 @@ -137,7 +137,7 @@ public final class ConcurrentContextJvm { final int threadLoops = getIntValue("threadLoops", args, 3); final int albumSize = getIntValue("albumSize", args, 4); final int lockType = getIntValue("lockType", args, 5); - final String hazelCastfileLocation = getStringValue("hazelcast file location", args, 6);; + final String hazelCastfileLocation = getStringValue("hazelcast file location", args, 6); System.setProperty("hazelcast.config", hazelCastfileLocation); @@ -162,10 +162,8 @@ public final class ConcurrentContextJvm { } catch (final Exception e) { LOGGER.error("error running test in JVM", e); - return; } // CHECKSTYLE:ON: checkstyle:magicNumber - } private static String getStringValue(final String key, final String[] args, final int position) { @@ -204,7 +202,7 @@ public final class ConcurrentContextJvm { // first non-loopback // IPv4 address // on a host - final TreeSet<String> ipAddressSet = new TreeSet<String>(); + final TreeSet<String> ipAddressSet = new TreeSet<>(); final Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (final NetworkInterface netint : Collections.list(nets)) { @@ -217,10 +215,10 @@ public final class ConcurrentContextJvm { } } - if (ipAddressSet.size() == 0) { + if (ipAddressSet.isEmpty()) { throw new Exception("cound not find real IP address for test"); } - System.out.println("Setting jgroups.tcp.address to: " + ipAddressSet.first()); + LOGGER.info("Setting jgroups.tcp.address to: " + ipAddressSet.first()); System.setProperty("jgroups.tcp.address", ipAddressSet.first()); } } diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java index 339c95d26..dca72391a 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/locking/ConcurrentContextJvmThread.java @@ -72,11 +72,11 @@ public class ConcurrentContextJvmThread implements Runnable, Closeable { commandList.add(System.getProperty("java.class.path")); commandList.add(ConcurrentContextJvm.class.getCanonicalName()); commandList.add(configrationProvider.getTestName()); - commandList.add(new Integer(jvm).toString()); - commandList.add(new Integer(configrationProvider.getThreadCount()).toString()); - commandList.add(new Integer(configrationProvider.getLoopSize()).toString()); - commandList.add(new Integer(configrationProvider.getAlbumSize()).toString()); - commandList.add(new Integer(configrationProvider.getLockType().getValue()).toString()); + commandList.add(Integer.toString(jvm)); + commandList.add(Integer.toString(configrationProvider.getThreadCount())); + commandList.add(Integer.toString(configrationProvider.getLoopSize())); + commandList.add(Integer.toString(configrationProvider.getAlbumSize())); + commandList.add(Integer.toString(configrationProvider.getLockType().getValue())); commandList.add(System.getProperty("hazelcast.config", "")); for (final Entry<String, ParameterGroup> parameterServiceEntry : ParameterService.getAll()) { diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ConfigrationProviderImpl.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ConfigrationProviderImpl.java index c63280966..70200943c 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ConfigrationProviderImpl.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/ConfigrationProviderImpl.java @@ -129,8 +129,7 @@ public class ConfigrationProviderImpl implements ConfigrationProvider { public ExecutorService getExecutorService() { final String name = getThreadFactoryName(jvmCount, testType); final IntegrationThreadFactory threadFactory = new IntegrationThreadFactory(name); - final ExecutorService executorService = Executors.newFixedThreadPool(threadCount, threadFactory); - return executorService; + return Executors.newFixedThreadPool(threadCount, threadFactory); } /* @@ -141,8 +140,7 @@ public class ConfigrationProviderImpl implements ConfigrationProvider { @Override public ExecutorService getExecutorService(final String threadFactoryName, final int threadPoolSize) { final IntegrationThreadFactory threadFactory = new IntegrationThreadFactory(threadFactoryName); - final ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize, threadFactory); - return executorService; + return Executors.newFixedThreadPool(threadPoolSize, threadFactory); } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java index 927876e8f..4761bc6f1 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/Constants.java @@ -45,7 +45,7 @@ public class Constants { public static final String EXCEPTION_MESSAGE = "Test should throw an exception"; public static final byte BYTE_VAL = (byte) 0xFF; public static final double PI_VAL = Math.PI; - public static final float FLOAT_VAL = 3.14159265359f; + public static final float FLOAT_VAL = 3.14159265359F; public static final String EXTERNAL_CONTEXT = "externalContext"; public static final String GLOBAL_CONTEXT_KEY = "globalContext"; public static final String STRING_GLOBAL_VAL = "This is a global context string"; diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/NetworkUtils.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/NetworkUtils.java index 980384043..d26ce955d 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/NetworkUtils.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/utils/NetworkUtils.java @@ -25,6 +25,7 @@ import java.net.NetworkInterface; import java.net.SocketException; import java.util.Collections; import java.util.Enumeration; +import java.util.SortedSet; import java.util.TreeSet; /** @@ -45,8 +46,8 @@ public class NetworkUtils { * @return Set of IPv4 addresses * @throws SocketException throw socket exception if error occurs */ - public static TreeSet<String> getIPv4NonLoopAddresses() throws SocketException { - final TreeSet<String> ipAddressSet = new TreeSet<String>(); + public static SortedSet<String> getIPv4NonLoopAddresses() throws SocketException { + final TreeSet<String> ipAddressSet = new TreeSet<>(); final Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (final NetworkInterface netint : Collections.list(nets)) { |