Esempio n. 1
0
        public void OnEventReceived(ServerSentEvent sse)
        {
            var serverSentEvent = EventUtil.ToEvent <object>(sse.Data);

            if (serverSentEvent == null)
            {
                _logger.LogError("Could not parse Event object {data}", sse.Data);
                return;
            }

            if (!IsNewCorrId(serverSentEvent.CorrId))
            {
                _logger.LogInformation("This EventListener has already started processing {corrId} for {ordgID}", serverSentEvent.CorrId, serverSentEvent.OrgId);
                return;
            }

            if (!ContainsOrganisationId(serverSentEvent.OrgId))
            {
                _logger.LogInformation("This is not EventListener for {org}", serverSentEvent.OrgId);
                return;
            }

            _logger.LogInformation("{orgId}: Event received {@Event}", serverSentEvent.OrgId, serverSentEvent.Action);
            // var accessToken = _tokenClient.AccessToken;
            _eventHandler.HandleEvent(serverSentEvent);
        }
        public void ConvertJsonToEvent()
        {
            String json = "{\"corrId\": \"9b71b7ab-c06d-400a-bca3-f06659006000\",  \"action\":" +
                          " \"GET_ALL_EMPLOYEES\",  \"status\": \"DOWNSTREAM_QUEUE\", " +
                          " \"time\": 1479909169834,  \"orgId\": \"rogfk.no\",  " +
                          "\"source\": \"employee\",  \"client\": \"vfs\",  \"message\": null, " +
                          "\"responseStatus\": \"ACCEPTED\"" +
                          "}";

            var evt = EventUtil.ToEvent <string>(json);

            Assert.True(evt != null);
            Assert.True(evt.Action == "GET_ALL_EMPLOYEES");
            Assert.True(evt.ResponseStatus == ResponseStatus.ACCEPTED);
        }
Esempio n. 3
0
        public EventHandlerServiceTest()
        {
            var json =
                "{\"corrId\":\"c978c986-8d50-496f-8afd-8d27bd68049b\",\"action\":\"health\",\"status\":\"NEW\",\"time\":1481116509260,\"orgId\":\"rogfk.no\",\"source\":\"source\",\"client\":\"client\",\"message\":null,\"data\": \"\"}";

            _evtObj = EventUtil.ToEvent <object>(json);

            _appSettingsMock = new Mock <IOptions <AppSettings> >();
            _httpServiceMock = new Mock <IHttpService>();

            _tilgangerServiceMock = new Mock <ITilgangerService>(); //PwfaService();
            _loggerMock           = new Mock <ILogger <EventHandlerService> >();
            _statusServiceMock    = new Mock <IEventStatusService>();

            _appSettingsMock.Setup(ap => ap.Value).Returns(new AppSettings
            {
                ResponseEndpoint = "https://example.com/api/response",
                StatusEndpoint   = "https://example.com/api/status"
            });
            _httpServiceMock.Setup(x => x.Post(It.IsAny <string>(), It.IsAny <Event <object> >()));
        }
        public void ConvertFullJsonToEvent()
        {
            String json = "{\n" +
                          "  \"corrId\": \"a91cdb9b-0292-4baf-9a27-578642634129\",\n" +
                          "  \"action\": \"GET_ALL\",\n" +
                          "  \"status\": \"NEW\",\n" +
                          "  \"time\": 1524131147134,\n" +
                          "  \"orgId\": \"rogfk.no\",\n" +
                          "  \"source\": \"fk\",\n" +
                          "  \"client\": \"myClient\",\n" +
                          "  \"data\": [],\n" +
                          "  \"message\": \"There is a disturbance in the Force\",\n" +
                          "  \"query\": \"what\",\n" +
                          "  \"problems\": [\n" +
                          "    {\n" +
                          "      \"field\": \"monkey\",\n" +
                          "      \"message\": \"Only chimpanzees allowed\",\n" +
                          "      \"code\": \"9999\"\n" +
                          "    },\n" +
                          "    {\n" +
                          "      \"field\": \"jedi\",\n" +
                          "      \"message\": \"Luke not found\",\n" +
                          "      \"code\": \"44\"\n" +
                          "    }\n" +
                          "  ],\n" +
                          "  \"statusCode\": \"JEDI-XX\",\n" +
                          "  \"responseStatus\": \"ERROR\"\n" +
                          "}";

            var evt = EventUtil.ToEvent <string>(json);

            Assert.NotNull(evt);
            Assert.Equal(ResponseStatus.ERROR, evt.ResponseStatus);
            Assert.Equal("JEDI-XX", evt.StatusCode);
            Assert.Equal(2, evt.Problems.Count);
            Assert.Equal("9999", evt.Problems[0].Code);
        }