Java Code Examples for akka.dispatch.Futures

The following examples show how to use akka.dispatch.Futures. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Author: ljygz   File: BaseTestingActorGateway.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Future<Object> ask(Object message, FiniteDuration timeout) {
	try {
		final Object result = handleMessage(message);

		return Futures.future(new Callable<Object>() {
			@Override
			public Object call() throws Exception {
				return result;
			}
		}, executionContext);

	} catch (final Exception e) {
		// if an exception occurred in the handleMessage method then return it as part of the future
		return Futures.future(new Callable<Object>() {
			@Override
			public Object call() throws Exception {
				throw e;
			}
		}, executionContext);
	}
}
 
Example #2
Source Project: sunbird-lms-service   Author: project-sunbird   File: UserFeedActorTest.java    License: MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  PowerMockito.mockStatic(ServiceFactory.class);
  PowerMockito.mockStatic(EsClientFactory.class);
  PowerMockito.mockStatic(ElasticSearchHelper.class);
  esService = mock(ElasticSearchService.class);
  esUtil = mock(ElasticSearchRestHighImpl.class);
  when(EsClientFactory.getInstance(Mockito.anyString())).thenReturn(esUtil);

  userFeed.put(JsonKey.ID, "123-456-789");
  response = new Response();
  Map<String, Object> responseMap = new HashMap<>();
  responseMap.put(Constants.RESPONSE, Arrays.asList(userFeed));
  response.getResult().putAll(responseMap);
  esResponse.put(JsonKey.CONTENT, Arrays.asList(userFeed));

  Map<String, Object> filters = new HashMap<>();
  filters.put(JsonKey.USER_ID, "123-456-789");
  SearchDTO search = new SearchDTO();
  search.getAdditionalProperties().put(JsonKey.FILTERS, filters);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(esResponse);
  when(ElasticSearchHelper.getResponseFromFuture(Mockito.any())).thenReturn(esResponse);
  PowerMockito.when(esService.search(search, ProjectUtil.EsType.userfeed.getTypeName()))
      .thenReturn(promise.future());
}
 
Example #3
Source Project: sunbird-lms-service   Author: project-sunbird   File: UserProfileActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testSetProfileVisibilitySuccess() {
  final String userId = "USER-ID";
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(createGetResponse(true));
  when(esUtil.getDataByIdentifier(ProjectUtil.EsType.user.getTypeName(), userId))
      .thenReturn(promise.future());
  when(ElasticSearchHelper.getResponseFromFuture(Mockito.any()))
      .thenReturn(createGetResponse(true));
  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.PROFILE_VISIBILITY.getValue());
  reqObj.put(JsonKey.USER_ID, userId);
  subject.tell(reqObj, probe.getRef());
  Response res = probe.expectMsgClass(duration("10 second"), Response.class);
  Assert.assertTrue(null != res && res.getResponseCode() == ResponseCode.OK);
}
 
Example #4
Source Project: sunbird-lms-service   Author: project-sunbird   File: UserProfileActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testSetProfileVisibilityFailure() {
  final String userId = "USER-ID";
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(null);
  when(esUtil.getDataByIdentifier(ProjectUtil.EsType.user.getTypeName(), userId))
      .thenReturn(promise.future());
  when(ElasticSearchHelper.getResponseFromFuture(Mockito.any())).thenReturn(null);
  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.PROFILE_VISIBILITY.getValue());
  reqObj.put(JsonKey.USER_ID, userId);
  subject.tell(reqObj, probe.getRef());
  ProjectCommonException res =
      probe.expectMsgClass(duration("10 second"), ProjectCommonException.class);
  Assert.assertTrue(res.getCode() == ResponseCode.userNotFound.getErrorCode());
}
 
Example #5
Source Project: sunbird-lms-service   Author: project-sunbird   File: UserAssignRoleTest.java    License: MIT License 6 votes vote down vote up
@Before
public void mockClasses() throws Exception {

  PowerMockito.mockStatic(ServiceFactory.class);
  PowerMockito.mockStatic(EsClientFactory.class);
  cassandraOperation = PowerMockito.mock(CassandraOperationImpl.class);
  PowerMockito.when(ServiceFactory.getInstance()).thenReturn(cassandraOperation);
  esService = PowerMockito.mock(ElasticSearchRestHighImpl.class);
  PowerMockito.when(EsClientFactory.getInstance(Mockito.anyString())).thenReturn(esService);
  Map<String, Object> roleMap = new HashMap<>();
  for (String role : ALL_ROLES) roleMap.put(role, role);
  PowerMockito.mockStatic(DataCacheHandler.class);
  PowerMockito.when(DataCacheHandler.getRoleMap()).thenReturn(roleMap);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(userOrg);
  Promise<Map<String, Object>> promise_es = Futures.promise();
  promise_es.success(esRespone);
  PowerMockito.when(esService.getDataByIdentifier(Mockito.any(), Mockito.any()))
      .thenReturn(promise.future());
  PowerMockito.when(esService.search(Mockito.any(), Mockito.any()))
      .thenReturn(promise_es.future());
}
 
