Ejemplo n.º 1
0
        private IResponse GenerateAuditHistory(ICruiseRequest request)
        {
            var velocityContext = new Hashtable();
            var links           = new List <IAbsoluteLink>();

            links.Add(new ServerLink(request.UrlBuilder, request.ServerSpecifier, "Server", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier, request.RetrieveSessionToken());

            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(request.UrlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerAuditHistoryServerPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            string sessionToken = request.RetrieveSessionToken(sessionRetriever);

            if (!string.IsNullOrEmpty(request.ProjectName))
            {
                velocityContext["currentProject"] = request.ProjectName;
                AuditFilterBase filter = AuditFilters.ByProject(request.ProjectName);
                velocityContext["auditHistory"] = farmService.ReadAuditRecords(request.ServerSpecifier, sessionToken, 0, 100, filter);
            }
            else
            {
                velocityContext["auditHistory"] = new ServerLink(request.UrlBuilder, request.ServerSpecifier, string.Empty, DiagnosticsActionName);
                velocityContext["auditHistory"] = farmService.ReadAuditRecords(request.ServerSpecifier, sessionToken, 0, 100);
            }

            return(viewGenerator.GenerateView(@"AuditHistory.vm", velocityContext));
        }
        public void Setup()
        {
            ProjectStatusOnServer server = new ProjectStatusOnServer(new ProjectStatus("myProject", IntegrationStatus.Success, DateTime.Now),
                                                                     new DefaultServerSpecifier("myServer"));
            ProjectStatusListAndExceptions statusList = new ProjectStatusListAndExceptions(
                new ProjectStatusOnServer[] {
                server
            }, new CruiseServerException[] {
            });

            farmServiceMock = new DynamicMock(typeof(IFarmService));
            farmServiceMock.SetupResult("GetProjectStatusListAndCaptureExceptions", statusList, typeof(IServerSpecifier), typeof(string));
            viewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator));
            linkFactoryMock   = new DynamicMock(typeof(ILinkFactory));
            ServerLocation serverConfig = new ServerLocation();

            serverConfig.ServerName = "myServer";
            configuration.Servers   = new ServerLocation[] {
                serverConfig
            };
            var urlBuilderMock = new DynamicMock(typeof(ICruiseUrlBuilder));

            urlBuilderMock.SetupResult("BuildProjectUrl", string.Empty, typeof(string), typeof(IProjectSpecifier));

            plugin = new ProjectReportProjectPlugin((IFarmService)farmServiceMock.MockInstance,
                                                    (IVelocityViewGenerator)viewGeneratorMock.MockInstance,
                                                    (ILinkFactory)linkFactoryMock.MockInstance,
                                                    configuration,
                                                    (ICruiseUrlBuilder)urlBuilderMock.MockInstance);

            cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest));
            cruiseRequest     = (ICruiseRequest )cruiseRequestMock.MockInstance;
        }
        public IResponse Execute(ICruiseRequest request)
        {
            Hashtable velocityContext = new Hashtable();
            var       links           = new List <IAbsoluteLink>();

            links.Add(new ServerLink(urlBuilder, request.ServerSpecifier, "Server Log", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier,
                                                                                                           request.RetrieveSessionToken());

            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(urlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerLogProjectPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            if (string.IsNullOrEmpty(request.ProjectName))
            {
                velocityContext["log"] = HttpUtility.HtmlEncode(farmService.GetServerLog(request.ServerSpecifier, request.RetrieveSessionToken()));
            }
            else
            {
                velocityContext["currentProject"] = request.ProjectSpecifier.ProjectName;
                velocityContext["log"]            = HttpUtility.HtmlEncode(farmService.GetServerLog(request.ProjectSpecifier, request.RetrieveSessionToken()));
            }

            return(viewGenerator.GenerateView(@"ServerLog.vm", velocityContext));
        }
        public void Setup()
        {
            ProjectStatusOnServer server = new ProjectStatusOnServer(new ProjectStatus("myProject", IntegrationStatus.Success, DateTime.Now),
                                                                     new DefaultServerSpecifier("myServer"));
            ProjectStatusListAndExceptions statusList = new ProjectStatusListAndExceptions(
                new ProjectStatusOnServer[] {
                server
            }, new CruiseServerException[] {
            });

            farmServiceMock = new Mock <IFarmService>();
            farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(It.IsAny <IServerSpecifier>(), It.IsAny <string>())).Returns(statusList);
            viewGeneratorMock = new Mock <IVelocityViewGenerator>();
            linkFactoryMock   = new Mock <ILinkFactory>();
            ServerLocation serverConfig = new ServerLocation();

            serverConfig.ServerName = "myServer";
            configuration.Servers   = new ServerLocation[] {
                serverConfig
            };
            var urlBuilderMock = new Mock <ICruiseUrlBuilder>();

            urlBuilderMock.Setup(builder => builder.BuildProjectUrl(It.IsAny <string>(), It.IsAny <IProjectSpecifier>())).Returns(string.Empty);

            plugin = new ProjectReportProjectPlugin((IFarmService)farmServiceMock.Object,
                                                    (IVelocityViewGenerator)viewGeneratorMock.Object,
                                                    (ILinkFactory)linkFactoryMock.Object,
                                                    configuration,
                                                    (ICruiseUrlBuilder)urlBuilderMock.Object);

            cruiseRequestMock = new Mock <ICruiseRequest>();
            cruiseRequest     = (ICruiseRequest )cruiseRequestMock.Object;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes the specified cruise request.
        /// </summary>
        /// <param name="cruiseRequest">The cruise request.</param>
        /// <returns></returns>
        public IResponse Execute(ICruiseRequest cruiseRequest)
        {
            ProjectStatusListAndExceptions projectStatuses = farmService.GetProjectStatusListAndCaptureExceptions(cruiseRequest.ServerSpecifier,
                                                                                                                  cruiseRequest.RetrieveSessionToken(sessionRetriever));
            ProjectStatus projectStatus = projectStatuses.GetStatusForProject(cruiseRequest.ProjectName);
            string        xml           = new CruiseXmlWriter().Write(projectStatus);

            return(new XmlFragmentResponse(xml));
        }
Ejemplo n.º 6
0
        private ProjectStatus FindProjectStatus(IProjectSpecifier projectSpecifier, ICruiseRequest request)
        {
            ProjectStatusListAndExceptions list = farmService.GetProjectStatusListAndCaptureExceptions(projectSpecifier.ServerSpecifier, request.RetrieveSessionToken());

            foreach (ProjectStatusOnServer status in list.StatusAndServerList)
            {
                if (string.Equals(status.ProjectStatus.Name, projectSpecifier.ProjectName, StringComparison.OrdinalIgnoreCase))
                {
                    return(status.ProjectStatus);
                }
            }
            throw new CruiseControlException("Unable to retrieve project status");
        }
		private HtmlFragmentResponse GenerateView(ProjectStatusListAndExceptions projectStatusListAndExceptions, Hashtable velocityContext, string actionName, IRequest request, IServerSpecifier serverSpecifier)
		{
			ProjectGridSortColumn sortColumn = GetSortColumn(request);
			bool sortReverse = SortAscending(request);

			velocityContext["projectNameSortLink"] = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.Name, sortColumn, sortReverse);
			velocityContext["buildStatusSortLink"] = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.BuildStatus, sortColumn, sortReverse);
			velocityContext["lastBuildDateSortLink"] = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.LastBuildDate, sortColumn, sortReverse);
			velocityContext["projectGrid"] = projectGrid.GenerateProjectGridRows(
                farmService, projectStatusListAndExceptions.StatusAndServerList, actionName, sortColumn, sortReverse);
			velocityContext["exceptions"] = projectStatusListAndExceptions.Exceptions;
			velocityContext["refreshButtonName"] = urlBuilder.BuildFormName(actionName);

			return viewGenerator.GenerateView(@"ProjectGrid.vm", velocityContext);
		}
Ejemplo n.º 8
0
        public void ShouldGenerateFarmServerProjectAndBuildLinksIfServerProjectAndBuildSpecified()
        {
            // Setup
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildName).Returns("myBuild").Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerSpecifier).Returns(serverSpecifier).Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerSpecifier).Returns(serverSpecifier).Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectSpecifier).Returns(projectSpecifier).Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildSpecifier).Returns(buildSpecifier).Verifiable();
            cruiseRequestMock.SetupGet(_cruiseRequest => _cruiseRequest.Request).Returns(requestMock.Object).Verifiable();
            requestMock.Setup(_request => _request.GetText("Category")).Returns("").Verifiable();

            ProjectStatus ps = new ProjectStatus("myProject", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "Queue 1", 1, new List <ParameterBase>());

            ProjectStatusOnServer[]        psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) };
            ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]);

            farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifier, null)).Returns(pslae).Verifiable();

            expectedVelocityContext["serverName"]   = "myServer";
            expectedVelocityContext["categoryName"] = "";
            expectedVelocityContext["projectName"]  = "myProject";
            expectedVelocityContext["buildName"]    = "myBuild";

            linkFactoryMock.Setup(factory => factory.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME)).Returns(link1).Verifiable();
            linkFactoryMock.Setup(factory => factory.CreateServerLink(serverSpecifier, ServerReportServerPlugin.ACTION_NAME)).Returns(link2).Verifiable();
            linkFactoryMock.Setup(factory => factory.CreateProjectLink(projectSpecifier, ProjectReportProjectPlugin.ACTION_NAME)).Returns(link3).Verifiable();
            linkFactoryMock.Setup(factory => factory.CreateBuildLink(buildSpecifier, BuildReportBuildPlugin.ACTION_NAME)).Returns(link4).Verifiable();
            expectedVelocityContext["farmLink"]    = link1;
            expectedVelocityContext["serverLink"]  = link2;
            expectedVelocityContext["projectLink"] = link3;
            expectedVelocityContext["buildLink"]   = link4;

            velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"TopMenu.vm", It.IsAny <Hashtable>())).
            Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, expectedVelocityContext)).Returns(response).Verifiable();

            // Execute & Verify
            Assert.AreEqual(response, viewBuilder.Execute());
            VerifyAll();
        }
Ejemplo n.º 9
0
        public void ShouldGenerateFarmServerProjectAndBuildLinksIfServerProjectAndBuildSpecified()
        {
            // Setup
            cruiseRequestMock.ExpectAndReturn("ServerName", "myServer");
            cruiseRequestMock.ExpectAndReturn("ServerName", "myServer");
            cruiseRequestMock.ExpectAndReturn("ProjectName", "myProject");
            cruiseRequestMock.ExpectAndReturn("ProjectName", "myProject");
            cruiseRequestMock.ExpectAndReturn("ProjectName", "myProject");
            cruiseRequestMock.ExpectAndReturn("BuildName", "myBuild");
            cruiseRequestMock.ExpectAndReturn("ServerSpecifier", serverSpecifier);
            cruiseRequestMock.ExpectAndReturn("ServerSpecifier", serverSpecifier);
            cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier);
            cruiseRequestMock.ExpectAndReturn("BuildSpecifier", buildSpecifier);
            cruiseRequestMock.ExpectAndReturn("Request", requestMock.MockInstance);
            requestMock.ExpectAndReturn("GetText", "", new object[] { "Category" });

            ProjectStatus ps = new ProjectStatus("myProject", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "Queue 1", 1, new List <ParameterBase>());

            ProjectStatusOnServer[]        psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) };
            ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]);

            farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", pslae, serverSpecifier, null);

            expectedVelocityContext["serverName"]   = "myServer";
            expectedVelocityContext["categoryName"] = "";
            expectedVelocityContext["projectName"]  = "myProject";
            expectedVelocityContext["buildName"]    = "myBuild";

            linkFactoryMock.ExpectAndReturn("CreateFarmLink", link1, "Dashboard", FarmReportFarmPlugin.ACTION_NAME);
            linkFactoryMock.ExpectAndReturn("CreateServerLink", link2, serverSpecifier, ServerReportServerPlugin.ACTION_NAME);
            linkFactoryMock.ExpectAndReturn("CreateProjectLink", link3, projectSpecifier, ProjectReportProjectPlugin.ACTION_NAME);
            linkFactoryMock.ExpectAndReturn("CreateBuildLink", link4, buildSpecifier, BuildReportBuildPlugin.ACTION_NAME);
            expectedVelocityContext["farmLink"]    = link1;
            expectedVelocityContext["serverLink"]  = link2;
            expectedVelocityContext["projectLink"] = link3;
            expectedVelocityContext["buildLink"]   = link4;

            velocityViewGeneratorMock.ExpectAndReturn("GenerateView", response, "TopMenu.vm", new HashtableConstraint(expectedVelocityContext));

            // Execute & Verify
            Assert.AreEqual(response, viewBuilder.Execute());
            VerifyAll();
        }
Ejemplo n.º 10
0
        private IResponse GenerateUserList(ICruiseRequest request, string message, string error)
        {
            Hashtable velocityContext = new Hashtable();

            velocityContext["message"] = message;
            velocityContext["error"]   = error;

            var links = new List <IAbsoluteLink>();

            links.Add(new ServerLink(request.UrlBuilder, request.ServerSpecifier, "User List", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier, request.RetrieveSessionToken());

            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(request.UrlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerUserListServerPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            string             sessionToken = request.RetrieveSessionToken(sessionRetriever);
            List <UserDetails> allUsers     = farmService.ListAllUsers(request.ServerSpecifier, sessionToken);

            foreach (UserDetails user in allUsers)
            {
                if (user.DisplayName == null)
                {
                    user.DisplayName = string.Empty;
                }
            }
            velocityContext["users"] = allUsers;
            if (!string.IsNullOrEmpty(request.ProjectName))
            {
                velocityContext["currentProject"]  = request.ProjectName;
                velocityContext["diagnosticsCall"] = new ProjectLink(request.UrlBuilder, request.ProjectSpecifier, string.Empty, DiagnosticsActionName);
            }
            else
            {
                velocityContext["diagnosticsCall"] = new ServerLink(request.UrlBuilder, request.ServerSpecifier, string.Empty, DiagnosticsActionName);
            }

            return(viewGenerator.GenerateView(@"UserList.vm", velocityContext));
        }
        public IResponse Execute(ICruiseRequest request)
        {
            Hashtable velocityContext = new Hashtable();
            var       links           = new List <IAbsoluteLink>();

            links.Add(new ServerLink(request.UrlBuilder, request.ServerSpecifier, "Server Security Configuration", ActionName));

            ProjectStatusListAndExceptions projects = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier, request.RetrieveSessionToken());

            foreach (ProjectStatusOnServer projectStatusOnServer in projects.StatusAndServerList)
            {
                DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(projectStatusOnServer.ServerSpecifier, projectStatusOnServer.ProjectStatus.Name);
                links.Add(new ProjectLink(request.UrlBuilder, projectSpecifier, projectSpecifier.ProjectName, ServerSecurityConfigurationServerPlugin.ActionName));
            }
            velocityContext["projectLinks"] = links;
            string sessionToken   = request.RetrieveSessionToken(sessionRetriever);
            string securityConfig = farmService.GetServerSecurity(request.ServerSpecifier, sessionToken);

            if (!string.IsNullOrEmpty(securityConfig))
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml(securityConfig);
                if (string.IsNullOrEmpty(request.ProjectName))
                {
                    securityConfig = document.SelectSingleNode("/security/manager").OuterXml;
                }
                else
                {
                    velocityContext["currentProject"] = request.ProjectSpecifier.ProjectName;
                    string xpath = string.Format(System.Globalization.CultureInfo.CurrentCulture, "/security/projects/projectSecurity[name='{0}']/authorisation", request.ProjectSpecifier.ProjectName);
                    securityConfig = document.SelectSingleNode(xpath).OuterXml;
                }
                string xmlData = FormatXml(securityConfig);
                velocityContext["log"] = xmlData;
            }
            else
            {
                velocityContext["log"] = "No security configuration could be retrieved from the server";
            }
            return(viewGenerator.GenerateView(@"SecurityConfiguration.vm", velocityContext));
        }
Ejemplo n.º 12
0
        public void ExecuteGeneratesReport()
        {
            var projectName      = "daProject";
            var farmService      = this.mocks.StrictMock <IFarmService>();
            var cruiseRequest    = this.mocks.StrictMock <ICruiseRequest>();
            var sessionRetriever = this.mocks.StrictMock <ISessionRetriever>();
            var server           = this.mocks.StrictMock <IServerSpecifier>();
            var project          = new ProjectStatus(projectName, IntegrationStatus.Success, new DateTime(2010, 1, 2, 3, 4, 5));

            project.ServerName = "TESTMACHINE";
            var status   = new ProjectStatusOnServer(project, server);
            var snapshot = new ProjectStatusListAndExceptions(
                new ProjectStatusOnServer[] { status },
                new CruiseServerException[0]);

            SetupResult.For(cruiseRequest.ProjectName).Return(projectName);
            SetupResult.For(cruiseRequest.ServerSpecifier).Return(server);
            SetupResult.For(cruiseRequest.RetrieveSessionToken(sessionRetriever)).Return(null);
            SetupResult.For(farmService.GetProjectStatusListAndCaptureExceptions(server, null))
            .Return(snapshot);

            this.mocks.ReplayAll();
            var report   = new ProjectXmlReport(farmService, sessionRetriever);
            var response = report.Execute(cruiseRequest);

            this.mocks.VerifyAll();
            Assert.IsInstanceOf <XmlFragmentResponse>(response);
            var actual   = response as XmlFragmentResponse;
            var expected = "<CruiseControl>" +
                           "<Projects>" +
                           "<Project name=\"daProject\" category=\"\" activity=\"Sleeping\" " +
                           "status=\"Running\" lastBuildStatus=\"Success\" lastBuildLabel=\"\" " +
                           "lastBuildTime=\"" + XmlConvert.ToString(project.LastBuildDate, XmlDateTimeSerializationMode.Local) +
                           "\" nextBuildTime=\"" + XmlConvert.ToString(project.NextBuildTime, XmlDateTimeSerializationMode.Local) + "\" " +
                           "webUrl=\"\" buildStage=\"\" serverName=\"TESTMACHINE\" />" +
                           "</Projects>" +
                           "<Queues />" +
                           "</CruiseControl>";

            Assert.AreEqual(expected, actual.ResponseFragment);
        }
        private HtmlFragmentResponse GenerateView(ProjectStatusListAndExceptions projectStatusListAndExceptions,
                                                  string actionName, ICruiseRequest request, IServerSpecifier serverSpecifier)
        {
            this.translations = Translations.RetrieveCurrent();
            cruiseUrlBuilder  = request.UrlBuilder;
            urlBuilder        = request.UrlBuilder.InnerBuilder;
            Hashtable velocityContext = new Hashtable();

            velocityContext["forceBuildMessage"] = ForceBuildIfNecessary(request.Request);
            velocityContext["parametersCall"]    = new ServerLink(cruiseUrlBuilder, new DefaultServerSpecifier("null"), string.Empty, ProjectParametersAction.ActionName).Url;

            velocityContext["wholeFarm"] = serverSpecifier == null ?  true : false;

            string category = request.Request.GetText("Category");

            velocityContext["showCategoryColumn"] = string.IsNullOrEmpty(category) ? true : false;

            ProjectGridSortColumn sortColumn = GetSortColumn(request.Request);
            bool sortReverse = SortAscending(request.Request);

            velocityContext["projectNameSortLink"]     = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.Name, sortColumn, sortReverse);
            velocityContext["buildStatusSortLink"]     = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.BuildStatus, sortColumn, sortReverse);
            velocityContext["lastBuildDateSortLink"]   = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.LastBuildDate, sortColumn, sortReverse);
            velocityContext["serverNameSortLink"]      = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.ServerName, sortColumn, sortReverse);
            velocityContext["projectCategorySortLink"] = GenerateSortLink(serverSpecifier, actionName, ProjectGridSortColumn.Category, sortColumn, sortReverse);

            ProjectGridRow[] projectGridRows = projectGrid.GenerateProjectGridRows(projectStatusListAndExceptions.StatusAndServerList, actionName, sortColumn, sortReverse, category, cruiseUrlBuilder, this.translations);

            velocityContext["projectGrid"] = projectGridRows;
            velocityContext["exceptions"]  = projectStatusListAndExceptions.Exceptions;

            Array categoryList = this.GenerateCategoryList(projectGridRows);

            velocityContext["categoryList"] = categoryList;
            velocityContext["barAtTop"]     = (this.SuccessIndicatorBarLocation == IndicatorBarLocation.Top) ||
                                              (this.SuccessIndicatorBarLocation == IndicatorBarLocation.TopAndBottom);
            velocityContext["barAtBottom"] = (this.SuccessIndicatorBarLocation == IndicatorBarLocation.Bottom) ||
                                             (this.SuccessIndicatorBarLocation == IndicatorBarLocation.TopAndBottom);

            return(viewGenerator.GenerateView(@"ProjectGrid.vm", velocityContext));
        }
