scala.concurrent.Promise Java Examples
The following examples show how to use
scala.concurrent.Promise.
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: 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 #2
Source File: SearchHandlerActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Before public void beforeTest() { PowerMockito.mockStatic(EsClientFactory.class); esService = mock(ElasticSearchRestHighImpl.class); when(EsClientFactory.getInstance(Mockito.anyString())).thenReturn(esService); Promise<Map<String, Object>> promise = Futures.promise(); promise.success(createResponseGet(true)); when(esService.search(Mockito.any(SearchDTO.class), Mockito.anyVararg())) .thenReturn(promise.future()); PowerMockito.mockStatic(ServiceFactory.class); when(ServiceFactory.getInstance()).thenReturn(cassandraOperation); when(cassandraOperation.getRecordsByProperties( Mockito.anyString(), Mockito.anyString(), Mockito.anyMap(), Mockito.anyList())) .thenReturn(getRecordByPropertyResponse()); }
Example #3
Source File: UserSkillManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
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()); }
Example #4
Source File: AmazonS3Storage.java From thunderbit with GNU Affero General Public License v3.0 | 6 votes |
@Override public F.Promise<Result> getDownload(String key, String name) { GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key); ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides(); responseHeaders.setContentDisposition("attachment; filename="+name); generatePresignedUrlRequest.setResponseHeaders(responseHeaders); AmazonS3 amazonS3 = new AmazonS3Client(credentials); try { URL url = amazonS3.generatePresignedUrl(generatePresignedUrlRequest); return F.Promise.pure(redirect(url.toString())); } catch (AmazonClientException ace) { logAmazonClientException (ace); return F.Promise.pure(internalServerError(error.render())); } }
Example #5
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 #6
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 #7
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 #8
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 #9
Source File: UserSkillManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
Source File: HealthActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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); }
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: 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 #29
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 #30
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); }