/** * Asserts that the manifest content within the "conversation" tag matches an * expected string. */ private void assertManifestXml(final String expected) { manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { XmlStringBuilder exp = XmlStringBuilder.createFromXmlString(expected); assertStructureEquivalent(exp.wrap("conversation"), doc); } }); }
/** * Asserts that the manifest content within the "conversation" tag matches an * expected string. */ private void assertManifestXml(final String expected) { manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { XmlStringBuilder exp = XmlStringBuilder.createFromXmlString(expected); assertStructureEquivalent(exp.wrap("conversation"), doc); } }); }
/** * Tests that WaveletBasedConversation does not die if an additional * conversation element is added to the manifest dynamically. */ public void testDynamicAdditionOfExtraConversationElementDoesNotFail() { // target is currently listening to the manifest, so we only need to poke it. manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { doc.createChildElement(doc.getDocumentElement(), DocumentBasedManifest.MANIFEST_TOP_TAG, Collections.<String, String>emptyMap()); } }); }
/** * Tests that WaveletBasedConversation does not die if an additional * conversation element is added to the manifest dynamically. */ public void testDynamicAdditionOfExtraConversationElementDoesNotFail() { // target is currently listening to the manifest, so we only need to poke it. manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { doc.createChildElement(doc.getDocumentElement(), DocumentBasedManifest.MANIFEST_TOP_TAG, Collections.<String, String>emptyMap()); } }); }
/** * Creates a Permissions view on top of the document. */ public static DocumentBasedRoles create(final ObservableMutableDocument<?, ?, ?> document) { return document.with(new Method<DocumentBasedRoles>() { @Override public <N, E extends N, T extends N> DocumentBasedRoles exec( ObservableMutableDocument<N, E, T> doc) { return new DocumentBasedRoles( DocumentBasedElementList.create(DefaultDocumentEventRouter.create(doc), doc.getDocumentElement(), ASSIGN_TAG, DocumentBasedAssignment.<E>factory())); } }); }
/** * Adds an entry to the target map's underlying state. This simulates a * concurrent modification by some other agent. */ private void addEntry(final Boolean state) { doc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(ObservableMutableDocument<N, E, T> doc) { E container = doc.getDocumentElement(); // Insert entries Attributes attrs = state != null ? new AttributesImpl(VALUE_ATTR, state.toString()) : Attributes.EMPTY_MAP; doc.createChildElement(container, ENTRY_TAG, attrs); } }); }
/** * Adds an entry to the target map's underlying state. This simulates a * concurrent modification by some other agent. */ private void addEntry(final Boolean state) { doc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(ObservableMutableDocument<N, E, T> doc) { E container = doc.getDocumentElement(); // Insert entries Attributes attrs = state != null ? new AttributesImpl(VALUE_ATTR, state.toString()) : Attributes.EMPTY_MAP; doc.createChildElement(container, ENTRY_TAG, attrs); } }); }
/** * Checks the document state. * * @param state the document state specified in terms of entries */ private void assertSubstrate(final List<Boolean> state) { doc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(ObservableMutableDocument<N, E, T> doc) { E container = doc.getDocumentElement(); E entry = DocHelper.getFirstChildElement(doc, container); // Skip over anything we don't care about while (entry != null && !ENTRY_TAG.equals(doc.getTagName(entry))) { entry = DocHelper.getNextSiblingElement(doc, entry); } for (Boolean b : state) { assertNotNull(entry); Attributes attrs = b != null ? new AttributesImpl(VALUE_ATTR, b.toString()) : Attributes.EMPTY_MAP; assertEquals(attrs, doc.getAttributes(entry)); entry = DocHelper.getNextSiblingElement(doc, entry); // Skip over anything we don't care about while (entry != null && !ENTRY_TAG.equals(doc.getTagName(entry))) { entry = DocHelper.getNextSiblingElement(doc, entry); } } assertNull("Unexpected element in subtrate: " + entry, entry); } }); }
/** * Checks the document state. * * @param state the document state specified in terms of entries */ private void assertSubstrate(final List<Boolean> state) { doc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(ObservableMutableDocument<N, E, T> doc) { E container = doc.getDocumentElement(); E entry = DocHelper.getFirstChildElement(doc, container); // Skip over anything we don't care about while (entry != null && !ENTRY_TAG.equals(doc.getTagName(entry))) { entry = DocHelper.getNextSiblingElement(doc, entry); } for (Boolean b : state) { assertNotNull(entry); Attributes attrs = b != null ? new AttributesImpl(VALUE_ATTR, b.toString()) : Attributes.EMPTY_MAP; assertEquals(attrs, doc.getAttributes(entry)); entry = DocHelper.getNextSiblingElement(doc, entry); // Skip over anything we don't care about while (entry != null && !ENTRY_TAG.equals(doc.getTagName(entry))) { entry = DocHelper.getNextSiblingElement(doc, entry); } } assertNull("Unexpected element in subtrate: " + entry, entry); } }); }
/** * Tests that WaveletBasedConversation does not die if it is loaded on a * manifest document with multiple conversation elements. */ public void testMultipleConversationElementsDoesNotPreventLoad() { manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { doc.createChildElement(doc.getDocumentElement(), DocumentBasedManifest.MANIFEST_TOP_TAG, Collections.<String, String>emptyMap()); } }); // Manifest now has multiple elements. Re-load conversation view. conversationView = WaveBasedConversationView.create(waveView, idGenerator); }
/** * Tests that WaveletBasedConversation does not die if it is loaded on a * manifest document with multiple conversation elements. */ public void testMultipleConversationElementsDoesNotPreventLoad() { manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { doc.createChildElement(doc.getDocumentElement(), DocumentBasedManifest.MANIFEST_TOP_TAG, Collections.<String, String>emptyMap()); } }); // Manifest now has multiple elements. Re-load conversation view. conversationView = WaveBasedConversationView.create(waveView, idGenerator); }
public void testWriteDoesNotCleanupForeignElements() { createTargetOn(Arrays.asList(false, true)); // Add some random element. final Object foreign = doc.with(new Method<Object>() { @Override public <N, E extends N, T extends N> Object exec(MutableDocument<N, E, T> doc) { return doc.createChildElement(doc.getDocumentElement(), "foreign", Attributes.EMPTY_MAP); } }); target.set(null); // Verify that the random element remains. doc.with(new MutableDocument.Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E top = DocHelper.getFirstChildElement(doc, doc.getDocumentElement()); assertEquals(foreign, top); assertNull(doc.getNextSibling(top)); } }); } }
public void testWriteDoesNotCleanupForeignElements() { createTargetOn(Arrays.asList(false, true)); // Add some random element. final Object foreign = doc.with(new Method<Object>() { @Override public <N, E extends N, T extends N> Object exec(MutableDocument<N, E, T> doc) { return doc.createChildElement(doc.getDocumentElement(), "foreign", Attributes.EMPTY_MAP); } }); target.set(null); // Verify that the random element remains. doc.with(new MutableDocument.Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { E top = DocHelper.getFirstChildElement(doc, doc.getDocumentElement()); assertEquals(foreign, top); assertNull(doc.getNextSibling(top)); } }); } }
/** * Creates a document-based boolean. */ private void createTargetOn(final List<Boolean> state) { doc = BasicFactories.observableDocumentProvider().create("blort", Attributes.EMPTY_MAP); for (Boolean b : state) { addEntry(b); } doc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(ObservableMutableDocument<N, E, T> doc) { target = DocumentBasedBoolean.create(DefaultDocumentEventRouter.create(doc), doc.getDocumentElement(), ENTRY_TAG, VALUE_ATTR); } }); }
/** * Creates a document-based boolean. */ private void createTargetOn(final List<Boolean> state) { doc = BasicFactories.observableDocumentProvider().create("blort", Attributes.EMPTY_MAP); for (Boolean b : state) { addEntry(b); } doc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(ObservableMutableDocument<N, E, T> doc) { target = DocumentBasedBoolean.create(DefaultDocumentEventRouter.create(doc), doc.getDocumentElement(), ENTRY_TAG, VALUE_ATTR); } }); }
/** * Test that we can cope with blips being added to the manifest but not to the * wavelet. */ public void testAddingBlipMissingFromWavelet() { manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { N rootThreadNode = doc.getFirstChild(doc.getDocumentElement()); E rootThread = doc.asElement(rootThreadNode); doc.createChildElement(rootThread, "blip", Collections.singletonMap( "id", idGenerator.newBlipId())); } }); assertNull(target.getRootThread().getFirstBlip()); assertEquals(Collections.emptyList(), getBlipList(target.getRootThread())); }
/** * Test that we can cope with blips being added to the manifest but not to the * wavelet. */ public void testAddingBlipMissingFromWavelet() { manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { N rootThreadNode = doc.getFirstChild(doc.getDocumentElement()); E rootThread = doc.asElement(rootThreadNode); doc.createChildElement(rootThread, "blip", Collections.singletonMap( "id", idGenerator.newBlipId())); } }); assertNull(target.getRootThread().getFirstBlip()); assertEquals(Collections.emptyList(), getBlipList(target.getRootThread())); }
/** * Test that iterating a thread whose manifest contains blips not backed by the * wavelet skips those blips. */ public void testMissingBlipIteration() { WaveletBasedConversationThread thread = target.getRootThread(); WaveletBasedConversationBlip first = thread.appendBlip(); manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { N rootThreadNode = doc.getFirstChild(doc.getDocumentElement()); E rootThread = doc.asElement(rootThreadNode); doc.createChildElement(rootThread, "blip", Collections.singletonMap( "id", idGenerator.newBlipId())); } }); WaveletBasedConversationBlip third = thread.appendBlip(); assertEquals(3, CollectionUtils.newArrayList(thread.getManifestThread().getBlips()).size()); assertEquals(Arrays.asList(first, third), getBlipList(thread)); }
/** * Test that iterating a thread whose manifest contains blips not backed by the * wavelet skips those blips. */ public void testMissingBlipIteration() { WaveletBasedConversationThread thread = target.getRootThread(); WaveletBasedConversationBlip first = thread.appendBlip(); manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) { N rootThreadNode = doc.getFirstChild(doc.getDocumentElement()); E rootThread = doc.asElement(rootThreadNode); doc.createChildElement(rootThread, "blip", Collections.singletonMap( "id", idGenerator.newBlipId())); } }); WaveletBasedConversationBlip third = thread.appendBlip(); assertEquals(3, CollectionUtils.newArrayList(thread.getManifestThread().getBlips()).size()); assertEquals(Arrays.asList(first, third), getBlipList(thread)); }
manifestDoc.with(new Action() { @Override public <N, E extends N, T extends N> void exec(MutableDocument<N, E, T> doc) {