Java Code Examples for scala.concurrent.Promise#trySuccess()

The following examples show how to use scala.concurrent.Promise#trySuccess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserTnCActorTest.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
@Test
public void testAcceptUserTncForBlockedUser() {
  Promise<Map<String, Object>> promise_recipientSearchQuery = Futures.promise();
  Map<String, Object> recipientSearchQuery = new HashMap<>();
  recipientSearchQuery.put(JsonKey.ROOT_ORG_ID, "anyRootId");
  recipientSearchQuery.put(JsonKey.IS_DELETED, true);
  promise_recipientSearchQuery.trySuccess(recipientSearchQuery);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise_recipientSearchQuery.future());
  ProjectCommonException response =
      setRequest(ACCEPTED_CORRECT_VERSION)
          .expectMsgClass(duration("10 second"), ProjectCommonException.class);
  Assert.assertEquals(ResponseCode.userAccountlocked.getErrorCode(), response.getCode());
  Assert.assertEquals("User account has been blocked .", response.getMessage());
}
 
Example 2
Source File: EmailServiceActorTest.java    From sunbird-lms-service with MIT License 4 votes vote down vote up
@Before
public void beforeTest() {

  PowerMockito.mockStatic(ServiceFactory.class);
  PowerMockito.mockStatic(ElasticSearchHelper.class);
  esService = mock(ElasticSearchRestHighImpl.class);
  PowerMockito.mockStatic(EsClientFactory.class);
  when(EsClientFactory.getInstance(Mockito.anyString())).thenReturn(esService);
  PowerMockito.mockStatic(org.sunbird.common.models.util.datasecurity.impl.ServiceFactory.class);
  PowerMockito.mockStatic(EmailTemplateDaoImpl.class);
  when(ServiceFactory.getInstance()).thenReturn(cassandraOperation);
  when(org.sunbird.common.models.util.datasecurity.impl.ServiceFactory
          .getDecryptionServiceInstance(null))
      .thenReturn(defaultDecryptionService);
  when(org.sunbird.common.models.util.datasecurity.impl.ServiceFactory
          .getEncryptionServiceInstance(null))
      .thenReturn(defaultEncryptionServivce);
  when(cassandraOperation.getRecordsByIdsWithSpecifiedColumns(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyList(), Mockito.anyList()))
      .thenReturn(cassandraGetRecordById());

  emailTemplateDao = mock(EmailTemplateDaoImpl.class);
  when(EmailTemplateDaoImpl.getInstance()).thenReturn(emailTemplateDao);
  when(emailTemplateDao.getTemplate(Mockito.anyString())).thenReturn("templateName");

  Map<String, Object> recipientSearchQuery = new HashMap<>();
  recipientSearchQuery.put(JsonKey.FILTERS, "anyName");
  recipientSearchQuery.put(JsonKey.ROOT_ORG_ID, "anyRootId");
  Map<String, Object> esOrgResult = new HashMap<>();
  esOrgResult.put(JsonKey.ORGANISATION_NAME, "anyOrgName");
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(createGetSkillResponse());
  when(esService.search(
          Mockito.eq(ElasticSearchHelper.createSearchDTO(recipientSearchQuery)),
          Mockito.eq(ProjectUtil.EsType.user.getTypeName())))
      .thenReturn(promise.future());
  Promise<Map<String, Object>> promise_recipientSearchQuery = Futures.promise();

  promise_recipientSearchQuery.trySuccess(recipientSearchQuery);
  when(esService.getDataByIdentifier(
          Mockito.eq(ProjectUtil.EsType.user.getTypeName()), Mockito.eq("001")))
      .thenReturn(promise_recipientSearchQuery.future());

  Promise<Map<String, Object>> promise_esOrgResult = Futures.promise();
  promise_esOrgResult.trySuccess(esOrgResult);
  when(esService.getDataByIdentifier(
          Mockito.eq(ProjectUtil.EsType.organisation.getTypeName()), Mockito.eq("anyRootId")))
      .thenReturn(promise_esOrgResult.future());
}