Skip to content

Commit 12de465

Browse files
author
eugenp
committed
cleanup work
1 parent 30171ef commit 12de465

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎spring-rest/src/main/java/org/baeldung/config/Application.java‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5-
import org.springframework.context.annotation.Bean;
65
import org.springframework.context.annotation.ComponentScan;
7-
import org.springframework.web.filter.ShallowEtagHeaderFilter;
86
import 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
}

‎spring-rest/src/main/java/org/baeldung/config/WebConfig.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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());

‎spring-rest/src/main/java/org/baeldung/web/controller/FooController.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.baeldung.web.controller;
22

33
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
4-
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
54

65
import org.baeldung.web.dto.Foo;
76
import 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

‎spring-rest/src/test/java/org/baeldung/client/RestTemplateBasicLiveTest.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import static org.baeldung.client.Consts.APPLICATION_PORT;
44
import static org.hamcrest.CoreMatchers.equalTo;
5+
import static org.hamcrest.CoreMatchers.is;
6+
import static org.hamcrest.CoreMatchers.notNullValue;
57
import static org.hamcrest.MatcherAssert.assertThat;
8+
import static org.mockito.Matchers.notNull;
69

710
import java.io.IOException;
811

12+
import org.baeldung.web.dto.Foo;
913
import org.junit.Before;
1014
import org.junit.Test;
1115
import 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
}

0 commit comments

Comments
 (0)