Search in sources :

Example 31 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-java-sdk by Alfresco.

the class AssocTypeFilterTest method should_testTrue_when_assocEventWithCorrespondingAssocTypeIsSent.

@Test
public void should_testTrue_when_assocEventWithCorrespondingAssocTypeIsSent() {
    final PeerAssociationResource peerAssociationResource = new PeerAssociationResource("source-id", "target-id", TEST_ASSOC_TYPE);
    final EventData<PeerAssociationResource> eventData = EventData.<PeerAssociationResource>builder().setResource(peerAssociationResource).build();
    final RepoEvent<? extends DataAttributes<? extends Resource>> repoEvent = RepoEvent.<EventData<PeerAssociationResource>>builder().setData(eventData).build();
    final boolean result = assocTypeFilter.test((RepoEvent<DataAttributes<Resource>>) repoEvent);
    assertThat(result).isTrue();
}
Also used : PeerAssociationResource(org.alfresco.event.sdk.model.v1.model.PeerAssociationResource) DataAttributes(org.alfresco.event.sdk.model.v1.model.DataAttributes) EventData(org.alfresco.event.sdk.model.v1.model.EventData) Test(org.junit.Test)

Example 32 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.

the class ChildAssociationRepoEventIT method testOneParentMultipleChildrenDifferentTransaction.

@Test
public void testOneParentMultipleChildrenDifferentTransaction() {
    final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef child1NodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef child2NodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef child3NodeRef = createNode(ContentModel.TYPE_CONTENT);
    List<NodeRef> children = Arrays.asList(child1NodeRef, child2NodeRef, child3NodeRef);
    checkNumOfEvents(4);
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(2);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(3);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(4);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    for (NodeRef child : children) {
        retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parentNodeRef, child, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
    }
    retryingTransactionHelper.doInTransaction(() -> {
        List<ChildAssociationRef> childAssocParent = nodeService.getChildAssocs(parentNodeRef);
        assertEquals(3, childAssocParent.size());
        return null;
    });
    checkNumOfEvents(7);
    // 3 assoc.child.Created events should be created
    List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
    assertEquals("Wrong association events number", 3, childAssocEvents.size());
    assertEquals(parentNodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getParent().getId());
    assertEquals(child1NodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getChild().getId());
    assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(0)).getAssocType());
    assertEquals(parentNodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getParent().getId());
    assertEquals(child2NodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getChild().getId());
    assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(1)).getAssocType());
    assertEquals(parentNodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getParent().getId());
    assertEquals(child3NodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getChild().getId());
    assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(2)).getAssocType());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 33 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.

the class ChildAssociationRepoEventIT method testRemoveChildAssociation.

@Test
public void testRemoveChildAssociation() {
    final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
    checkNumOfEvents(2);
    RepoEvent<EventData<NodeResource>> parentRepoEvent = getRepoEventWithoutWait(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), parentRepoEvent.getType());
    RepoEvent<EventData<NodeResource>> childRepoEvent = getRepoEventWithoutWait(2);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), childRepoEvent.getType());
    ChildAssociationRef childAssociationRef = retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parentNodeRef, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
    List<ChildAssociationRef> childAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getChildAssocs(parentNodeRef));
    assertEquals(1, childAssociationRefs.size());
    assertFalse(childAssociationRefs.get(0).isPrimary());
    checkNumOfEvents(3);
    retryingTransactionHelper.doInTransaction(() -> nodeService.removeChildAssociation(childAssociationRef));
    childAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getChildAssocs(parentNodeRef));
    assertEquals(0, childAssociationRefs.size());
    checkNumOfEvents(4);
    final RepoEvent<EventData<ChildAssociationResource>> childAssocRepoEvent = getRepoEventWithoutWait(4);
    assertEquals("Wrong repo event type.", EventType.CHILD_ASSOC_DELETED.getType(), childAssocRepoEvent.getType());
    assertNotNull("Repo event ID is not available. ", childAssocRepoEvent.getId());
    assertNotNull("Source is not available", childAssocRepoEvent.getSource());
    assertEquals("Repo event source is not available. ", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), childAssocRepoEvent.getSource().toString());
    assertNotNull("Repo event creation time is not available. ", childAssocRepoEvent.getTime());
    assertEquals("Repo event datacontenttype", "application/json", childAssocRepoEvent.getDatacontenttype());
    assertNotNull(childAssocRepoEvent.getDataschema());
    assertEquals(EventJSONSchema.CHILD_ASSOC_DELETED_V1.getSchema(), childAssocRepoEvent.getDataschema());
    final EventData<ChildAssociationResource> nodeResourceEventData = getEventData(childAssocRepoEvent);
    // EventData attributes
    assertNotNull("Event data group ID is not available. ", nodeResourceEventData.getEventGroupId());
    assertNull("resourceBefore property is not available", nodeResourceEventData.getResourceBefore());
    final ChildAssociationResource childAssociationResource = getChildAssocResource(childAssocRepoEvent);
    assertEquals("Wrong parent", parentNodeRef.getId(), childAssociationResource.getParent().getId());
    assertEquals("Wrong child", childNodeRef.getId(), childAssociationResource.getChild().getId());
    assertEquals("Wrong assoc type", "cm:contains", childAssociationResource.getAssocType());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 34 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.