Example #6
Source Project: sunbird-lms-service   Author: project-sunbird   File: RestUtil.java    License: MIT License 6 votes vote down vote up
public static Future<HttpResponse<JsonNode>> executeAsync(BaseRequest request) {
  ProjectLogger.log("RestUtil:execute: request url = " + request.getHttpRequest().getUrl());
  Promise<HttpResponse<JsonNode>> promise = Futures.promise();

  request.asJsonAsync(
      new Callback<JsonNode>() {

        @Override
        public void failed(UnirestException e) {
          promise.failure(e);
        }

        @Override
        public void completed(HttpResponse<JsonNode> response) {
          promise.success(response);
        }

        @Override
        public void cancelled() {
          promise.failure(new Exception("cancelled"));
        }
      });

  return promise.future();
}
 
Example #7
Source Project: sunbird-lms-service   Author: project-sunbird   File: UserBadgeAssertionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testRevokeBadgeToUser() {
  Promise<Boolean> promise = Futures.promise();
  promise.success(true);
  PowerMockito.when(
          esService.update(ProjectUtil.EsType.user.getTypeName(), "userId-123", tempMap))
      .thenReturn(promise.future());

  PowerMockito.when(
          cassandraOperation.deleteRecord(
              dbInfo.getKeySpace(), dbInfo.getTableName(), "userId-123"))
      .thenReturn(new Response());

  actorMessage.setOperation(BadgeOperations.revokeBadgeFromUser.name());

  subject.tell(actorMessage, probe.getRef());

  Response response = probe.expectMsgClass(ACTOR_MAX_WAIT_DURATION, Response.class);
  Assert.assertTrue(null != response);
}
 
Example #8
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrganisationMetricsActorTest.java    License: MIT License 6 votes vote down vote up
@Before
public void before() {
  PowerMockito.mockStatic(HttpClientBuilder.class);
  PowerMockito.mockStatic(ServiceFactory.class);
  PowerMockito.mockStatic(EsClientFactory.class);
  cassandraOperation = mock(CassandraOperationImpl.class);
  esService = mock(ElasticSearchRestHighImpl.class);
  when(EsClientFactory.getInstance(Mockito.anyString())).thenReturn(esService);
  when(ServiceFactory.getInstance()).thenReturn(cassandraOperation);
  Response response = createCassandraInsertSuccessResponse();
  when(cassandraOperation.insertRecord(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(response);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(userOrgMap);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
}
 
Example #9
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrganisationMetricsActorTest.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testOrgCreationMetricsWithInvalidOrgId() {
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(prop);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(null);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());

  Request actorMessage = new Request();
  actorMessage.put(JsonKey.ORG_ID, "ORG_001_INVALID");
  actorMessage.put(JsonKey.PERIOD, "7d");
  actorMessage.setOperation(ActorOperations.ORG_CREATION_METRICS.getValue());

  subject.tell(actorMessage, probe.getRef());
  ProjectCommonException e =
      probe.expectMsgClass(duration("10 second"), ProjectCommonException.class);
  Assert.assertEquals(ResponseCode.invalidOrgData.getErrorCode(), e.getCode());
}
 
Example #10
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrganisationMetricsActorTest.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testOrgConsumptionMetricsWithInvalidOrgId() {
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(prop);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(null);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());

  Request actorMessage = new Request();
  actorMessage.put(JsonKey.ORG_ID, "ORG_001_INVALID");
  actorMessage.put(JsonKey.PERIOD, "7d");
  actorMessage.setOperation(ActorOperations.ORG_CONSUMPTION_METRICS.getValue());

  subject.tell(actorMessage, probe.getRef());
  ProjectCommonException e =
      probe.expectMsgClass(duration("10 second"), ProjectCommonException.class);
  Assert.assertEquals(ResponseCode.invalidOrgData.getErrorCode(), e.getCode());
}
 
