示例#1
0
 @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()));
 }
示例#2
0
  @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());
  }
示例#3
0
  @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());
  }
示例#4
0
  @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());
  }
示例#5
0
  @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());
  }
示例#6
0
  @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());
  }
示例#7
0
 @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());
 }
示例#8
0
  @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());
  }
示例#9
0
  @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());
  }