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 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");
		}
		public void Setup()
		{
			urlBuilderMock = new DynamicMock(typeof (IUrlBuilder));
			serverSpecifier = new DefaultServerSpecifier("myserver");
			projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myproject");
			buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "mybuild");
			cruiseUrlBuilder = new DefaultCruiseUrlBuilder((IUrlBuilder) urlBuilderMock.MockInstance);
		}
        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override bool Equals(object obj)
        {
            DefaultServerSpecifier other = obj as DefaultServerSpecifier;

            if (other != null)
            {
                return(this.ServerName == other.ServerName);
            }
            return(false);
        }
		public void ShouldGenerateServerLinks()
		{
			string action = "ViewServerReport";
			IServerSpecifier serverSpecifier1 = new DefaultServerSpecifier("myserver");
			IServerSpecifier serverSpecifier2 = new DefaultServerSpecifier("myotherserver");

			IAbsoluteLink link1 = new GeneralAbsoluteLink("link 1");
			IAbsoluteLink link2 = new GeneralAbsoluteLink("link 2");

			linkFactoryMock.ExpectAndReturn("CreateServerLink", link1, serverSpecifier1, action);
			linkFactoryMock.ExpectAndReturn("CreateServerLink", link2, serverSpecifier2, action);

			IAbsoluteLink[] returnedLinks = linkListFactory.CreateServerLinkList(new IServerSpecifier[] { serverSpecifier1, serverSpecifier2 }, action);

			Assert.AreEqual(2, returnedLinks.Length);
			Assert.AreEqual(link1, returnedLinks[0]);
			Assert.AreEqual(link2, returnedLinks[1]);

			VerifyAll();
		}
		public void Setup()
		{
			serverSpecifier = new DefaultServerSpecifier(serverName);
			projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, projectName);
			buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, buildName);
			linkFactoryMock = new DynamicMock(typeof (ILinkFactory));
			configurationMock = new DynamicMock(typeof (IPluginConfiguration));
			Plugins = new DefaultPluginLinkCalculator((ILinkFactory) linkFactoryMock.MockInstance, (IPluginConfiguration) configurationMock.MockInstance);

			pluginMock1 = new DynamicMock(typeof (IPlugin));
			pluginMock2 = new DynamicMock(typeof (IPlugin));
			action1 = new ImmutableNamedAction("Action Name 1", null);
			action2 = new ImmutableNamedAction("Action Name 2", null);
			action3 = new ImmutableNamedAction("Action Name 3", null);
			pluginMock1.ExpectAndReturn("LinkDescription", "Description 1");
			pluginMock1.ExpectAndReturn("NamedActions", new INamedAction[] {action1});
			pluginMock2.ExpectAndReturn("LinkDescription", "Description 2");
			pluginMock2.ExpectAndReturn("NamedActions", new INamedAction[] {action2});
			link1 = (IAbsoluteLink) new DynamicMock(typeof (IAbsoluteLink)).MockInstance;
			link2 = (IAbsoluteLink) new DynamicMock(typeof (IAbsoluteLink)).MockInstance;
		}
		public void Setup()
		{
			configurationMock = new DynamicMock(typeof (IRemoteServicesConfiguration));
            cruiseManagerFactoryMock = new DynamicMock(typeof(ICruiseServerClientFactory));
			cruiseManagerMock = new DynamicMock(typeof (ICruiseServerClient));
			serverSpecifier = new DefaultServerSpecifier("myserver");
			projectSpecifier = new DefaultProjectSpecifier(serverSpecifier, "myproject");
			buildSpecifier = new DefaultBuildSpecifier(projectSpecifier, "mybuild");
			buildSpecifierForUnknownServer = new DefaultBuildSpecifier(new DefaultProjectSpecifier(new DefaultServerSpecifier("unknownServer"), "myProject"), "myBuild");

			managerWrapper = new ServerAggregatingCruiseManagerWrapper(
				(IRemoteServicesConfiguration) configurationMock.MockInstance,
                (ICruiseServerClientFactory)cruiseManagerFactoryMock.MockInstance
				);

			serverLocation = new ServerLocation();
			serverLocation.Name = "myserver";
			serverLocation.Url = "http://myurl";
			serverLocation.AllowForceBuild = true;

			otherServerLocation = new ServerLocation();
			otherServerLocation.Name = "myotherserver";
			otherServerLocation.Url = "http://myotherurl";
		}
		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, new List<ParameterBase>());
			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();
		}
		public void ShouldReturnProjectsSortedByServerIfServerNameColumnSpecifiedAsSortSeed()
		{
			// Setup
			IServerSpecifier serverSpecifierA = new DefaultServerSpecifier("Aserver");
			IServerSpecifier serverSpecifierB = new DefaultServerSpecifier("Bserver");
			IProjectSpecifier projectA = new DefaultProjectSpecifier(serverSpecifierA, "a");
			IProjectSpecifier projectB = new DefaultProjectSpecifier(serverSpecifierB, "b");

			ProjectStatus projectStatus1 = new ProjectStatus("a", "category",
				ProjectActivity.Sleeping, IntegrationStatus.Success, ProjectIntegratorState.Running, "url",
                DateTime.Today, "1", null, DateTime.Today, "", "", 0, new List<ParameterBase>());
			ProjectStatus projectStatus2 = new ProjectStatus("b", "category",
				ProjectActivity.Sleeping, IntegrationStatus.Failure, ProjectIntegratorState.Running, "url",
                DateTime.Today.AddHours(1), "1", null, DateTime.Today, "", "", 0, new List<ParameterBase>());
			ProjectStatusOnServer[] statusses = new ProjectStatusOnServer[]
				{
					new ProjectStatusOnServer(projectStatus1, serverSpecifierA),
					new ProjectStatusOnServer(projectStatus2, serverSpecifierB)
				};
			SetupProjectLinkExpectation(projectA);
			SetupProjectLinkExpectation(projectB);

			// Execute
            mocks.ReplayAll();
            ProjectGridRow[] rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.ServerName, true, "", urlBuilderMock, new Translations("en-US"));

			// Verify
			Assert.AreEqual(2, rows.Length);
			Assert.AreEqual("a", rows[0].Name);
			Assert.AreEqual("b", rows[1].Name);

			// Setup
			SetupProjectLinkExpectation(projectA);
			SetupProjectLinkExpectation(projectB);

			// Execute
            rows = projectGrid.GenerateProjectGridRows(statusses, "myAction", ProjectGridSortColumn.ServerName, false, "", urlBuilderMock, new Translations("en-US"));

			// Verify
			Assert.AreEqual(2, rows.Length);
			Assert.AreEqual("b", rows[0].Name);
			Assert.AreEqual("a", rows[1].Name);

			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();
		}
예제 #11
0
                GetBuildGraph(int amountOfBuilds, Boolean buildsAreInSameDay)
        {        
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier[] builds;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultProjectSpecifier ProjectSpecifier;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultServerSpecifier ServerSpecifier;
            CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory LinkFactory;
            CruiseControl.WebDashboard.Dashboard.DefaultBuildNameFormatter BuildNameFormatter;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultUrlBuilder UrlBuilder;
            CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultCruiseUrlBuilder CruiseUrlBuilder;
            CruiseControl.Core.Project project;

            project = new CruiseControl.Core.Project();
            project.Name = "TestProject";

            ServerSpecifier = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultServerSpecifier("local");

            ProjectSpecifier = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultProjectSpecifier(ServerSpecifier,project.Name);
            
            builds = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier[amountOfBuilds];

            for(int i=0; i < amountOfBuilds; i++)
            {
                if (buildsAreInSameDay)                
                    builds[i] = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier( ProjectSpecifier , string.Format(System.Globalization.CultureInfo.CurrentCulture,"log20050801015223Lbuild.0.0.0.{0}.xml", i) );
                  else
                    builds[i] = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultBuildSpecifier( ProjectSpecifier , string.Format(System.Globalization.CultureInfo.CurrentCulture,"log200508{0}015223Lbuild.0.0.0.{1}.xml", (i+1).ToString("00"), i) );
            }

            UrlBuilder = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultUrlBuilder();
            CruiseUrlBuilder = new CruiseControl.Core.Reporting.Dashboard.Navigation.DefaultCruiseUrlBuilder(UrlBuilder);
            BuildNameFormatter = new CruiseControl.WebDashboard.Dashboard.DefaultBuildNameFormatter();
            
            LinkFactory = new  CruiseControl.WebDashboard.Dashboard.DefaultLinkFactory(UrlBuilder,CruiseUrlBuilder,BuildNameFormatter);
        
            return new CruiseControl.WebDashboard.Plugins.Statistics.BuildGraph(builds, LinkFactory, new Translations("en-US"));
        }