Exemplo n.º 1
0
        public void TestGetTaskIdByName()
        {
            // 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_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.GetTaskIdByName("one");

            // THEN
            taskID.ShouldEqual(50);
        }
Exemplo n.º 2
0
        public void TestGetTaskIdByNameFailsIfInvalid()
        {
            // 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.GetTaskIdByName("one"));
        }