public void FindQueueNotFound()
 {
     Configuration config = new Configuration();
     IQueueConfiguration foundConfig = config.FindQueueConfiguration("Test Queue");
     Assert.IsNotNull(foundConfig);
     Assert.That(foundConfig, Is.InstanceOf<DefaultQueueConfiguration>());
     Assert.AreEqual("Test Queue", foundConfig.Name);
     Assert.AreEqual(QueueDuplicateHandlingMode.UseFirst, foundConfig.HandlingMode);
 }
 public void FindQueueFound()
 {
     DefaultQueueConfiguration queueConfig = new DefaultQueueConfiguration("Test Queue");
     Configuration config = new Configuration();
     config.QueueConfigurations.Add(queueConfig);
     IQueueConfiguration foundConfig = config.FindQueueConfiguration("Test Queue");
     Assert.IsNotNull(foundConfig);
     Assert.AreSame(queueConfig, foundConfig);
 }
		public void CreateIntegrators()
		{
			Project project1 = new Project();
			project1.Name = "project1";
			Project project2 = new Project();
			project2.Name = "project2";

			Configuration config = new Configuration();
			config.AddProject(project1);
			config.AddProject(project2);
		}
        public void SetUp()
        {
            project = new Project();
            project.Name = TestQueueName;

            configuration = new Configuration();
            configuration.AddProject(project);
            stateManagerMock = new DynamicMock(typeof(IProjectStateManager));

            queueManager = new IntegrationQueueManager(new ProjectIntegratorListFactory(),            
                configuration,
                (IProjectStateManager)stateManagerMock.MockInstance);
        }
 public IConfiguration Read(XmlDocument document)
 {
     VerifyDocumentHasValidRootElement(document);
     try
     {
         Configuration configuration = new Configuration();
         foreach (XmlNode node in document.DocumentElement)
         {
             if (!(node is XmlComment))
             {
                 IProject project = reader.Read(node) as IProject;	// could this be null?  should check
                 configuration.AddProject(project);
             }
         }
         return configuration;
     }
     catch (NetReflectorException ex)
     {
         throw new ConfigurationException("Unable to instantiate CruiseControl projects from configuration document. " +
             "Configuration document is likely missing Xml nodes required for properly populating CruiseControl configuration." + ex.Message, ex);
     }
 }
예제 #6
0
        private object ValidateElement(HtmlElement tableEl, XmlNode node, int row, Configuration configuration)
        {
            HtmlAttribute rowClass = new HtmlAttribute("class", (row % 2) == 1 ? "even" : "odd");
            object loadedItem = null;
            try
            {
                loadedItem = myConfigReader.Read(node);
                this.configurationHierarchy.Add(loadedItem);
                if (loadedItem is IProject)
                {
                    IProject project = loadedItem as IProject;
                    configuration.AddProject(project);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", project.Name),
                            GenerateElement("td", "Project"),
                            GenerateElement("td", "Yes")));
                    LogMessage(string.Format("Loaded project '{0}'", project.Name));
                }
                else if (loadedItem is IQueueConfiguration)
                {
                    IQueueConfiguration queueConfig = loadedItem as IQueueConfiguration;
                    configuration.QueueConfigurations.Add(queueConfig);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", queueConfig.Name),
                            GenerateElement("td", "Queue"),
                            GenerateElement("td", "Yes")));
                    LogMessage(string.Format("Loaded queue '{0}'", queueConfig.Name));
                }
                else if (loadedItem is ISecurityManager)
                {
                    ISecurityManager securityManager = loadedItem as ISecurityManager;
                    configuration.SecurityManager = securityManager as ISecurityManager;
                    LogMessage("Loaded security manager");
                }
                else
                {
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                            GenerateElement("td", node.Name),
                            GenerateElement("td", "No")));
                    var message = "Unknown configuration type: " + loadedItem.GetType().Name;
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td",
                                new HtmlAttribute("colspan", "3"),
                                GenerateElement("div",
                                    new HtmlAttribute("class", "error"),
                                    message))));
                    LogMessage(message);
                    isConfigValid = false;
                }
            }
            catch (Exception error)
            {
                string errorMsg = error.Message;
                int index = errorMsg.IndexOf("Xml Source");
                if (index >= 0) errorMsg = errorMsg.Substring(0, index - 1);
                tableEl.AppendChild(
                    GenerateElement("tr",
                        rowClass,
                        GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                        GenerateElement("td", node.Name),
                        GenerateElement("td", "No")));
                tableEl.AppendChild(
                    GenerateElement("tr",
                        rowClass,
                        GenerateElement("td",
                            new HtmlAttribute("colspan", "3"),
                            GenerateElement("div",
                                new HtmlAttribute("class", "error"),
                                errorMsg))));
                isConfigValid = false;
                LogMessage(error.Message);
            }

            return loadedItem;
        }
예제 #7
0
        private void ValidateData(XmlDocument document)
        {
            var rootElement = document.DocumentElement.Name == "cruisecontrol" ? document.DocumentElement : null;
            if (rootElement == null)
            {
                var message = "Configuration is missing root <cruisecontrol> element";
                myBodyEl.AppendChild(
                    GenerateElement("div",
                    new HtmlAttribute("class", "error"),
                    GenerateElement("div", message)));
                LogMessage(message);
                isConfigValid = false;
            }
            else
            {
                HtmlElement tableEl = GenerateElement("table",
                    new HtmlAttribute("class", "results"),
                    GenerateHeader());
                Configuration configuration = new Configuration();
                if (!string.IsNullOrEmpty(rootElement.NamespaceURI))
                {
                    var parts = rootElement.NamespaceURI.Split('/');
                    var version = parts[parts.Length - 2] + "." + parts[parts.Length - 1];
                    myBodyEl.AppendChild(GenerateElement("div", "Target Version: " + version));
                }
                else
                {
                    myBodyEl.AppendChild(GenerateElement("div", "No version information"));
                }

                XmlNodeList nodes = rootElement.SelectNodes("*");
                int row = 0;
                double increment = (double)80 / nodes.Count;
                List<ConfigurationItem> items = new List<ConfigurationItem>();
                foreach (XmlNode childElement in nodes)
                {
                    DisplayProgressMessage("Validating elements, please wait...", Convert.ToInt32(10 + row * increment));
                    object config = ValidateElement(tableEl, childElement, row++, configuration);
                    if (config != null)
                    {
                        items.Add(new ConfigurationItem(childElement.Name, config));
                    }
                    else
                    {
                        isConfigValid = false;
                    }
                }

                myBodyEl.AppendChild(tableEl);
                isConfigValid &= InternalValidation(configuration);

                DisplayProcessedConfiguration(items);
                this.configurationHierarchy.Finalise();
            }
        }
예제 #8
0
        private bool RunValidationCheck(Configuration configuration, IConfigurationValidation validator, string name, ref int row, IConfigurationErrorProcesser errorProcesser)
        {
            bool isValid = true;

            try
            {
                validator.Validate(configuration, ConfigurationTrace.Start(configuration), errorProcesser);
            }
            catch (Exception error)
            {
                var message = string.Format("Internal validation failed for {0}: {1}",
                            name,
                            error.Message);
                HtmlAttribute rowClass = new HtmlAttribute("class", (row % 2) == 1 ? "even" : "odd");
                myBodyEl.AppendChild(
                    GenerateElement("div",
                        rowClass,
                        GenerateElement("div",
                        new HtmlAttribute("class", "error"),
                        message)));
                LogMessage(message);
                isValid = false;
                row++;
            }
            return isValid;
        }
예제 #9
0
        private bool InternalValidation(Configuration configuration)
        {
            var errorProcesser = new ValidationErrorProcesser(validationResults);
            DisplayProgressMessage("Validating internal integrity, please wait...", 90);

            HtmlElement nameEl = GenerateElement("div",
                new HtmlAttribute("class", "titleLine"),
                GenerateElement("b", "Internal validation"));
            myBodyEl.AppendChild(nameEl);
            bool isValid = true;
            int row = 0;

            foreach (IProject project in configuration.Projects)
            {
                if (project is IConfigurationValidation)
                {
                    errorProcesser.ItemName = string.Format("project '{0}'", project.Name);
                    isValid &= RunValidationCheck(configuration, project as IConfigurationValidation, errorProcesser.ItemName, ref row, errorProcesser);
                }
            }

            foreach (IQueueConfiguration queue in configuration.QueueConfigurations)
            {
                if (queue is IConfigurationValidation)
                {
                    errorProcesser.ItemName = string.Format("queue '{0}'", queue.Name);
                    isValid &= RunValidationCheck(configuration, queue as IConfigurationValidation, errorProcesser.ItemName, ref row, errorProcesser);
                }
            }

            if (configuration.SecurityManager is IConfigurationValidation)
            {
                errorProcesser.ItemName = "security manager";
                isValid &= RunValidationCheck(configuration, configuration.SecurityManager as IConfigurationValidation, errorProcesser.ItemName, ref row, errorProcesser);
            }

            if (isValid && errorProcesser.Passed)
            {
                var message = "Internal validation passed";
                myBodyEl.AppendChild(
                    GenerateElement("div",
                    message));
                LogMessage(message);
            }
            return isValid;
        }
