formatting work
This commit is contained in:
parent
cbf878ba34
commit
76485ab399
|
@ -10,7 +10,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.4.2.RELEASE</version>
|
||||
<version>1.4.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -343,7 +343,7 @@
|
|||
<protobuf-java.version>3.1.0</protobuf-java.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<xstream.version>1.4.9</xstream.version>
|
||||
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>20.0</guava.version>
|
||||
<rest-assured.version>2.9.0</rest-assured.version>
|
||||
|
|
|
@ -35,10 +35,10 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
|||
builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
|
||||
messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
|
||||
// messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
|
||||
|
||||
|
||||
// messageConverters.add(createXmlHttpMessageConverter());
|
||||
// messageConverters.add(new MappingJackson2HttpMessageConverter());
|
||||
|
||||
|
||||
messageConverters.add(new ProtobufHttpMessageConverter());
|
||||
messageConverters.add(new KryoHttpMessageConverter());
|
||||
super.configureMessageConverters(messageConverters);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.baeldung.web.controller.mediatypes;
|
||||
|
||||
|
||||
import org.baeldung.web.dto.BaeldungItem;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -9,12 +8,10 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/", produces = "application/vnd.baeldung.api.v1+json",
|
||||
consumes = "application/vnd.baeldung.api.v1+json")
|
||||
@RequestMapping(value = "/", produces = "application/vnd.baeldung.api.v1+json", consumes = "application/vnd.baeldung.api.v1+json")
|
||||
public class CustomMediaTypeController {
|
||||
|
||||
@RequestMapping(value = "/public/api/endpoint", produces = "application/vnd.baeldung.api.v1+json",
|
||||
consumes = "application/vnd.baeldung.api.v1+json")
|
||||
@RequestMapping(value = "/public/api/endpoint", produces = "application/vnd.baeldung.api.v1+json", consumes = "application/vnd.baeldung.api.v1+json")
|
||||
public @ResponseBody ResponseEntity<BaeldungItem> getItem() {
|
||||
return new ResponseEntity<>(new BaeldungItem("itemId1"), HttpStatus.OK);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.baeldung.web.dto;
|
||||
|
||||
|
||||
public class BaeldungItem {
|
||||
private final String itemId;
|
||||
|
||||
|
|
|
@ -17,9 +17,7 @@ public class DefaultContentTypeInterceptor implements Interceptor {
|
|||
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||
|
||||
Request originalRequest = chain.request();
|
||||
Request requestWithUserAgent = originalRequest.newBuilder()
|
||||
.header("Content-Type", contentType)
|
||||
.build();
|
||||
Request requestWithUserAgent = originalRequest.newBuilder().header("Content-Type", contentType).build();
|
||||
|
||||
return chain.proceed(requestWithUserAgent);
|
||||
}
|
||||
|
|
|
@ -19,15 +19,12 @@ public class OkHttpHeaderLiveTest {
|
|||
@Before
|
||||
public void init() {
|
||||
|
||||
client = new OkHttpClient();
|
||||
client = new OkHttpClient();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetHeader_thenCorrect() throws IOException {
|
||||
Request request = new Request.Builder()
|
||||
.url(SAMPLE_URL)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Request request = new Request.Builder().url(SAMPLE_URL).addHeader("Content-Type", "application/json").build();
|
||||
|
||||
Call call = client.newCall(request);
|
||||
Response response = call.execute();
|
||||
|
@ -37,13 +34,9 @@ public class OkHttpHeaderLiveTest {
|
|||
@Test
|
||||
public void whenSetDefaultHeader_thenCorrect() throws IOException {
|
||||
|
||||
OkHttpClient clientWithInterceptor = new OkHttpClient.Builder()
|
||||
.addInterceptor(new DefaultContentTypeInterceptor("application/json"))
|
||||
.build();
|
||||
OkHttpClient clientWithInterceptor = new OkHttpClient.Builder().addInterceptor(new DefaultContentTypeInterceptor("application/json")).build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(SAMPLE_URL)
|
||||
.build();
|
||||
Request request = new Request.Builder().url(SAMPLE_URL).build();
|
||||
|
||||
Call call = clientWithInterceptor.newCall(request);
|
||||
Response response = call.execute();
|
||||
|
|
|
@ -49,11 +49,7 @@ public class OkHttpPostingLiveTest {
|
|||
public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException {
|
||||
final String postBody = "test post";
|
||||
|
||||
final Request request = new Request.Builder()
|
||||
.url(URL_SECURED_BY_BASIC_AUTHENTICATION)
|
||||
.addHeader("Authorization", Credentials.basic("test", "test"))
|
||||
.post(RequestBody.create(MediaType.parse("text/x-markdown; charset=utf-8"), "test post"))
|
||||
.build();
|
||||
final Request request = new Request.Builder().url(URL_SECURED_BY_BASIC_AUTHENTICATION).addHeader("Authorization", Credentials.basic("test", "test")).post(RequestBody.create(MediaType.parse("text/x-markdown; charset=utf-8"), "test post")).build();
|
||||
|
||||
final Call call = client.newCall(request);
|
||||
final Response response = call.execute();
|
||||
|
|
|
@ -17,13 +17,9 @@ public class OkHttpRedirectLiveTest {
|
|||
@Test
|
||||
public void whenSetFollowRedirects_thenNotRedirected() throws IOException {
|
||||
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.followRedirects(false)
|
||||
.build();
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().followRedirects(false).build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url("http://t.co/I5YYd9tddw")
|
||||
.build();
|
||||
Request request = new Request.Builder().url("http://t.co/I5YYd9tddw").build();
|
||||
|
||||
Call call = client.newCall(request);
|
||||
Response response = call.execute();
|
||||
|
|
|
@ -71,4 +71,3 @@ public class ProgressRequestWrapper extends RequestBody {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,44 +10,40 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||
|
||||
public class SpringUriBuilderTest {
|
||||
|
||||
@Test
|
||||
public void constructUri() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com")
|
||||
.path("/junit-5").build();
|
||||
@Test
|
||||
public void constructUri() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com").path("/junit-5").build();
|
||||
|
||||
assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString());
|
||||
}
|
||||
assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructUriEncoded() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com")
|
||||
.path("/junit 5").build().encode();
|
||||
@Test
|
||||
public void constructUriEncoded() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com").path("/junit 5").build().encode();
|
||||
|
||||
assertEquals("http://www.baeldung.com/junit%205", uriComponents.toUriString());
|
||||
}
|
||||
assertEquals("http://www.baeldung.com/junit%205", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructUriFromTemplate() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com")
|
||||
.path("/{article-name}").buildAndExpand("junit-5");
|
||||
@Test
|
||||
public void constructUriFromTemplate() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.baeldung.com").path("/{article-name}").buildAndExpand("junit-5");
|
||||
|
||||
assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString());
|
||||
}
|
||||
assertEquals("http://www.baeldung.com/junit-5", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructUriWithQueryParameter() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.google.com")
|
||||
.path("/").query("q={keyword}").buildAndExpand("baeldung");
|
||||
@Test
|
||||
public void constructUriWithQueryParameter() {
|
||||
UriComponents uriComponents = UriComponentsBuilder.newInstance().scheme("http").host("www.google.com").path("/").query("q={keyword}").buildAndExpand("baeldung");
|
||||
|
||||
assertEquals("http://www.google.com/?q=baeldung", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandWithRegexVar() {
|
||||
String template = "/myurl/{name:[a-z]{1,5}}/show";
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(template).build();
|
||||
uriComponents = uriComponents.expand(Collections.singletonMap("name", "test"));
|
||||
|
||||
assertEquals("/myurl/test/show", uriComponents.getPath());
|
||||
}
|
||||
assertEquals("http://www.google.com/?q=baeldung", uriComponents.toUriString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandWithRegexVar() {
|
||||
String template = "/myurl/{name:[a-z]{1,5}}/show";
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(template).build();
|
||||
uriComponents = uriComponents.expand(Collections.singletonMap("name", "test"));
|
||||
|
||||
assertEquals("/myurl/test/show", uriComponents.getPath());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.springframework.web.context.WebApplicationContext;
|
|||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = WebConfig.class)
|
||||
@WebAppConfiguration
|
||||
|
@ -33,9 +32,6 @@ public class CustomMediaTypeControllerTest {
|
|||
|
||||
@Test
|
||||
public void shouldSendRequestForItem() throws Exception {
|
||||
mockMvc.perform(get("/public/api/endpoint")
|
||||
.contentType("application/vnd.baeldung.api.v1+json")
|
||||
.accept("application/vnd.baeldung.api.v1+json"))
|
||||
.andExpect(status().isOk());
|
||||
mockMvc.perform(get("/public/api/endpoint").contentType("application/vnd.baeldung.api.v1+json").accept("application/vnd.baeldung.api.v1+json")).andExpect(status().isOk());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue