Skip to content

Commit

Permalink
yegor256#953 TkServletApp renamed and put inside SrvTakeTest
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Jan 25, 2019
1 parent 5fee57b commit a5a6af3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 68 deletions.
49 changes: 47 additions & 2 deletions src/test/java/org/takes/servlet/SrvTakeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,33 @@

import com.jcabi.http.request.JdkRequest;
import com.jcabi.http.response.RestResponse;
import java.io.IOException;
import java.net.HttpURLConnection;
import javax.servlet.ServletContext;
import org.cactoos.text.FormattedText;
import org.cactoos.text.UncheckedText;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.servlet.ServletRegistration;
import org.glassfish.grizzly.servlet.WebappContext;
import org.hamcrest.core.StringContains;
import org.junit.jupiter.api.Test;
import org.takes.Request;
import org.takes.Response;
import org.takes.Take;
import org.takes.rs.RsText;

/**
* Test case for {@link SrvTake}.
*
* @since 1.16
*/
public final class SrvTakeTest {
/**
* Message returned if servlet Takes is executed correctly.
*/
private static final String MSG =
"Hello servlet! Using [%s] ServletContext.";

@Test
public void executeATakesAsAServlet() throws Exception {
final String name = "webapp";
Expand All @@ -49,7 +62,7 @@ public void executeATakesAsAServlet() throws Exception {
"takes",
SrvTake.class
);
servlet.setInitParameter("take", TkServletApp.class.getName());
servlet.setInitParameter("take", TkApp.class.getName());
servlet.addMapping("/test");
context.deploy(server);
server.start();
Expand All @@ -60,11 +73,43 @@ public void executeATakesAsAServlet() throws Exception {
.assertBody(
new StringContains(
new FormattedText(
"Hello servlet! Using [%s] ServletContext.",
SrvTakeTest.MSG,
name
).asString()
)
);
server.shutdownNow();
}

/**
* Fake TkApp (for {@link SrvTake} test only).
*
* @since 1.16
*/
final class TkApp implements Take {
/**
* ServletContext.
*/
private final ServletContext context;

/**
* Ctor.
* @param ctx A ServletContext
*/
TkApp(final ServletContext ctx) {
this.context = ctx;
}

@Override
public Response act(final Request req) throws IOException {
return new RsText(
new UncheckedText(
new FormattedText(
SrvTakeTest.MSG,
this.context.getServletContextName()
)
).asString()
);
}
}
}
66 changes: 0 additions & 66 deletions src/test/java/org/takes/servlet/TkServletApp.java

This file was deleted.

0 comments on commit a5a6af3

Please sign in to comment.