akka.dispatch.Futures Java Examples
The following examples show how to use
akka.dispatch.Futures.
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: UserBadgeAssertionTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #2
Source File: RestUtil.java From sunbird-lms-service with MIT License | 6 votes |
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 #3
Source File: UserAssignRoleTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #4
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #5
Source File: UserProfileActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #6
Source File: FeedServiceImplTest.java From sunbird-lms-service with MIT License | 6 votes |
@Before public void setUp() throws Exception { Map<String, Object> filters = new HashMap<>(); filters.put(JsonKey.USER_ID, "123-456-789"); search.getAdditionalProperties().put(JsonKey.FILTERS, filters); PowerMockito.mockStatic(ServiceFactory.class); PowerMockito.mockStatic(EsClientFactory.class); PowerMockito.mockStatic(ElasticSearchHelper.class); esUtil = mock(ElasticSearchService.class); esUtil = mock(ElasticSearchRestHighImpl.class); promise = Futures.promise(); promise.success(esResponse); when(EsClientFactory.getInstance(Mockito.anyString())).thenReturn(esUtil); cassandraOperation = mock(CassandraOperationImpl.class); PowerMockito.when(ServiceFactory.getInstance()).thenReturn(cassandraOperation); when(FeedServiceImpl.getCassandraInstance()).thenReturn(cassandraOperation); when(FeedServiceImpl.getESInstance()).thenReturn(esUtil); when(esUtil.search(search, ProjectUtil.EsType.userfeed.getTypeName())) .thenReturn(promise.future()); when(ElasticSearchHelper.getResponseFromFuture(Mockito.any())).thenReturn(esResponse); initCassandraForSuccess(); }
Example #7
Source File: DockerSwarmServiceDiscovery.java From ditto with Eclipse Public License 2.0 | 6 votes |
private Future<Resolved> resolveService(final Lookup lookup) { final String serviceName = lookup.serviceName(); return Futures.<Resolved>future(() -> { final InetAddress[] allResolvedHosts; try { allResolvedHosts = InetAddress.getAllByName(serviceName); } catch (final UnknownHostException e) { return new Resolved(serviceName, JavaConverters.<ResolvedTarget>asScalaBuffer(Collections.emptyList()).toList()); } final List<ResolvedTarget> resolvedTargets = Arrays.stream(allResolvedHosts) .map(a -> new ResolvedTarget(a.getCanonicalHostName(), Option.empty(), Option.apply(a))) .collect(Collectors.toList()); final Resolved resolved = new Resolved(serviceName, JavaConverters.asScalaBuffer(resolvedTargets).toList()); system.log().debug("[DockerSwarmServiceDiscovery] Resolved <{}> via InetAddress to: {}", lookup, resolved); return resolved; }, system.dispatcher()); }
Example #8
Source File: QueryActor.java From yahoo-streaming-benchmark with Apache License 2.0 | 6 votes |
public Future<Object> queryStateFutureWithFailover(final int tries, final QueryState<K> queryState) { @SuppressWarnings("unchecked") Future<Object> result = queryStateFuture(queryState).recoverWith(new Recover<Future<Object>>() { @Override public Future<Object> recover(Throwable failure) throws Throwable { if (tries > 0) { LOG.debug("Query state failed with {}. Try to recover. #{} left.", failure, tries - 1); return queryStateFutureWithFailover(tries - 1, queryState); } else { return Futures.failed(failure); } } }, executor); return result; }
Example #9
Source File: UserFeedActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #10
Source File: BaseTestingActorGateway.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@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 #11
Source File: UserProfileActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #12
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #13
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #14
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #15
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #16
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #17
Source File: OrganisationMetricsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #18
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #19
Source File: OrganisationMetricsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #20
Source File: OrganisationMetricsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #21
Source File: OrganisationMetricsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #22
Source File: OrganisationMetricsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #23
Source File: OrganisationMetricsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #24
Source File: OrganisationMetricsActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #25
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #26
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #27
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #28
Source File: OrgManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #29
Source File: OrgManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #30
Source File: NotesManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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); }