Java Code Examples for akka.testkit.javadsl.TestKit#expectMsgClass()
The following examples show how to use
akka.testkit.javadsl.TestKit#expectMsgClass() .
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: GeoLocationManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void sendNotificationGeoLocationSuccess() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request actorMessage = new Request(); actorMessage.getRequest().put(JsonKey.REQUESTED_BY, userId); actorMessage.getRequest().put(JsonKey.LOCATION, "updated location"); actorMessage.getRequest().put(JsonKey.TYPE, type); actorMessage.getRequest().put(JsonKey.LOCATION_ID, id); actorMessage.setOperation(ActorOperations.SEND_NOTIFICATION.getValue()); subject.tell(actorMessage, probe.getRef()); Response res = probe.expectMsgClass(duration("100 second"), Response.class); Assert.assertTrue(null != res.get(JsonKey.RESPONSE)); }
Example 2
Source File: GeoLocationManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void getGeoLocationSuccessWithLocationId() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request actorMessage = new Request(); actorMessage.getRequest().put(JsonKey.REQUESTED_BY, userId); actorMessage.getRequest().put(JsonKey.TYPE, JsonKey.LOCATION); actorMessage.getRequest().put(JsonKey.ID, id); actorMessage.setOperation(ActorOperations.GET_GEO_LOCATION.getValue()); actorMessage.getRequest().put(JsonKey.ROOT_ORG_ID, orgId); subject.tell(actorMessage, probe.getRef()); Response res = probe.expectMsgClass(duration("100 second"), Response.class); Assert.assertTrue(null != res.get(JsonKey.RESPONSE)); }
Example 3
Source File: UserExternalIdManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testUpsertUserExternalIdentityDetailsAddSuccess() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request request = new Request(); request.setOperation(UserActorOperations.UPSERT_USER_EXTERNAL_IDENTITY_DETAILS.getValue()); HashMap<String, Object> innerMap = new HashMap<>(); innerMap.put(JsonKey.OPERATION_TYPE, "UPDATE"); List<Map<String, Object>> list = new ArrayList<>(); Map<String, Object> extIdMap = new HashMap<>(); extIdMap.put(JsonKey.OPERATION, "ADD"); extIdMap.put(JsonKey.ID_TYPE, "anyIdType"); extIdMap.put(JsonKey.PROVIDER, "anyProvider"); list.add(extIdMap); innerMap.put(JsonKey.EXTERNAL_IDS, list); request.setRequest(innerMap); subject.tell(request, probe.getRef()); Response response = probe.expectMsgClass(duration("100 second"), Response.class); Assert.assertTrue(null != response && response.getResponseCode() == ResponseCode.OK); }
Example 4
Source File: UserAssignRoleTest.java From sunbird-lms-service with MIT License | 6 votes |
@Ignore public void testAssignEmptyRoleSuccess() throws Exception { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request reqObj = new Request(); reqObj.setOperation(ActorOperations.ASSIGN_ROLES.getValue()); Map<String, Object> request = new HashMap<String, Object>(); request.put(JsonKey.USER_ID, userId); request.put(JsonKey.ORGANISATION_ID, orgId); List<String> roles = new ArrayList<>(); request.put(JsonKey.ROLES, roles); reqObj.setRequest(request); initCassandraForSuccess(); subject.tell(reqObj, probe.getRef()); Response res = probe.expectMsgClass(ACTOR_MAX_WAIT_DURATION, Response.class); assertTrue(null != res); }
Example 5
Source File: GeoLocationManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void getGeoLocationFailureWithNullType() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request actorMessage = new Request(); actorMessage.getRequest().put(JsonKey.REQUESTED_BY, userId); actorMessage.getRequest().put(JsonKey.TYPE, null); actorMessage.getRequest().put(JsonKey.ID, orgId); actorMessage.setOperation(ActorOperations.GET_GEO_LOCATION.getValue()); actorMessage.getRequest().put(JsonKey.ROOT_ORG_ID, orgId); subject.tell(actorMessage, probe.getRef()); ProjectCommonException exc = probe.expectMsgClass(duration("10 second"), ProjectCommonException.class); assertTrue(exc.getCode().equals(ResponseCode.invalidRequestData.getErrorCode())); }
Example 6
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 7
Source File: BulkUploadManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testBulkUploadGetStatus() { Response response = getCassandraRecordByIdForBulkUploadResponse(); when(cassandraOperation.getRecordById( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyList())) .thenReturn(response); TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request reqObj = new Request(); reqObj.setOperation(ActorOperations.GET_BULK_OP_STATUS.getValue()); reqObj.getRequest().put(JsonKey.PROCESS_ID, PROCESS_ID); subject.tell(reqObj, probe.getRef()); Response res = probe.expectMsgClass(duration("10 second"), Response.class); List<Map<String, Object>> list = (List<Map<String, Object>>) res.get(JsonKey.RESPONSE); if (!list.isEmpty()) { Map<String, Object> map = list.get(0); String processId = (String) map.get(JsonKey.PROCESS_ID); Assert.assertTrue(null != processId); } }
Example 8
Source File: TenantPreferenceManagementActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testUpdateTanentPreferenceFailureWithInvalidOrgId() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request actorMessage = new Request(); List<Map<String, Object>> reqList = new ArrayList<>(); actorMessage.getRequest().put(JsonKey.TENANT_PREFERENCE, reqList); actorMessage.getRequest().put(JsonKey.ROOT_ORG_ID, ""); actorMessage.getRequest().put(JsonKey.REQUESTED_BY, USER_ID); actorMessage.setOperation(ActorOperations.UPDATE_TENANT_PREFERENCE.getValue()); subject.tell(actorMessage, probe.getRef()); ProjectCommonException exc = probe.expectMsgClass(duration("10 second"), ProjectCommonException.class); Assert.assertTrue(null != exc); }
Example 9
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 10
Source File: DbOperationActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testA2Update() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request reqObj = new Request(); reqObj.setOperation(ActorOperations.UPDATE_DATA.getValue()); Map<String, Object> map = new HashMap<>(); map.put("entityName", "announcement"); map.put("indexed", true); Map<String, Object> innerMap = new HashMap<>(); innerMap.put("id", "454ee9-17-a2-47-id"); innerMap.put("sourceid", "45_sourceId"); innerMap.put("userid", "230cb747-userId"); innerMap.put("status", "inactive"); map.put("payload", innerMap); reqObj.setRequest(map); subject.tell(reqObj, probe.getRef()); Response res = probe.expectMsgClass(duration("20 second"), Response.class); Assert.assertTrue(null != res.get(JsonKey.RESPONSE)); }
Example 11
Source File: DbOperationActorTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testA5Search() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request reqObj = new Request(); reqObj.setOperation(ActorOperations.SEARCH_DATA.getValue()); Map<String, Object> map = new HashMap<>(); map.put("entityName", "announcement"); List<String> list = new ArrayList<>(); list.add("id"); map.put("requiredFields", list); Map<String, Object> filter = new HashMap<>(); map.put(JsonKey.FILTERS, filter); reqObj.setRequest(map); subject.tell(reqObj, probe.getRef()); Response res = probe.expectMsgClass(duration("20 second"), Response.class); Assert.assertTrue(null != res.get(JsonKey.RESPONSE)); }
Example 12
Source File: WebsocketMessageToProducerRecordTranslatorITCase.java From ari-proxy with GNU Affero General Public License v3.0 | 6 votes |
@Test void verifyProcessingPipelineWorksAsExpectedForBogusMessages() { final TestKit catchAllProbe = new TestKit(system); final Source<Message, NotUsed> source = Source.single(new Strict("invalid message from ws")); final Sink<ProducerRecord<String, String>, NotUsed> sink = Sink.actorRef(catchAllProbe.getRef(), new ProducerRecord<String, String>("none", "completed")); WebsocketMessageToProducerRecordTranslator.eventProcessing() .on(system) .withHandler(() -> catchAllProbe.getRef().tell("Application replaced", catchAllProbe.getRef())) .withCallContextProvider(catchAllProbe.getRef()) .withMetricsService(catchAllProbe.getRef()) .from(source) .to(sink) .run(); final ProducerRecord<String, String> completeMsg = catchAllProbe.expectMsgClass(ProducerRecord.class); assertThat(completeMsg.topic(), is("none")); assertThat(completeMsg.value(), is("completed")); }
Example 13
Source File: GeoLocationManagementActorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void deleteGeoLocationSuccess() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request actorMessage = new Request(); actorMessage.getRequest().put(JsonKey.LOCATION_ID, id); actorMessage.setOperation(ActorOperations.DELETE_GEO_LOCATION.getValue()); subject.tell(actorMessage, probe.getRef()); Response res = probe.expectMsgClass(duration("100 second"), Response.class); Assert.assertTrue(null != res.get(JsonKey.RESPONSE)); }
Example 14
Source File: GeoLocationManagementActorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void createGeoLocationTestWithInvalidOrgId() { List<Map<String, Object>> dataList = new ArrayList<>(); Map<String, Object> dataMap = new HashMap<>(); dataMap.put(JsonKey.LOCATION, "location"); dataMap.put(JsonKey.TYPE, type); dataList.add(dataMap); TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request actorMessage = new Request(); actorMessage.getRequest().put(JsonKey.REQUESTED_BY, userId); actorMessage.setOperation(ActorOperations.CREATE_GEO_LOCATION.getValue()); actorMessage.getRequest().put(JsonKey.DATA, dataList); actorMessage.getRequest().put(JsonKey.ROOT_ORG_ID, "invalidOrgId"); when(cassandraOperation.getRecordById( Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(getFailureResponse()); subject.tell(actorMessage, probe.getRef()); ProjectCommonException exc = probe.expectMsgClass(duration("10 second"), ProjectCommonException.class); assertTrue(exc.getCode().equals(ResponseCode.invalidOrgId.getErrorCode())); }
Example 15
Source File: PersistentCacheTest.java From ari-proxy with GNU Affero General Public License v3.0 | 5 votes |
@Test void updateStillRecordsMetricsIfRedisSetFails() { final TestKit probe = new TestKit(system); final TestKit metricsService = new TestKit(system); final ActorRef cache = system.actorOf(Props.create(Cache.class, metricsService.getRef()), "cache"); probe.send(cache, new UpdateCache("failure", VALUE)); probe.expectMsgClass(Duration.ofMillis(150), Failure.class); final RedisUpdateTimerStart updateTimerStart = metricsService.expectMsgClass(RedisUpdateTimerStart.class); final RedisUpdateTimerStop updateTimerStop = metricsService.expectMsgClass(RedisUpdateTimerStop.class); assertThat(updateTimerStart.getContext(), is(updateTimerStop.getContext())); }
Example 16
Source File: DbOperationActorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testInvalidOperation() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request reqObj = new Request(); reqObj.setOperation("INVALID_OPERATION"); subject.tell(reqObj, probe.getRef()); ProjectCommonException exc = probe.expectMsgClass(ProjectCommonException.class); Assert.assertTrue(null != exc); }
Example 17
Source File: BulkUploadManagementActorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void userBulkUploadWithInvalidHeaders() { TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); byte[] bytes = getFileAsBytes("BulkUploadUserWithInvalidHeaders.csv"); Response response = getCassandraRecordByIdForOrgResponse(); when(cassandraOperation.getRecordById( Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(response); Response insertResponse = createCassandraInsertSuccessResponse(); when(cassandraOperation.insertRecord( Mockito.anyString(), Mockito.anyString(), Mockito.anyMap())) .thenReturn(insertResponse); Request reqObj = new Request(); reqObj.setOperation(ActorOperations.BULK_UPLOAD.getValue()); HashMap<String, Object> innerMap = new HashMap<>(); innerMap.put(JsonKey.CREATED_BY, USER_ID); innerMap.put(JsonKey.OBJECT_TYPE, JsonKey.USER); innerMap.put(JsonKey.ORGANISATION_ID, refOrgId); innerMap.put(JsonKey.FILE, bytes); reqObj.getRequest().put(JsonKey.DATA, innerMap); subject.tell(reqObj, probe.getRef()); ProjectCommonException ex = probe.expectMsgClass(duration("10 seconds"), ProjectCommonException.class); Assert.assertTrue(null != ex); Assert.assertEquals(ResponseCode.invalidColumns.getErrorCode(), ex.getCode()); Assert.assertEquals( "Invalid column: password. Valid columns are: firstName, lastName, phone, countryCode, email, userName, phoneVerified, emailVerified, roles, position, grade, location, dob, gender, language, profileSummary, subject, webPages, externalIdProvider, externalId, externalIdType, externalIds.", ex.getMessage()); }
Example 18
Source File: HealthActorTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test @PrepareForTest(ServiceFactory.class) public void getCASSANDRAHealthCheck() { cassandraOperation = PowerMockito.mock(CassandraOperation.class); when(ServiceFactory.getInstance()).thenReturn(cassandraOperation); when(cassandraOperation.getAllRecords(badgesDbInfo.getKeySpace(), badgesDbInfo.getTableName())) .thenReturn(new Response()); TestKit probe = new TestKit(system); ActorRef subject = system.actorOf(props); Request reqObj = new Request(); reqObj.setOperation(ActorOperations.CASSANDRA.getValue()); subject.tell(reqObj, probe.getRef()); Response res = probe.expectMsgClass(duration("200 second"), Response.class); Assert.assertTrue(null != res.get(JsonKey.RESPONSE)); }
Example 19
Source File: KafkaPublisherActorTest.java From ditto with Eclipse Public License 2.0 | 4 votes |
@Override protected void publisherCreated(final TestKit kit, final ActorRef publisherActor) { kit.expectMsgClass(Status.Success.class); }
Example 20
Source File: WebsocketMessageToProducerRecordTranslatorITCase.java From ari-proxy with GNU Affero General Public License v3.0 | 4 votes |
@Test @DisplayName("A websocket message shall be converted into a kafka producer record while also recording metrics") void verifyProsessingPipelineWorksAsExpected() { final TestKit callcontextProvider = new TestKit(system); final TestKit metricsService = new TestKit(system); final TestKit kafkaProducer = new TestKit(system); final TestKit applicationReplacedHandler = new TestKit(system); final Strict stasisStartEvent = new Strict(StasisEvents.stasisStartEvent); final String resourceId = "1532965104.0"; final Source<Message, NotUsed> source = Source.single(stasisStartEvent); final Sink<ProducerRecord<String, String>, NotUsed> sink = Sink.actorRef(kafkaProducer.getRef(), new ProducerRecord<String, String>("none", "completed")); WebsocketMessageToProducerRecordTranslator.eventProcessing() .on(system) .withHandler(() -> applicationReplacedHandler.getRef().tell("Application replaced", ActorRef.noSender())) .withCallContextProvider(callcontextProvider.getRef()) .withMetricsService(metricsService.getRef()) .from(source) .to(sink) .run(); final ProvideCallContext provideCallContextForMetrics = callcontextProvider.expectMsgClass(ProvideCallContext.class); assertThat(provideCallContextForMetrics.resourceId(), is(resourceId)); assertThat(provideCallContextForMetrics.policy(), is(ProviderPolicy.CREATE_IF_MISSING)); callcontextProvider.reply(CALL_CONTEXT_PROVIDED); kafkaProducer.expectMsgClass(ProducerRecord.class); final IncreaseCounter eventTypeCounter = metricsService.expectMsgClass(IncreaseCounter.class); assertThat(eventTypeCounter.getName(), CoreMatchers.is(AriMessageType.STASIS_START.name())); final IncreaseCounter callsStartedCounter = metricsService.expectMsgClass(IncreaseCounter.class); assertThat(callsStartedCounter.getName(), is("CallsStarted")); final ProvideCallContext provideCallContextForRouting = callcontextProvider.expectMsgClass(ProvideCallContext.class); assertThat(provideCallContextForRouting.resourceId(), is(resourceId)); assertThat(provideCallContextForRouting.policy(), is(ProviderPolicy.CREATE_IF_MISSING)); callcontextProvider.reply(CALL_CONTEXT_PROVIDED); final StartCallSetupTimer startCallSetupTimer = metricsService.expectMsgClass(StartCallSetupTimer.class); assertThat(startCallSetupTimer.getCallContext(), is(CALL_CONTEXT_PROVIDED.callContext())); final ProducerRecord completedRecord = kafkaProducer.expectMsgClass(ProducerRecord.class); assertThat(completedRecord.topic(), is("none")); assertThat(completedRecord.value(), is("completed")); }