File tree Expand file tree Collapse file tree
test/java/org/baeldung/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import org .springframework .boot .SpringApplication ;
44import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
5- import org .springframework .context .annotation .Bean ;
65import org .springframework .context .annotation .ComponentScan ;
7- import org .springframework .web .filter .ShallowEtagHeaderFilter ;
86import org .springframework .web .servlet .config .annotation .WebMvcConfigurerAdapter ;
97
108@ EnableAutoConfiguration
@@ -15,8 +13,4 @@ public static void main(final String[] args) {
1513 SpringApplication .run (Application .class , args );
1614 }
1715
18- @ Bean
19- public ShallowEtagHeaderFilter shallowEtagHeaderFilter () {
20- return new ShallowEtagHeaderFilter ();
21- }
2216}
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public void configureMessageConverters(final List<HttpMessageConverter<?>> messa
3636 messageConverters .add (new MappingJackson2HttpMessageConverter (builder .build ()));
3737 // messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
3838
39- messageConverters .add (createXmlHttpMessageConverter ());
39+ // messageConverters.add(createXmlHttpMessageConverter());
4040 // messageConverters.add(new MappingJackson2HttpMessageConverter());
4141
4242 messageConverters .add (new ProtobufHttpMessageConverter ());
Original file line number Diff line number Diff line change 11package org .baeldung .web .controller ;
22
33import static org .apache .commons .lang3 .RandomStringUtils .randomAlphabetic ;
4- import static org .apache .commons .lang3 .RandomStringUtils .randomNumeric ;
54
65import org .baeldung .web .dto .Foo ;
76import org .baeldung .web .dto .FooProtos ;
@@ -26,7 +25,7 @@ public FooController() {
2625 @ RequestMapping (method = RequestMethod .GET , value = "/foos/{id}" )
2726 @ ResponseBody
2827 public Foo findById (@ PathVariable final long id ) {
29- return new Foo (Long . parseLong ( randomNumeric ( 2 )) , randomAlphabetic (4 ));
28+ return new Foo (id , randomAlphabetic (4 ));
3029 }
3130
3231 // API - write
Original file line number Diff line number Diff line change 22
33import static org .baeldung .client .Consts .APPLICATION_PORT ;
44import static org .hamcrest .CoreMatchers .equalTo ;
5+ import static org .hamcrest .CoreMatchers .is ;
6+ import static org .hamcrest .CoreMatchers .notNullValue ;
57import static org .hamcrest .MatcherAssert .assertThat ;
8+ import static org .mockito .Matchers .notNull ;
69
710import java .io .IOException ;
811
12+ import org .baeldung .web .dto .Foo ;
913import org .junit .Before ;
1014import org .junit .Test ;
1115import org .springframework .http .HttpStatus ;
@@ -41,7 +45,15 @@ public void givenResourceUrl_whenSendGetForRequestEntity_thenBodyCorrect() throw
4145 ObjectMapper mapper = new ObjectMapper ();
4246 JsonNode root = mapper .readTree (response .getBody ());
4347 JsonNode name = root .path ("name" );
44- assertThat (name .asText (), equalTo ( "bar" ));
48+ assertThat (name .asText (), is ( notNull () ));
4549 }
46-
50+
51+ @ Test
52+ public void givenResourceUrl_whenRetrievingResource_thenCorrect () throws IOException {
53+ final Foo foo = restTemplate .getForObject (fooResourceUrl + "/1" , Foo .class );
54+
55+ assertThat (foo .getName (), notNullValue ());
56+ assertThat (foo .getId (), is (1L ));
57+ }
58+
4759}
You can’t perform that action at this time.
0 commit comments