public void RulesPluginBuilder_LanguageSetToNull_Fails() { // Arrange RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger()); // Act and assert AssertException.Expect<ArgumentNullException>(() => builder.SetLanguage(null)); AssertException.Expect<ArgumentNullException>(() => builder.SetLanguage("")); }
public void RulesPluginBuilder_LanguageSetToNull_Fails() { // Arrange RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger()); // Act and assert AssertException.Expect <ArgumentNullException>(() => builder.SetLanguage(null)); AssertException.Expect <ArgumentNullException>(() => builder.SetLanguage("")); }
private void BuildPlugin(IPackage package, string language, string rulesFilePath, string sqaleFilePath, PluginManifest pluginDefn, string baseTempDirectory, string outputDirectory) { this.logger.LogInfo(UIResources.APG_GeneratingPlugin); // Make the .jar name match the format [artefactid]-[version].jar // i.e. the format expected by Maven Directory.CreateDirectory(outputDirectory); string fullJarPath = Path.Combine(outputDirectory, package.Id + "-plugin-" + pluginDefn.Version + ".jar"); RulesPluginBuilder builder = new RulesPluginBuilder(logger); builder.SetLanguage(language) .SetRulesFilePath(rulesFilePath) .SetProperties(pluginDefn) .SetJarFilePath(fullJarPath); if (!string.IsNullOrWhiteSpace(sqaleFilePath)) { builder.SetSqaleFilePath(sqaleFilePath); } AddRoslynMetadata(baseTempDirectory, builder, package); builder.Build(); this.logger.LogInfo(UIResources.APG_PluginGenerated, fullJarPath); }
public void RulesPluginBuilder_RulesFileValidation() { // Arrange MockJdkWrapper mockJdkWrapper = new MockJdkWrapper(); RulesPluginBuilder builder = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger()); SetValidCoreProperties(builder); builder.SetLanguage("aLanguage"); // 1. Rules file not specified -> error AssertException.Expect <InvalidOperationException>(() => builder.Build()); // 2. Non-existent rules file specified -> error string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext); string rulesFile = Path.Combine(testDir, "missingFile.txt"); mockJdkWrapper.AssertCodeNotCompiled(); builder.SetRulesFilePath(rulesFile); FileNotFoundException ex = AssertException.Expect <FileNotFoundException>(() => builder.Build()); Assert.AreEqual(ex.FileName, rulesFile); mockJdkWrapper.AssertCodeNotCompiled(); // 3. Rules file exists -> succeeds AddValidDummyRulesFiles(builder); builder.Build(); // should succeed mockJdkWrapper.AssertJarBuilt(); }
public void RulesPluginBuilder_CreateSimplePlugin_Succeeds() { string inputDir = TestUtils.CreateTestDirectory(this.TestContext, "input"); string outputDir = TestUtils.CreateTestDirectory(this.TestContext, "output"); string fullJarFilePath = Path.Combine(outputDir, "myPlugin.jar"); string language = "xx"; string rulesXmlFilePath = TestUtils.CreateTextFile("rules.xml", inputDir, "<xml Rules />"); string sqaleXmlFilePath = TestUtils.CreateTextFile("sqale.xml", inputDir, "<xml sqale />"); PluginManifest defn = new PluginManifest() { Key = "MyPlugin", Name = "My Plugin", Description = "Generated plugin", Version = "0.1-SNAPSHOT", Organization = "ACME Software Ltd", License = "Commercial", Developers = typeof(RulesPluginBuilder).FullName }; MockJdkWrapper mockJdkWrapper = new MockJdkWrapper(); RulesPluginBuilder builder = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger()); builder.SetLanguage(language) .SetRulesFilePath(rulesXmlFilePath) .SetSqaleFilePath(sqaleXmlFilePath) .SetJarFilePath(fullJarFilePath) .SetProperties(defn); builder.Build(); // should not fail mockJdkWrapper.AssertJarBuilt(); }
public void RulesPluginBuilder_SqaleFileValidation() { // Arrange string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext); MockJdkWrapper mockJdkWrapper = new MockJdkWrapper(); RulesPluginBuilder builder = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger()); SetValidCoreProperties(builder); builder.SetLanguage("aLanguage"); AddValidDummyRulesFiles(builder); // 1. Sqale file not specified -> ok builder.Build(); // 2. Non-existent Sqale file specified -> error mockJdkWrapper.ClearCalledMethodList(); string sqaleFile = Path.Combine(testDir, "missingFile.txt"); builder.SetSqaleFilePath(sqaleFile); FileNotFoundException ex = AssertException.Expect <FileNotFoundException>(() => builder.Build()); Assert.AreEqual(ex.FileName, sqaleFile); mockJdkWrapper.AssertCodeNotCompiled(); // 3. Sqale file exists -> succeeds sqaleFile = TestUtils.CreateTextFile("sqale.txt", testDir, "dummy sqale file"); builder.SetSqaleFilePath(sqaleFile); builder.Build(); // should succeed mockJdkWrapper.AssertJarBuilt(); }
static int Main(string[] args) { ILogger logger = new ConsoleLogger(); Utilities.LogAssemblyVersion(typeof(Program).Assembly, UIResources.AssemblyDescription, logger); if (args.Length != 2 && args.Length != 3) { logger.LogError(UIResources.Cmd_Error_IncorrectArguments); return(ERROR_CODE); } string pluginDefnFilePath = args[0]; string rulesFilePath = args[1]; PluginManifest defn = PluginManifest.Load(pluginDefnFilePath); string fullNewJarFilePath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileNameWithoutExtension(pluginDefnFilePath) + ".jar"); string sqaleFilePath = null; if (args.Length == 3) { sqaleFilePath = args[2]; } //TODO: support multiple languages string language = "cs"; RulesPluginBuilder builder = new RulesPluginBuilder(logger); builder.SetLanguage(language) .SetRulesFilePath(rulesFilePath) .SetSqaleFilePath(sqaleFilePath) .SetProperties(defn) .SetJarFilePath(fullNewJarFilePath); builder.Build(); return(SUCCESS_CODE); }
static int Main(string[] args) { ILogger logger = new ConsoleLogger(); Utilities.LogAssemblyVersion(typeof(Program).Assembly, UIResources.AssemblyDescription, logger); if (args.Length != 2 && args.Length != 3) { logger.LogError(UIResources.Cmd_Error_IncorrectArguments); return ERROR_CODE; } string pluginDefnFilePath = args[0]; string rulesFilePath = args[1]; PluginManifest defn = PluginManifest.Load(pluginDefnFilePath); string fullNewJarFilePath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetFileNameWithoutExtension(pluginDefnFilePath) + ".jar"); string sqaleFilePath = null; if (args.Length == 3) { sqaleFilePath = args[2]; } //TODO: support multiple languages string language = "cs"; RulesPluginBuilder builder = new RulesPluginBuilder(logger); builder.SetLanguage(language) .SetRulesFilePath(rulesFilePath) .SetSqaleFilePath(sqaleFilePath) .SetProperties(defn) .SetJarFilePath(fullNewJarFilePath); builder.Build(); return SUCCESS_CODE; }
public void RulesPluginBuilder_RulesFileValidation() { // Arrange MockJdkWrapper mockJdkWrapper = new MockJdkWrapper(); RulesPluginBuilder builder = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger()); SetValidCoreProperties(builder); builder.SetLanguage("aLanguage"); // 1. Rules file not specified -> error AssertException.Expect<InvalidOperationException>(() => builder.Build()); // 2. Non-existent rules file specified -> error string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext); string rulesFile = Path.Combine(testDir, "missingFile.txt"); mockJdkWrapper.AssertCodeNotCompiled(); builder.SetRulesFilePath(rulesFile); FileNotFoundException ex = AssertException.Expect<FileNotFoundException>(() => builder.Build()); Assert.AreEqual(ex.FileName, rulesFile); mockJdkWrapper.AssertCodeNotCompiled(); // 3. Rules file exists -> succeeds AddValidDummyRulesFiles(builder); builder.Build(); // should succeed mockJdkWrapper.AssertJarBuilt(); }
public void RulesPluginBuilder_SqaleFileValidation() { // Arrange string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext); MockJdkWrapper mockJdkWrapper = new MockJdkWrapper(); RulesPluginBuilder builder = new RulesPluginBuilder(mockJdkWrapper, new MockMavenArtifactHandler(), new TestLogger()); SetValidCoreProperties(builder); builder.SetLanguage("aLanguage"); AddValidDummyRulesFiles(builder); // 1. Sqale file not specified -> ok builder.Build(); // 2. Non-existent Sqale file specified -> error mockJdkWrapper.ClearCalledMethodList(); string sqaleFile = Path.Combine(testDir, "missingFile.txt"); builder.SetSqaleFilePath(sqaleFile); FileNotFoundException ex = AssertException.Expect<FileNotFoundException>(() => builder.Build()); Assert.AreEqual(ex.FileName, sqaleFile); mockJdkWrapper.AssertCodeNotCompiled(); // 3. Sqale file exists -> succeeds sqaleFile = TestUtils.CreateTextFile("sqale.txt", testDir, "dummy sqale file"); builder.SetSqaleFilePath(sqaleFile); builder.Build(); // should succeed mockJdkWrapper.AssertJarBuilt(); }