AttrHistorical*Test.java: additional asserts
AttrHistorical*Test.java:
Added asserts on the attribute value after each modification replay.
| | |
| | | } |
| | | } |
| | | |
| | | private static final String ATTRIBUTE_NAME = "description"; |
| | | |
| | | private CSNGenerator csnGen = new CSNGenerator(1025, System.currentTimeMillis()); |
| | | private AttrHistoricalMultiple attrHist; |
| | | private CSN csn; |
| | |
| | | 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); |
| | | |
| | |
| | | { |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | mod = newModification(ADD, "Y"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | assertAttributeValues(entry, "Y"); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | { |
| | | mod = newModification(DELETE, "Y"); |
| | | replayOperationSuppressMod(csn, entry, mod, E.CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | mod = newModification(DELETE, "X"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | | @Test |
| | |
| | | { |
| | | 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 |
| | |
| | | { |
| | | mod = newModification(REPLACE, "X"); |
| | | replayOperation(csn, entry, mod, E.NO_CONFLICT); |
| | | assertAttributeValues(entry, "X"); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | mod = newModification(REPLACE, "Y"); |
| | | replayOperationSuppressMod(t[1], entry, mod, E.CONFLICT_BUT_SHOULD_NOT_BE); |
| | | assertAttributeValues(entry, "Y"); |
| | | } |
| | | |
| | | private CSN[] newCSNs(int nb) |
| | |
| | | |
| | | 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) |
| | |
| | | { |
| | | 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, |
| | |
| | | |
| | | 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); |
| | |
| | | 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(); |
| | |
| | | @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; |
| | |
| | | { |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | { |
| | | mod = newModification(DELETE, "X"); |
| | | replayOperationSuppressMod(csn, entry, mod, CONFLICT); |
| | | assertNoAttributeValue(entry); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | 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"); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | mod = newModification(ADD, "X"); |
| | | entry.applyModification(mod); |
| | | assertAttributeValue(entry, "X"); |
| | | |
| | | mod = newModification(DELETE, "Y"); |
| | | replayOperationSuppressMod(t[1], entry, mod, CONFLICT); |
| | | assertAttributeValue(entry, "X"); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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 |
| | |
| | | |
| | | 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 |
| | |
| | | |
| | | 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) |
| | |
| | | { |
| | | 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, |
| | |
| | | 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); |
| | |
| | | |
| | | 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(); |