Example #11
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrganisationMetricsActorTest.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testOrgCreationMetricsInvalidPeriod() {
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(prop);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(userOrgMap);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());

  Request actorMessage = new Request();
  actorMessage.put(JsonKey.ORG_ID, orgId);
  actorMessage.put(JsonKey.PERIOD, "10d");
  actorMessage.setOperation(ActorOperations.ORG_CREATION_METRICS.getValue());

  subject.tell(actorMessage, probe.getRef());
  ProjectCommonException e =
      probe.expectMsgClass(duration("10 second"), ProjectCommonException.class);
  Assert.assertEquals("INVALID_PERIOD", e.getCode());
}
 
Example #12
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrganisationMetricsActorTest.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test
public void testOrgConsumptionMetricsWithInvalidPeriod() {
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(prop);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(userOrgMap);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());

  Request actorMessage = new Request();
  actorMessage.put(JsonKey.ORG_ID, orgId);
  actorMessage.put(JsonKey.PERIOD, "10d");
  actorMessage.setOperation(ActorOperations.ORG_CONSUMPTION_METRICS.getValue());

  subject.tell(actorMessage, probe.getRef());
  ProjectCommonException e =
      probe.expectMsgClass(duration("10 second"), ProjectCommonException.class);
  Assert.assertEquals("INVALID_PERIOD", e.getCode());
}
 
Example #13
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrganisationMetricsActorTest.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings({"deprecation", "unchecked"})
@Test
public void testOrgCreationMetricsReportDataSuccess() {
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(prop);

  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(userOrgMap);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());

  Request actorMessage = new Request();
  actorMessage.put(JsonKey.ORG_ID, orgId);
  actorMessage.put(JsonKey.PERIOD, "7d");
  actorMessage.put(JsonKey.REQUESTED_BY, userId);
  actorMessage.put(JsonKey.FORMAT, "csv");
  actorMessage.setOperation(ActorOperations.ORG_CREATION_METRICS_REPORT.getValue());

  subject.tell(actorMessage, probe.getRef());
  Response res = probe.expectMsgClass(duration("10 second"), Response.class);
  Map<String, Object> data = res.getResult();
  String id = (String) data.get(JsonKey.REQUEST_ID);
  Assert.assertNotNull(id);
}
 
Example #14
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrganisationMetricsActorTest.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings({"deprecation", "unchecked"})
@Test
public void testOrgConsumptionMetricsReportDataSuccess() {
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(prop);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(userOrgMap);
  when(esService.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());

  Request actorMessage = new Request();
  actorMessage.put(JsonKey.ORG_ID, orgId);
  actorMessage.put(JsonKey.PERIOD, "7d");
  actorMessage.put(JsonKey.REQUESTED_BY, userId);
  actorMessage.put(JsonKey.FORMAT, "csv");
  actorMessage.setOperation(ActorOperations.ORG_CONSUMPTION_METRICS_REPORT.getValue());

  subject.tell(actorMessage, probe.getRef());
  Response res = probe.expectMsgClass(duration("10 second"), Response.class);
  Map<String, Object> data = res.getResult();
  String id = (String) data.get(JsonKey.REQUEST_ID);
  Assert.assertNotNull(id);
}
 
