diff options
Diffstat (limited to 'context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java')
-rw-r--r-- | context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiation.java | 125 |
1 files changed, 73 insertions, 52 deletions
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()); |