Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize ArC subclasses when getting the overriding options
Fixes #352
- Loading branch information
Showing
11 changed files
with
2,073 additions
and
1 deletion.
There are no files selected for viewing
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
111 changes: 111 additions & 0 deletions
111
...d-airline/src/main/java/io/quarkiverse/githubapp/it/command/airline/ArcSubclassesCli.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package io.quarkiverse.githubapp.it.command.airline; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.io.IOException; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.annotation.Priority; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InterceptorBinding; | ||
import javax.interceptor.InvocationContext; | ||
|
||
import org.kohsuke.github.GHEventPayload; | ||
import org.kohsuke.github.GHEventPayload.IssueComment; | ||
|
||
import com.github.rvesse.airline.annotations.Cli; | ||
import com.github.rvesse.airline.annotations.Command; | ||
|
||
import io.quarkiverse.githubapp.command.airline.CliOptions; | ||
import io.quarkiverse.githubapp.command.airline.CommandOptions; | ||
import io.quarkiverse.githubapp.command.airline.CommandOptions.CommandScope; | ||
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestApplicationScopedCommand1; | ||
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestApplicationScopedCommand2; | ||
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestSubclassCommand1; | ||
import io.quarkiverse.githubapp.it.command.airline.ArcSubclassesCli.TestSubclassCommand2; | ||
import io.quarkiverse.githubapp.it.command.airline.DefaultCommandOptionsCli.TestCommand; | ||
|
||
@Cli(name = "@arc", commands = { TestApplicationScopedCommand1.class, TestApplicationScopedCommand2.class, | ||
TestSubclassCommand1.class, TestSubclassCommand2.class }) | ||
@CliOptions(defaultCommandOptions = @CommandOptions(scope = CommandScope.ISSUES)) | ||
public class ArcSubclassesCli { | ||
|
||
@Command(name = "application-scoped-command1") | ||
@ApplicationScoped | ||
static class TestApplicationScopedCommand1 implements TestCommand { | ||
|
||
@Override | ||
public void run(IssueComment issueCommentPayload) throws IOException { | ||
issueCommentPayload.getIssue().comment("hello from @arc application-scoped-command1"); | ||
} | ||
} | ||
|
||
@Command(name = "application-scoped-command2") | ||
@CommandOptions(scope = CommandScope.ISSUES_AND_PULL_REQUESTS) | ||
@ApplicationScoped | ||
static class TestApplicationScopedCommand2 implements TestCommand { | ||
|
||
@Override | ||
public void run(IssueComment issueCommentPayload) throws IOException { | ||
issueCommentPayload.getIssue().comment("hello from @arc application-scoped-command2"); | ||
} | ||
} | ||
|
||
// we add an interceptor to generate a `_Subclass` | ||
@Command(name = "subclass-command1") | ||
@DoNothing | ||
static class TestSubclassCommand1 implements TestCommand { | ||
|
||
@Override | ||
public void run(IssueComment issueCommentPayload) throws IOException { | ||
issueCommentPayload.getIssue().comment("hello from @arc subclass-command1"); | ||
} | ||
} | ||
|
||
// we add an interceptor to generate a `_Subclass` | ||
@Command(name = "subclass-command2") | ||
@CommandOptions(scope = CommandScope.ISSUES_AND_PULL_REQUESTS) | ||
@DoNothing | ||
static class TestSubclassCommand2 implements TestCommand { | ||
|
||
@Override | ||
public void run(IssueComment issueCommentPayload) throws IOException { | ||
issueCommentPayload.getIssue().comment("hello from @arc subclass-command2"); | ||
} | ||
} | ||
|
||
public interface DefaultCommand { | ||
|
||
void run(GHEventPayload.IssueComment issueCommentPayload) throws IOException; | ||
} | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface DoNothing { | ||
} | ||
|
||
@DoNothing | ||
@Priority(2020) | ||
@Interceptor | ||
public static class LoggingInterceptor { | ||
|
||
@AroundInvoke | ||
Object logInvocation(InvocationContext context) { | ||
// do nothing specific, we just want an interceptor | ||
|
||
try { | ||
return context.proceed(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...rline/src/test/java/io/quarkiverse/githubapp/it/command/airline/ArcSubclassesCliTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package io.quarkiverse.githubapp.it.command.airline; | ||
|
||
import static io.quarkiverse.githubapp.it.command.airline.util.CommandTestUtils.verifyCommandExecution; | ||
import static io.quarkiverse.githubapp.testing.GitHubAppTesting.when; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.kohsuke.github.GHEvent; | ||
import org.kohsuke.github.ReactionContent; | ||
|
||
import io.quarkiverse.githubapp.testing.GitHubAppTest; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
@GitHubAppTest | ||
public class ArcSubclassesCliTest { | ||
|
||
@Test | ||
void testApplicationScopedScopeIssues() throws IOException { | ||
when().payloadFromClasspath("/issue-comment-arc-application-scoped-command1-issue.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verify(mocks.issueComment(1093016219)) | ||
.createReaction(ReactionContent.ROCKET); | ||
verify(mocks.issue(1168785554)) | ||
.comment("hello from @arc application-scoped-command1"); | ||
verify(mocks.issueComment(1093016219)) | ||
.createReaction(ReactionContent.PLUS_ONE); | ||
verifyNoMoreInteractions(mocks.ghObjects()); | ||
}); | ||
when().payloadFromClasspath("/issue-comment-arc-application-scoped-command1-pr.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verifyNoMoreInteractions(mocks.ghObjects()); | ||
}); | ||
} | ||
|
||
@Test | ||
void testApplicationScopedScopeIssuesAndPullRequests() throws IOException { | ||
when().payloadFromClasspath("/issue-comment-arc-application-scoped-command2-issue.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verifyCommandExecution(mocks, "hello from @arc application-scoped-command2"); | ||
}); | ||
when().payloadFromClasspath("/issue-comment-arc-application-scoped-command2-pr.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verifyCommandExecution(mocks, "hello from @arc application-scoped-command2"); | ||
}); | ||
} | ||
|
||
@Test | ||
void testSubclassScopeIssues() throws IOException { | ||
when().payloadFromClasspath("/issue-comment-arc-subclass-command1-issue.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verify(mocks.issueComment(1093016219)) | ||
.createReaction(ReactionContent.ROCKET); | ||
verify(mocks.issue(1168785554)) | ||
.comment("hello from @arc subclass-command1"); | ||
verify(mocks.issueComment(1093016219)) | ||
.createReaction(ReactionContent.PLUS_ONE); | ||
verifyNoMoreInteractions(mocks.ghObjects()); | ||
}); | ||
when().payloadFromClasspath("/issue-comment-arc-subclass-command1-pr.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verifyNoMoreInteractions(mocks.ghObjects()); | ||
}); | ||
} | ||
|
||
@Test | ||
void testSubclassScopeIssuesAndPullRequests() throws IOException { | ||
when().payloadFromClasspath("/issue-comment-arc-subclass-command2-issue.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verifyCommandExecution(mocks, "hello from @arc subclass-command2"); | ||
}); | ||
when().payloadFromClasspath("/issue-comment-arc-subclass-command2-pr.json") | ||
.event(GHEvent.ISSUE_COMMENT) | ||
.then().github(mocks -> { | ||
verifyCommandExecution(mocks, "hello from @arc subclass-command2"); | ||
}); | ||
} | ||
} |
Oops, something went wrong.