Skip to content

Commit

Permalink
#31 test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 11, 2017
1 parent c9a0cdf commit 72e524b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 45 deletions.
94 changes: 51 additions & 43 deletions src/main/java/io/jare/tk/TkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.takes.facets.fallback.TkFallback;
import org.takes.facets.flash.TkFlash;
import org.takes.facets.fork.FkAuthenticated;
import org.takes.facets.fork.FkFixed;
import org.takes.facets.fork.FkHost;
import org.takes.facets.fork.FkRegex;
import org.takes.facets.fork.TkFork;
Expand All @@ -40,6 +41,7 @@
import org.takes.rs.RsWithBody;
import org.takes.rs.RsWithStatus;
import org.takes.rs.RsWithType;
import org.takes.tk.TkGzip;
import org.takes.tk.TkMeasured;
import org.takes.tk.TkVersioned;
import org.takes.tk.TkWithHeaders;
Expand Down Expand Up @@ -95,52 +97,58 @@ public TkApp(final Base base) throws IOException {
)
)
),
new FkRegex("/robots.txt", ""),
new FkRegex(
"/xsl/[a-z\\-]+\\.xsl",
new TkWithType(
new TkRefresh("./src/main/xsl"),
"text/xsl"
)
),
new FkRegex(
"/css/[a-z]+\\.css",
new TkWithType(
new TkRefresh("./src/main/scss"),
"text/css"
)
),
new FkRegex(
"/images/[a-z]+\\.svg",
new TkWithType(
new TkRefresh("./src/main/resources"),
"image/svg+xml"
)
),
new FkRegex(
"/images/[a-z]+\\.png",
new TkWithType(
new TkRefresh("./src/main/resources"),
"image/png"
)
),
new FkRegex("/", new TkIndex(base)),
new FkRegex(
"/invalidate",
new TkInvalidate(
Manifests.read("Jare-CloudFrontKey"),
Manifests.read("Jare-CloudFrontSecret")
)
),
new FkAuthenticated(
new TkSecure(
new FkFixed(
new TkGzip(
new TkFork(
new FkRegex("/domains", new TkDomains(base)),
new FkRegex("/robots.txt", ""),
new FkRegex(
"/add",
new TkMethods(new TkAdd(base), "POST")
"/xsl/[a-z\\-]+\\.xsl",
new TkWithType(
new TkRefresh("./src/main/xsl"),
"text/xsl"
)
),
new FkRegex("/delete", new TkDelete(base))
new FkRegex(
"/css/[a-z]+\\.css",
new TkWithType(
new TkRefresh("./src/main/scss"),
"text/css"
)
),
new FkRegex(
"/images/[a-z]+\\.svg",
new TkWithType(
new TkRefresh("./src/main/resources"),
"image/svg+xml"
)
),
new FkRegex(
"/images/[a-z]+\\.png",
new TkWithType(
new TkRefresh("./src/main/resources"),
"image/png"
)
),
new FkRegex("/", new TkIndex(base)),
new FkRegex(
"/invalidate",
new TkInvalidate(
Manifests.read("Jare-CloudFrontKey"),
Manifests.read("Jare-CloudFrontSecret")
)
),
new FkAuthenticated(
new TkSecure(
new TkFork(
new FkRegex("/domains", new TkDomains(base)),
new FkRegex(
"/add",
new TkMethods(new TkAdd(base), "POST")
),
new FkRegex("/delete", new TkDelete(base))
)
)
)
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/jare/tk/TkAppFallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ private static Take make(final Take take) {
new FbStatus(
HttpURLConnection.HTTP_NOT_FOUND,
new RsWithStatus(
new RsText("page not found"),
new RsText("Page not found"),
HttpURLConnection.HTTP_NOT_FOUND
)
),
new FbStatus(
HttpURLConnection.HTTP_BAD_REQUEST,
new RsWithStatus(
new RsText("bad request"),
new RsText("Bad request"),
HttpURLConnection.HTTP_BAD_REQUEST
)
),
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/io/jare/tk/TkAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.jare.fake.FkBase;
import java.net.HttpURLConnection;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.takes.Take;
import org.takes.http.FtRemote;
Expand Down Expand Up @@ -102,4 +103,19 @@ public void rendersHomePageViaHttp() throws Exception {
);
}

/**
* App can render not found.
* @throws Exception If some problem inside
*/
@Test
public void rendersNotFoundPage() throws Exception {
final Take take = new TkApp(new FkBase());
MatcherAssert.assertThat(
new RsPrint(
take.act(new RqFake("HEAD", "/not-found"))
).printBody(),
Matchers.equalTo("Page not found")
);
}

}

0 comments on commit 72e524b

Please sign in to comment.