cleanup work
This commit is contained in:
parent
30171ef89b
commit
12de46529d
|
@ -2,9 +2,7 @@ package org.baeldung.config;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.web.filter.ShallowEtagHeaderFilter;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
|
@ -15,8 +13,4 @@ public class Application extends WebMvcConfigurerAdapter {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ShallowEtagHeaderFilter shallowEtagHeaderFilter() {
|
|
||||||
return new ShallowEtagHeaderFilter();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -36,7 +36,7 @@ public class WebConfig extends WebMvcConfigurerAdapter {
|
||||||
messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
|
messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
|
||||||
// messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
|
// messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
|
||||||
|
|
||||||
messageConverters.add(createXmlHttpMessageConverter());
|
// messageConverters.add(createXmlHttpMessageConverter());
|
||||||
// messageConverters.add(new MappingJackson2HttpMessageConverter());
|
// messageConverters.add(new MappingJackson2HttpMessageConverter());
|
||||||
|
|
||||||
messageConverters.add(new ProtobufHttpMessageConverter());
|
messageConverters.add(new ProtobufHttpMessageConverter());
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.baeldung.web.controller;
|
package org.baeldung.web.controller;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||||
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
|
|
||||||
|
|
||||||
import org.baeldung.web.dto.Foo;
|
import org.baeldung.web.dto.Foo;
|
||||||
import org.baeldung.web.dto.FooProtos;
|
import org.baeldung.web.dto.FooProtos;
|
||||||
|
@ -26,7 +25,7 @@ public class FooController {
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/foos/{id}")
|
@RequestMapping(method = RequestMethod.GET, value = "/foos/{id}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Foo findById(@PathVariable final long id) {
|
public Foo findById(@PathVariable final long id) {
|
||||||
return new Foo(Long.parseLong(randomNumeric(2)), randomAlphabetic(4));
|
return new Foo(id, randomAlphabetic(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
// API - write
|
// API - write
|
||||||
|
|
|
@ -2,10 +2,14 @@ package org.baeldung.client;
|
||||||
|
|
||||||
import static org.baeldung.client.Consts.APPLICATION_PORT;
|
import static org.baeldung.client.Consts.APPLICATION_PORT;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.mockito.Matchers.notNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.baeldung.web.dto.Foo;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -41,7 +45,15 @@ public class RestTemplateBasicLiveTest {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode root = mapper.readTree(response.getBody());
|
JsonNode root = mapper.readTree(response.getBody());
|
||||||
JsonNode name = root.path("name");
|
JsonNode name = root.path("name");
|
||||||
assertThat(name.asText(), equalTo("bar"));
|
assertThat(name.asText(), is(notNull()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenResourceUrl_whenRetrievingResource_thenCorrect() throws IOException {
|
||||||
|
final Foo foo = restTemplate.getForObject(fooResourceUrl + "/1", Foo.class);
|
||||||
|
|
||||||
|
assertThat(foo.getName(), notNullValue());
|
||||||
|
assertThat(foo.getId(), is(1L));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue