Example #1
0
        public void TestGetEsbTaskIdByName()
        {
            // GIVEN
            var taskIdResponse = new Models.TalendApiResponseTaskId {
                ReturnCode    = 0,
                ExecutionTime = new Models.TalendApiResponse.Executiontime {
                    millis  = 500,
                    seconds = 2
                },
                taskId = 50
            };
            var response = Substitute.For <RestResponse <Models.TalendApiResponseTaskId> >();

            response.Data = taskIdResponse;

            var apiCommand = new Models.ApiCommandRequestGetTaskIdByName {
                authPass   = _settings.TalendAdminPassword,
                authUser   = _settings.TalendAdminUsername,
                actionName = TalendAdminApiCommands.GET_ESB_TASK_ID_BY_NAME,
                taskName   = "one"
            };
            var encodedApiCommand = GetMetaservletCommand(apiCommand);

            var restClient = Substitute.For <IRestClient>();

            restClient.Execute <Models.TalendApiResponseTaskId>(
                Arg.Do <RestRequest>(x => x.Resource.ShouldEqual($"metaServlet?{encodedApiCommand}"))).Returns(response);

            // WHEN
            ITalendAdminApi api    = new TalendAdminApi(_settings.TalendAdminAddress, _settings.TalendAdminUsername, _settings.TalendAdminPassword, restClient);
            var             taskID = api.GetEsbTaskIdByName("one");

            // THEN
            taskID.ShouldEqual(50);
        }
Example #2
0
        public void TestGetEsbTaskIdByNameFailsIfInvalid()
        {
            // GIVEN
            var taskIdResponse = new Models.TalendApiResponseTaskId {
                ReturnCode = 5
            };
            var response = Substitute.For <RestResponse <Models.TalendApiResponseTaskId> >();

            response.Data = taskIdResponse;

            var restClient = Substitute.For <IRestClient>();

            restClient.Execute <Models.TalendApiResponseTaskId>(Arg.Any <RestRequest>()).Returns(response);

            // WHEN & THEN
            ITalendAdminApi api = new TalendAdminApi(_settings.TalendAdminAddress, _settings.TalendAdminUsername, _settings.TalendAdminPassword, restClient);

            Assert.Throws <System.Exception>(() => api.GetEsbTaskIdByName("one"));
        }