Example #15
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrgManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testCreateOrgSuccessWithExternalIdAndProvider() {
  when(cassandraOperation.getRecordsByCompositeKey(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getRecordsByProperty(true));
  when(cassandraOperation.insertRecord(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getSuccess());
  when(cassandraOperation.getRecordsByProperties(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getRecordsByProperty(true));
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(getValidateChannelEsResponse(true));

  when(esService.search(Mockito.any(), Mockito.anyString())).thenReturn(promise.future());
  boolean result =
      testScenario(
          getRequest(
              getRequestDataForOrgCreate(basicRequestData),
              ActorOperations.CREATE_ORG.getValue()),
          null);
  assertTrue(result);
}
 
Example #16
Source Project: sunbird-lms-service   Author: project-sunbird   File: OrgManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testCreateOrgSuccessWithoutExternalIdAndProvider() {
  when(cassandraOperation.getRecordsByCompositeKey(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getRecordsByProperty(true));
  when(cassandraOperation.insertRecord(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getSuccess());
  when(cassandraOperation.getRecordsByProperties(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getRecordsByProperty(true));
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(getValidateChannelEsResponse(true));

  when(esService.search(Mockito.any(), Mockito.anyString())).thenReturn(promise.future());
  Map<String, Object> map = getRequestDataForOrgCreate(basicRequestData);
  map.remove(JsonKey.EXTERNAL_ID);
  boolean result = testScenario(getRequest(map, ActorOperations.CREATE_ORG.getValue()), null);
  assertTrue(result);
}
 
Example #17
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testCreateNoteSuccess() {
  Request req = new Request();
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, userId);
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.CREATE_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
  when(cassandraOperation.insertRecord(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getSuccessResponse());
  boolean result = testScenario(req, null);
  assertTrue(result);
}
 
Example #18
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testUpdateNoteFailure() {
  beforeEachTest();
  Request req = new Request();
  req.getContext().put(JsonKey.USER_ID, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.UPDATE_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(new HashMap<>());
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
  boolean result = testScenario(req, ResponseCode.unAuthorized);
  assertTrue(result);
}
 
Example #19
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testUpdateNoteFailurewithUserIdMismatch() {
  Request req = new Request();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, "misMatch");
  req.setRequest(reqMap);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);

  req.setOperation(ActorOperations.UPDATE_NOTE.getValue());
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
  boolean result = testScenario(req, ResponseCode.errorForbidden);
  assertTrue(result);
}
 
Example #20
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testUpdateNoteFailurewithEmptyNote() {
  Request req = new Request();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, userId);
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.UPDATE_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  Promise<Map<String, Object>> promiseAny = Futures.promise();
  promiseAny.success(new HashMap<>());
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future())
      .thenReturn(promiseAny.future());
  boolean result = testScenario(req, ResponseCode.invalidNoteId);
  assertTrue(result);
}
 
Example #21
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testUpdateNoteSuccess() {
  Request req = new Request();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, userId);
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.UPDATE_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future())
      .thenReturn(promise.future());
  when(cassandraOperation.updateRecord(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getSuccessResponse());
  boolean result = testScenario(req, null);
  assertTrue(result);
}
 
Example #22
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testGetNoteFailurewithUserIdMismatch() {
  Request req = new Request();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, "misMatch");
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.GET_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);

  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
  boolean result = testScenario(req, ResponseCode.errorForbidden);
  assertTrue(result);
}
 
Example #23
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testGetNoteFailureWithInvalidNoteId() {
  Request req = new Request();
  Map<String, Object> reqMap = new HashMap<>();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  reqMap.put(JsonKey.USER_ID, userId);
  reqMap.put(JsonKey.COUNT, 0L);
  req.setRequest(reqMap);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
  when(esUtil.search(Mockito.any(), Mockito.anyString())).thenReturn(promise.future());
  req.setOperation(ActorOperations.GET_NOTE.getValue());
  boolean result = testScenario(req, ResponseCode.invalidNoteId);
  assertTrue(result);
}
 
Example #24
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testGetNoteSuccess() {
  Request req = new Request();
  Map<String, Object> reqMap = new HashMap<>();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  reqMap.put(JsonKey.USER_ID, userId);
  reqMap.put(JsonKey.COUNT, 1L);
  req.setRequest(reqMap);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
  when(esUtil.search(Mockito.any(), Mockito.anyString())).thenReturn(promise.future());
  req.setOperation(ActorOperations.GET_NOTE.getValue());
  boolean result = testScenario(req, null);
  assertTrue(result);
}
 
Example #25
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testDeleteNoteSuccess() {
  Request req = new Request();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, userId);
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.DELETE_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future())
      .thenReturn(promise.future());
  when(cassandraOperation.updateRecord(
          Mockito.anyString(), Mockito.anyString(), Mockito.anyMap()))
      .thenReturn(getSuccessResponse());
  boolean result = testScenario(req, null);
  assertTrue(result);
}
 
Example #26
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testDeleteNoteFailurewithEmptyNote() {
  Request req = new Request();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, userId);
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.DELETE_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  Promise<Map<String, Object>> promise_any = Futures.promise();
  promise_any.success(new HashMap<>());
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future())
      .thenReturn(promise_any.future());
  boolean result = testScenario(req, ResponseCode.invalidNoteId);
  assertTrue(result);
}
 
