public void PreProc_NonEmptySonarRunnerProperties() { // Checks the ruleset generator is called with the expected arguments // Arrange string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); string propertiesFile = CreatePropertiesFile(testDir, "my url", "my user name", "my password"); MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher(); MockRulesetGenerator mockRulesetGenerator = new MockRulesetGenerator(); TestLogger logger = new TestLogger(); string expectedConfigFileName; using (PreprocessTestUtils.CreateValidLegacyTeamBuildScope("tfs uri", "build uri", testDir)) { TeamBuildSettings settings = TeamBuildSettings.GetSettingsFromEnvironment(new ConsoleLogger()); Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly"); expectedConfigFileName = settings.AnalysisConfigFilePath; TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator); // Act preProcessor.Execute(logger, "key", "name", "ver", propertiesFile); } // Assert mockPropertiesFetcher.AssertFetchPropertiesCalled(); mockPropertiesFetcher.CheckFetcherArguments("my url", "key"); mockRulesetGenerator.AssertGenerateCalled(); mockRulesetGenerator.CheckGeneratorArguments("my url", "key"); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); }
public void PreProc_InvalidArgs() { // Arrange TestLogger validLogger = new TestLogger(); string[] validArgs = new string[] { "/k:key", "/n:name", "/v:1.0" }; MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher(); MockRulesetGenerator mockRulesetGenerator = new MockRulesetGenerator(); MockTargetsInstaller mockTargetsInstaller = new MockTargetsInstaller(); TeamBuildPreProcessor preprocessor = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator, mockTargetsInstaller); // Act and assert AssertException.Expects <ArgumentNullException>(() => preprocessor.Execute(null, validLogger)); AssertException.Expects <ArgumentNullException>(() => preprocessor.Execute(validArgs, null)); }
public void PreProc_EmptySonarRunnerProperties() { // Checks the pre-processor creates a valid config file // Arrange string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); string propertiesFile = CreateEmptyPropertiesFile(testDir); MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher(); MockRulesetGenerator mockRulesetGenerator = new MockRulesetGenerator(); TestLogger logger = new TestLogger(); string expectedConfigFileName; using (PreprocessTestUtils.CreateValidLegacyTeamBuildScope("tfs uri", "http://builduri", testDir)) { TeamBuildSettings settings = TeamBuildSettings.GetSettingsFromEnvironment(new ConsoleLogger()); Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly"); expectedConfigFileName = settings.AnalysisConfigFilePath; TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator); // Act preProcessor.Execute(logger, "key", "name", "ver", propertiesFile); } // Assert Assert.IsTrue(File.Exists(expectedConfigFileName), "Config file does not exist: {0}", expectedConfigFileName); AnalysisConfig config = AnalysisConfig.Load(expectedConfigFileName); Assert.IsTrue(Directory.Exists(config.SonarOutputDir), "Output directory was not created: {0}", config.SonarOutputDir); Assert.IsTrue(Directory.Exists(config.SonarConfigDir), "Config directory was not created: {0}", config.SonarConfigDir); Assert.AreEqual("key", config.SonarProjectKey); Assert.AreEqual("name", config.SonarProjectName); Assert.AreEqual("ver", config.SonarProjectVersion); Assert.AreEqual("http://builduri", config.GetBuildUri()); Assert.AreEqual("tfs uri", config.GetTfsUri()); Assert.AreEqual(propertiesFile, config.SonarRunnerPropertiesPath); mockPropertiesFetcher.AssertFetchPropertiesCalled(); mockPropertiesFetcher.CheckFetcherArguments("http://localhost:9000", "key"); mockRulesetGenerator.AssertGenerateCalled(); mockRulesetGenerator.CheckGeneratorArguments("http://localhost:9000", "key"); }
public void PreProc_EndToEnd_SuccessCase() { // Checks end-to-end happy path for the pre-processor i.e. // * arguments are parsed // * targets are installed // * server properties are fetched // * rulesets are generated // * config file is created // Arrange string workingDir = TestUtils.CreateTestSpecificFolder(this.TestContext); MockRulesetGenerator mockRulesetGenerator = new MockRulesetGenerator(); TestLogger logger = new TestLogger(); MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher(); mockPropertiesFetcher.PropertiesToReturn = new Dictionary<string, string>(); MockTargetsInstaller mockTargetsInstaller = new MockTargetsInstaller(); // The set of server properties to return mockPropertiesFetcher.PropertiesToReturn.Add("server.key", "server value 1"); string[] validArgs = new string[] { "/k:key", "/n:name", "/v:1.0", "/d:cmd.line1=cmdline.value.1", "/d:sonar.host.url=http://host", "/d:sonar.log.level=INFO|DEBUG"}; TeamBuildSettings settings; using (PreprocessTestUtils.CreateValidNonTeamBuildScope()) using (new WorkingDirectoryScope(workingDir)) { settings = TeamBuildSettings.GetSettingsFromEnvironment(new TestLogger()); Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly"); Assert.AreEqual(BuildEnvironment.NotTeamBuild, settings.BuildEnvironment, "Test setup error: build environment was not set correctly"); TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator, mockTargetsInstaller); // Act bool success = preProcessor.Execute(validArgs, logger); Assert.IsTrue(success, "Expecting the pre-processing to complete successfully"); } // Assert AssertDirectoryExists(settings.AnalysisBaseDirectory); AssertDirectoryExists(settings.SonarConfigDirectory); AssertDirectoryExists(settings.SonarOutputDirectory); // The bootstrapper is responsible for creating the bin directory mockTargetsInstaller.AssertsTargetsCopied(); mockPropertiesFetcher.AssertFetchPropertiesCalled(); mockRulesetGenerator.AssertGenerateCalled(2); // C# and VB logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); logger.AssertVerbosity(LoggerVerbosity.Debug); AssertConfigFileExists(settings.AnalysisConfigFilePath); AnalysisConfig actualConfig = AnalysisConfig.Load(settings.AnalysisConfigFilePath); Assert.AreEqual("key", actualConfig.SonarProjectKey, "Unexpected project key"); Assert.AreEqual("name", actualConfig.SonarProjectName, "Unexpected project name"); Assert.AreEqual("1.0", actualConfig.SonarProjectVersion, "Unexpected project version"); AssertExpectedLocalSetting(SonarProperties.HostUrl, "http://host", actualConfig); AssertExpectedLocalSetting("cmd.line1", "cmdline.value.1", actualConfig); AssertExpectedServerSetting("server.key", "server value 1", actualConfig); }
public void PreProc_InvalidArgs() { // Arrange TestLogger validLogger = new TestLogger(); string[] validArgs = new string[] { "/k:key", "/n:name", "/v:1.0" }; MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher(); MockRulesetGenerator mockRulesetGenerator = new MockRulesetGenerator(); MockTargetsInstaller mockTargetsInstaller = new MockTargetsInstaller(); TeamBuildPreProcessor preprocessor = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator, mockTargetsInstaller); // Act and assert AssertException.Expects<ArgumentNullException>(() => preprocessor.Execute(null, validLogger)); AssertException.Expects<ArgumentNullException>(() => preprocessor.Execute(validArgs, null)); }
public void PreProc_EndToEnd_SuccessCase() { // Checks end-to-end happy path for the pre-processor i.e. // * arguments are parsed // * targets are installed // * server properties are fetched // * rulesets are generated // * config file is created // Arrange string workingDir = TestUtils.CreateTestSpecificFolder(this.TestContext); MockRulesetGenerator mockRulesetGenerator = new MockRulesetGenerator(); TestLogger logger = new TestLogger(); MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher(); mockPropertiesFetcher.PropertiesToReturn = new Dictionary <string, string>(); MockTargetsInstaller mockTargetsInstaller = new MockTargetsInstaller(); // The set of server properties to return mockPropertiesFetcher.PropertiesToReturn.Add("server.key", "server value 1"); string[] validArgs = new string[] { "/k:key", "/n:name", "/v:1.0", "/d:cmd.line1=cmdline.value.1", "/d:sonar.host.url=http://host", "/d:sonar.log.level=INFO|DEBUG" }; TeamBuildSettings settings; using (PreprocessTestUtils.CreateValidNonTeamBuildScope()) using (new WorkingDirectoryScope(workingDir)) { settings = TeamBuildSettings.GetSettingsFromEnvironment(new TestLogger()); Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly"); Assert.AreEqual(BuildEnvironment.NotTeamBuild, settings.BuildEnvironment, "Test setup error: build environment was not set correctly"); TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator, mockTargetsInstaller); // Act bool success = preProcessor.Execute(validArgs, logger); Assert.IsTrue(success, "Expecting the pre-processing to complete successfully"); } // Assert AssertDirectoryExists(settings.AnalysisBaseDirectory); AssertDirectoryExists(settings.SonarConfigDirectory); AssertDirectoryExists(settings.SonarOutputDirectory); // The bootstrapper is responsible for creating the bin directory mockTargetsInstaller.AssertsTargetsCopied(); mockPropertiesFetcher.AssertFetchPropertiesCalled(); mockRulesetGenerator.AssertGenerateCalled(2); // C# and VB logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); logger.AssertVerbosity(LoggerVerbosity.Debug); AssertConfigFileExists(settings.AnalysisConfigFilePath); AnalysisConfig actualConfig = AnalysisConfig.Load(settings.AnalysisConfigFilePath); Assert.AreEqual("key", actualConfig.SonarProjectKey, "Unexpected project key"); Assert.AreEqual("name", actualConfig.SonarProjectName, "Unexpected project name"); Assert.AreEqual("1.0", actualConfig.SonarProjectVersion, "Unexpected project version"); AssertExpectedLocalSetting(SonarProperties.HostUrl, "http://host", actualConfig); AssertExpectedLocalSetting("cmd.line1", "cmdline.value.1", actualConfig); AssertExpectedServerSetting("server.key", "server value 1", actualConfig); }