Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verifying that web methods may be defined as default interface methods #113

Merged
merged 2 commits into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion core/src/test/java/org/kohsuke/stapler/DispatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,38 @@ public void testPutInheritance() throws Exception {
assertEquals("POST: Hello\n", p.getContent());
}


public void testInterfaceMethods() throws Exception {
WebClient wc = new WebClient();
try {
wc.getPage(new URL(url, "usesInterfaceMethods/foo"));
fail();
} catch (FailingHttpStatusCodeException x) {
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, x.getStatusCode());
}
assertEquals("default", wc.getPage(new WebRequestSettings(new URL(url, "usesInterfaceMethods/foo"), HttpMethod.POST)).getWebResponse().getContentAsString().trim());
try {
wc.getPage(new URL(url, "overridesInterfaceMethods/foo"));
fail();
} catch (FailingHttpStatusCodeException x) {
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, x.getStatusCode());
}
assertEquals("due to UnionAnnotatedElement it is even inherited", "overridden", wc.getPage(new WebRequestSettings(new URL(url, "overridesInterfaceMethods/foo"), HttpMethod.POST)).getWebResponse().getContentAsString().trim());
}
public interface InterfaceWithWebMethods {
@RequirePOST
default HttpResponse doFoo() {
return HttpResponses.plainText("default");
}
}
public class UsesInterfaceMethods implements InterfaceWithWebMethods {}
public class OverridesInterfaceMethods implements InterfaceWithWebMethods {
@Override
public HttpResponse doFoo() {
return HttpResponses.plainText("overridden");
}
}
public final UsesInterfaceMethods usesInterfaceMethods = new UsesInterfaceMethods();
public final OverridesInterfaceMethods overridesInterfaceMethods = new OverridesInterfaceMethods();

//===================================================================

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.level>7</java.level>
<java.level>8</java.level>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires a decision by Stapler maintainers. LGTM, but may require extra backporting methods if somebody wants to just update LTS version to the Master branch. I don't

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires a decision by Stapler maintainers.

Well, I cut the last release…

if somebody wants to just update LTS version to the Master branch

I think generally we do not do that. Rather, we would create a backport branch and cherry-pick selected fixes.

</properties>

<build>
Expand Down