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();
        }
        public void RulesPluginBuilder_SqaleFileSetToNull_Fails()
        {
            // Arrange
            RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger());

            // Act and assert
            AssertException.Expect <ArgumentNullException>(() => builder.SetSqaleFilePath(null));
            AssertException.Expect <ArgumentNullException>(() => builder.SetSqaleFilePath(""));
        }
        public void RulesPluginBuilder_SqaleFileSetToNull_Fails()
        {
            // Arrange
            RulesPluginBuilder builder = new RulesPluginBuilder(new TestLogger());

            // Act and assert
            AssertException.Expect<ArgumentNullException>(() => builder.SetSqaleFilePath(null));
            AssertException.Expect<ArgumentNullException>(() => builder.SetSqaleFilePath(""));
        }
Esempio n. 4
0
        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);
        }
        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_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();
        }