Example #27
Source Project: sunbird-lms-service   Author: project-sunbird   File: NotesManagementActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testDeleteNoteFailurewithUserIdMismatch() {
  Request req = new Request();
  req.getContext().put(JsonKey.REQUESTED_BY, userId);
  req.getContext().put(JsonKey.NOTE_ID, noteId);
  Map<String, Object> reqMap = new HashMap<>();
  reqMap.put(JsonKey.USER_ID, "misMatch");
  req.setRequest(reqMap);
  req.setOperation(ActorOperations.DELETE_NOTE.getValue());
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(reqMap);
  when(esUtil.getDataByIdentifier(Mockito.anyString(), Mockito.anyString()))
      .thenReturn(promise.future());
  boolean result = testScenario(req, ResponseCode.errorForbidden);
  assertTrue(result);
}
 
Example #28
Source Project: sunbird-lms-service   Author: project-sunbird   File: HealthActorTest.java    License: MIT License 6 votes vote down vote up
@Test
public void getESHealthCheck() {
  ElasticSearchService elasticSearchService = PowerMockito.mock(ElasticSearchService.class);
  Promise<Boolean> promise = Futures.promise();
  promise.success(true);
  PowerMockito.mockStatic(EsClientFactory.class);
  when(EsClientFactory.getInstance(JsonKey.REST)).thenReturn(elasticSearchService);
  when(elasticSearchService.healthCheck()).thenReturn(promise.future());
  TestKit probe = new TestKit(system);
  ActorRef subject = system.actorOf(props);
  Request reqObj = new Request();
  reqObj.setOperation(ActorOperations.ES.getValue());
  subject.tell(reqObj, probe.getRef());
  Response res = probe.expectMsgClass(duration("200 second"), Response.class);
  Assert.assertTrue(null != res.get(JsonKey.RESPONSE));
}
 
Example #29
Source Project: sunbird-lms-service   Author: project-sunbird   File: UserSkillManagementActorTest.java    License: MIT License 6 votes vote down vote up
private void mockGetSkillResponse(String userId) {
  Map<String, Object> esDtoMap = new HashMap<>();
  Map<String, Object> filters = new HashMap<>();
  filters.put(JsonKey.USER_ID, userId);
  esDtoMap.put(JsonKey.FILTERS, filters);
  List<String> fields = new ArrayList<>();
  fields.add(JsonKey.SKILLS);
  esDtoMap.put(JsonKey.FIELDS, fields);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(createGetSkillResponse());
  when(esService.search(
          Mockito.eq(ElasticSearchHelper.createSearchDTO(esDtoMap)),
          Mockito.eq(ProjectUtil.EsType.user.getTypeName())))
      .thenReturn(promise.future());
  Promise<Map<String, Object>> promise_esDtoMap = Futures.promise();
  promise_esDtoMap.success(esDtoMap);

  when(esService.getDataByIdentifier(
          Mockito.eq(ProjectUtil.EsType.user.getTypeName()), Mockito.eq(userId)))
      .thenReturn(promise_esDtoMap.future());
  when(ElasticSearchHelper.getResponseFromFuture(promise_esDtoMap.future())).thenReturn(esDtoMap);
  when(ElasticSearchHelper.getResponseFromFuture(promise.future()))
      .thenReturn(createGetSkillResponse());
}
 
Example #30
Source Project: sunbird-lms-service   Author: project-sunbird   File: UserSkillManagementActorTest.java    License: MIT License 6 votes vote down vote up
private void mockGetSkillEmptyResponse(String userId) {
  Map<String, Object> esDtoMap = new HashMap<>();
  Map<String, Object> filters = new HashMap<>();
  filters.put(JsonKey.USER_ID, userId);
  esDtoMap.put(JsonKey.FILTERS, filters);
  List<String> fields = new ArrayList<>();
  fields.add(JsonKey.SKILLS);
  esDtoMap.put(JsonKey.FIELDS, fields);
  Promise<Map<String, Object>> promise = Futures.promise();
  promise.success(createGetSkillResponse());
  when(esService.search(
          Mockito.eq(ElasticSearchHelper.createSearchDTO(esDtoMap)),
          Mockito.eq(ProjectUtil.EsType.user.getTypeName())))
      .thenReturn(promise.future());
  Promise<Map<String, Object>> promise_esDtoMap = Futures.promise();
  promise_esDtoMap.success(esDtoMap);
  when(esService.getDataByIdentifier(
          Mockito.eq(ProjectUtil.EsType.user.getTypeName()), Mockito.eq(userId)))
      .thenReturn(promise_esDtoMap.future());
  when(ElasticSearchHelper.getResponseFromFuture(promise_esDtoMap.future())).thenReturn(esDtoMap);
  when(ElasticSearchHelper.getResponseFromFuture(promise.future()))
      .thenReturn(createGetSkillEmptyContentResponse());
}