Created
March 9, 2021 16:38
-
-
Save xstefank/0fccfec136daf0d167c30a9a46cfca41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tyr-core/src/test/java/org/jboss/tyr/TestUtils.java b/tyr-core/src/test/java/org/jboss/tyr/TestUtils.java | |
index ab47155..f790417 100644 | |
--- a/tyr-core/src/test/java/org/jboss/tyr/TestUtils.java | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/TestUtils.java | |
@@ -46,6 +46,7 @@ public class TestUtils { | |
public static final JsonObject EMPTY_PAYLOAD = createEmptyJsonPayload(); | |
public static final JsonArray TEST_COMMITS_PAYLOAD = loadJsonArray(JSON_DIR + "/testCommitsPayload.json"); | |
+ public static final JsonArray MULTIPLE_COMMIT_MESSAGES_PAYLOAD = loadJsonArray(JSON_DIR + "/multipleCommitMessagesPayload.json"); | |
public static final FormatYaml FORMAT_CONFIG = loadFormatFromYamlFile(YAML_DIR + "/testTemplate.yaml"); | |
public static final FormatYaml FORMAT_CONFIG_CI = loadFormatFromYamlFile(YAML_DIR + "/testTemplateCI.yaml"); | |
@@ -88,6 +89,15 @@ public class TestUtils { | |
} | |
} | |
+ public static File getFile(String fileName) { | |
+ try { | |
+ String path = TestUtils.class.getClassLoader().getResource(fileName).getFile(); | |
+ return new File(URLDecoder.decode(path, "UTF-8")); | |
+ } catch (UnsupportedEncodingException e) { | |
+ throw new IllegalStateException("Cannot get file " + fileName, e); | |
+ } | |
+ } | |
+ | |
private static JsonObject loadJson(String fileName) { | |
try { | |
return Json.createReader(new FileReader(getFile(fileName))).readObject(); | |
@@ -115,13 +125,4 @@ public class TestUtils { | |
throw new IllegalStateException("Cannot get path of file: " + fileName, e); | |
} | |
} | |
- | |
- private static File getFile(String fileName) { | |
- try { | |
- String path = TestUtils.class.getClassLoader().getResource(fileName).getFile(); | |
- return new File(URLDecoder.decode(path, "UTF-8")); | |
- } catch (UnsupportedEncodingException e) { | |
- throw new IllegalStateException("Cannot get file " + fileName, e); | |
- } | |
- } | |
} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/additional/AdditionalResourcesTest.java b/tyr-core/src/test/java/org/jboss/tyr/additional/AdditionalResourcesTest.java | |
index 6e1f591..20ea3d7 100644 | |
--- a/tyr-core/src/test/java/org/jboss/tyr/additional/AdditionalResourcesTest.java | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/additional/AdditionalResourcesTest.java | |
@@ -23,7 +23,6 @@ import org.jboss.tyr.additional.resource.DummyAdditionalCommand; | |
import org.jboss.tyr.check.TemplateChecker; | |
import org.jboss.tyr.whitelist.WhitelistProcessing; | |
import org.junit.jupiter.api.Assertions; | |
-import org.junit.jupiter.api.Disabled; | |
import org.junit.jupiter.api.Test; | |
import javax.inject.Inject; | |
@@ -58,10 +57,8 @@ public class AdditionalResourcesTest { | |
TemplateChecker templateChecker; | |
@Test | |
- @Disabled("templateChecker.init(TestUtils.FORMAT_CONFIG)") | |
public void additionalChecksInvokedTest() throws InvalidPayloadException { | |
DummyAdditionalCheck.clearCounter(); // incremented by different test checking the valid PR check invocation | |
-// templateChecker.init(TestUtils.FORMAT_CONFIG); | |
String result = templateChecker.checkPR(TestUtils.TEST_PAYLOAD); | |
@@ -80,32 +77,4 @@ public class AdditionalResourcesTest { | |
Assertions.assertTrue(DummyAdditionalCommand.isTriggered()); | |
} | |
- | |
- | |
- @Test | |
- @Disabled("Quarkus support for different config values,templateChecker.init(TestUtils.FORMAT_CONFIG)") | |
- public void invalidPathAdditionalResourcesTest() throws InvalidPayloadException { | |
-// templateChecker.init(TestUtils.FORMAT_CONFIG); | |
- whitelistProcessing.init(TestUtils.FORMAT_CONFIG); | |
- | |
- // should not fail, logs warning | |
- String result = templateChecker.checkPR(TestUtils.TEST_PAYLOAD); | |
- whitelistProcessing.processPRComment(TestUtils.ISSUE_PAYLOAD); | |
- | |
- Assertions.assertTrue(result.isEmpty()); | |
- Assertions.assertFalse(DummyAdditionalCommand.isTriggered()); | |
- } | |
- | |
- @Test | |
- @Disabled("Quarkus support for different config values,templateChecker.init(TestUtils.FORMAT_CONFIG)") | |
- public void emptyAdditionalResourcesPropertyTest() throws InvalidPayloadException { | |
-// templateChecker.init(TestUtils.FORMAT_CONFIG); | |
-// whitelistProcessing.init(TestUtils.FORMAT_CONFIG); | |
- | |
- String result = templateChecker.checkPR(TestUtils.TEST_PAYLOAD); | |
- whitelistProcessing.processPRComment(TestUtils.ISSUE_PAYLOAD); | |
- | |
- Assertions.assertTrue(result.isEmpty()); | |
- Assertions.assertFalse(DummyAdditionalCommand.isTriggered()); | |
- } | |
} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/check/CommitMessagesCheckTest.java b/tyr-core/src/test/java/org/jboss/tyr/check/CommitMessagesCheckTest.java | |
index 2c36c50..e2eb53c 100644 | |
--- a/tyr-core/src/test/java/org/jboss/tyr/check/CommitMessagesCheckTest.java | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/check/CommitMessagesCheckTest.java | |
@@ -21,7 +21,6 @@ import org.jboss.tyr.TestUtils; | |
import org.jboss.tyr.model.yaml.RegexDefinition; | |
import org.junit.jupiter.api.Assertions; | |
import org.junit.jupiter.api.BeforeEach; | |
-import org.junit.jupiter.api.Disabled; | |
import org.junit.jupiter.api.Test; | |
import javax.inject.Inject; | |
@@ -77,15 +76,4 @@ public class CommitMessagesCheckTest { | |
Assertions.assertEquals(CommitMessagesCheck.DEFAULT_MESSAGE, commitMessagesCheck.check(TestUtils.TEST_PAYLOAD), "Unexpected message returned"); | |
} | |
- | |
- @Test | |
- @Disabled("multiple mocks support in quarkus (1.4 or 1.3.x)") | |
- public void testMultipleCommitMessages() throws InvalidPayloadException { | |
-// PowerMockito.stub(method(GitHubAPI.class, TestUtils.GET_JSON_WITH_COMMITS, JsonObject.class)).toReturn(TestUtils.MULTIPLE_COMMIT_MESSAGES_PAYLOAD); | |
- | |
- commitRegexDefinition.setPattern(Pattern.compile("Test commit")); | |
- commitMessagesCheck.setRegex(commitRegexDefinition); | |
- | |
- Assertions.assertNull(commitMessagesCheck.check(TestUtils.TEST_PAYLOAD)); | |
- } | |
} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/check/MultipleCommitMessagesTest.java b/tyr-core/src/test/java/org/jboss/tyr/check/MultipleCommitMessagesTest.java | |
new file mode 100644 | |
index 0000000..f4182a3 | |
--- /dev/null | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/check/MultipleCommitMessagesTest.java | |
@@ -0,0 +1,39 @@ | |
+package org.jboss.tyr.check; | |
+ | |
+import io.quarkus.test.junit.QuarkusTest; | |
+import io.quarkus.test.junit.mockito.InjectMock; | |
+import org.jboss.tyr.InvalidPayloadException; | |
+import org.jboss.tyr.TestUtils; | |
+import org.jboss.tyr.github.GitHubService; | |
+import org.jboss.tyr.model.yaml.RegexDefinition; | |
+import org.junit.jupiter.api.Assertions; | |
+import org.junit.jupiter.api.Test; | |
+import org.mockito.Mockito; | |
+ | |
+import javax.inject.Inject; | |
+import javax.json.JsonObject; | |
+import java.util.regex.Pattern; | |
+ | |
+import static org.mockito.ArgumentMatchers.isA; | |
+ | |
+@QuarkusTest | |
+public class MultipleCommitMessagesTest { | |
+ | |
+ @Inject | |
+ CommitMessagesCheck commitMessagesCheck; | |
+ | |
+ @InjectMock | |
+ GitHubService gitHubServiceMock; | |
+ | |
+ @Test | |
+ public void testMultipleCommitMessages() throws InvalidPayloadException { | |
+ Mockito.when(gitHubServiceMock.getCommitsJSON(isA(JsonObject.class))).thenReturn(TestUtils.MULTIPLE_COMMIT_MESSAGES_PAYLOAD); | |
+ Mockito.when(gitHubServiceMock.getPullRequestJSON(isA(JsonObject.class))).thenReturn(TestUtils.TEST_PAYLOAD); | |
+ | |
+ RegexDefinition commitRegexDefinition = new RegexDefinition(); | |
+ commitRegexDefinition.setPattern(Pattern.compile("Test commit")); | |
+ commitMessagesCheck.setRegex(commitRegexDefinition); | |
+ | |
+ Assertions.assertNull(commitMessagesCheck.check(TestUtils.TEST_PAYLOAD)); | |
+ } | |
+} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/check/TemplateCheckerTest.java b/tyr-core/src/test/java/org/jboss/tyr/check/TemplateCheckerTest.java | |
index ccad01f..6edfe70 100644 | |
--- a/tyr-core/src/test/java/org/jboss/tyr/check/TemplateCheckerTest.java | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/check/TemplateCheckerTest.java | |
@@ -18,9 +18,7 @@ package org.jboss.tyr.check; | |
import io.quarkus.test.junit.QuarkusTest; | |
import org.jboss.tyr.InvalidPayloadException; | |
import org.jboss.tyr.TestUtils; | |
-import org.jboss.tyr.model.yaml.FormatYaml; | |
import org.junit.jupiter.api.Assertions; | |
-import org.junit.jupiter.api.Disabled; | |
import org.junit.jupiter.api.Test; | |
import javax.inject.Inject; | |
@@ -32,24 +30,8 @@ public class TemplateCheckerTest { | |
TemplateChecker templateChecker; | |
@Test | |
- @Disabled("templateChecker.init(TestUtils.FORMAT_CONFIG_CI)") | |
public void testValidTemplateConfig() throws InvalidPayloadException { | |
-// templateChecker.init(TestUtils.FORMAT_CONFIG_CI); | |
Assertions.assertEquals("Dummy check failure", templateChecker.checkPR(TestUtils.TEST_PAYLOAD), | |
"Valid PR should only fail with included additional check"); | |
} | |
- | |
- @Test | |
- @Disabled("templateChecker.init(null)") | |
- public void testNullConfigParameter() { | |
-// Assertions.assertThrows(IllegalArgumentException.class, () -> templateChecker.init(null)); | |
- } | |
- | |
- @Test | |
- @Disabled("templateChecker.init(testConfig)") | |
- public void testNullFormatParameter() { | |
- FormatYaml testConfig = new FormatYaml(); | |
- testConfig.setFormat(null); | |
-// Assertions.assertThrows(IllegalArgumentException.class, () -> templateChecker.init(testConfig)); | |
- } | |
} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/config/AdditionalResourcesEmptyTest.java b/tyr-core/src/test/java/org/jboss/tyr/config/AdditionalResourcesEmptyTest.java | |
new file mode 100644 | |
index 0000000..f8f47db | |
--- /dev/null | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/config/AdditionalResourcesEmptyTest.java | |
@@ -0,0 +1,45 @@ | |
+package org.jboss.tyr.config; | |
+ | |
+import io.quarkus.test.junit.QuarkusTest; | |
+import io.quarkus.test.junit.QuarkusTestProfile; | |
+import io.quarkus.test.junit.TestProfile; | |
+import org.jboss.tyr.InvalidPayloadException; | |
+import org.jboss.tyr.TestUtils; | |
+import org.jboss.tyr.additional.resource.DummyAdditionalCommand; | |
+import org.jboss.tyr.check.TemplateChecker; | |
+import org.jboss.tyr.whitelist.WhitelistProcessing; | |
+import org.junit.jupiter.api.Assertions; | |
+import org.junit.jupiter.api.Test; | |
+ | |
+import javax.inject.Inject; | |
+import java.util.Map; | |
+ | |
+@QuarkusTest | |
+@TestProfile(AdditionalResourcesEmptyTest.Profile.class) | |
+public class AdditionalResourcesEmptyTest { | |
+ | |
+ public static final class Profile implements QuarkusTestProfile { | |
+ @Override | |
+ public Map<String, String> getConfigOverrides() { | |
+ // override the file set in src/test/resources/application.properties | |
+ return Map.of("tyr.additional-resources", ""); | |
+ } | |
+ } | |
+ | |
+ @Inject | |
+ TemplateChecker templateChecker; | |
+ | |
+ @Inject | |
+ WhitelistProcessing whitelistProcessing; | |
+ | |
+ @Test | |
+ public void emptyAdditionalResourcesPropertyTest() throws InvalidPayloadException { | |
+ whitelistProcessing.init(TestUtils.FORMAT_CONFIG); | |
+ | |
+ String result = templateChecker.checkPR(TestUtils.TEST_PAYLOAD); | |
+ whitelistProcessing.processPRComment(TestUtils.ISSUE_PAYLOAD); | |
+ | |
+ Assertions.assertTrue(result.isEmpty()); | |
+ Assertions.assertFalse(DummyAdditionalCommand.isTriggered()); | |
+ } | |
+} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/config/AdditionalResourcesWrongPathTest.java b/tyr-core/src/test/java/org/jboss/tyr/config/AdditionalResourcesWrongPathTest.java | |
new file mode 100644 | |
index 0000000..7d29dc4 | |
--- /dev/null | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/config/AdditionalResourcesWrongPathTest.java | |
@@ -0,0 +1,46 @@ | |
+package org.jboss.tyr.config; | |
+ | |
+import io.quarkus.test.junit.QuarkusTest; | |
+import io.quarkus.test.junit.QuarkusTestProfile; | |
+import io.quarkus.test.junit.TestProfile; | |
+import org.jboss.tyr.InvalidPayloadException; | |
+import org.jboss.tyr.TestUtils; | |
+import org.jboss.tyr.additional.resource.DummyAdditionalCommand; | |
+import org.jboss.tyr.check.TemplateChecker; | |
+import org.jboss.tyr.whitelist.WhitelistProcessing; | |
+import org.junit.jupiter.api.Assertions; | |
+import org.junit.jupiter.api.Test; | |
+ | |
+import javax.inject.Inject; | |
+import java.util.Map; | |
+ | |
+@QuarkusTest | |
+@TestProfile(AdditionalResourcesWrongPathTest.Profile.class) | |
+public class AdditionalResourcesWrongPathTest { | |
+ | |
+ public static final class Profile implements QuarkusTestProfile { | |
+ @Override | |
+ public Map<String, String> getConfigOverrides() { | |
+ // override the file set in src/test/resources/application.properties | |
+ return Map.of("tyr.additional-resources", "generated/nonExistentPath.jar"); | |
+ } | |
+ } | |
+ | |
+ @Inject | |
+ TemplateChecker templateChecker; | |
+ | |
+ @Inject | |
+ WhitelistProcessing whitelistProcessing; | |
+ | |
+ @Test | |
+ public void invalidPathAdditionalResourcesTest() throws InvalidPayloadException { | |
+ whitelistProcessing.init(TestUtils.FORMAT_CONFIG); | |
+ | |
+ // should not fail, logs warning | |
+ String result = templateChecker.checkPR(TestUtils.TEST_PAYLOAD); | |
+ whitelistProcessing.processPRComment(TestUtils.ISSUE_PAYLOAD); | |
+ | |
+ Assertions.assertTrue(result.isEmpty()); | |
+ Assertions.assertFalse(DummyAdditionalCommand.isTriggered()); | |
+ } | |
+} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/config/FormatNotSetTest.java b/tyr-core/src/test/java/org/jboss/tyr/config/FormatNotSetTest.java | |
new file mode 100644 | |
index 0000000..1504f93 | |
--- /dev/null | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/config/FormatNotSetTest.java | |
@@ -0,0 +1,33 @@ | |
+package org.jboss.tyr.config; | |
+ | |
+import io.quarkus.test.junit.QuarkusTest; | |
+import io.quarkus.test.junit.QuarkusTestProfile; | |
+import io.quarkus.test.junit.TestProfile; | |
+import org.jboss.tyr.TestUtils; | |
+import org.jboss.tyr.check.TemplateChecker; | |
+import org.junit.jupiter.api.Assertions; | |
+import org.junit.jupiter.api.Test; | |
+ | |
+import javax.inject.Inject; | |
+import java.util.Map; | |
+ | |
+@QuarkusTest | |
+@TestProfile(FormatNotSetTest.Profile.class) | |
+public class FormatNotSetTest { | |
+ | |
+ public static final class Profile implements QuarkusTestProfile { | |
+ @Override | |
+ public Map<String, String> getConfigOverrides() { | |
+ // override the file set in src/test/resources/application.properties | |
+ return Map.of("tyr.template.format.file", ""); | |
+ } | |
+ } | |
+ | |
+ @Inject | |
+ TemplateChecker templateChecker; | |
+ | |
+ @Test | |
+ public void testNullConfigParameter() { | |
+ Assertions.assertThrows(IllegalArgumentException.class, () -> templateChecker.processPullRequest(TestUtils.TEST_PAYLOAD)); | |
+ } | |
+} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/config/pushstatus/TemplateCheckPushStatusTest.java b/tyr-core/src/test/java/org/jboss/tyr/config/PushStatusFalseTest.java | |
similarity index 65% | |
rename from tyr-core/src/test/java/org/jboss/tyr/config/pushstatus/TemplateCheckPushStatusTest.java | |
rename to tyr-core/src/test/java/org/jboss/tyr/config/PushStatusFalseTest.java | |
index 43c3376..103eaf1 100644 | |
--- a/tyr-core/src/test/java/org/jboss/tyr/config/pushstatus/TemplateCheckPushStatusTest.java | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/config/PushStatusFalseTest.java | |
@@ -1,6 +1,7 @@ | |
-package org.jboss.tyr.config.pushstatus; | |
+package org.jboss.tyr.config; | |
import io.quarkus.test.junit.QuarkusTest; | |
+import io.quarkus.test.junit.QuarkusTestProfile; | |
import io.quarkus.test.junit.TestProfile; | |
import io.quarkus.test.junit.mockito.InjectMock; | |
import org.jboss.tyr.TestUtils; | |
@@ -13,11 +14,22 @@ import org.mockito.Mockito; | |
import javax.inject.Inject; | |
+import java.util.Map; | |
+ | |
+import static org.jboss.tyr.TestUtils.YAML_DIR; | |
import static org.mockito.ArgumentMatchers.isA; | |
@QuarkusTest | |
-@TestProfile(PushStatusFalseTestProfile.class) | |
-public class TemplateCheckPushStatusTest { | |
+@TestProfile(PushStatusFalseTest.Profile.class) | |
+public class PushStatusFalseTest { | |
+ | |
+ public static final class Profile implements QuarkusTestProfile { | |
+ @Override | |
+ public Map<String, String> getConfigOverrides() { | |
+ return Map.of("tyr.github.status.push", "false", | |
+ "tyr.template.format.file", TestUtils.getFile(YAML_DIR + "/testTemplateCI.yaml").getAbsolutePath()); | |
+ } | |
+ } | |
@Inject | |
TemplateChecker templateChecker; | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/config/WrongFormatFileTest.java b/tyr-core/src/test/java/org/jboss/tyr/config/WrongFormatFileTest.java | |
new file mode 100644 | |
index 0000000..90f88ae | |
--- /dev/null | |
+++ b/tyr-core/src/test/java/org/jboss/tyr/config/WrongFormatFileTest.java | |
@@ -0,0 +1,33 @@ | |
+package org.jboss.tyr.config; | |
+ | |
+import io.quarkus.test.junit.QuarkusTest; | |
+import io.quarkus.test.junit.QuarkusTestProfile; | |
+import io.quarkus.test.junit.TestProfile; | |
+import org.jboss.tyr.TestUtils; | |
+import org.jboss.tyr.check.TemplateChecker; | |
+import org.junit.jupiter.api.Assertions; | |
+import org.junit.jupiter.api.Test; | |
+ | |
+import javax.inject.Inject; | |
+import java.util.Map; | |
+ | |
+@QuarkusTest | |
+@TestProfile(WrongFormatFileTest.Profile.class) | |
+public class WrongFormatFileTest { | |
+ | |
+ public static final class Profile implements QuarkusTestProfile { | |
+ @Override | |
+ public Map<String, String> getConfigOverrides() { | |
+ // override the file set in src/test/resources/application.properties | |
+ return Map.of("tyr.template.format.file", TestUtils.getFile(TestUtils.YAML_DIR + "/wrongTemplate.yaml").getAbsolutePath()); | |
+ } | |
+ } | |
+ | |
+ @Inject | |
+ TemplateChecker templateChecker; | |
+ | |
+ @Test | |
+ public void testNullFormatParameter() { | |
+ Assertions.assertThrows(IllegalArgumentException.class, () -> templateChecker.processPullRequest(TestUtils.TEST_PAYLOAD)); | |
+ } | |
+} | |
diff --git a/tyr-core/src/test/java/org/jboss/tyr/config/pushstatus/PushStatusFalseTestProfile.java b/tyr-core/src/test/java/org/jboss/tyr/config/pushstatus/PushStatusFalseTestProfile.java | |
deleted file mode 100644 | |
index 674d4bd..0000000 | |
--- a/tyr-core/src/test/java/org/jboss/tyr/config/pushstatus/PushStatusFalseTestProfile.java | |
+++ /dev/null | |
@@ -1,13 +0,0 @@ | |
-package org.jboss.tyr.config.pushstatus; | |
- | |
-import io.quarkus.test.junit.QuarkusTestProfile; | |
- | |
-import java.util.Map; | |
- | |
-public class PushStatusFalseTestProfile implements QuarkusTestProfile { | |
- | |
- @Override | |
- public Map<String, String> getConfigOverrides() { | |
- return Map.of("tyr.github.status.push", "false"); | |
- } | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment