public void ReturnsServerLogFromRequestedServerForSpecificProject() { // Setup IServerSpecifier serverSpecifier = new DefaultServerSpecifier("foo"); IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "foo-project"); string serverLog = "server log"; Hashtable expectedHashtable = new Hashtable(); expectedHashtable["log"] = serverLog; expectedHashtable["projectLinks"] = new IsAnything(); expectedHashtable["currentProject"] = projectSpecifier.ProjectName; IResponse response = new HtmlFragmentResponse("foo"); requestMock.SetupResult("ServerSpecifier", serverSpecifier); requestMock.SetupResult("ProjectName", projectSpecifier.ProjectName); requestMock.SetupResult("ProjectSpecifier", projectSpecifier); farmServiceMock.ExpectAndReturn("GetServerLog", serverLog, projectSpecifier, null); farmServiceMock.ExpectAndReturn("GetProjectStatusListAndCaptureExceptions", new ProjectStatusListAndExceptions(new ProjectStatusOnServer[0], null), serverSpecifier, null); viewGeneratorMock.ExpectAndReturn("GenerateView", response, @"ServerLog.vm", new HashtableConstraint(expectedHashtable)); // Execute Assert.AreEqual(response, action.Execute((ICruiseRequest)requestMock.MockInstance)); VerifyAll(); }
public void ShouldGenerateProjectViewIfServerAndProjectButNoBuildSpecified() { // Setup IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer"); cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", "myProject"); cruiseRequestWrapperMock.ExpectAndReturn("BuildName", ""); cruiseRequestWrapperMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); pluginLinkCalculatorMock.ExpectAndReturn("GetProjectPluginLinks", links, projectSpecifier); string recentBuildsView = ""; recentBuildsViewBuilderMock.ExpectAndReturn("BuildRecentBuildsTable", recentBuildsView, projectSpecifier, null); velocityContext["links"] = links; velocityContext["recentBuildsTable"] = recentBuildsView; velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"ProjectSideBar.vm", new HashtableConstraint(velocityContext)); // Execute HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest); // Verify Assert.AreEqual(velocityResponse, returnedResponse); VerifyAll(); }
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 ShouldGenerateProjectViewIfServerAndProjectButNoBuildSpecified() { // Setup IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildName).Returns("").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectSpecifier).Returns(projectSpecifier).Verifiable(); pluginLinkCalculatorMock.Setup(calculator => calculator.GetProjectPluginLinks(projectSpecifier)).Returns(links).Verifiable(); string recentBuildsView = ""; recentBuildsViewBuilderMock.Setup(builder => builder.BuildRecentBuildsTable(projectSpecifier, null)).Returns(recentBuildsView).Verifiable(); velocityContext["links"] = links; velocityContext["recentBuildsTable"] = recentBuildsView; velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"ProjectSideBar.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 Setup() { cruiseRequestMock = new DynamicMock(typeof(ICruiseRequest)); requestMock = new DynamicMock(typeof(IRequest)); linkFactoryMock = new DynamicMock(typeof(ILinkFactory)); velocityViewGeneratorMock = new DynamicMock(typeof(IVelocityViewGenerator)); farmServiceMock = new DynamicMock(typeof(IFarmService)); viewBuilder = new TopControlsViewBuilder( (ICruiseRequest)cruiseRequestMock.MockInstance, (ILinkFactory)linkFactoryMock.MockInstance, (IVelocityViewGenerator)velocityViewGeneratorMock.MockInstance, (IFarmService)farmServiceMock.MockInstance, null, null); serverSpecifier = new DefaultServerSpecifier("myServer"); projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myProject"); buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild"); expectedVelocityContext = new Hashtable(); response = new HtmlFragmentResponse("foo"); link1 = new GeneralAbsoluteLink("1"); link2 = new GeneralAbsoluteLink("2"); link3 = new GeneralAbsoluteLink("3"); link4 = new GeneralAbsoluteLink("4"); }
private string ForceBuildIfNecessary(IRequest request) { // Previousely the mere existence of the forcebuild field on the webform would trigger a build. A secod condition was // added to check that the field's value is set to true. if (request.FindParameterStartingWith("forcebuild") != string.Empty) { string forceBuildProject = request.GetText("forceBuildProject"); string forceBuildServer = request.GetText("forceBuildServer"); IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier( new DefaultServerSpecifier(forceBuildServer), forceBuildProject); if (request.GetText("forcebuild").ToLower() == "true") { bool forceWasAllowed = false; forceWasAllowed = farmService.ForceBuild(projectSpecifier); if (forceWasAllowed) { return(string.Format("Build successfully forced for {0}", forceBuildProject)); } else { return(string.Format("Build was not allowed to be forced for {0}", forceBuildProject)); } } else //Kill Button { farmService.Kill(projectSpecifier); return(string.Format("Build for {0} was successfully killed", forceBuildProject)); } } else { return(""); } }
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 ProjectGridRow[] GenerateProjectGridRows(ProjectStatusOnServer[] statusList, string forceBuildActionName, ProjectGridSortColumn sortColumn, bool sortIsAscending, string categoryFilter, ICruiseUrlBuilder urlBuilder, Translations translations) { var rows = new List <ProjectGridRow>(); foreach (ProjectStatusOnServer statusOnServer in statusList) { ProjectStatus status = statusOnServer.ProjectStatus; IServerSpecifier serverSpecifier = statusOnServer.ServerSpecifier; DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, status.Name); if ((categoryFilter != string.Empty) && (categoryFilter != status.Category)) { continue; } rows.Add( new ProjectGridRow(status, serverSpecifier, urlBuilder.BuildProjectUrl(ProjectReportProjectPlugin.ACTION_NAME, projectSpecifier), urlBuilder.BuildProjectUrl(ProjectParametersAction.ActionName, projectSpecifier), translations)); } return(rows.OrderBy(a => a, GetComparer(sortColumn, sortIsAscending)).ToArray()); }
public ProjectGridRow[] GenerateProjectGridRows(IFarmService farmService, ProjectStatusOnServer[] statusList, string forceBuildActionName, ProjectGridSortColumn sortColumn, bool sortIsAscending) { ArrayList rows = new ArrayList(); foreach (ProjectStatusOnServer statusOnServer in statusList) { ProjectStatus status = statusOnServer.ProjectStatus; IServerSpecifier serverSpecifier = statusOnServer.ServerSpecifier; string projectName = status.Name; IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName); string baseUrl = Regex.Replace(statusOnServer.ProjectStatus.WebURL, @"default\.aspx\?.*", ""); string projectLink = baseUrl + linkFactory.CreateProjectLink(projectSpecifier, ProjectReportProjectPlugin.ACTION_NAME).Url; IBuildSpecifier[] buildSpecifiers = farmService.GetMostRecentBuildSpecifiers(projectSpecifier, 1); string mostRecentBuildUrl; if (buildSpecifiers.Length == 1) { mostRecentBuildUrl = baseUrl + linkFactory.CreateProjectLink(projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME).Url; } else { mostRecentBuildUrl = projectLink; } String[] logMessages = farmService.GetLogMessages(projectSpecifier); String lastLogMessage = String.Empty; if (logMessages.Length > 0) { lastLogMessage = logMessages[logMessages.Length - 1]; } rows.Add( new ProjectGridRow( projectName, statusOnServer.ServerSpecifier.ServerName, status.BuildStatus.ToString(), CalculateHtmlColor(status.BuildStatus), status.LastBuildDate, status.LastBuildDuration, (status.LastBuildLabel != null ? status.LastBuildLabel : "no build available"), status.Status.ToString(), status.Activity.ToString(), urlBuilder.BuildFormName(forceBuildActionName), projectLink, mostRecentBuildUrl, ChangeSet.Convert(status.Modifications), status.Forcee, status.CurrentBuildStartTime, status.BuildCondition.ToString(), lastLogMessage, logMessages )); } rows.Sort(GetComparer(sortColumn, sortIsAscending)); return((ProjectGridRow[])rows.ToArray(typeof(ProjectGridRow))); }
public override bool Equals(object obj) { if (obj is DefaultProjectSpecifier) { DefaultProjectSpecifier other = obj as DefaultProjectSpecifier; return(this.ProjectName == other.ProjectName && this.ServerSpecifier.Equals(other.ServerSpecifier)); } return(false); }
public void ShouldReturnProjectsSortedByCategoryIfCategoryColumnSpecifiedAsSortSeed() { // Setup IProjectSpecifier projectA = new DefaultProjectSpecifier(serverSpecifier, "A"); IProjectSpecifier projectB = new DefaultProjectSpecifier(serverSpecifier, "B"); IProjectSpecifier projectC = new DefaultProjectSpecifier(serverSpecifier, "C"); ProjectStatus projectStatusA = new ProjectStatus("A", "CategoryX", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatus projectStatusB = new ProjectStatus("B", "CategoryY", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatus projectStatusC = new ProjectStatus("C", "CategoryX", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatusOnServer[] status = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatusA, serverSpecifier), new ProjectStatusOnServer(projectStatusB, serverSpecifier), new ProjectStatusOnServer(projectStatusC, serverSpecifier) }; SetupProjectLinkExpectation(projectA); SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectC); // Execute mocks.ReplayAll(); mocks.ReplayAll(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(status, "myAction", ProjectGridSortColumn.Category, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(3, rows.Length); Assert.AreEqual("C", rows[0].Name); Assert.AreEqual("A", rows[1].Name); Assert.AreEqual("B", rows[2].Name); // Setup SetupProjectLinkExpectation(projectA); SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectC); // Execute rows = projectGrid.GenerateProjectGridRows(status, "myAction", ProjectGridSortColumn.Category, false, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(3, rows.Length); Assert.AreEqual("B", rows[0].Name); Assert.AreEqual("C", rows[1].Name); Assert.AreEqual("A", rows[2].Name); VerifyAll(); }
public void ShouldReturnWarningMessageIfNoBuildsAvailable() { IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); cruiseRequestMock.SetupGet(_request => _request.ProjectSpecifier).Returns(projectSpecifier).Verifiable(); farmServiceMock.Setup(services => services.GetMostRecentBuildSpecifiers(projectSpecifier, 1, null)).Returns(new IBuildSpecifier[0]).Verifiable(); IResponse returnedReponse = plugin.Execute(cruiseRequest); Assert.IsTrue(returnedReponse is HtmlFragmentResponse); Assert.AreEqual("There are no complete builds for this project", ((HtmlFragmentResponse)returnedReponse).ResponseFragment); }
public void Setup() { cruiseManagerWrapperMock = new Mock <ICruiseManagerWrapper>(); nameBuildRetriever = new CruiseManagerBuildNameRetriever((ICruiseManagerWrapper)cruiseManagerWrapperMock.Object); serverName = "my Server"; projectName = "my Project"; buildName = "myLogfile.xml"; projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier(serverName), projectName); buildSpecifier = new DefaultBuildSpecifier(this.projectSpecifier, buildName); buildSpecifiers = new IBuildSpecifier[] { CreateBuildSpecifier("log3"), CreateBuildSpecifier("log2"), CreateBuildSpecifier("log1") }; }
public void ShouldReturnRedirectToActualBuildReportPageIfBuildAvailable() { IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild"); cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); farmServiceMock.ExpectAndReturn("GetMostRecentBuildSpecifiers", new IBuildSpecifier[] { buildSpecifier }, projectSpecifier, 1, null); linkFactoryMock.ExpectAndReturn("CreateBuildLink", new GeneralAbsoluteLink("foo", "buildUrl"), buildSpecifier, BuildReportBuildPlugin.ACTION_NAME); IResponse returnedReponse = plugin.Execute(cruiseRequest); Assert.IsTrue(returnedReponse is RedirectResponse); Assert.AreEqual("buildUrl", ((RedirectResponse)returnedReponse).Url); }
public void ShouldReturnRedirectToActualBuildReportPageIfBuildAvailable() { IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild"); cruiseRequestMock.SetupGet(_request => _request.ProjectSpecifier).Returns(projectSpecifier).Verifiable(); farmServiceMock.Setup(services => services.GetMostRecentBuildSpecifiers(projectSpecifier, 1, null)).Returns(new IBuildSpecifier[] { buildSpecifier }).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateBuildLink(buildSpecifier, BuildReportBuildPlugin.ACTION_NAME)).Returns(new GeneralAbsoluteLink("foo", "buildUrl")).Verifiable(); IResponse returnedReponse = plugin.Execute(cruiseRequest); Assert.IsTrue(returnedReponse is RedirectResponse); Assert.AreEqual("buildUrl", ((RedirectResponse)returnedReponse).Url); }
public void ShouldGenerateBuildViewIfServerAndProjectAndBuildSpecified() { // Setup IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild"); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ServerName).Returns("myServer").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectName).Returns("myProject").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildName).Returns("myBuild").Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.BuildSpecifier).Returns(buildSpecifier).Verifiable(); cruiseRequestWrapperMock.SetupGet(_cruiseRequest => _cruiseRequest.ProjectSpecifier).Returns(projectSpecifier).Verifiable(); pluginLinkCalculatorMock.Setup(calculator => calculator.GetBuildPluginLinks(buildSpecifier)).Returns(links).Verifiable(); string recentBuildsView = ""; recentBuildsViewBuilderMock.Setup(builder => builder.BuildRecentBuildsTable(buildSpecifier, null)).Returns(recentBuildsView).Verifiable(); IBuildSpecifier nextBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "next"); IBuildSpecifier previousBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "previous"); IAbsoluteLink latestLink = new GeneralAbsoluteLink("test latest"); IAbsoluteLink nextLink = new GeneralAbsoluteLink("test next"); IAbsoluteLink previousLink = new GeneralAbsoluteLink("test previous"); buildNameRetrieverMock.Setup(retriever => retriever.GetNextBuildSpecifier(buildSpecifier, null)).Returns(nextBuildSpecifier).Verifiable(); buildNameRetrieverMock.Setup(retriever => retriever.GetPreviousBuildSpecifier(buildSpecifier, null)).Returns(previousBuildSpecifier).Verifiable(); string action = BuildReportBuildPlugin.ACTION_NAME; linkFactoryMock.Setup(factory => factory.CreateProjectLink(projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME)).Returns(latestLink).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateBuildLink(nextBuildSpecifier, "", action)).Returns(nextLink).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateBuildLink(previousBuildSpecifier, "", action)).Returns(previousLink).Verifiable(); velocityContext["links"] = links; velocityContext["recentBuildsTable"] = recentBuildsView; velocityContext["latestLink"] = latestLink; velocityContext["nextLink"] = nextLink; velocityContext["previousLink"] = previousLink; velocityViewGeneratorMock.Setup(generator => generator.GenerateView(@"BuildSideBar.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 ShouldReturnCorrectMessageIfBuildForcedSuccessfully() { DefaultProjectSpecifier projectSpecifier = new DefaultProjectSpecifier( new DefaultServerSpecifier("myServer"), "myProject"); cruiseRequestMock.SetupGet(_request => _request.ProjectSpecifier).Returns(projectSpecifier); cruiseRequestMock.SetupGet(_request => _request.ProjectName).Returns("myProject"); mockFarmService.Setup(service => service.ForceBuild(projectSpecifier, (string)null)).Verifiable(); IResponse response = reportAction.Execute(cruiseRequest); Assert.IsTrue(response is XmlFragmentResponse); Assert.AreEqual("<ForceBuildResult>Build Forced for myProject</ForceBuildResult>", ((XmlFragmentResponse)response).ResponseFragment); }
public void ReturnsLatestLogNameFromCorrectProjectOnCorrectServer() { string buildName = "mylogformyserverformyproject"; MockRepository mocks = new MockRepository(MockBehavior.Default); ServerAggregatingCruiseManagerWrapper serverWrapper = InitialiseServerWrapper(mocks, delegate(CruiseServerClientBase manager) { Mock.Get(manager).Setup(_manager => _manager.GetLatestBuildName(It.IsAny <string>())) .Returns(buildName); }); DefaultProjectSpecifier myProjectMyServer = new DefaultProjectSpecifier(new DefaultServerSpecifier("myserver"), "myproject"); Assert.AreEqual(new DefaultBuildSpecifier(myProjectMyServer, buildName), serverWrapper.GetLatestBuildSpecifier(myProjectMyServer, null)); }
public void ShouldGenerateBuildViewIfServerAndProjectAndBuildSpecified() { // Setup IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild"); cruiseRequestWrapperMock.ExpectAndReturn("ServerName", "myServer"); cruiseRequestWrapperMock.ExpectAndReturn("ProjectName", "myProject"); cruiseRequestWrapperMock.ExpectAndReturn("BuildName", "myBuild"); cruiseRequestWrapperMock.ExpectAndReturn("BuildSpecifier", buildSpecifier); cruiseRequestWrapperMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); pluginLinkCalculatorMock.ExpectAndReturn("GetBuildPluginLinks", links, buildSpecifier); string recentBuildsView = ""; recentBuildsViewBuilderMock.ExpectAndReturn("BuildRecentBuildsTable", recentBuildsView, buildSpecifier, null); IBuildSpecifier nextBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "next"); IBuildSpecifier previousBuildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "previous"); IAbsoluteLink latestLink = new GeneralAbsoluteLink("test latest"); IAbsoluteLink nextLink = new GeneralAbsoluteLink("test next"); IAbsoluteLink previousLink = new GeneralAbsoluteLink("test previous"); buildNameRetrieverMock.ExpectAndReturn("GetNextBuildSpecifier", nextBuildSpecifier, buildSpecifier, null); buildNameRetrieverMock.ExpectAndReturn("GetPreviousBuildSpecifier", previousBuildSpecifier, buildSpecifier, null); string action = BuildReportBuildPlugin.ACTION_NAME; linkFactoryMock.ExpectAndReturn("CreateProjectLink", latestLink, projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME); linkFactoryMock.ExpectAndReturn("CreateBuildLink", nextLink, nextBuildSpecifier, "", action); linkFactoryMock.ExpectAndReturn("CreateBuildLink", previousLink, previousBuildSpecifier, "", action); velocityContext["links"] = links; velocityContext["recentBuildsTable"] = recentBuildsView; velocityContext["latestLink"] = latestLink; velocityContext["nextLink"] = nextLink; velocityContext["previousLink"] = previousLink; velocityViewGeneratorMock.ExpectAndReturn("GenerateView", velocityResponse, @"BuildSideBar.vm", new HashtableConstraint(velocityContext)); // Execute HtmlFragmentResponse returnedResponse = sideBarViewBuilder.Execute(cruiseRequestWrapperMock.MockInstance as ICruiseRequest); // Verify Assert.AreEqual(velocityResponse, returnedResponse); VerifyAll(); }
public void ShouldReturnProjectsSortedByLastBuildDateIfLastBuildDateColumnSpecifiedAsSortSeed() { // Setup IProjectSpecifier projectA = new DefaultProjectSpecifier(serverSpecifier, "a"); IProjectSpecifier projectB = new DefaultProjectSpecifier(serverSpecifier, "b"); ProjectStatus projectStatus1 = new ProjectStatus("b", "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today, "1", null, DateTime.Today, "", "", 0); ProjectStatus projectStatus2 = new ProjectStatus("a", "category", ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url", DateTime.Today.AddHours(1), "1", null, DateTime.Today, "", "", 0); ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[] { new ProjectStatusOnServer(projectStatus1, serverSpecifier), new ProjectStatusOnServer(projectStatus2, serverSpecifier) }; SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectA); // Execute mocks.ReplayAll(); ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.LastBuildDate, true, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(2, rows.Length); Assert.AreEqual("b", rows[0].Name); Assert.AreEqual("a", rows[1].Name); // Setup SetupProjectLinkExpectation(projectB); SetupProjectLinkExpectation(projectA); // Execute rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.LastBuildDate, false, "", urlBuilderMock, new Translations("en-US")); // Verify Assert.AreEqual(2, rows.Length); Assert.AreEqual("a", rows[0].Name); Assert.AreEqual("b", rows[1].Name); VerifyAll(); }
public void ShouldPassValidModelToBuilderAndReturnBuildersResult() { IResponse response = new HtmlFragmentResponse("foo"); // Setup IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); string expectedMessage = "Please confirm you want to delete myProject, and choose which extra delete actions you want to perform"; viewBuilderMock.ExpectAndReturn("BuildView", response, new DeleteProjectModel(projectSpecifier, expectedMessage, true, true, true, true)); // Execute IResponse returnedResponse = showDeleteProjectAction.Execute(cruiseRequest); // Verify Assert.AreEqual(response, returnedResponse); VerifyAll(); }
public void ReturnsLatestLogNameFromCorrectProjectOnCorrectServer() { string buildName = "mylogformyserverformyproject"; MockRepository mocks = new MockRepository(); ServerAggregatingCruiseManagerWrapper serverWrapper = InitialiseServerWrapper(mocks, delegate(CruiseServerClientBase manager) { SetupResult.For(manager.GetLatestBuildName(null)) .IgnoreArguments() .Return(buildName); }); mocks.ReplayAll(); DefaultProjectSpecifier myProjectMyServer = new DefaultProjectSpecifier(new DefaultServerSpecifier("myserver"), "myproject"); Assert.AreEqual(new DefaultBuildSpecifier(myProjectMyServer, buildName), serverWrapper.GetLatestBuildSpecifier(myProjectMyServer, null)); }
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 ProjectGridRow[] GenerateProjectGridRows(IFarmService farmService, ProjectStatusOnServer[] statusList, string forceBuildActionName, ProjectGridSortColumn sortColumn, bool sortIsAscending) { ArrayList rows = new ArrayList(); foreach (ProjectStatusOnServer statusOnServer in statusList) { ProjectStatus status = statusOnServer.ProjectStatus; IServerSpecifier serverSpecifier = statusOnServer.ServerSpecifier; string projectName = status.Name; IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName); string projectLink = linkFactory.CreateProjectLink(projectSpecifier, ProjectReportProjectPlugin.ACTION_NAME).Url; IBuildSpecifier[] buildSpecifiers = farmService.GetMostRecentBuildSpecifiers(projectSpecifier, 1); string mostRecentBuildUrl; if (buildSpecifiers.Length == 1) { mostRecentBuildUrl = linkFactory.CreateProjectLink(projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME).Url; } else { mostRecentBuildUrl = projectLink; } rows.Add( new ProjectGridRow( projectName, statusOnServer.ServerSpecifier.ServerName, status.BuildStatus.ToString(), CalculateHtmlColor(status.BuildStatus), status.LastBuildDate, (status.LastBuildLabel != null ? status.LastBuildLabel : "no build available"), status.Status.ToString(), status.Activity.ToString(), urlBuilder.BuildFormName(forceBuildActionName), projectLink, mostRecentBuildUrl )); } rows.Sort(GetComparer(sortColumn, sortIsAscending)); return((ProjectGridRow[])rows.ToArray(typeof(ProjectGridRow))); }
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)); }
public void ShouldCallFarmServiceAndIfSuccessfulShowSuccessMessage() { IResponse response = new HtmlFragmentResponse("foo"); // Setup IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); requestMock.ExpectAndReturn("GetChecked", true, "PurgeWorkingDirectory"); requestMock.ExpectAndReturn("GetChecked", false, "PurgeArtifactDirectory"); requestMock.ExpectAndReturn("GetChecked", true, "PurgeSourceControlEnvironment"); farmServiceMock.Expect("DeleteProject", projectSpecifier, true, false, true, null); string expectedMessage = "Project Deleted"; viewBuilderMock.ExpectAndReturn("BuildView", response, new DeleteProjectModel(projectSpecifier, expectedMessage, false, true, false, true)); // Execute IResponse returnedResponse = doDeleteProjectAction.Execute(cruiseRequest); // Verify Assert.AreEqual(response, returnedResponse); VerifyAll(); }
public void ReturnsServerLogFromRequestedServerForSpecificProject() { // Setup IServerSpecifier serverSpecifier = new DefaultServerSpecifier("foo"); IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "foo-project"); string serverLog = "server log"; HtmlFragmentResponse response = new HtmlFragmentResponse("foo"); requestMock.SetupGet(_request => _request.ServerSpecifier).Returns(serverSpecifier); requestMock.SetupGet(_request => _request.ProjectName).Returns(projectSpecifier.ProjectName); requestMock.SetupGet(_request => _request.ProjectSpecifier).Returns(projectSpecifier); farmServiceMock.Setup(service => service.GetServerLog(projectSpecifier, null)).Returns(serverLog).Verifiable(); farmServiceMock.Setup(service => service.GetProjectStatusListAndCaptureExceptions(serverSpecifier, null)).Returns(new ProjectStatusListAndExceptions(new ProjectStatusOnServer[0], null)).Verifiable(); viewGeneratorMock.Setup(generator => generator.GenerateView(@"ServerLog.vm", It.Is <Hashtable>(t => t.Count == 3 && (string)t["log"] == serverLog && t.ContainsKey("projectLinks") && (string)t["currentProject"] == projectSpecifier.ProjectName))). Returns(response).Verifiable(); // Execute Assert.AreEqual(response, action.Execute((ICruiseRequest)requestMock.Object)); VerifyAll(); }
public void ShouldGetProjectDetailsAndUseCorrectTemplate() { // Setup ExternalLink[] links = new ExternalLink[] { new ExternalLink("foo", "bar") }; IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); //IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild"); IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "log20050818103522Lbuild.0.0.0.9.xml"); Hashtable expectedContext = new Hashtable(); var requestStub = new Mock <IRequest>(); IRequest request = (IRequest)requestStub.Object; cruiseRequestMock.SetupGet(r => r.Request).Returns(request); requestStub.SetupGet(r => r.ApplicationPath).Returns("myAppPath"); farmServiceMock.Setup(service => service.GetRSSFeed(projectSpecifier, It.IsAny <string>())).Returns("").Verifiable(); expectedContext["projectName"] = "myProject"; expectedContext["externalLinks"] = links; expectedContext["noLogsAvailable"] = false; expectedContext["mostRecentBuildUrl"] = "buildUrl"; expectedContext["applicationPath"] = "myAppPath"; expectedContext["rssDataPresent"] = false; expectedContext["rss"] = new GeneralAbsoluteLink("RSS", @"http://localhost/myServer"); HtmlFragmentResponse response = new HtmlFragmentResponse("myView"); cruiseRequestMock.SetupGet(r => r.ProjectSpecifier).Returns(projectSpecifier).Verifiable(); farmServiceMock.Setup(service => service.GetMostRecentBuildSpecifiers(projectSpecifier, 1, null)).Returns(new IBuildSpecifier[] { buildSpecifier }).Verifiable(); farmServiceMock.Setup(service => service.GetExternalLinks(projectSpecifier, null)).Returns(links).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateProjectLink(projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME)).Returns(new GeneralAbsoluteLink("foo", "buildUrl")).Verifiable(); linkFactoryMock.Setup(factory => factory.CreateProjectLink(projectSpecifier, ThoughtWorks.CruiseControl.WebDashboard.Plugins.RSS.RSSFeed.ACTION_NAME)).Returns(new GeneralAbsoluteLink("RSS", @"myServer")).Verifiable(); farmServiceMock.Setup(service => service.GetMostRecentBuildSpecifiers(projectSpecifier, ProjectReportProjectPlugin.AmountOfBuildsToRetrieve, null)).Returns(new IBuildSpecifier[] { buildSpecifier }).Verifiable(); expectedContext["graphDayInfo"] = new ArrayList(); expectedContext["highestAmountPerDay"] = 1; expectedContext["dateMultiPlier"] = 1; expectedContext["OKPercent"] = 100; expectedContext["NOKPercent"] = 0; expectedContext["server"] = new DefaultServerSpecifier("myServer"); expectedContext["StatusMessage"] = string.Empty; expectedContext["status"] = null; expectedContext["StartStopButtonName"] = "StartBuild"; expectedContext["StartStopButtonValue"] = "Start"; expectedContext["ForceAbortBuildButtonName"] = "ForceBuild"; expectedContext["ForceAbortBuildButtonValue"] = "Force"; viewGeneratorMock.Setup(generator => generator.GenerateView(@"ProjectReport.vm", It.IsAny <Hashtable>())). Callback <string, Hashtable>((name, context) => Assert.AreEqual(context, expectedContext)).Returns(response).Verifiable(); // Execute IResponse returnedResponse = plugin.Execute(cruiseRequest); // Verify Assert.AreEqual(response, returnedResponse); VerifyAll(); }
public void ShouldGetProjectDetailsAndUseCorrectTemplate() { // Setup ExternalLink[] links = new ExternalLink[] { new ExternalLink("foo", "bar") }; IProjectSpecifier projectSpecifier = new DefaultProjectSpecifier(new DefaultServerSpecifier("myServer"), "myProject"); //IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "myBuild"); IBuildSpecifier buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "log20050818103522Lbuild.0.0.0.9.xml"); Hashtable expectedContext = new Hashtable(); DynamicMock requestStub = new DynamicMock(typeof(IRequest)); IRequest request = (IRequest)requestStub.MockInstance; cruiseRequestMock.SetupResult("Request", request); requestStub.SetupResult("ApplicationPath", "myAppPath"); farmServiceMock.ExpectAndReturn("GetRSSFeed", "", projectSpecifier); expectedContext["projectName"] = "myProject"; expectedContext["externalLinks"] = links; expectedContext["noLogsAvailable"] = false; expectedContext["mostRecentBuildUrl"] = "buildUrl"; expectedContext["applicationPath"] = "myAppPath"; expectedContext["rssDataPresent"] = false; expectedContext["rss"] = new GeneralAbsoluteLink("RSS", @"http://localhost/myServer"); IResponse response = new HtmlFragmentResponse("myView"); cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); cruiseRequestMock.ExpectAndReturn("ProjectSpecifier", projectSpecifier); farmServiceMock.ExpectAndReturn("GetMostRecentBuildSpecifiers", new IBuildSpecifier[] { buildSpecifier }, projectSpecifier, 1, null); farmServiceMock.ExpectAndReturn("GetExternalLinks", links, projectSpecifier, null); linkFactoryMock.ExpectAndReturn("CreateProjectLink", new GeneralAbsoluteLink("foo", "buildUrl"), projectSpecifier, LatestBuildReportProjectPlugin.ACTION_NAME); linkFactoryMock.ExpectAndReturn("CreateProjectLink", new GeneralAbsoluteLink("RSS", @"myServer"), projectSpecifier, ThoughtWorks.CruiseControl.WebDashboard.Plugins.RSS.RSSFeed.ACTION_NAME); farmServiceMock.ExpectAndReturn("GetMostRecentBuildSpecifiers", new IBuildSpecifier[] { buildSpecifier }, projectSpecifier, ProjectReportProjectPlugin.AmountOfBuildsToRetrieve, null); expectedContext["graphDayInfo"] = new NMock.Constraints.IsTypeOf(typeof(ArrayList)); expectedContext["highestAmountPerDay"] = 1; expectedContext["dateMultiPlier"] = 1; expectedContext["OKPercent"] = 100; expectedContext["NOKPercent"] = 0; expectedContext["server"] = new DefaultServerSpecifier("myServer"); expectedContext["StatusMessage"] = string.Empty; expectedContext["status"] = null; expectedContext["StartStopButtonName"] = "StartBuild"; expectedContext["StartStopButtonValue"] = "Start"; expectedContext["ForceAbortBuildButtonName"] = "ForceBuild"; expectedContext["ForceAbortBuildButtonValue"] = "Force"; viewGeneratorMock.ExpectAndReturn("GenerateView", response, @"ProjectReport.vm", new HashtableConstraint(expectedContext)); // Execute IResponse returnedResponse = plugin.Execute(cruiseRequest); // Verify Assert.AreEqual(response, returnedResponse); VerifyAll(); }