@Test public void shouldDeletePendingEmails() throws Exception { Message<?> message = new AllMessage<String>(MessEngineConstants.DELETE_PENDING_EMAILS_TYPE, "delete"); messEngine.send(message); verify(defaultTemplate).delete(anyString(), eq(message.getBody())); }
@Test public void shouldReturnNullResponseIfLibraryBackendFails() throws Exception { when(syncTemplate.postForObject( anyString(), eq(JsonConverter.toJson(request)), eq(String.class))) .thenThrow(new RuntimeException("Some server error")); messEngine.send(mergeRequest); @SuppressWarnings("unchecked") Message<SyncValueObject> response = (Message<SyncValueObject>) messEngine.getMessage(MessEngineConstants.SYNC_LIBRARY_MERGE_RESPONSE); assertNotNull(response); assertNull(response.getBody()); }
@Test public void shouldForwardMergeRequestsToLibraryBackend() throws Exception { when(syncTemplate.postForObject( anyString(), eq(JsonConverter.toJson(request)), eq(String.class))) .thenReturn(JsonConverter.toJson(expectedResponse)); messEngine.send(mergeRequest); @SuppressWarnings("unchecked") Message<SyncValueObject> response = (Message<SyncValueObject>) messEngine.getMessage(MessEngineConstants.SYNC_LIBRARY_MERGE_RESPONSE); assertNotNull(response); assertEquals(expectedResponse, response.getBody()); }
@Test public void shouldGetLocalFeeds() throws Exception { when(defaultTemplate.getForObject(anyString(), eq(String.class), eq(feedUserIdRequest))) .thenReturn(JsonConverter.toJson(expectedFeedResponse)); messEngine.send(localFeedsRequest); @SuppressWarnings("unchecked") Message<FeedsResponse> response = (Message<FeedsResponse>) messEngine.getMessage(MessEngineConstants.FEEDS_LOCAL_RESPONSE); assertNotNull(response); assertEquals(expectedFeedResponse.getFeeds(), response.getBody().getFeeds()); assertEquals(expectedFeedResponse.getOwnerId(), response.getBody().getOwnerId()); assertEquals( expectedFeedResponse.getCurrentServerTime(), response.getBody().getCurrentServerTime()); }
@Test public void shouldReturnSameRequestWithoutEventsIfCannotCommitDeltaToLibraryBackend() throws Exception { when(syncTemplate.postForObject( anyString(), eq(JsonConverter.toJson(request)), eq(String.class))) .thenThrow(new RuntimeException("Some server error")); assertNotNull(request.getEvents()); messEngine.send(commitRequest); @SuppressWarnings("unchecked") Message<SyncValueObject> response = (Message<SyncValueObject>) messEngine.getMessage(MessEngineConstants.SYNC_SEND_DELTA_RESPONSE); assertNotNull(response); assertEquals(request, response.getBody()); assertNull(request.getEvents()); }
@Test public void shouldGetAlerts() throws Exception { @SuppressWarnings("deprecation") MusicContentAlert alert = new MusicContentAlert( new ContactInfo(), new ContactInfo(), new Date(), new ModelCollection(), "message"); List<Alert> expectedList = new ArrayList<Alert>(); expectedList.add(alert); String userId = "userID"; when(defaultTemplate.getForObject(anyString(), eq(String.class), eq(userId))) .thenReturn(JsonConverter.toJson(expectedList)); messEngine.send(new AllMessage<String>(MessEngineConstants.ALERTS_REQUEST_TYPE, userId)); verify(defaultTemplate).getForObject(anyString(), eq(String.class), eq(userId)); Message<?> responseMessage = messEngine.getMessage(MessEngineConstants.ALERTS_RESPONSE_TYPE); assertNotNull(responseMessage); assertEquals(expectedList, responseMessage.getBody()); }
@Test public void shouldUpdateContactProfile() throws Exception { @SuppressWarnings("deprecation") ContactInfo contactInfo = new ContactInfo(); contactInfo.setEmail("*****@*****.**"); contactInfo.setId(1L); Message<?> message = new AllMessage<ContactInfo>( MessEngineConstants.UPDATE_CONTACT_PROFILE_REQUEST, contactInfo); when(defaultTemplate.postForObject( anyString(), eq(JsonConverter.toJson(contactInfo)), eq(String.class))) .thenReturn(JsonConverter.toJson(contactInfo)); messEngine.send(message); verify(defaultTemplate) .postForObject(anyString(), eq(JsonConverter.toJson(contactInfo)), eq(String.class)); Message<?> response = messEngine.getMessage(MessEngineConstants.UPDATE_CONTACT_PROFILE_RESPONSE); assertNotNull(response); assertEquals(contactInfo, response.getBody()); }
@Test public void shouldForwardCommitRequestToLibraryBackendAndReturnResponseWithoutEvents() throws Exception { when(syncTemplate.postForObject( anyString(), eq(JsonConverter.toJson(request)), eq(String.class))) .thenReturn(JsonConverter.toJson(expectedResponse)); assertNotNull(request.getEvents()); assertNotNull(expectedResponse.getEvents()); messEngine.send(commitRequest); @SuppressWarnings("unchecked") Message<SyncValueObject> response = (Message<SyncValueObject>) messEngine.getMessage(MessEngineConstants.SYNC_SEND_DELTA_RESPONSE); assertNotNull(response); SyncValueObject actualResponse = response.getBody(); assertEquals(expectedResponse, actualResponse); assertNull(actualResponse.getEvents()); }
@Test public void shouldCreatePendingEmail() throws Exception { final PendingEmail pendingEmail = new PendingEmail(1L, "*****@*****.**"); Message<?> message = new AllMessage<PendingEmail>(MessEngineConstants.SEND_EMAIL_TYPE, pendingEmail); when(defaultTemplate.postForObject( anyString(), eq(JsonConverter.toJson(message.getBody())), eq(String.class))) .thenAnswer( new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { pendingEmail.setId(100L); return JsonConverter.toJson(pendingEmail); } }); messEngine.send(message); assertNotNull(pendingEmail.getId()); Message<?> response = messEngine.getMessage(MessEngineConstants.PUSH_PENDING_EMAIL_TYPE); assertNotNull(response); PendingEmail actual = (PendingEmail) response.getBody(); assertEquals(pendingEmail.getId(), actual.getId()); }