the class ChildAssociationRepoEventIT method testOneChildListOfParentsAssociations.

@Test
public void testOneChildListOfParentsAssociations() {
    final NodeRef parent1NodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef parent2NodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef parent3NodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
    List<NodeRef> parents = Arrays.asList(parent1NodeRef, parent2NodeRef, parent3NodeRef);
    checkNumOfEvents(4);
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(2);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(3);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(4);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parents, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
    retryingTransactionHelper.doInTransaction(() -> {
        List<ChildAssociationRef> childAssocParent1 = nodeService.getChildAssocs(parent1NodeRef);
        List<ChildAssociationRef> childAssocParent2 = nodeService.getChildAssocs(parent2NodeRef);
        List<ChildAssociationRef> childAssocParent3 = nodeService.getChildAssocs(parent3NodeRef);
        assertEquals(1, childAssocParent1.size());
        assertEquals(1, childAssocParent2.size());
        assertEquals(1, childAssocParent3.size());
        return null;
    });
    checkNumOfEvents(7);
    // 3 assoc.child.Created events should be created
    List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
    assertEquals("Wrong association events number", 3, childAssocEvents.size());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 35 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.

the class ChildAssociationRepoEventIT method testDeleteAssociationOneParentMultipleChildrenDifferentTransactions.

@Test
public void testDeleteAssociationOneParentMultipleChildrenDifferentTransactions() {
    final NodeRef parent1NodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef parent2NodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef parent3NodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
    List<NodeRef> parents = Arrays.asList(parent1NodeRef, parent2NodeRef, parent3NodeRef);
    checkNumOfEvents(4);
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(2);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(3);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    resultRepoEvent = getRepoEventWithoutWait(4);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parents, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
    List<ChildAssociationRef> listChildAssociationRefs = retryingTransactionHelper.doInTransaction(() -> {
        List<ChildAssociationRef> childAssocParent1 = nodeService.getChildAssocs(parent1NodeRef);
        List<ChildAssociationRef> childAssocParent2 = nodeService.getChildAssocs(parent2NodeRef);
        List<ChildAssociationRef> childAssocParent3 = nodeService.getChildAssocs(parent3NodeRef);
        assertEquals(1, childAssocParent1.size());
        assertEquals(1, childAssocParent2.size());
        assertEquals(1, childAssocParent3.size());
        return Arrays.asList(childAssocParent1.get(0), childAssocParent2.get(0), childAssocParent3.get(0));
    });
    for (ChildAssociationRef childAssociationRef : listChildAssociationRefs) {
        retryingTransactionHelper.doInTransaction(() -> nodeService.removeChildAssociation(childAssociationRef));
    }
    checkNumOfEvents(10);
    // 3 assoc.child.Deleted events should be created
    List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
    assertEquals("Wrong association events number", 3, childAssocEvents.size());
    assertEquals(parent1NodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getParent().getId());
    assertEquals(childNodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getChild().getId());
    assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(0)).getAssocType());
    assertEquals(parent2NodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getParent().getId());
    assertEquals(childNodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getChild().getId());
    assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(1)).getAssocType());
    assertEquals(parent3NodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getParent().getId());
    assertEquals(childNodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getChild().getId());
    assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(2)).getAssocType());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)79 EventData (org.alfresco.event.sdk.model.v1.model.EventData)54 DataAttributes (org.alfresco.event.sdk.model.v1.model.DataAttributes)52 NodeResource (org.alfresco.event.sdk.model.v1.model.NodeResource)51 EventData (org.alfresco.repo.event.v1.model.EventData)25 NodeRef (org.alfresco.service.cmr.repository.NodeRef)25 RepoEvent (org.alfresco.repo.event.v1.model.RepoEvent)12 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 ChildAssociationResource (org.alfresco.repo.event.v1.model.ChildAssociationResource)11 NodeResource (org.alfresco.repo.event.v1.model.NodeResource)8 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 PeerAssociationResource (org.alfresco.repo.event.v1.model.PeerAssociationResource)4 ContentInfo (org.alfresco.event.sdk.model.v1.model.ContentInfo)3 PeerAssociationResource (org.alfresco.event.sdk.model.v1.model.PeerAssociationResource)3 CreateEventOptions (com.ibm.watson.discovery.v1.model.CreateEventOptions)2 CreateEventResponse (com.ibm.watson.discovery.v1.model.CreateEventResponse)2 EventData (com.ibm.watson.discovery.v1.model.EventData)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2