Example #1
0
        public void TestGetEsbTaskListReturnsItems()
        {
            // GIVEN
            var taskList = new Models.TalendApiListResponse <Models.EsbTask> {
                ReturnCode    = 0,
                ExecutionTime = new Models.TalendApiResponse.Executiontime {
                    millis  = 500,
                    seconds = 2
                },
                Results = new System.Collections.Generic.List <Models.EsbTask> {
                    new Models.EsbTask {
                        label = "test-task",
                        applicationFeatureURL = "feature 2",
                        applicationName       = "application 35",
                        applicationType       = "type 45",
                        applicationVersion    = "version 0.54",
                        contextName           = "default",
                        id = 42,
                        jobServerLabelHost = "test-label",
                        pid            = "102",
                        repositoryName = "repository 12"
                    }
                }
            };
            var response = Substitute.For <RestResponse <Models.TalendApiListResponse <Models.EsbTask> > >();

            response.Data = taskList;

            var apiCommand = new Models.ApiCommandRequest {
                authPass   = _settings.TalendAdminPassword,
                authUser   = _settings.TalendAdminUsername,
                actionName = TalendAdminApiCommands.LIST_ESB_TASKS
            };
            var encodedApiCommand = GetMetaservletCommand(apiCommand);

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

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

            // WHEN
            ITalendAdminApi api   = new TalendAdminApi(_settings.TalendAdminAddress, _settings.TalendAdminUsername, _settings.TalendAdminPassword, restClient);
            var             items = api.GetEsbTaskList();

            // THEN
            items.ShouldNotBeEmpty();
            items.First().label.ShouldEqual("test-task");
        }
Example #2
0
        public void TestGetEsbTaskListFailsIfInvalid()
        {
            // GIVEN
            var taskList = new Models.TalendApiListResponse <Models.EsbTask> {
                ReturnCode = 5
            };
            var response = Substitute.For <RestResponse <Models.TalendApiListResponse <Models.EsbTask> > >();

            response.Data = taskList;

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

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

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

            Assert.Throws <System.Exception>(() => api.GetEsbTaskList());
        }