예제 #10
0
		protected void SetUp()
		{
			projectSerializerMock = new DynamicMock(typeof (IProjectSerializer));

			integratorMock1 = new DynamicMock(typeof (IProjectIntegrator));
			integratorMock2 = new DynamicMock(typeof (IProjectIntegrator));
			integratorMock3 = new DynamicMock(typeof (IProjectIntegrator));
			integrator1 = (IProjectIntegrator) integratorMock1.MockInstance;
			integrator2 = (IProjectIntegrator) integratorMock2.MockInstance;
			integrator3 = (IProjectIntegrator) integratorMock3.MockInstance;
            integratorMock1.SetupResult("Name", "Project 1");
			integratorMock2.SetupResult("Name", "Project 2");
			integratorMock3.SetupResult("Name", "Project 3");

			fileSystem = mocks.DynamicMock<IFileSystem>();
			executionEnvironment = mocks.DynamicMock<IExecutionEnvironment>();

			SetupResult.For(executionEnvironment.IsRunningOnWindows).Return(true);
			SetupResult.For(executionEnvironment.GetDefaultProgramDataFolder(ApplicationType.Server)).Return(applicationDataPath);
			SetupResult.For(fileSystem.DirectoryExists(applicationDataPath)).Return(true);
			mocks.ReplayAll();

			integrationQueue = null; // We have no way of injecting currently.

			configuration = new Configuration();
			project1 = new Project();
			project1.Name = "Project 1";
            integratorMock1.SetupResult("Project", project1);
			
			project2 = new Project();
			project2.Name = "Project 2";
            integratorMock2.SetupResult("Project", project1);

			mockProject = new DynamicMock(typeof(IProject));
			mockProject.SetupResult("Name", "Project 3");
            mockProject.SetupResult("QueueName", "Project 3");
            mockProject.SetupResult("QueueName", "Project 3");
            mockProjectInstance = (IProject)mockProject.MockInstance;
			mockProject.SetupResult("Name", "Project 3");
            mockProject.SetupResult("StartupMode", ProjectStartupMode.UseLastState);
            integratorMock3.SetupResult("Project", mockProjectInstance);

			configuration.AddProject(project1);
			configuration.AddProject(project2);
			configuration.AddProject(mockProjectInstance);

			integratorList = new ProjectIntegratorList();
			integratorList.Add(integrator1);
			integratorList.Add(integrator2);
			integratorList.Add(integrator3);
            
			configServiceMock = new DynamicMock(typeof (IConfigurationService));
			configServiceMock.ExpectAndReturn("Load", configuration);

			projectIntegratorListFactoryMock = new DynamicMock(typeof (IProjectIntegratorListFactory));
			projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue);

            stateManagerMock = new DynamicMock(typeof(IProjectStateManager));
            stateManagerMock.SetupResult("CheckIfProjectCanStart", true, typeof(string));

			server = new CruiseServer((IConfigurationService) configServiceMock.MockInstance,
			                          (IProjectIntegratorListFactory) projectIntegratorListFactoryMock.MockInstance,
			                          (IProjectSerializer) projectSerializerMock.MockInstance,
                                      (IProjectStateManager)stateManagerMock.MockInstance,
									  fileSystem,
									  executionEnvironment,
                                      null);
		}
예제 #11
0
		public void OnRestartKillAllIntegratorsRefreshConfigAndStartupNewIntegrators()
		{
			integratorMock1.Expect("Start");
			integratorMock2.Expect("Start");

			server.Start();

			integratorMock1.Expect("Stop",true);
			integratorMock1.Expect("WaitForExit");
			integratorMock2.Expect("Stop",true);
			integratorMock2.Expect("WaitForExit");

			configuration = new Configuration();
			configuration.AddProject(project1);
			integratorList = new ProjectIntegratorList();
			integratorList.Add(integrator1);
			configServiceMock.ExpectAndReturn("Load", configuration);
			projectIntegratorListFactoryMock.ExpectAndReturn("CreateProjectIntegrators", integratorList, configuration.Projects, integrationQueue);

			integratorMock1.Expect("Start");
			integratorMock2.ExpectNoCall("Start");

			server.Restart();

			VerifyAll();
		}