Ejemplo n.º 14
0
        public IResponse Execute(ICruiseRequest request)
        {
            Hashtable velocityContext = new Hashtable();

            ProjectStatusListAndExceptions projectList = farmService.GetProjectStatusListAndCaptureExceptions(request.ServerSpecifier,
                                                                                                              request.RetrieveSessionToken(sessionRetriever));
            List <ProjectStatus> projects = new List <ProjectStatus>();

            for (int projectLoop = 0; projectLoop < projectList.StatusAndServerList.Length; projectLoop++)
            {
                ProjectStatus projectStatus = projectList.StatusAndServerList[projectLoop].ProjectStatus;

                projects.Add(projectStatus);
            }

            projects.Sort(CompareProjectStatusByQueueAndQueuePriority);

            velocityContext["projects"] = projects.ToArray();

            return(viewGenerator.GenerateView(@"ProjectServerConfiguration.vm", velocityContext));
        }
Ejemplo n.º 15
0
        public void ShouldGenerateFarmViewIfNoServerSpecified()
        {
            // Setup
            cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("").Verifiable();
            pluginLinkCalculatorMock.Setup(calculator => calculator.GetFarmPluginLinks()).Returns(links).Verifiable();
            farmServiceMock.Setup(service => service.GetServerSpecifiers()).Returns(serverSpecifiers).Verifiable();
            linkListFactoryMock.Setup(factory => factory.CreateServerLinkList(serverSpecifiers, "ViewServerReport")).Returns(serverLinks).Verifiable();

            ProjectStatus ps = new ProjectStatus("", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0, new List <ParameterBase>());

            ProjectStatusOnServer[]        psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifiers[0]) };
            ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]);

            farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifiers[0], null)).Returns(pslae).Verifiable();

            velocityContext["links"]       = links;
            velocityContext["serverlinks"] = serverLinks;

            velocityContext["showCategories"] = false;
            velocityContext["categorylinks"]  = null;
            CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory x = new DefaultLinkFactory(new DefaultUrlBuilder(), null, null);

            IAbsoluteLink farmLink = x.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME);

            linkFactoryMock.Setup(factory => factory.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME)).Returns(farmLink).Verifiable();
            velocityContext["farmLink"] = farmLink;

            System.Diagnostics.Debug.WriteLine("starting");

            velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"FarmSideBar.vm", It.IsAny <Hashtable>())).
            Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, velocityContext)).Returns(velocityResponse).Verifiable();

            // Execute
            HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.Object as ICruiseRequest);

            // Verify
            Assert.AreEqual(velocityResponse, returnedResponse);
            VerifyAll();
        }
Ejemplo n.º 16
0
        public void ShouldGenerateServerViewIfServerButNoProjectSpecified()
        {
            // Setup
            IServerSpecifier serverSpecifier = new DefaultServerSpecifier("myServer");

            cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable();
            cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("").Verifiable();
            cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerSpecifier).Returns(serverSpecifier).Verifiable();

            pluginLinkCalculatorMock.Setup(calculator => calculator.GetServerPluginLinks(serverSpecifier)).Returns(links).Verifiable();

            ProjectStatus ps = new ProjectStatus("", "myCategory", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0, new List <ParameterBase>());

            ProjectStatusOnServer[]        psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) };
            ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]);

            farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifier, null)).Returns(pslae).Verifiable();

            IAbsoluteLink link = new GeneralAbsoluteLink("link");

            IAbsoluteLink[] categoryLinks = new GeneralAbsoluteLink[] { new GeneralAbsoluteLink("myCategory", "?Category=myCategory") };
            linkFactoryMock.Setup(factory => factory.CreateServerLink(serverSpecifier, ServerReportServerPlugin.ACTION_NAME)).Returns(link).Verifiable();
            linkFactoryMock.Setup(factory => factory.CreateServerLink(serverSpecifier, ServerReportServerPlugin.ACTION_NAME)).Returns(link).Verifiable();

            velocityContext["links"]          = links;
            velocityContext["serverlink"]     = link;
            velocityContext["showCategories"] = true;
            velocityContext["categorylinks"]  = categoryLinks;

            velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"ServerSideBar.vm", It.IsAny <Hashtable>())).
            Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, velocityContext)).Returns(velocityResponse).Verifiable();

            // Execute
            HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.Object as ICruiseRequest);

            // Verify
            Assert.AreEqual(velocityResponse, returnedResponse);
            VerifyAll();
        }
        public void ShouldGenerateFarmViewIfNoServerSpecified()
        {
            // Setup
            cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "");
            pluginLinkCalculatorMock.ExpectAndReturn("GetFarmPluginLinks", links);
            farmServiceMock.ExpectAndReturn("GetServerSpecifiers", serverSpecifiers);
            linkListFactoryMock.ExpectAndReturn("CreateServerLinkList", serverLinks, serverSpecifiers, "ViewServerReport");

            ProjectStatus ps = new ProjectStatus("", "", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0);

            ProjectStatusOnServer[]        psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifiers[0]) };
            ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]);

            farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", pslae, serverSpecifiers[0], (string)null);

            velocityContext["links"]       = links;
            velocityContext["serverlinks"] = serverLinks;

            velocityContext["showCategories"] = false;
            velocityContext["categorylinks"]  = null;
            CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory x = new DefaultLinkFactory(new DefaultUrlBuilder(), null, null);

            IAbsoluteLink farmLink = x.CreateFarmLink("Dashboard", FarmReportFarmPlugin.ACTION_NAME);

            linkFactoryMock.ExpectAndReturn("CreateFarmLink", farmLink, "Dashboard", FarmReportFarmPlugin.ACTION_NAME);
            velocityContext["farmLink"] = farmLink;

            System.Diagnostics.Debug.WriteLine("starting");

            velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"FarmSideBar.vm", new HashtableConstraint(velocityContext));

            // Execute
            HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest);

            // Verify
            Assert.AreEqual(velocityResponse, returnedResponse);
            VerifyAll();
        }
        public void ShouldGenerateServerViewIfServerButNoProjectSpecified()
        {
            // Setup
            IServerSpecifier serverSpecifier = new DefaultServerSpecifier("myServer");

            cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer");
            cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", "");
            cruiseRequestWrapperMock.ExpectAndReturn("ServerSpecifier", serverSpecifier);

            pluginLinkCalculatorMock.ExpectAndReturn("GetServerPluginLinks", links, serverSpecifier);

            ProjectStatus ps = new ProjectStatus("", "myCategory", null, 0, 0, null, DateTime.Now, null, null, DateTime.Now, null, "", 0);

            ProjectStatusOnServer[]        psosa = new ProjectStatusOnServer[] { new ProjectStatusOnServer(ps, serverSpecifier) };
            ProjectStatusListAndExceptions pslae = new ProjectStatusListAndExceptions(psosa, new CruiseServerException[0]);

            farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", pslae, serverSpecifier, (string)null);

            IAbsoluteLink link = new GeneralAbsoluteLink("link");

            IAbsoluteLink[] categoryLinks = new GeneralAbsoluteLink[] { new GeneralAbsoluteLink("myCategory", "?Category=myCategory") };
            linkFactoryMock.ExpectAndReturn("CreateServerLink", link, serverSpecifier, ServerReportServerPlugin.ACTION_NAME);
            linkFactoryMock.ExpectAndReturn("CreateServerLink", link, serverSpecifier, ServerReportServerPlugin.ACTION_NAME);

            velocityContext["links"]          = links;
            velocityContext["serverlink"]     = link;
            velocityContext["showCategories"] = true;
            velocityContext["categorylinks"]  = categoryLinks;

            velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"ServerSideBar.vm", new HashtableConstraint(velocityContext));

            // Execute
            HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest);

            // Verify
            Assert.AreEqual(velocityResponse, returnedResponse);
            VerifyAll();
        }
Ejemplo n.º 19
0
        public IResponse Execute(IRequest request)
        {
            ProjectStatusListAndExceptions allProjectStatus = farmService.GetProjectStatusListAndCaptureExceptions(null);

            StringWriter  stringWriter = new StringWriter();
            XmlTextWriter xmlWriter    = new XmlTextWriter(stringWriter);

            xmlWriter.WriteStartElement("Projects");

            // bvc enhancement
            xmlWriter.WriteAttributeString("CCType", "CCNet"); // to identify the type of cruisecontrol, .Net, .rb, ...
            //todo xmlWriter.WriteAttributeString("CCVersion", farmService.GetServerVersion( )); // to identify the version of the server



            foreach (ProjectStatusOnServer projectStatusOnServer in allProjectStatus.StatusAndServerList)
            {
                WriteProjectStatus(xmlWriter, projectStatusOnServer.ProjectStatus, projectStatusOnServer.ServerSpecifier);
            }

            xmlWriter.WriteEndElement();

            return(new XmlFragmentResponse(stringWriter.ToString()));
        }