Skip to content

Commit 5afd21c

Browse files
shryhustboychuk
authored andcommitted
GP-83 update pom and dao
1 parent 1dcf33f commit 5afd21c

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# <img src="https://raw.githubusercontent.com/bobocode-projects/resources/master/image/logo_transparent_background.png" height=50/>Account REST API exercise :muscle:
1+
# <img src="https://raw.githubusercontent.com/bobocode-projects/resources/master/image/logo_transparent_background.png" height=50/>Account REST API exercise 💪
22
Improve your *Spring MVC* configuration and rest mapping skills
33
### Task
44
This webapp provides a **simple REST API for `Account`**. The data is stored using in-memory fake DAO. Your job is to
@@ -8,14 +8,14 @@ This webapp provides a **simple REST API for `Account`**. The data is stored usi
88
To verify your configuration, run `AccountRestControllerTest.java` :white_check_mark:
99

1010

11-
### Pre-conditions :heavy_exclamation_mark:
11+
### Pre-conditions
1212
You're supposed to be familiar with *Spring MVC*
1313

14-
### How to start :question:
14+
### How to start
1515
* Just clone the repository and start implementing the **todo** section, verify your changes by running tests
1616
* If you don't have enough knowledge about this domain, check out the [links below](#related-materials-information_source)
1717
* Don't worry if you got stuck, checkout the **exercise/completed** branch and see the final implementation
1818

19-
### Related materials :information_source:
20-
* [Spring REST basics tutorial](https://github.com/bobocode-projects/spring-framework-tutorial/tree/master/rest-basics)<img src="https://raw.githubusercontent.com/bobocode-projects/resources/master/image/logo_transparent_background.png" height=20/>
19+
### Related materials
20+
* todo
2121

3-0-spring-framework/3-2-1-account-rest-api/pom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,22 @@
4343
<dependency>
4444
<groupId>com.fasterxml.jackson.core</groupId>
4545
<artifactId>jackson-core</artifactId>
46-
<version>2.9.7</version>
46+
<version>2.12.2</version>
4747
</dependency>
4848
<dependency>
4949
<groupId>com.fasterxml.jackson.core</groupId>
5050
<artifactId>jackson-databind</artifactId>
51-
<version>2.9.7</version>
51+
<version>2.12.2</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.jayway.jsonpath</groupId>
55+
<artifactId>json-path</artifactId>
56+
<version>2.3.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.jayway.jsonpath</groupId>
60+
<artifactId>json-path-assert</artifactId>
61+
<version>2.3.0</version>
5262
</dependency>
5363
</dependencies>
5464

3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/config/WebConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
* todo: 3. Enable component scanning for package "web" using annotation value
99
*/
1010
public class WebConfig {
11-
1211
}

3-0-spring-framework/3-2-1-account-rest-api/src/main/java/com/bobocode/dao/impl/InMemoryAccountDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@ public void remove(Account account) {
4848

4949
public void clear() {
5050
accountMap.clear();
51+
idSequence = 1L;
5152
}
5253
}

3-0-spring-framework/3-2-1-account-rest-api/src/test/java/com/bobocode/AccountRestControllerTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
2626
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2727

28-
@SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class})
2928
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
29+
@SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class})
3030
class AccountRestControllerTest {
3131
@Autowired
3232
private WebApplicationContext applicationContext;
@@ -65,8 +65,8 @@ void accountRestControllerRequestMapping() {
6565
@Test
6666
@Order(3)
6767
@DisplayName("AccountDao is injected using constructor")
68-
void accountDaoInjection() throws NoSuchMethodException {
69-
Constructor<AccountRestController> constructor = AccountRestController.class.getConstructor();
68+
void accountDaoInjection() {
69+
Constructor<?> constructor = AccountRestController.class.getConstructors()[0];
7070

7171
assertThat(constructor.getParameterTypes()).contains(AccountDao.class);
7272
}
@@ -140,24 +140,25 @@ private Account create(String firstName, String lastName, String email) {
140140

141141
@Test
142142
@Order(9)
143-
@DisplayName("Removing account is implemented")
144-
void removeAccount() throws Exception {
143+
@DisplayName("Updating account is implemented")
144+
void updateAccount() throws Exception {
145145
Account account = create("Johnny", "Boy", "jboy@gmail.com");
146146
accountDao.save(account);
147147

148-
mockMvc.perform(delete(String.format("/accounts/%d", account.getId())))
148+
mockMvc.perform(put(String.format("/accounts/%d", account.getId())).contentType(MediaType.APPLICATION_JSON)
149+
.content(String.format("{\"id\":\"%d\", \"firstName\":\"Johnny\", \"lastName\":\"Boy\", \"email\":\"johnny.boy@gmail.com\"}", account.getId())))
149150
.andExpect(status().isNoContent());
150151
}
151152

152153
@Test
153154
@Order(10)
154-
@DisplayName("Updating account is implemented")
155-
void updateAccount() throws Exception {
155+
@DisplayName("Removing account is implemented")
156+
void removeAccount() throws Exception {
156157
Account account = create("Johnny", "Boy", "jboy@gmail.com");
157158
accountDao.save(account);
158159

159-
mockMvc.perform(put(String.format("/accounts/%d", account.getId())).contentType(MediaType.APPLICATION_JSON)
160-
.content(String.format("{\"id\":\"%d\", \"firstName\":\"Johnny\", \"lastName\":\"Boy\", \"email\":\"johnny.boy@gmail.com\"}", account.getId())))
160+
mockMvc.perform(delete(String.format("/accounts/%d", account.getId())))
161161
.andExpect(status().isNoContent());
162162
}
163163
}
164+

0 commit comments

Comments
 (0)