BAEL-3059: Update Play Framework (#7674)
* Implementation of Introduction to Play Framework in Java * Implementation of Introduction to Play Framework in Java * Implementation of Introduction to Play Framework in Java * Implementation of the tutorial for Introduction to Play Framework. * Updated code for Play Routing to 2.7.3 * Updated code for Play Routing to 2.7.3 * Initial Commit * Added request object to create end point * Finished implementing student-api * Finished implementing student-api * Implementation of the tutorial for Introduction to Play Framework. * Updated test names * Removed Lombok dependency * Corrected isSuccessful spelling and removed the +1 on student ids
This commit is contained in:
committed by
KevinGilmore
parent
0d648321dc
commit
5bce8b22a1
@@ -1,6 +1,7 @@
|
||||
logs
|
||||
target
|
||||
/.idea
|
||||
/.g8
|
||||
/.idea_modules
|
||||
/.classpath
|
||||
/.project
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
This software is licensed under the Apache 2 license, quoted below.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with
|
||||
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the License.
|
||||
@@ -1,49 +0,0 @@
|
||||
This is your new Play application
|
||||
=================================
|
||||
|
||||
This file will be packaged with your application when using `activator dist`.
|
||||
|
||||
There are several demonstration files available in this template.
|
||||
|
||||
Controllers
|
||||
===========
|
||||
|
||||
- HomeController.java:
|
||||
|
||||
Shows how to handle simple HTTP requests.
|
||||
|
||||
- AsyncController.java:
|
||||
|
||||
Shows how to do asynchronous programming when handling a request.
|
||||
|
||||
- CountController.java:
|
||||
|
||||
Shows how to inject a component into a controller and use the component when
|
||||
handling requests.
|
||||
|
||||
Components
|
||||
==========
|
||||
|
||||
- Module.java:
|
||||
|
||||
Shows how to use Guice to bind all the components needed by your application.
|
||||
|
||||
- Counter.java:
|
||||
|
||||
An example of a component that contains state, in this case a simple counter.
|
||||
|
||||
- ApplicationTimer.java:
|
||||
|
||||
An example of a component that starts when the application starts and stops
|
||||
when the application stops.
|
||||
|
||||
Filters
|
||||
=======
|
||||
|
||||
- Filters.java:
|
||||
|
||||
Creates the list of HTTP filters used by your application.
|
||||
|
||||
- ExampleFilter.java
|
||||
|
||||
A simple filter that adds a header to every response.
|
||||
@@ -1,46 +0,0 @@
|
||||
import javax.inject.*;
|
||||
import play.*;
|
||||
import play.mvc.EssentialFilter;
|
||||
import play.http.HttpFilters;
|
||||
import play.mvc.*;
|
||||
|
||||
import filters.ExampleFilter;
|
||||
|
||||
/**
|
||||
* This class configures filters that run on every request. This
|
||||
* class is queried by Play to get a list of filters.
|
||||
*
|
||||
* Play will automatically use filters from any class called
|
||||
* <code>Filters</code> that is placed the root package. You can load filters
|
||||
* from a different class by adding a `play.http.filters` setting to
|
||||
* the <code>application.conf</code> configuration file.
|
||||
*/
|
||||
@Singleton
|
||||
public class Filters implements HttpFilters {
|
||||
|
||||
private final Environment env;
|
||||
private final EssentialFilter exampleFilter;
|
||||
|
||||
/**
|
||||
* @param env Basic environment settings for the current application.
|
||||
* @param exampleFilter A demonstration filter that adds a header to
|
||||
*/
|
||||
@Inject
|
||||
public Filters(Environment env, ExampleFilter exampleFilter) {
|
||||
this.env = env;
|
||||
this.exampleFilter = exampleFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EssentialFilter[] filters() {
|
||||
// Use the example filter if we're running development mode. If
|
||||
// we're running in production or test mode then don't use any
|
||||
// filters at all.
|
||||
if (env.mode().equals(Mode.DEV)) {
|
||||
return new EssentialFilter[] { exampleFilter };
|
||||
} else {
|
||||
return new EssentialFilter[] {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import com.google.inject.AbstractModule;
|
||||
import java.time.Clock;
|
||||
|
||||
import services.ApplicationTimer;
|
||||
import services.AtomicCounter;
|
||||
import services.Counter;
|
||||
|
||||
/**
|
||||
* This class is a Guice module that tells Guice how to bind several
|
||||
* different types. This Guice module is created when the Play
|
||||
* application starts.
|
||||
*
|
||||
* Play will automatically use any class called `Module` that is in
|
||||
* the root package. You can create modules in other locations by
|
||||
* adding `play.modules.enabled` settings to the `application.conf`
|
||||
* configuration file.
|
||||
*/
|
||||
public class Module extends AbstractModule {
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
// Use the system clock as the default implementation of Clock
|
||||
bind(Clock.class).toInstance(Clock.systemDefaultZone());
|
||||
// Ask Guice to create an instance of ApplicationTimer when the
|
||||
// application starts.
|
||||
bind(ApplicationTimer.class).asEagerSingleton();
|
||||
// Set AtomicCounter as the implementation for Counter.
|
||||
bind(Counter.class).to(AtomicCounter.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package controllers;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import play.*;
|
||||
import play.mvc.*;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.ExecutionContextExecutor;
|
||||
|
||||
/**
|
||||
* This controller contains an action that demonstrates how to write
|
||||
* simple asynchronous code in a controller. It uses a timer to
|
||||
* asynchronously delay sending a response for 1 second.
|
||||
*
|
||||
* @param actorSystem We need the {@link ActorSystem}'s
|
||||
* {@link Scheduler} to run code after a delay.
|
||||
* @param exec We need a Java {@link Executor} to apply the result
|
||||
* of the {@link CompletableFuture} and a Scala
|
||||
* {@link ExecutionContext} so we can use the Akka {@link Scheduler}.
|
||||
* An {@link ExecutionContextExecutor} implements both interfaces.
|
||||
*/
|
||||
@Singleton
|
||||
public class AsyncController extends Controller {
|
||||
|
||||
private final ActorSystem actorSystem;
|
||||
private final ExecutionContextExecutor exec;
|
||||
|
||||
@Inject
|
||||
public AsyncController(ActorSystem actorSystem, ExecutionContextExecutor exec) {
|
||||
this.actorSystem = actorSystem;
|
||||
this.exec = exec;
|
||||
}
|
||||
|
||||
/**
|
||||
* An action that returns a plain text message after a delay
|
||||
* of 1 second.
|
||||
* <p>
|
||||
* The configuration in the <code>routes</code> file means that this method
|
||||
* will be called when the application receives a <code>GET</code> request with
|
||||
* a path of <code>/message</code>.
|
||||
*/
|
||||
public CompletionStage<Result> message() {
|
||||
return getFutureMessage(1, TimeUnit.SECONDS).thenApplyAsync(Results::ok, exec);
|
||||
}
|
||||
|
||||
private CompletionStage<String> getFutureMessage(long time, TimeUnit timeUnit) {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
actorSystem.scheduler().scheduleOnce(
|
||||
Duration.create(time, timeUnit),
|
||||
() -> future.complete("Hi!"),
|
||||
exec
|
||||
);
|
||||
return future;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package controllers;
|
||||
|
||||
import javax.inject.*;
|
||||
import play.*;
|
||||
import play.mvc.*;
|
||||
|
||||
import services.Counter;
|
||||
|
||||
/**
|
||||
* This controller demonstrates how to use dependency injection to
|
||||
* bind a component into a controller class. The class contains an
|
||||
* action that shows an incrementing count to users. The {@link Counter}
|
||||
* object is injected by the Guice dependency injection system.
|
||||
*/
|
||||
@Singleton
|
||||
public class CountController extends Controller {
|
||||
|
||||
private final Counter counter;
|
||||
|
||||
@Inject
|
||||
public CountController(Counter counter) {
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* An action that responds with the {@link Counter}'s current
|
||||
* count. The result is plain text. This action is mapped to
|
||||
* <code>GET</code> requests with a path of <code>/count</code>
|
||||
* requests by an entry in the <code>routes</code> config file.
|
||||
*/
|
||||
public Result count() {
|
||||
return ok(Integer.toString(counter.nextCount()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,25 @@
|
||||
package controllers;
|
||||
|
||||
import play.libs.concurrent.HttpExecutionContext;
|
||||
import play.mvc.*;
|
||||
import play.twirl.api.Html;
|
||||
|
||||
import views.html.*;
|
||||
import javax.inject.Inject;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
import static java.util.concurrent.CompletableFuture.supplyAsync;
|
||||
|
||||
/**
|
||||
* This controller contains an action to handle HTTP requests
|
||||
* to the application's home page.
|
||||
*/
|
||||
public class HomeController extends Controller {
|
||||
private HttpExecutionContext ec;
|
||||
|
||||
@Inject
|
||||
public HomeController(HttpExecutionContext ec) {
|
||||
this.ec = ec;
|
||||
}
|
||||
|
||||
/**
|
||||
* An action that renders an HTML page with a welcome message.
|
||||
@@ -17,7 +28,41 @@ public class HomeController extends Controller {
|
||||
* <code>GET</code> request with a path of <code>/</code>.
|
||||
*/
|
||||
public Result index() {
|
||||
return ok(index.render("Your new application is ready."));
|
||||
return ok(views.html.index.render());
|
||||
}
|
||||
|
||||
public Result applyHtml() {
|
||||
return ok(Html.apply("<h1>This text will appear as a heading 1</h1>"));
|
||||
}
|
||||
|
||||
public Result badRequestPage() {
|
||||
return badRequest("Your request data has issues.");
|
||||
}
|
||||
|
||||
public Result notFoundPage() {
|
||||
return notFound("Could not find the page you requested.");
|
||||
}
|
||||
|
||||
public Result customContentType() {
|
||||
return ok("This is some text content").as("text/html");
|
||||
}
|
||||
|
||||
public CompletionStage<Result> asyncOperation() {
|
||||
return supplyAsync(() -> {
|
||||
return longRunningTask();
|
||||
}, ec.current())
|
||||
.thenApplyAsync(s -> {
|
||||
return ok("Got result -> " + s);
|
||||
}, ec.current());
|
||||
}
|
||||
|
||||
private String longRunningTask() {
|
||||
return "Long running task has completed";
|
||||
}
|
||||
|
||||
public Result setHeaders() {
|
||||
return ok("This is some text content")
|
||||
.as("text/html")
|
||||
.withHeader("Header-Key", "Some value");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package controllers;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import models.Student;
|
||||
import models.StudentStore;
|
||||
import play.libs.Json;
|
||||
import play.mvc.Controller;
|
||||
import play.mvc.Result;
|
||||
import util.Util;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class StudentController extends Controller {
|
||||
public Result create() {
|
||||
JsonNode json = request().body().asJson();
|
||||
if (json == null) {
|
||||
return badRequest(Util.createResponse("Expecting Json data", false));
|
||||
}
|
||||
Student student = StudentStore.getInstance().addStudent(Json.fromJson(json, Student.class));
|
||||
JsonNode jsonObject = Json.toJson(student);
|
||||
return created(Util.createResponse(jsonObject, true));
|
||||
}
|
||||
|
||||
public Result update() {
|
||||
JsonNode json = request().body().asJson();
|
||||
if (json == null) {
|
||||
return badRequest(Util.createResponse("Expecting Json data", false));
|
||||
}
|
||||
Student student = StudentStore.getInstance().updateStudent(Json.fromJson(json, Student.class));
|
||||
if (student == null) {
|
||||
return notFound(Util.createResponse("Student not found", false));
|
||||
}
|
||||
|
||||
JsonNode jsonObject = Json.toJson(student);
|
||||
return ok(Util.createResponse(jsonObject, true));
|
||||
}
|
||||
|
||||
public Result retrieve(int id) {
|
||||
if (StudentStore.getInstance().getStudent(id) == null) {
|
||||
return notFound(Util.createResponse("Student with id:" + id + " not found", false));
|
||||
}
|
||||
JsonNode jsonObjects = Json.toJson(StudentStore.getInstance().getStudent(id));
|
||||
return ok(Util.createResponse(jsonObjects, true));
|
||||
}
|
||||
|
||||
public Result listStudents() {
|
||||
Set<Student> result = StudentStore.getInstance().getAllStudents();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
JsonNode jsonData = mapper.convertValue(result, JsonNode.class);
|
||||
return ok(Util.createResponse(jsonData, true));
|
||||
|
||||
}
|
||||
|
||||
public Result delete(int id) {
|
||||
if (!StudentStore.getInstance().deleteStudent(id)) {
|
||||
return notFound(Util.createResponse("Student with id:" + id + " not found", false));
|
||||
}
|
||||
return ok(Util.createResponse("Student with id:" + id + " deleted", true));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package filters;
|
||||
|
||||
import akka.stream.Materializer;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Function;
|
||||
import javax.inject.*;
|
||||
import play.mvc.*;
|
||||
import play.mvc.Http.RequestHeader;
|
||||
|
||||
|
||||
/**
|
||||
* This is a simple filter that adds a header to all requests. It's
|
||||
* added to the application's list of filters by the
|
||||
* {@link Filters} class.
|
||||
*/
|
||||
@Singleton
|
||||
public class ExampleFilter extends Filter {
|
||||
|
||||
private final Executor exec;
|
||||
|
||||
/**
|
||||
* @param mat This object is needed to handle streaming of requests
|
||||
* and responses.
|
||||
* @param exec This class is needed to execute code asynchronously.
|
||||
* It is used below by the <code>thenAsyncApply</code> method.
|
||||
*/
|
||||
@Inject
|
||||
public ExampleFilter(Materializer mat, Executor exec) {
|
||||
super(mat);
|
||||
this.exec = exec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Result> apply(
|
||||
Function<RequestHeader, CompletionStage<Result>> next,
|
||||
RequestHeader requestHeader) {
|
||||
|
||||
return next.apply(requestHeader).thenApplyAsync(
|
||||
result -> result.withHeader("X-ExampleFilter", "foo"),
|
||||
exec
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package models;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class StudentStore {
|
||||
private static StudentStore instance;
|
||||
private Map<Integer, Student> students = new HashMap<>();
|
||||
|
||||
public static StudentStore getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new StudentStore();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Student addStudent(Student student) {
|
||||
int id = students.size();
|
||||
student.setId(id);
|
||||
students.put(id, student);
|
||||
return student;
|
||||
}
|
||||
|
||||
public Student getStudent(int id) {
|
||||
return students.get(id);
|
||||
}
|
||||
|
||||
public Set<Student> getAllStudents() {
|
||||
return new HashSet<>(students.values());
|
||||
}
|
||||
|
||||
public Student updateStudent(Student student) {
|
||||
int id = student.getId();
|
||||
if (students.containsKey(id)) {
|
||||
students.put(id, student);
|
||||
return student;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean deleteStudent(int id) {
|
||||
return students.remove(id) != null;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package services;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import javax.inject.*;
|
||||
import play.Logger;
|
||||
import play.inject.ApplicationLifecycle;
|
||||
|
||||
/**
|
||||
* This class demonstrates how to run code when the
|
||||
* application starts and stops. It starts a timer when the
|
||||
* application starts. When the application stops it prints out how
|
||||
* long the application was running for.
|
||||
*
|
||||
* This class is registered for Guice dependency injection in the
|
||||
* {@link Module} class. We want the class to start when the application
|
||||
* starts, so it is registered as an "eager singleton". See the code
|
||||
* in the {@link Module} class to see how this happens.
|
||||
*
|
||||
* This class needs to run code when the server stops. It uses the
|
||||
* application's {@link ApplicationLifecycle} to register a stop hook.
|
||||
*/
|
||||
@Singleton
|
||||
public class ApplicationTimer {
|
||||
|
||||
private final Clock clock;
|
||||
private final ApplicationLifecycle appLifecycle;
|
||||
private final Instant start;
|
||||
|
||||
@Inject
|
||||
public ApplicationTimer(Clock clock, ApplicationLifecycle appLifecycle) {
|
||||
this.clock = clock;
|
||||
this.appLifecycle = appLifecycle;
|
||||
// This code is called when the application starts.
|
||||
start = clock.instant();
|
||||
Logger.info("ApplicationTimer demo: Starting application at " + start);
|
||||
|
||||
// When the application starts, register a stop hook with the
|
||||
// ApplicationLifecycle object. The code inside the stop hook will
|
||||
// be run when the application stops.
|
||||
appLifecycle.addStopHook(() -> {
|
||||
Instant stop = clock.instant();
|
||||
Long runningTime = stop.getEpochSecond() - start.getEpochSecond();
|
||||
Logger.info("ApplicationTimer demo: Stopping application at " + clock.instant() + " after " + runningTime + "s.");
|
||||
return CompletableFuture.completedFuture(null);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package services;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.inject.*;
|
||||
|
||||
/**
|
||||
* This class is a concrete implementation of the {@link Counter} trait.
|
||||
* It is configured for Guice dependency injection in the {@link Module}
|
||||
* class.
|
||||
*
|
||||
* This class has a {@link Singleton} annotation because we need to make
|
||||
* sure we only use one counter per application. Without this
|
||||
* annotation we would get a new instance every time a {@link Counter} is
|
||||
* injected.
|
||||
*/
|
||||
@Singleton
|
||||
public class AtomicCounter implements Counter {
|
||||
|
||||
private final AtomicInteger atomicCounter = new AtomicInteger();
|
||||
|
||||
@Override
|
||||
public int nextCount() {
|
||||
return atomicCounter.getAndIncrement();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package services;
|
||||
|
||||
/**
|
||||
* This interface demonstrates how to create a component that is injected
|
||||
* into a controller. The interface represents a counter that returns a
|
||||
* incremented number each time it is called.
|
||||
*
|
||||
* The {@link Modules} class binds this interface to the
|
||||
* {@link AtomicCounter} implementation.
|
||||
*/
|
||||
public interface Counter {
|
||||
int nextCount();
|
||||
}
|
||||
@@ -1,20 +1,5 @@
|
||||
@*
|
||||
* This template takes a single argument, a String containing a
|
||||
* message to display.
|
||||
*@
|
||||
@(message: String)
|
||||
@()
|
||||
|
||||
@*
|
||||
* Call the `main` template with two arguments. The first
|
||||
* argument is a `String` with the title of the page, the second
|
||||
* argument is an `Html` object containing the body of the page.
|
||||
*@
|
||||
@main("Welcome to Play") {
|
||||
|
||||
@*
|
||||
* Get an `Html` object by calling the built-in Play welcome
|
||||
* template and passing a `String` message.
|
||||
*@
|
||||
@play20.welcome(message, style = "Java")
|
||||
|
||||
<h1>Welcome to Play!</h1>
|
||||
}
|
||||
|
||||
@@ -13,11 +13,12 @@
|
||||
<title>@title</title>
|
||||
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
|
||||
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
|
||||
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
@* And here's where we render the `Html` object containing
|
||||
* the page content. *@
|
||||
@content
|
||||
|
||||
<script src="@routes.Assets.versioned("javascripts/main.js")" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
-397
File diff suppressed because it is too large
Load Diff
-248
@@ -1,248 +0,0 @@
|
||||
@REM activator launcher script
|
||||
@REM
|
||||
@REM Environment:
|
||||
@REM In order for Activator to work you must have Java available on the classpath
|
||||
@REM JAVA_HOME - location of a JDK home dir (optional if java on path)
|
||||
@REM CFG_OPTS - JVM options (optional)
|
||||
@REM Configuration:
|
||||
@REM activatorconfig.txt found in the ACTIVATOR_HOME or ACTIVATOR_HOME/ACTIVATOR_VERSION
|
||||
@setlocal enabledelayedexpansion
|
||||
|
||||
@echo off
|
||||
|
||||
set "var1=%~1"
|
||||
if defined var1 (
|
||||
if "%var1%"=="help" (
|
||||
echo.
|
||||
echo Usage activator [options] [command]
|
||||
echo.
|
||||
echo Commands:
|
||||
echo ui Start the Activator UI
|
||||
echo new [name] [template-id] Create a new project with [name] using template [template-id]
|
||||
echo list-templates Print all available template names
|
||||
echo help Print this message
|
||||
echo.
|
||||
echo Options:
|
||||
echo -jvm-debug [port] Turn on JVM debugging, open at the given port. Defaults to 9999 if no port given.
|
||||
echo.
|
||||
echo Environment variables ^(read from context^):
|
||||
echo JAVA_OPTS Environment variable, if unset uses ""
|
||||
echo SBT_OPTS Environment variable, if unset uses ""
|
||||
echo ACTIVATOR_OPTS Environment variable, if unset uses ""
|
||||
echo.
|
||||
echo Please note that in order for Activator to work you must have Java available on the classpath
|
||||
echo.
|
||||
goto :end
|
||||
)
|
||||
)
|
||||
|
||||
@REM determine ACTIVATOR_HOME environment variable
|
||||
set BIN_DIRECTORY=%~dp0
|
||||
set BIN_DIRECTORY=%BIN_DIRECTORY:~0,-1%
|
||||
for %%d in (%BIN_DIRECTORY%) do set ACTIVATOR_HOME=%%~dpd
|
||||
set ACTIVATOR_HOME=%ACTIVATOR_HOME:~0,-1%
|
||||
|
||||
echo ACTIVATOR_HOME=%ACTIVATOR_HOME%
|
||||
|
||||
set ERROR_CODE=0
|
||||
set APP_VERSION=1.3.10
|
||||
set ACTIVATOR_LAUNCH_JAR=activator-launch-%APP_VERSION%.jar
|
||||
|
||||
rem Detect if we were double clicked, although theoretically A user could
|
||||
rem manually run cmd /c
|
||||
for %%x in (%cmdcmdline%) do if %%~x==/c set DOUBLECLICKED=1
|
||||
|
||||
set SBT_HOME=%BIN_DIRECTORY
|
||||
|
||||
rem Detect if we were double clicked, although theoretically A user could
|
||||
rem manually run cmd /c
|
||||
for %%x in (%cmdcmdline%) do if %%~x==/c set DOUBLECLICKED=1
|
||||
|
||||
rem FIRST we load the config file of extra options.
|
||||
set FN=%SBT_HOME%\..\conf\sbtconfig.txt
|
||||
set CFG_OPTS=
|
||||
FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%FN%") DO (
|
||||
set DO_NOT_REUSE_ME=%%i
|
||||
rem ZOMG (Part #2) WE use !! here to delay the expansion of
|
||||
rem CFG_OPTS, otherwise it remains "" for this loop.
|
||||
set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME!
|
||||
)
|
||||
|
||||
rem FIRST we load a config file of extra options (if there is one)
|
||||
set "CFG_FILE_HOME=%UserProfile%\.activator\activatorconfig.txt"
|
||||
set "CFG_FILE_VERSION=%UserProfile%\.activator\%APP_VERSION%\activatorconfig.txt"
|
||||
if exist %CFG_FILE_VERSION% (
|
||||
FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE_VERSION%") DO (
|
||||
set DO_NOT_REUSE_ME=%%i
|
||||
rem ZOMG (Part #2) WE use !! here to delay the expansion of
|
||||
rem CFG_OPTS, otherwise it remains "" for this loop.
|
||||
set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME!
|
||||
)
|
||||
)
|
||||
if "%CFG_OPTS%"=="" (
|
||||
if exist %CFG_FILE_HOME% (
|
||||
FOR /F "tokens=* eol=# usebackq delims=" %%i IN ("%CFG_FILE_HOME%") DO (
|
||||
set DO_NOT_REUSE_ME=%%i
|
||||
rem ZOMG (Part #2) WE use !! here to delay the expansion of
|
||||
rem CFG_OPTS, otherwise it remains "" for this loop.
|
||||
set CFG_OPTS=!CFG_OPTS! !DO_NOT_REUSE_ME!
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
rem We use the value of the JAVACMD environment variable if defined
|
||||
set _JAVACMD=%JAVACMD%
|
||||
|
||||
if "%_JAVACMD%"=="" (
|
||||
if not "%JAVA_HOME%"=="" (
|
||||
if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe"
|
||||
|
||||
rem if there is a java home set we make sure it is the first picked up when invoking 'java'
|
||||
SET "PATH=%JAVA_HOME%\bin;%PATH%"
|
||||
)
|
||||
)
|
||||
|
||||
if "%_JAVACMD%"=="" set _JAVACMD=java
|
||||
|
||||
rem Detect if this java is ok to use.
|
||||
for /F %%j in ('"%_JAVACMD%" -version 2^>^&1') do (
|
||||
if %%~j==java set JAVAINSTALLED=1
|
||||
if %%~j==openjdk set JAVAINSTALLED=1
|
||||
)
|
||||
|
||||
rem Detect the same thing about javac
|
||||
if "%_JAVACCMD%"=="" (
|
||||
if not "%JAVA_HOME%"=="" (
|
||||
if exist "%JAVA_HOME%\bin\javac.exe" set "_JAVACCMD=%JAVA_HOME%\bin\javac.exe"
|
||||
)
|
||||
)
|
||||
if "%_JAVACCMD%"=="" set _JAVACCMD=javac
|
||||
for /F %%j in ('"%_JAVACCMD%" -version 2^>^&1') do (
|
||||
if %%~j==javac set JAVACINSTALLED=1
|
||||
)
|
||||
|
||||
rem BAT has no logical or, so we do it OLD SCHOOL! Oppan Redmond Style
|
||||
set JAVAOK=true
|
||||
if not defined JAVAINSTALLED set JAVAOK=false
|
||||
if not defined JAVACINSTALLED set JAVAOK=false
|
||||
|
||||
if "%JAVAOK%"=="false" (
|
||||
echo.
|
||||
echo A Java JDK is not installed or can't be found.
|
||||
if not "%JAVA_HOME%"=="" (
|
||||
echo JAVA_HOME = "%JAVA_HOME%"
|
||||
)
|
||||
echo.
|
||||
echo Please go to
|
||||
echo http://www.oracle.com/technetwork/java/javase/downloads/index.html
|
||||
echo and download a valid Java JDK and install before running Activator.
|
||||
echo.
|
||||
echo If you think this message is in error, please check
|
||||
echo your environment variables to see if "java.exe" and "javac.exe" are
|
||||
echo available via JAVA_HOME or PATH.
|
||||
echo.
|
||||
if defined DOUBLECLICKED pause
|
||||
exit /B 1
|
||||
)
|
||||
|
||||
rem Check what Java version is being used to determine what memory options to use
|
||||
for /f "tokens=3" %%g in ('java -version 2^>^&1 ^| findstr /i "version"') do (
|
||||
set JAVA_VERSION=%%g
|
||||
)
|
||||
|
||||
rem Strips away the " characters
|
||||
set JAVA_VERSION=%JAVA_VERSION:"=%
|
||||
|
||||
rem TODO Check if there are existing mem settings in JAVA_OPTS/CFG_OPTS and use those instead of the below
|
||||
for /f "delims=. tokens=1-3" %%v in ("%JAVA_VERSION%") do (
|
||||
set MAJOR=%%v
|
||||
set MINOR=%%w
|
||||
set BUILD=%%x
|
||||
|
||||
set META_SIZE=-XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=256M
|
||||
if "!MINOR!" LSS "8" (
|
||||
set META_SIZE=-XX:PermSize=64M -XX:MaxPermSize=256M
|
||||
)
|
||||
|
||||
set MEM_OPTS=!META_SIZE!
|
||||
)
|
||||
|
||||
rem We use the value of the JAVA_OPTS environment variable if defined, rather than the config.
|
||||
set _JAVA_OPTS=%JAVA_OPTS%
|
||||
if "%_JAVA_OPTS%"=="" set _JAVA_OPTS=%CFG_OPTS%
|
||||
|
||||
set DEBUG_OPTS=
|
||||
|
||||
rem Loop through the arguments, building remaining args in args variable
|
||||
set args=
|
||||
:argsloop
|
||||
if not "%~1"=="" (
|
||||
rem Checks if the argument contains "-D" and if true, adds argument 1 with 2 and puts an equal sign between them.
|
||||
rem This is done since batch considers "=" to be a delimiter so we need to circumvent this behavior with a small hack.
|
||||
set arg1=%~1
|
||||
if "!arg1:~0,2!"=="-D" (
|
||||
set "args=%args% "%~1"="%~2""
|
||||
shift
|
||||
shift
|
||||
goto argsloop
|
||||
)
|
||||
|
||||
if "%~1"=="-jvm-debug" (
|
||||
if not "%~2"=="" (
|
||||
rem This piece of magic somehow checks that an argument is a number
|
||||
for /F "delims=0123456789" %%i in ("%~2") do (
|
||||
set var="%%i"
|
||||
)
|
||||
if defined var (
|
||||
rem Not a number, assume no argument given and default to 9999
|
||||
set JPDA_PORT=9999
|
||||
) else (
|
||||
rem Port was given, shift arguments
|
||||
set JPDA_PORT=%~2
|
||||
shift
|
||||
)
|
||||
) else (
|
||||
set JPDA_PORT=9999
|
||||
)
|
||||
shift
|
||||
|
||||
set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=!JPDA_PORT!
|
||||
goto argsloop
|
||||
)
|
||||
rem else
|
||||
set "args=%args% "%~1""
|
||||
shift
|
||||
goto argsloop
|
||||
)
|
||||
|
||||
:run
|
||||
|
||||
if "!args!"=="" (
|
||||
if defined DOUBLECLICKED (
|
||||
set CMDS="ui"
|
||||
) else set CMDS=!args!
|
||||
) else set CMDS=!args!
|
||||
|
||||
rem We add a / in front, so we get file:///C: instead of file://C:
|
||||
rem Java considers the later a UNC path.
|
||||
rem We also attempt a solid effort at making it URI friendly.
|
||||
rem We don't even bother with UNC paths.
|
||||
set JAVA_FRIENDLY_HOME_1=/!ACTIVATOR_HOME:\=/!
|
||||
set JAVA_FRIENDLY_HOME=/!JAVA_FRIENDLY_HOME_1: =%%20!
|
||||
|
||||
rem Checks if the command contains spaces to know if it should be wrapped in quotes or not
|
||||
set NON_SPACED_CMD=%_JAVACMD: =%
|
||||
if "%_JAVACMD%"=="%NON_SPACED_CMD%" %_JAVACMD% %DEBUG_OPTS% %MEM_OPTS% %ACTIVATOR_OPTS% %SBT_OPTS% %_JAVA_OPTS% "-Dactivator.home=%JAVA_FRIENDLY_HOME%" -jar "%ACTIVATOR_HOME%\libexec\%ACTIVATOR_LAUNCH_JAR%" %CMDS%
|
||||
if NOT "%_JAVACMD%"=="%NON_SPACED_CMD%" "%_JAVACMD%" %DEBUG_OPTS% %MEM_OPTS% %ACTIVATOR_OPTS% %SBT_OPTS% %_JAVA_OPTS% "-Dactivator.home=%JAVA_FRIENDLY_HOME%" -jar "%ACTIVATOR_HOME%\libexec\%ACTIVATOR_LAUNCH_JAR%" %CMDS%
|
||||
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
|
||||
@endlocal
|
||||
|
||||
exit /B %ERROR_CODE%
|
||||
@@ -1,13 +1,10 @@
|
||||
name := """student-api"""
|
||||
name := """introduction"""
|
||||
organization := "com.baeldung"
|
||||
|
||||
version := "1.0-SNAPSHOT"
|
||||
|
||||
lazy val root = (project in file(".")).enablePlugins(PlayJava)
|
||||
|
||||
scalaVersion := "2.11.7"
|
||||
scalaVersion := "2.13.0"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
javaJdbc,
|
||||
cache,
|
||||
javaWs
|
||||
)
|
||||
libraryDependencies += guice
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,12 +27,6 @@
|
||||
<logger name="play" level="INFO" />
|
||||
<logger name="application" level="DEBUG" />
|
||||
|
||||
<!-- Off these ones as they are annoying, and anyway we manage configuration ourselves -->
|
||||
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
|
||||
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
|
||||
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
|
||||
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="ASYNCFILE" />
|
||||
<appender-ref ref="ASYNCSTDOUT" />
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
# This file defines all application routes (Higher priority routes first)
|
||||
# ~~~~
|
||||
|
||||
GET / controllers.StudentController.listStudents()
|
||||
POST /:id controllers.StudentController.retrieve(id:Int)
|
||||
POST / controllers.StudentController.create()
|
||||
PUT / controllers.StudentController.update()
|
||||
DELETE /:id controllers.StudentController.delete(id:Int)
|
||||
# An example controller showing a sample home page
|
||||
GET / controllers.HomeController.index
|
||||
GET /baeldung/html controllers.HomeController.applyHtml
|
||||
GET /baeldung/bad-req controllers.HomeController.badRequestPage
|
||||
GET /baeldung/not-found controllers.HomeController.notFoundPage
|
||||
GET /baeldung/custom-content-type controllers.HomeController.customContentType
|
||||
GET /baeldung/async controllers.HomeController.asyncOperation
|
||||
GET /baeldung/headers controllers.HomeController.setHeaders
|
||||
|
||||
# Map static resources from the /public folder to the /assets URL path
|
||||
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
|
||||
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
|
||||
|
||||
Binary file not shown.
@@ -1,4 +1 @@
|
||||
#Activator-generated Properties
|
||||
#Wed Sep 07 12:29:40 EAT 2016
|
||||
template.uuid=c373963b-f5ad-433b-8e74-178e7ae25b1c
|
||||
sbt.version=0.13.11
|
||||
sbt.version=1.2.8
|
||||
|
||||
@@ -1,21 +1,7 @@
|
||||
// The Play plugin
|
||||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.6")
|
||||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.3")
|
||||
|
||||
// Web plugins
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
|
||||
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.2")
|
||||
|
||||
// Play enhancer - this automatically generates getters/setters for public fields
|
||||
// and rewrites accessors of these fields to use the getters/setters. Remove this
|
||||
// plugin if you prefer not to have this feature, or disable on a per project
|
||||
// basis using disablePlugins(PlayEnhancer) in your build.sbt
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
|
||||
|
||||
// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
|
||||
// enablePlugins(PlayEbean).
|
||||
// addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
|
||||
// Defines scaffolding (found under .g8 folder)
|
||||
// http://www.foundweekends.org/giter8/scaffolding.html
|
||||
// sbt "g8Scaffold form"
|
||||
addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.11.0")
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
if (window.console) {
|
||||
console.log("Welcome to your Play application's JavaScript!");
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import model.Student;
|
||||
import play.test.*;
|
||||
import static play.test.Helpers.*;
|
||||
|
||||
public class ApplicationLiveTest{
|
||||
private static final String BASE_URL = "http://localhost:9000";
|
||||
|
||||
@Test
|
||||
public void testInServer() throws Exception {
|
||||
TestServer server = testServer(3333);
|
||||
running(server, () -> {
|
||||
try {
|
||||
WSClient ws = play.libs.ws.WS.newClient(3333);
|
||||
CompletionStage<WSResponse> completionStage = ws.url("/").get();
|
||||
WSResponse response = completionStage.toCompletableFuture().get();
|
||||
ws.close();
|
||||
assertEquals(OK, response.getStatus());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@Test
|
||||
public void whenCreatesRecord_thenCorrect() {
|
||||
Student student = new Student("jody", "west", 50);
|
||||
JSONObject obj = new JSONObject(makeRequest(BASE_URL, "POST", new JSONObject(student)));
|
||||
assertTrue(obj.getBoolean("isSuccessfull"));
|
||||
JSONObject body = obj.getJSONObject("body");
|
||||
assertEquals(student.getAge(), body.getInt("age"));
|
||||
assertEquals(student.getFirstName(), body.getString("firstName"));
|
||||
assertEquals(student.getLastName(), body.getString("lastName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeletesCreatedRecord_thenCorrect() {
|
||||
Student student = new Student("Usain", "Bolt", 25);
|
||||
JSONObject ob1 = new JSONObject(makeRequest(BASE_URL, "POST", new JSONObject(student))).getJSONObject("body");
|
||||
int id = ob1.getInt("id");
|
||||
JSONObject obj1 = new JSONObject(makeRequest(BASE_URL + "/" + id, "POST", new JSONObject()));
|
||||
assertTrue(obj1.getBoolean("isSuccessfull"));
|
||||
makeRequest(BASE_URL + "/" + id, "DELETE", null);
|
||||
JSONObject obj2 = new JSONObject(makeRequest(BASE_URL + "/" + id, "POST", new JSONObject()));
|
||||
assertFalse(obj2.getBoolean("isSuccessfull"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUpdatesCreatedRecord_thenCorrect() {
|
||||
Student student = new Student("john", "doe", 50);
|
||||
JSONObject body1 = new JSONObject(makeRequest(BASE_URL, "POST", new JSONObject(student))).getJSONObject("body");
|
||||
assertEquals(student.getAge(), body1.getInt("age"));
|
||||
int newAge = 60;
|
||||
body1.put("age", newAge);
|
||||
JSONObject body2 = new JSONObject(makeRequest(BASE_URL, "PUT", body1)).getJSONObject("body");
|
||||
assertFalse(student.getAge() == body2.getInt("age"));
|
||||
assertTrue(newAge == body2.getInt("age"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetsAllRecords_thenCorrect() {
|
||||
Student student1 = new Student("jane", "daisy", 50);
|
||||
Student student2 = new Student("john", "daniel", 60);
|
||||
Student student3 = new Student("don", "mason", 55);
|
||||
Student student4 = new Student("scarlet", "ohara", 90);
|
||||
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student1));
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student2));
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student3));
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student4));
|
||||
|
||||
JSONObject objects = new JSONObject(makeRequest(BASE_URL, "GET", null));
|
||||
assertTrue(objects.getBoolean("isSuccessfull"));
|
||||
JSONArray array = objects.getJSONArray("body");
|
||||
assertTrue(array.length() >= 4);
|
||||
}
|
||||
|
||||
public static String makeRequest(String myUrl, String httpMethod, JSONObject parameters) {
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(myUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
conn.setDoInput(true);
|
||||
|
||||
conn.setReadTimeout(10000);
|
||||
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
DataOutputStream dos = null;
|
||||
int respCode = 0;
|
||||
String inputString = null;
|
||||
try {
|
||||
conn.setRequestMethod(httpMethod);
|
||||
|
||||
if (Arrays.asList("POST", "PUT").contains(httpMethod)) {
|
||||
String params = parameters.toString();
|
||||
|
||||
conn.setDoOutput(true);
|
||||
|
||||
dos = new DataOutputStream(conn.getOutputStream());
|
||||
dos.writeBytes(params);
|
||||
dos.flush();
|
||||
dos.close();
|
||||
}
|
||||
respCode = conn.getResponseCode();
|
||||
if (respCode != 200 && respCode != 201) {
|
||||
String error = inputStreamToString(conn.getErrorStream());
|
||||
return error;
|
||||
}
|
||||
inputString = inputStreamToString(conn.getInputStream());
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return inputString;
|
||||
}
|
||||
|
||||
public static String inputStreamToString(InputStream is) {
|
||||
BufferedReader br = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String line;
|
||||
try {
|
||||
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package controllers;
|
||||
|
||||
import org.junit.Test;
|
||||
import play.Application;
|
||||
import play.inject.guice.GuiceApplicationBuilder;
|
||||
import play.mvc.Http;
|
||||
import play.mvc.Result;
|
||||
import play.test.WithApplication;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static play.mvc.Http.Status.*;
|
||||
import static play.test.Helpers.GET;
|
||||
import static play.test.Helpers.route;
|
||||
|
||||
public class HomeControllerUnitTest extends WithApplication {
|
||||
|
||||
@Override
|
||||
protected Application provideApplication() {
|
||||
return new GuiceApplicationBuilder().build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenRootPath_ThenStatusOkay() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(OK, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenHtmlPath_ThenStatusOkay() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/html");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(OK, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenBadRequest_ThenStatusBadRequest() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/bad-req");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(BAD_REQUEST, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenNotFound_ThenStatusNotFound() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/not-found");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(NOT_FOUND, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenCustomContentTypePath_ThenContextTypeTextHtml() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/custom-content-type");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertTrue(result.contentType().isPresent());
|
||||
assertEquals("text/html", result.contentType().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenAsyncPath_ThenStatusOkay() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/async");
|
||||
|
||||
Result result = route(app, request);
|
||||
assertEquals(OK, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenHeadersPath_ThenCustomHeaderFieldSet() {
|
||||
Http.RequestBuilder request = new Http.RequestBuilder()
|
||||
.method(GET)
|
||||
.uri("/baeldung/headers");
|
||||
|
||||
Result result = route(app, request);
|
||||
final Optional<String> headerOptional = result.header("Header-Key");
|
||||
assertTrue(headerOptional.isPresent());
|
||||
assertEquals("Some value", headerOptional.get());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
This software is licensed under the Apache 2 license, quoted below.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with
|
||||
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
||||
language governing permissions and limitations under the License.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user