Merge pull request #7439 from amit2103/BAEL-16045-12
[BAEL-16045] - Check Article Code Matches GitHub for https://www.bael…
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,7 +30,7 @@ out/
|
||||
.DS_Store
|
||||
|
||||
# Maven
|
||||
log/
|
||||
log/*
|
||||
target/
|
||||
|
||||
# Gradle
|
||||
|
||||
@@ -150,6 +150,11 @@
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -276,6 +281,7 @@
|
||||
<json.path.version>2.2.0</json.path.version>
|
||||
<pact.version>3.5.11</pact.version>
|
||||
<rest-assured.version>3.1.0</rest-assured.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
<start-class>com.baeldung.sampleapp.config.MainApplication</start-class>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
package com.baeldung.web.log.app;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRegistration;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
import com.baeldung.web.log.config.CustomeRequestLoggingFilter;
|
||||
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@@ -14,4 +24,18 @@ public class Application extends SpringBootServletInitializer {
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext container) throws ServletException {
|
||||
|
||||
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||
context.setConfigLocation("com.baeldung.web.log");
|
||||
container.addListener(new ContextLoaderListener(context));
|
||||
|
||||
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(context));
|
||||
dispatcher.setLoadOnStartup(1);
|
||||
dispatcher.addMapping("/");
|
||||
|
||||
container.addFilter("customRequestLoggingFilter", CustomeRequestLoggingFilter.class).addMappingForServletNames(null, false, "dispatcher");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.web.log.config;
|
||||
|
||||
import org.springframework.web.filter.CommonsRequestLoggingFilter;
|
||||
|
||||
public class CustomeRequestLoggingFilter extends CommonsRequestLoggingFilter {
|
||||
|
||||
public CustomeRequestLoggingFilter() {
|
||||
super.setIncludeQueryString(true);
|
||||
super.setIncludePayload(true);
|
||||
super.setMaxPayloadLength(10000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.web.log.app.Application;
|
||||
import com.baeldung.web.log.data.TaxiRide;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = { Application.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class TaxiFareControllerIntegrationTest {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Test
|
||||
public void givenRequest_whenFetchTaxiFareRateCard_thanOK() {
|
||||
|
||||
String URL = "http://localhost:" + port + "/spring-rest";
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
TaxiRide taxiRide = new TaxiRide(true, 10l);
|
||||
String fare = testRestTemplate.postForObject(
|
||||
URL + "/taxifare/calculate/",
|
||||
taxiRide, String.class);
|
||||
|
||||
assertThat(fare, equalTo("200"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user