public void testErrorOnFailingConnection() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(connector.fetchCapabilities(any(RobotAccountData.class), anyString())).thenThrow( new CapabilityFetchException("")); operationService.execute(operation, context, ROBOT); verify(accountStore, never()).putAccount(any(AccountData.class)); verify(context).constructErrorResponse(eq(operation), anyString()); }
public void testDontUpdateIfHashesMatch() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, OLD_HASH)); operationService.execute(operation, context, ROBOT); verifyZeroInteractions(connector); verify(accountStore, never()).putAccount(any(AccountData.class)); }
public void testDontUpdateIfHashesMatch() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, OLD_HASH)); operationService.execute(operation, context, ROBOT); verifyZeroInteractions(connector); verify(accountStore, never()).putAccount(any(AccountData.class)); }
/** * Constructs an instance representing an explicitly set range. * * @param blip the blip to represent. * @param start the start index of the range. * @param end the end index of the range. * @return an instance of blip references. */ public static BlipContentRefs range(Blip blip, int start, int end) { return new BlipContentRefs(blip, new BlipIterator.SingleshotIterator(blip, start, end), Parameter.of(ParamsProperty.RANGE, new Range(start, end))); }
public void testAnnotate() throws Exception { OperationRequest operation = operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId, Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.ANNOTATE, Collections.singletonList(ANNOTATION_VALUE), ANNOTATION_KEY, NO_ELEMENTS, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.INDEX, CONTENT_START_TEXT)); service.execute(operation, helper.getContext(), ALEX); String annotation = getRootBlip().getContent().getAnnotation(CONTENT_START_XML, ANNOTATION_KEY); assertEquals("Expected the text to be annotated", ANNOTATION_VALUE, annotation); assertNull("Expected this text not to be annotated", getRootBlip().getContent().getAnnotation(CONTENT_START_XML + 1, ANNOTATION_KEY)); }
/** * Appends a new blip to the end of the thread of the given blip. * * @param blip the blip whose thread will be appended. * @return an instance of {@link Blip} that represents the new blip. */ public Blip continueThreadOfBlip(Blip blip) { Blip newBlip = newBlip(blip.getWavelet(), "", blip.getParentBlipId(), generateTempBlipId(blip.getWavelet()), blip.getThread().getId()); appendOperation(OperationType.BLIP_CONTINUE_THREAD, blip, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
public void testFailOnMultipleWhereParams() throws Exception { OperationRequest operation = operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId, Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction()), Parameter.of(ParamsProperty.RANGE, new Range(0, 1)), Parameter.of(ParamsProperty.INDEX, 0)); try { service.execute(operation, helper.getContext(), ALEX); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } }
public void testAnnotate() throws Exception { OperationRequest operation = operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId, Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.ANNOTATE, Collections.singletonList(ANNOTATION_VALUE), ANNOTATION_KEY, NO_ELEMENTS, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.INDEX, CONTENT_START_TEXT)); service.execute(operation, helper.getContext(), ALEX); String annotation = getRootBlip().getContent().getAnnotation(CONTENT_START_XML, ANNOTATION_KEY); assertEquals("Expected the text to be annotated", ANNOTATION_VALUE, annotation); assertNull("Expected this text not to be annotated", getRootBlip().getContent().getAnnotation(CONTENT_START_XML + 1, ANNOTATION_KEY)); }
/** * Appends a blip to a wavelet. * * @param wavelet the wavelet to append the new blip to. * @param initialContent the initial content of the new blip. * @return an instance of {@link Blip} that represents the new blip. */ public Blip appendBlipToWavelet(Wavelet wavelet, String initialContent) { Blip newBlip = newBlip(wavelet, initialContent, null, generateTempBlipId(wavelet), wavelet.getRootThread().getId()); appendOperation(OperationType.WAVELET_APPEND_BLIP, wavelet, Parameter.of(ParamsProperty.BLIP_DATA, newBlip.serialize())); return newBlip; }
public void testDelete() throws Exception { OperationRequest operation = operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId, Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.DELETE, NO_VALUES, NO_ANNOTATION_KEY, NO_ELEMENTS, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.INDEX, CONTENT_START_TEXT)); service.execute(operation, helper.getContext(), ALEX); // Cut off the /n String after = getApiView().apiContents().substring(1); assertEquals("First character should be deleted", INITIAL_CONTENT.substring(1), after); }
/** * Modifies the role of a participant in a wavelet. * * @param wavelet the wavelet that the participant is on * @param participant whose role to modify * @param role to set for the participant */ public void modifyParticipantRoleOfWavelet(Wavelet wavelet, String participant, String role) { appendOperation(OperationType.WAVELET_MODIFY_PARTICIPANT_ROLE, wavelet, Parameter.of(ParamsProperty.PARTICIPANT_ID, participant), Parameter.of(ParamsProperty.PARTICIPANT_ROLE, role)); }
/** * Appends content with markup to a blip. * * @param blip the blip where this markup content should be added to. * @param content the markup content that should be added to the blip. */ public void appendMarkupToDocument(Blip blip, String content) { appendOperation(OperationType.DOCUMENT_APPEND_MARKUP, blip, Parameter.of(ParamsProperty.CONTENT, content)); }
/** * Sets the title of a wavelet. * * @param wavelet the wavelet whose title will be changed. * @param title the new title to be set. */ public void setTitleOfWavelet(Wavelet wavelet, String title) { appendOperation(OperationType.WAVELET_SET_TITLE, wavelet, Parameter.of(ParamsProperty.WAVELET_TITLE, title)); }
/** * Sets a key-value pair on the data document of a wavelet. * * @param wavelet to set the data document on. * @param name the name of this data. * @param value the value of this data. */ public void setDatadocOfWavelet(Wavelet wavelet, String name, String value) { appendOperation(OperationType.WAVELET_SET_DATADOC, wavelet, Parameter.of(ParamsProperty.DATADOC_NAME, name), Parameter.of(ParamsProperty.DATADOC_VALUE, value)); }
/** * Export attachment. * * @param attachmentId the id of attachment. */ public void exportAttachment(AttachmentId attachmentId) { appendOperation(OperationType.ROBOT_EXPORT_ATTACHMENT, Parameter.of(ParamsProperty.ATTACHMENT_ID, attachmentId.serialise())); }
/** * Adds a participant to a wavelet. * * @param wavelet the wavelet that the new participant should be added to. * @param participantId the id of the new participant. */ public void addParticipantToWavelet(Wavelet wavelet, String participantId) { appendOperation(OperationType.WAVELET_ADD_PARTICIPANT_NEWSYNTAX, wavelet, Parameter.of(ParamsProperty.PARTICIPANT_ID, participantId)); }
public void testUpdateCapabilites() throws Exception { OperationRequest operation = new OperationRequest( "robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); operationService.execute(operation, context, ROBOT); verify(connector).fetchCapabilities(eq(ROBOT_ACCOUNT), anyString()); verify(accountStore).putAccount(NEW_ROBOT_ACCOUNT); }
public void testDelete() throws Exception { OperationRequest operation = operationRequest(OperationType.DOCUMENT_MODIFY, rootBlipId, Parameter.of(ParamsProperty.MODIFY_ACTION, new DocumentModifyAction(ModifyHow.DELETE, NO_VALUES, NO_ANNOTATION_KEY, NO_ELEMENTS, NO_BUNDLED_ANNOTATIONS, false)), Parameter.of(ParamsProperty.INDEX, CONTENT_START_TEXT)); service.execute(operation, helper.getContext(), ALEX); // Cut off the /n String after = getApiView().apiContents().substring(1); assertEquals("First character should be deleted", INITIAL_CONTENT.substring(1), after); }
/** * Imports deltas of wavelet. * * @param waveId the id of the wave that should be imported. * @param waveletId the id of the wavelet that should be imported. * @param history the history in deltas. */ public void importRawDeltas(WaveId waveId, WaveletId waveletId, List<byte[]> history) { appendOperation(OperationType.ROBOT_IMPORT_DELTAS, waveId, waveletId, null, Parameter.of(ParamsProperty.RAW_DELTAS, history)); }
/** * Removes a participant from a wavelet. * * @param wavelet the wavelet that the participant should be removed from. * @param participantId the id of the participant to be removed. */ public void removeParticipantFromWavelet(Wavelet wavelet, String participantId) { appendOperation(OperationType.WAVELET_REMOVE_PARTICIPANT_NEWSYNTAX, wavelet, Parameter.of(ParamsProperty.PARTICIPANT_ID, participantId)); }