Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Cleanup and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Apr 18, 2015
1 parent ce47bc8 commit ed70d2f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/main/java/se/bjurr/prnfs/listener/UrlInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public String getUrlParam() {
return urlParam;
}

public static Logger getLogger() {
return logger;
}

@VisibleForTesting
public boolean shouldPostContent() {
return (method.equals("POST") || method.equals("PUT")) && postContent.isPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,84 @@ public void testThatFilterCanIncludeRescopedFrom() {
.withId(10L).withPullRequestAction(RESCOPED).build()).invokedUrl(0, "http://bjurr.se/");
}

@Test
public void testThatFilterCanBeUsedWithComments() {
prnfsTestBuilder()
.isLoggedInAsAdmin()
.withNotification(
notificationBuilder()
.withFieldValue(
AdminFormValues.FIELDS.url,
"http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}&version=${"
+ PrnfsRenderer.PrnfsVariable.PULL_REQUEST_VERSION + "}")
.withFieldValue(AdminFormValues.FIELDS.events, COMMENTED.name())
.withFieldValue(
FIELDS.filter_string,
"${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_TO_ID.name() + "}:${"
+ PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT.name() + "}:")
.withFieldValue(FIELDS.filter_regexp, ".*:.*?keyword.*?:.*").build()).store().trigger(pullRequestEventBuilder() //
.withFromRef(pullRequestRefBuilder().withHash("from")) //
.withToRef(pullRequestRefBuilder().withId("123")) //
.withCommentText("keyword A nice comment").withId(10L).withPullRequestAction(COMMENTED).build())
.invokedUrl(0, "http://bjurr.se/?comment=keyword%20A%20nice%20comment&version=0");
}

@Test
public void testThatFilterCanBeUsedWithCommentsAndSpecialEscapedChars() {
prnfsTestBuilder()
.isLoggedInAsAdmin()
.withNotification(
notificationBuilder()
.withFieldValue(
AdminFormValues.FIELDS.url,
"http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}&version=${"
+ PrnfsRenderer.PrnfsVariable.PULL_REQUEST_VERSION + "}")
.withFieldValue(AdminFormValues.FIELDS.events, COMMENTED.name())
.withFieldValue(
FIELDS.filter_string,
"${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_TO_ID.name() + "}:${"
+ PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT.name() + "}:")
.withFieldValue(FIELDS.filter_regexp, ".*:\\skeyword\\s:.*").build()).store().trigger(pullRequestEventBuilder() //
.withFromRef(pullRequestRefBuilder().withHash("from")) //
.withToRef(pullRequestRefBuilder().withId("123")) //
.withCommentText(" keyword ").withId(10L).withPullRequestAction(COMMENTED).build())
.invokedUrl(0, "http://bjurr.se/?comment=%20keyword%20&version=0");
}

@Test
public void testThatFilterCanBeUsedWithCommentsIgnore() {
prnfsTestBuilder()
.isLoggedInAsAdmin()
.withNotification(
notificationBuilder()
.withFieldValue(
AdminFormValues.FIELDS.url,
"http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}&version=${"
+ PrnfsRenderer.PrnfsVariable.PULL_REQUEST_VERSION + "}")
.withFieldValue(AdminFormValues.FIELDS.events, COMMENTED.name())
.withFieldValue(
FIELDS.filter_string,
"${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_TO_ID.name() + "}:${"
+ PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT.name() + "}:")
.withFieldValue(FIELDS.filter_regexp, ".*:.*?keyword.*?:.*").build()).store().trigger(pullRequestEventBuilder() //
.withFromRef(pullRequestRefBuilder().withHash("from")) //
.withToRef(pullRequestRefBuilder().withId("123")) //
.withCommentText("notkw A nice comment").withId(10L).withPullRequestAction(COMMENTED).build()).invokedNoUrl();
}

@Test
public void testThatStringWithVariableCommentIsEmptyIfNotACommentEvent() {
prnfsTestBuilder()
.isLoggedInAsAdmin()
.withNotification(
notificationBuilder()
.withFieldValue(AdminFormValues.FIELDS.url,
"http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}")
.withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()).build()).store()
.trigger(pullRequestEventBuilder() //
.withId(10L).withPullRequestAction(OPENED).build()).invokedUrl(0, "http://bjurr.se/?comment=");
}

@Test
public void testThatURLCanIncludeRescopedFrom() {
prnfsTestBuilder()
Expand Down

0 comments on commit ed70d2f

Please sign in to comment.