2013-12-31 16:40:21 +08:00
|
|
|
package sample.jsp;
|
2013-08-24 06:23:45 +08:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.http.client.ClientHttpResponse;
|
|
|
|
import org.springframework.web.client.DefaultResponseErrorHandler;
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
2014-01-22 06:37:18 +08:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
2013-08-24 06:23:45 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic integration tests for JSP application.
|
2013-11-16 15:42:40 +08:00
|
|
|
*
|
2013-08-24 06:23:45 +08:00
|
|
|
* @author Phillip Webb
|
|
|
|
*/
|
|
|
|
public class SampleWebJspApplicationTests {
|
|
|
|
|
|
|
|
private static ConfigurableApplicationContext context;
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void start() throws Exception {
|
|
|
|
Future<ConfigurableApplicationContext> future = Executors
|
|
|
|
.newSingleThreadExecutor().submit(
|
|
|
|
new Callable<ConfigurableApplicationContext>() {
|
|
|
|
@Override
|
|
|
|
public ConfigurableApplicationContext call() throws Exception {
|
2013-11-16 15:42:40 +08:00
|
|
|
return SpringApplication
|
2013-08-24 06:23:45 +08:00
|
|
|
.run(SampleWebJspApplication.class);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
context = future.get(60, TimeUnit.SECONDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
public static void stop() {
|
|
|
|
if (context != null) {
|
|
|
|
context.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testJspWithEl() throws Exception {
|
|
|
|
ResponseEntity<String> entity = getRestTemplate().getForEntity(
|
|
|
|
"http://localhost:8080", String.class);
|
|
|
|
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
2013-11-16 15:42:40 +08:00
|
|
|
assertTrue("Wrong body:\n" + entity.getBody(),
|
|
|
|
entity.getBody().contains("/resources/text.txt"));
|
2013-08-24 06:23:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private RestTemplate getRestTemplate() {
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
|
|
|
@Override
|
|
|
|
public void handleError(ClientHttpResponse response) throws IOException {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return restTemplate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|