From 9f4232f5cea37ff63b195574c9cde1106bb93589 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jn.rouvignac@gmail.com>
Date: Fri, 28 Aug 2015 13:48:22 +0000
Subject: [PATCH] AttrHistorical*Test.java: additional asserts
---
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java | 67 ++++++++++++++++++++--
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java | 94 +++++++++++++++++++++++++------
2 files changed, 136 insertions(+), 25 deletions(-)
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java
index 16aaf22..5ec12e9 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalMultipleTest.java
@@ -75,6 +75,8 @@
}
}
+ private static final String ATTRIBUTE_NAME = "description";
+
private CSNGenerator csnGen = new CSNGenerator(1025, System.currentTimeMillis());
private AttrHistoricalMultiple attrHist;
private CSN csn;
@@ -162,7 +164,7 @@
assertEquals(attrInfo4.getValuesHistorical().size(), 1);
// Check
- AttributeType type = DirectoryServer.getAttributeType("description");
+ AttributeType type = DirectoryServer.getAttributeType(ATTRIBUTE_NAME);
attrInfo3.delete(Attributes.create(type, att), updateTime) ;
assertEquals(attrInfo3.getValuesHistorical().size(), 1);
@@ -176,9 +178,11 @@
{
mod = newModification(ADD, "X");
replayOperation(csn, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(DELETE, "X");
replayOperation(csn, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertNoAttributeValue(entry);
}
@Test
@@ -188,12 +192,15 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(ADD, "Y");
replayOperation(t[2], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X", "Y");
mod = newModification(DELETE, "Y");
replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
}
@Test
@@ -205,6 +212,7 @@
mod = newModification(ADD, "Y");
replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "Y");
}
@Test
@@ -214,12 +222,15 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(DELETE, "X");
replayOperation(t[2], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertNoAttributeValue(entry);
mod = newModification(ADD, "X");
replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertNoAttributeValue(entry);
}
@Test
@@ -229,9 +240,11 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(ADD, "X");
replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT);
+ assertAttributeValues(entry, "X");
}
@Test
@@ -241,12 +254,15 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(DELETE, "X");
replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertNoAttributeValue(entry);
mod = newModification(ADD, "X");
replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
}
@Test
@@ -254,6 +270,7 @@
{
mod = newModification(DELETE, "Y");
replayOperationSuppressMod(csn, entry, mod, E.CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -263,9 +280,11 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(DELETE, "X");
replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertNoAttributeValue(entry);
}
@Test
@@ -277,6 +296,7 @@
mod = newModification(DELETE, "X");
replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -296,9 +316,11 @@
{
mod = newModification(ADD, "X");
replayOperation(tAdd, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(DELETE);
replayOperation(tDel, entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertNoAttributeValue(entry);
}
@Test
@@ -306,6 +328,7 @@
{
mod = newModification(REPLACE, "X");
replayOperation(csn, entry, mod, E.NO_CONFLICT);
+ assertAttributeValues(entry, "X");
}
@Test
@@ -315,9 +338,11 @@
mod = newModification(ADD, "X");
replayOperation(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X");
mod = newModification(REPLACE, "Y");
replayOperation(t[0], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "X", "Y");
}
@Test
@@ -329,6 +354,7 @@
mod = newModification(REPLACE, "Y");
replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE);
+ assertAttributeValues(entry, "Y");
}
private CSN[] newCSNs(int nb)
@@ -343,12 +369,12 @@
private Modification newModification(ModificationType modType, String attrValue)
{
- return new Modification(modType, Attributes.create("description", attrValue));
+ return new Modification(modType, Attributes.create(ATTRIBUTE_NAME, attrValue));
}
private Modification newModification(ModificationType modType)
{
- return new Modification(modType, Attributes.empty("description"));
+ return new Modification(modType, Attributes.empty(ATTRIBUTE_NAME));
}
private void replayOperationSuppressMod(CSN csn, Entry entry, Modification mod, E conflictStatus)
@@ -356,12 +382,14 @@
{
Iterator<Modification> itMod = mock(Iterator.class);
replayOperation(itMod, csn, entry, mod, conflictStatus);
- verifyModNotReplayed(itMod);
+ verifyModSuppressed(itMod);
}
private void replayOperation(CSN csn, Entry entry, Modification mod, E conflictStatus) throws Exception
{
- replayOperation(null, csn, entry, mod, conflictStatus);
+ Iterator<Modification> itMod = mock(Iterator.class);
+ replayOperation(itMod, csn, entry, mod, conflictStatus);
+ verifyZeroInteractions(itMod);
}
private void replayOperation(Iterator<Modification> modsIterator, CSN csn, Entry entry, Modification mod,
@@ -409,7 +437,11 @@
private List<ByteString> getValues(Entry entry, Modification mod)
{
- List<Attribute> attributes = entry.getAttribute(mod.getAttribute().getAttributeType());
+ return getValues(entry.getAttribute(mod.getAttribute().getAttributeType()));
+ }
+
+ private List<ByteString> getValues(List<Attribute> attributes)
+ {
if (attributes != null)
{
assertThat(attributes).hasSize(1);
@@ -428,7 +460,28 @@
return results;
}
- private void verifyModNotReplayed(Iterator<Modification> it)
+ private void assertNoAttributeValue(Entry entry)
+ {
+ assertAttributeValues(entry);
+ }
+
+ private void assertAttributeValues(Entry entry, String... expectedValues)
+ {
+ List<ByteString> actualValues = getValues(entry.getAttribute(ATTRIBUTE_NAME));
+ assertThat(actualValues).containsOnly(toByteStrings(expectedValues));
+ }
+
+ private ByteString[] toByteStrings(String... strings)
+ {
+ ByteString[] results = new ByteString[strings.length];
+ for (int i = 0; i < results.length; i++)
+ {
+ results[i] = ByteString.valueOf(strings[i]);
+ }
+ return results;
+ }
+
+ private void verifyModSuppressed(Iterator<Modification> it)
{
verify(it, times(1)).remove();
verify(it, only()).remove();
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java
index 93b3199..2b819bd 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AttrHistoricalSingleTest.java
@@ -48,8 +48,10 @@
@SuppressWarnings("javadoc")
public class AttrHistoricalSingleTest extends ReplicationTestCase
{
+ private static final String ATTRIBUTE_NAME = "display";
private static final boolean CONFLICT = true;
private static final boolean NO_CONFLICT = false;
+
private CSNGenerator csnGen = new CSNGenerator(1025, System.currentTimeMillis());
private AttrHistoricalSingle attrHist;
private CSN csn;
@@ -77,9 +79,11 @@
{
mod = newModification(ADD, "X");
replayOperation(csn, entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE, "X");
replayOperation(csn, entry, mod, NO_CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -89,12 +93,15 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
- mod = newModification(DELETE, "X");
+ mod = newModification(DELETE);
replayOperation(t[2], entry, mod, NO_CONFLICT);
+ assertNoAttributeValue(entry);
- mod = newModification(ADD, "X");
+ mod = newModification(ADD, "Z");
replayOperationSuppressMod(t[1], entry, mod, CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -104,15 +111,19 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE, "X");
replayOperation(t[1], entry, mod, NO_CONFLICT);
+ assertNoAttributeValue(entry);
mod = newModification(ADD, "X");
replayOperation(t[3], entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
mod = newModification(ADD, "Y");
replayOperation(t[2], entry, mod, CONFLICT);
+ assertAttributeValue(entry, "X");
}
@Test
@@ -122,12 +133,15 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE, "X");
replayOperation(t[1], entry, mod, NO_CONFLICT);
+ assertNoAttributeValue(entry);
mod = newModification(DELETE, "X");
replayOperationSuppressMod(t[2], entry, mod, CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -136,10 +150,12 @@
CSN[] t = newCSNs(2);
mod = newModification(ADD, "X");
- replayOperation(t[1], null, mod, NO_CONFLICT);
+ replayOperation(t[1], entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE, "X");
replayOperationSuppressMod(t[0], entry, mod, CONFLICT);
+ assertAttributeValue(entry, "X");
}
@Test
@@ -147,6 +163,7 @@
{
mod = newModification(DELETE, "X");
replayOperationSuppressMod(csn, entry, mod, CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -156,9 +173,11 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE, "Y");
replayOperationSuppressMod(t[1], entry, mod, CONFLICT);
+ assertAttributeValue(entry, "X");
}
/**
@@ -175,9 +194,11 @@
mod = newModification(ADD, "X");
entry.applyModification(mod);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE, "Y");
replayOperationSuppressMod(t[1], entry, mod, CONFLICT);
+ assertAttributeValue(entry, "X");
}
/**
@@ -194,23 +215,27 @@
attrHist.assign(histAttrVal.getHistKey(), histAttrVal.getAttributeValue(), csn);
mod = newModification(ADD, "X");
entry.applyModification(mod);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE, "Y");
replayOperationSuppressMod(csn, entry, mod, CONFLICT);
+ assertAttributeValue(entry, "X");
}
@Test
public void replay_replaceWithValue() throws Exception
{
mod = newModification(REPLACE, "X");
- replayOperation(csn, null, mod, NO_CONFLICT);
+ replayOperation(csn, entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
}
@Test
public void replay_replaceNoValue() throws Exception
{
mod = newModification(REPLACE);
- replayOperation(csn, null, mod, NO_CONFLICT);
+ replayOperation(csn, entry, mod, NO_CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -220,12 +245,15 @@
mod = newModification(ADD, "X");
replayOperation(t[0], entry, mod, NO_CONFLICT);
+ assertAttributeValue(entry, "X");
mod = newModification(DELETE);
replayOperation(t[2], entry, mod, NO_CONFLICT);
+ assertNoAttributeValue(entry);
mod = newModification(REPLACE);
replayOperationSuppressMod(t[1], entry, mod, CONFLICT);
+ assertNoAttributeValue(entry);
}
@Test
@@ -248,17 +276,19 @@
private Modification newModification(ModificationType modType, String attrValue)
{
- return new Modification(modType, Attributes.create("display", attrValue));
+ return new Modification(modType, Attributes.create(ATTRIBUTE_NAME, attrValue));
}
private Modification newModification(ModificationType modType)
{
- return new Modification(modType, Attributes.empty("display"));
+ return new Modification(modType, Attributes.empty(ATTRIBUTE_NAME));
}
private void replayOperation(CSN csn, Entry entry, Modification mod, boolean shouldConflict) throws Exception
{
- replayOperation(null, csn, entry, mod, shouldConflict);
+ Iterator<Modification> itMod = mock(Iterator.class);
+ replayOperation(itMod, csn, entry, mod, shouldConflict);
+ verifyZeroInteractions(itMod);
}
private void replayOperationSuppressMod(CSN csn, Entry entry, Modification mod, boolean shouldConflict)
@@ -266,7 +296,7 @@
{
Iterator<Modification> itMod = mock(Iterator.class);
replayOperation(itMod, csn, entry, mod, shouldConflict);
- verifyModNotReplayed(itMod);
+ verifyModSuppressed(itMod);
}
private void replayOperation(Iterator<Modification> modsIterator, CSN csn, Entry entry, Modification mod,
@@ -288,10 +318,28 @@
switch (mod.getModificationType().asEnum())
{
case ADD:
- case REPLACE:
- ByteString expectedValue = uniqueValue(mod.getAttribute());
+ {
+ Attribute attribute = mod.getAttribute();
+ assertThat(attribute).hasSize(1);
+ ByteString expectedValue = attribute.iterator().next();
assertEquals(actualValue, expectedValue);
return;
+ }
+
+ case REPLACE:
+ {
+ Attribute attribute = mod.getAttribute();
+ if (!attribute.isEmpty())
+ {
+ ByteString expectedValue = attribute.iterator().next();
+ assertEquals(actualValue, expectedValue);
+ }
+ else
+ {
+ assertNull(actualValue);
+ }
+ return;
+ }
case DELETE:
assertNull(actualValue);
@@ -301,23 +349,33 @@
private ByteString getActualValue(Entry entry, Modification mod)
{
- List<Attribute> attributes = entry.getAttribute(mod.getAttribute().getAttributeType());
+ return getActualValue(entry.getAttribute(mod.getAttribute().getAttributeType()));
+ }
+
+ private ByteString getActualValue(List<Attribute> attributes)
+ {
if (attributes != null)
{
assertThat(attributes).hasSize(1);
- return uniqueValue(attributes.get(0));
+ Attribute attribute = attributes.get(0);
+ assertThat(attribute).hasSize(1);
+ return attribute.iterator().next();
}
return null;
}
- private ByteString uniqueValue(Attribute attribute)
+ private void assertNoAttributeValue(Entry entry)
{
- assertThat(attribute).hasSize(1);
- ByteString attrValue = attribute.iterator().next();
- return attrValue;
+ assertAttributeValue(entry, (String) null);
}
- private void verifyModNotReplayed(Iterator<Modification> it)
+ private void assertAttributeValue(Entry entry, String expectedValue)
+ {
+ ByteString actualValue = getActualValue(entry.getAttribute(ATTRIBUTE_NAME));
+ assertEquals(actualValue, expectedValue != null ? ByteString.valueOf(expectedValue) : null);
+ }
+
+ private void verifyModSuppressed(Iterator<Modification> it)
{
verify(it, times(1)).remove();
verify(it, only()).remove();
--
Gitblit v1.10.0