use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.
the class PeerAssociationRepoEventIT method testRemovePeerAssociation.
@Test
public void testRemovePeerAssociation() {
final NodeRef content1NodeRef = createNode(ContentModel.TYPE_CONTENT);
final NodeRef content2NodeRef = createNode(ContentModel.TYPE_CONTENT);
checkNumOfEvents(2);
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());
// Create peer association
retryingTransactionHelper.doInTransaction(() -> nodeService.createAssociation(content1NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL));
List<AssociationRef> peerAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
assertEquals(1, peerAssociationRefs.size());
checkNumOfEvents(4);
// Remove peer association
retryingTransactionHelper.doInTransaction(() -> {
nodeService.removeAssociation(content1NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL);
return null;
});
peerAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
assertEquals(0, peerAssociationRefs.size());
checkNumOfEvents(6);
// Check the peer assoc created event
final RepoEvent<EventData<PeerAssociationResource>> peerAssocRepoEvent = getFilteredEvent(EventType.PEER_ASSOC_CREATED, 0);
assertEquals("Wrong repo event type.", EventType.PEER_ASSOC_CREATED.getType(), peerAssocRepoEvent.getType());
assertNotNull("Repo event ID is not available. ", peerAssocRepoEvent.getId());
assertNotNull("Source is not available", peerAssocRepoEvent.getSource());
assertEquals("Repo event source is not available. ", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), peerAssocRepoEvent.getSource().toString());
assertNotNull("Repo event creation time is not available. ", peerAssocRepoEvent.getTime());
assertEquals("Repo event datacontenttype", "application/json", peerAssocRepoEvent.getDatacontenttype());
assertNotNull(peerAssocRepoEvent.getDataschema());
assertEquals(EventJSONSchema.PEER_ASSOC_CREATED_V1.getSchema(), peerAssocRepoEvent.getDataschema());
final EventData<PeerAssociationResource> nodeResourceEventData = getEventData(peerAssocRepoEvent);
// EventData attributes
assertNotNull("Event data group ID is not available. ", nodeResourceEventData.getEventGroupId());
assertNull("resourceBefore property is not available", nodeResourceEventData.getResourceBefore());
final PeerAssociationResource peerAssociationResource = getPeerAssocResource(peerAssocRepoEvent);
assertEquals("Wrong source", content1NodeRef.getId(), peerAssociationResource.getSource().getId());
assertEquals("Wrong target", content2NodeRef.getId(), peerAssociationResource.getTarget().getId());
assertEquals("Wrong assoc type", "cm:original", peerAssociationResource.getAssocType());
// Check the peer assoc deleted event
final RepoEvent<EventData<PeerAssociationResource>> peerAssocRepoEvent2 = getFilteredEvent(EventType.PEER_ASSOC_DELETED, 0);
assertEquals("Wrong repo event type.", EventType.PEER_ASSOC_DELETED.getType(), peerAssocRepoEvent2.getType());
assertNotNull("Repo event ID is not available. ", peerAssocRepoEvent2.getId());
assertNotNull("Source is not available", peerAssocRepoEvent2.getSource());
assertEquals("Repo event source is not available. ", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), peerAssocRepoEvent2.getSource().toString());
assertNotNull("Repo event creation time is not available. ", peerAssocRepoEvent2.getTime());
assertEquals("Repo event datacontenttype", "application/json", peerAssocRepoEvent2.getDatacontenttype());
assertNotNull(peerAssocRepoEvent2.getDataschema());
assertEquals(EventJSONSchema.PEER_ASSOC_DELETED_V1.getSchema(), peerAssocRepoEvent2.getDataschema());
final EventData<PeerAssociationResource> nodeResourceEventData2 = getEventData(peerAssocRepoEvent2);
// EventData attributes
assertNotNull("Event data group ID is not available. ", nodeResourceEventData2.getEventGroupId());
assertNull("resourceBefore property is not available", nodeResourceEventData2.getResourceBefore());
final PeerAssociationResource peerAssociationResource2 = getPeerAssocResource(peerAssocRepoEvent2);
assertEquals("Wrong source", content1NodeRef.getId(), peerAssociationResource2.getSource().getId());
assertEquals("Wrong target", content2NodeRef.getId(), peerAssociationResource2.getTarget().getId());
assertEquals("Wrong assoc type", "cm:original", peerAssociationResource2.getAssocType());
}
use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.
the class UpdateRepoEventIT method testCreateAndUpdateNodeTypeInTheSameTransaction.
@Test
public void testCreateAndUpdateNodeTypeInTheSameTransaction() {
retryingTransactionHelper.doInTransaction(() -> {
final NodeRef nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef();
// old type
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
nodeService.setType(nodeRef, ContentModel.TYPE_FOLDER);
// new type
assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(nodeRef));
return null;
});
// we should have only 1 event, node.Created
checkNumOfEvents(1);
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
NodeResource nodeResource = getNodeResource(resultRepoEvent);
assertEquals("Incorrect node type was found", "cm:folder", nodeResource.getNodeType());
}
use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.
the class UpdateRepoEventIT method testUpdateTwiceNodeTypeInTheSameTransaction.
@Test
public void testUpdateTwiceNodeTypeInTheSameTransaction() {
final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
// node.Created event should be generated
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
NodeResource nodeResource = getNodeResource(resultRepoEvent);
assertEquals("Incorrect node type was found", "cm:content", nodeResource.getNodeType());
// old type
assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
retryingTransactionHelper.doInTransaction(() -> {
nodeService.setType(nodeRef, ContentModel.TYPE_FOLDER);
nodeService.setType(nodeRef, ContentModel.TYPE_CONTENT);
// new type
assertEquals("Wrong node type", ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
return null;
});
// we should have only 2 events, node.Created and node.Updated
checkNumOfEvents(2);
resultRepoEvent = getRepoEvent(2);
assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
nodeResource = getNodeResource(resultRepoEvent);
assertEquals("Incorrect node type was found", "cm:content", nodeResource.getNodeType());
NodeResource resourceBefore = getNodeResourceBefore(2);
assertEquals("Incorrect node type was found", "cm:folder", resourceBefore.getNodeType());
// assertNotNull(resourceBefore.getModifiedAt()); uncomment this when the issue will be fixed
assertNull(resourceBefore.getId());
assertNull(resourceBefore.getContent());
assertNull(resourceBefore.isFile());
assertNull(resourceBefore.isFolder());
assertNull(resourceBefore.getModifiedByUser());
assertNull(resourceBefore.getCreatedAt());
assertNull(resourceBefore.getCreatedByUser());
assertNull(resourceBefore.getProperties());
assertNull(resourceBefore.getAspectNames());
assertNull(resourceBefore.getPrimaryHierarchy());
}
use of com.ibm.watson.discovery.v1.model.EventData in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method createEventIsSuccessful.
/**
* Creates the event is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void createEventIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(createEventResp));
Long displayRank = 1L;
String sessionToken = "mock_session_token";
EventData eventData = new EventData.Builder().environmentId(environmentId).collectionId(collectionId).documentId(documentId).displayRank(displayRank).sessionToken(sessionToken).clientTimestamp(date).build();
CreateEventOptions createEventOptions = new CreateEventOptions.Builder().type(CreateEventOptions.Type.CLICK).data(eventData).build();
CreateEventResponse response = discoveryService.createEvent(createEventOptions).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(CREATE_EVENT_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(CreateEventOptions.Type.CLICK, response.getType());
assertEquals(environmentId, response.getData().environmentId());
assertEquals(collectionId, response.getData().collectionId());
assertEquals(documentId, response.getData().documentId());
assertNotNull(response.getData().clientTimestamp());
assertEquals(displayRank, response.getData().displayRank());
assertEquals(queryId, response.getData().queryId());
assertEquals(sessionToken, response.getData().sessionToken());
}
use of com.ibm.watson.discovery.v1.model.EventData in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testCreateEventWOptions.
// Test the createEvent operation with a valid options model parameter
@Test
public void testCreateEventWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"type\": \"click\", \"data\": {\"environment_id\": \"environmentId\", \"session_token\": \"sessionToken\", \"client_timestamp\": \"2019-01-01T12:00:00.000Z\", \"display_rank\": 11, \"collection_id\": \"collectionId\", \"document_id\": \"documentId\", \"query_id\": \"queryId\"}}";
String createEventPath = "/v1/events";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the EventData model
EventData eventDataModel = new EventData.Builder().environmentId("testString").sessionToken("testString").clientTimestamp(DateUtils.parseAsDateTime("2019-01-01T12:00:00.000Z")).displayRank(Long.valueOf("26")).collectionId("testString").documentId("testString").build();
// Construct an instance of the CreateEventOptions model
CreateEventOptions createEventOptionsModel = new CreateEventOptions.Builder().type("click").data(eventDataModel).build();
// Invoke createEvent() with a valid options model and verify the result
Response<CreateEventResponse> response = discoveryService.createEvent(createEventOptionsModel).execute();
assertNotNull(response);
CreateEventResponse responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, createEventPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
Aggregations