-
-
Swagger REST Api Documentation
+
", 200);
- perform(MockMvcRequestBuilders.put(REST_URL + MEAL1_ID)
- .contentType(MediaType.APPLICATION_JSON)
- .content(JsonUtil.writeValue(invalid))
- .with(userHttpBasic(user)))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR));
- }
-
- @Test
- @Transactional(propagation = Propagation.NEVER)
- void updateDuplicate() throws Exception {
- Meal invalid = new Meal(MEAL1_ID, meal2.getDateTime(), "Dummy", 200);
-
- perform(MockMvcRequestBuilders.put(REST_URL + MEAL1_ID)
- .contentType(MediaType.APPLICATION_JSON)
- .content(JsonUtil.writeValue(invalid))
- .with(userHttpBasic(user)))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR))
- .andExpect(detailMessage(EXCEPTION_DUPLICATE_DATETIME));
- }
-
- @Test
- @Transactional(propagation = Propagation.NEVER)
- void createDuplicate() throws Exception {
- Meal invalid = new Meal(null, adminMeal1.getDateTime(), "Dummy", 200);
- perform(MockMvcRequestBuilders.post(REST_URL)
- .contentType(MediaType.APPLICATION_JSON)
- .content(JsonUtil.writeValue(invalid))
- .with(userHttpBasic(admin)))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR))
- .andExpect(detailMessage(EXCEPTION_DUPLICATE_DATETIME));
- }
}
\ No newline at end of file
diff --git a/src/test/java/ru/javawebinar/topjava/web/user/AdminRestControllerTest.java b/src/test/java/ru/javawebinar/topjava/web/user/AdminRestControllerTest.java
index 2abfaa933..dc52b0083 100644
--- a/src/test/java/ru/javawebinar/topjava/web/user/AdminRestControllerTest.java
+++ b/src/test/java/ru/javawebinar/topjava/web/user/AdminRestControllerTest.java
@@ -5,9 +5,7 @@
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-import ru.javawebinar.topjava.model.Role;
+import ru.javawebinar.topjava.UserTestData;
import ru.javawebinar.topjava.model.User;
import ru.javawebinar.topjava.service.UserService;
import ru.javawebinar.topjava.util.exception.NotFoundException;
@@ -20,8 +18,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static ru.javawebinar.topjava.TestUtil.userHttpBasic;
import static ru.javawebinar.topjava.UserTestData.*;
-import static ru.javawebinar.topjava.util.exception.ErrorType.VALIDATION_ERROR;
-import static ru.javawebinar.topjava.web.ExceptionInfoHandler.EXCEPTION_DUPLICATE_EMAIL;
class AdminRestControllerTest extends AbstractControllerTest {
@@ -91,14 +87,13 @@ void getForbidden() throws Exception {
@Test
void update() throws Exception {
User updated = getUpdated();
- updated.setId(null);
perform(MockMvcRequestBuilders.put(REST_URL + USER_ID)
.contentType(MediaType.APPLICATION_JSON)
.with(userHttpBasic(admin))
.content(jsonWithPassword(updated, updated.getPassword())))
.andExpect(status().isNoContent());
- USER_MATCHER.assertMatch(userService.get(USER_ID), getUpdated());
+ USER_MATCHER.assertMatch(userService.get(USER_ID), updated);
}
@Test
@@ -148,72 +143,4 @@ void enable() throws Exception {
assertFalse(userService.get(USER_ID).isEnabled());
}
-
- @Test
- void createInvalid() throws Exception {
- User invalid = new User(null, null, "", "newPass", 7300, Role.USER, Role.ADMIN);
- perform(MockMvcRequestBuilders.post(REST_URL)
- .contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(admin))
- .content(jsonWithPassword(invalid, "newPass")))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR));
- }
-
- @Test
- void updateInvalid() throws Exception {
- User invalid = new User(user);
- invalid.setName("");
- perform(MockMvcRequestBuilders.put(REST_URL + USER_ID)
- .contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(admin))
- .content(jsonWithPassword(invalid, "password")))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR));
- }
-
- @Test
- void updateHtmlUnsafe() throws Exception {
- User updated = new User(user);
- updated.setName("");
- perform(MockMvcRequestBuilders.put(REST_URL + USER_ID)
- .contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(admin))
- .content(jsonWithPassword(updated, "password")))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR));
- }
-
- @Test
- @Transactional(propagation = Propagation.NEVER)
- void updateDuplicate() throws Exception {
- User updated = new User(user);
- updated.setId(null);
- updated.setEmail("admin@gmail.com");
- perform(MockMvcRequestBuilders.put(REST_URL + USER_ID)
- .contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(admin))
- .content(jsonWithPassword(updated, "password")))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR))
- .andExpect(detailMessage(EXCEPTION_DUPLICATE_EMAIL));
- }
-
- @Test
- @Transactional(propagation = Propagation.NEVER)
- void createDuplicate() throws Exception {
- User expected = new User(null, "New", "user@yandex.ru", "newPass", 2300, Role.USER, Role.ADMIN);
- perform(MockMvcRequestBuilders.post(REST_URL)
- .contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(admin))
- .content(jsonWithPassword(expected, "newPass")))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR))
- .andExpect(detailMessage(EXCEPTION_DUPLICATE_EMAIL));
- }
}
\ No newline at end of file
diff --git a/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerSpringTest.java b/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerSpringTest.java
index 7568d0f52..40af802e0 100644
--- a/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerSpringTest.java
+++ b/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerSpringTest.java
@@ -21,7 +21,7 @@ class InMemoryAdminRestControllerSpringTest {
private InMemoryUserRepository repository;
@BeforeEach
- void setup() {
+ public void setUp() {
repository.init();
}
diff --git a/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerTest.java b/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerTest.java
index c41fa0e6b..75b8a5a82 100644
--- a/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerTest.java
+++ b/src/test/java/ru/javawebinar/topjava/web/user/InMemoryAdminRestControllerTest.java
@@ -30,13 +30,13 @@ static void beforeClass() {
@AfterAll
static void afterClass() {
- // May cause during JUnit "Cache is not alive (STATUS_SHUTDOWN)" as JUnit share Spring context for speed
- // http://stackoverflow.com/questions/16281802/ehcache-shutdown-causing-an-exception-while-running-test-suite
- // appCtx.close();
+// May cause during JUnit "Cache is not alive (STATUS_SHUTDOWN)" as JUnit share Spring context for speed
+// http://stackoverflow.com/questions/16281802/ehcache-shutdown-causing-an-exception-while-running-test-suite
+// appCtx.close();
}
@BeforeEach
- void setup() {
+ public void setup() {
// re-initialize
repository.init();
}
diff --git a/src/test/java/ru/javawebinar/topjava/web/user/ProfileRestControllerTest.java b/src/test/java/ru/javawebinar/topjava/web/user/ProfileRestControllerTest.java
index bc71318c8..ae91e2da9 100644
--- a/src/test/java/ru/javawebinar/topjava/web/user/ProfileRestControllerTest.java
+++ b/src/test/java/ru/javawebinar/topjava/web/user/ProfileRestControllerTest.java
@@ -5,12 +5,10 @@
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
import ru.javawebinar.topjava.model.User;
import ru.javawebinar.topjava.service.UserService;
import ru.javawebinar.topjava.to.UserTo;
-import ru.javawebinar.topjava.util.UsersUtil;
+import ru.javawebinar.topjava.util.UserUtil;
import ru.javawebinar.topjava.web.AbstractControllerTest;
import ru.javawebinar.topjava.web.json.JsonUtil;
@@ -19,8 +17,6 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static ru.javawebinar.topjava.TestUtil.userHttpBasic;
import static ru.javawebinar.topjava.UserTestData.*;
-import static ru.javawebinar.topjava.util.exception.ErrorType.VALIDATION_ERROR;
-import static ru.javawebinar.topjava.web.ExceptionInfoHandler.EXCEPTION_DUPLICATE_EMAIL;
import static ru.javawebinar.topjava.web.user.ProfileRestController.REST_URL;
class ProfileRestControllerTest extends AbstractControllerTest {
@@ -54,7 +50,7 @@ void delete() throws Exception {
@Test
void register() throws Exception {
UserTo newTo = new UserTo(null, "newName", "newemail@ya.ru", "newPassword", 1500);
- User newUser = UsersUtil.createNewFromTo(newTo);
+ User newUser = UserUtil.createNewFromTo(newTo);
ResultActions action = perform(MockMvcRequestBuilders.post(REST_URL)
.contentType(MediaType.APPLICATION_JSON)
.content(JsonUtil.writeValue(newTo)))
@@ -70,7 +66,6 @@ void register() throws Exception {
@Test
void update() throws Exception {
- // ValidationUtil.assureIdConsistent called after validation, needs workaround
UserTo updatedTo = new UserTo(null, "newName", "user@yandex.ru", "newPassword", 1500);
perform(MockMvcRequestBuilders.put(REST_URL).contentType(MediaType.APPLICATION_JSON)
.with(userHttpBasic(user))
@@ -78,7 +73,7 @@ void update() throws Exception {
.andDo(print())
.andExpect(status().isNoContent());
- USER_MATCHER.assertMatch(userService.get(USER_ID), UsersUtil.updateFromTo(new User(user), updatedTo));
+ USER_MATCHER.assertMatch(userService.get(USER_ID), UserUtil.updateFromTo(new User(user), updatedTo));
}
@Test
@@ -91,41 +86,4 @@ void getWithMeals() throws Exception {
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(USER_WITH_MEALS_MATCHER.contentJson(user));
}
-
- @Test
- void registerInvalid() throws Exception {
- UserTo newTo = new UserTo(null, null, null, null, 1);
- perform(MockMvcRequestBuilders.post(REST_URL)
- .contentType(MediaType.APPLICATION_JSON)
- .content(JsonUtil.writeValue(newTo)))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR));
- }
-
- @Test
- void updateInvalid() throws Exception {
- UserTo updatedTo = new UserTo(null, null, "password", null, 1500);
- perform(MockMvcRequestBuilders.put(REST_URL)
- .contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(user))
- .content(JsonUtil.writeValue(updatedTo)))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR));
- }
-
- @Test
- @Transactional(propagation = Propagation.NEVER)
- void updateDuplicate() throws Exception {
- UserTo updatedTo = new UserTo(null, "newName", "admin@gmail.com", "newPassword", 1500);
-
- perform(MockMvcRequestBuilders.put(REST_URL).contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(user))
- .content(JsonUtil.writeValue(updatedTo)))
- .andDo(print())
- .andExpect(status().isUnprocessableEntity())
- .andExpect(errorType(VALIDATION_ERROR))
- .andExpect(detailMessage(EXCEPTION_DUPLICATE_EMAIL));
- }
}
\ No newline at end of file
diff --git a/src/test/java/ru/javawebinar/topjava/web/user/VdsRestControllerTest.java b/src/test/java/ru/javawebinar/topjava/web/user/VdsRestControllerTest.java
deleted file mode 100644
index fc05eb977..000000000
--- a/src/test/java/ru/javawebinar/topjava/web/user/VdsRestControllerTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package ru.javawebinar.topjava.web.user;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.http.MediaType;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
-import ru.javawebinar.topjava.UserTestData;
-import ru.javawebinar.topjava.util.exception.ErrorType;
-import ru.javawebinar.topjava.web.AbstractControllerTest;
-
-import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-import static ru.javawebinar.topjava.Profiles.VDS;
-import static ru.javawebinar.topjava.TestUtil.userHttpBasic;
-import static ru.javawebinar.topjava.UserTestData.*;
-import static ru.javawebinar.topjava.util.exception.UpdateRestrictionException.EXCEPTION_UPDATE_RESTRICTION;
-
-@ActiveProfiles(VDS)
-class VdsRestControllerTest extends AbstractControllerTest {
-
- private static final String REST_URL = AdminRestController.REST_URL + '/';
-
- @Test
- void delete() throws Exception {
- perform(MockMvcRequestBuilders.delete(REST_URL + USER_ID)
- .with(userHttpBasic(admin)))
- .andDo(print())
- .andExpect(errorType(ErrorType.VALIDATION_ERROR))
- .andExpect(detailMessage(EXCEPTION_UPDATE_RESTRICTION))
- .andExpect(status().isUnprocessableEntity());
- }
-
- @Test
- void update() throws Exception {
- perform(MockMvcRequestBuilders.put(REST_URL + USER_ID)
- .contentType(MediaType.APPLICATION_JSON)
- .with(userHttpBasic(admin))
- .content(UserTestData.jsonWithPassword(user, "password")))
- .andExpect(errorType(ErrorType.VALIDATION_ERROR))
- .andExpect(detailMessage(EXCEPTION_UPDATE_RESTRICTION))
- .andExpect(status().isUnprocessableEntity());
- }
-}
diff --git a/src/test/resources/spring/inmemory.xml b/src/test/resources/spring/inmemory.xml
index 1207399dd..f7e2dbbd4 100644
--- a/src/test/resources/spring/inmemory.xml
+++ b/src/test/resources/spring/inmemory.xml
@@ -5,7 +5,6 @@
-
-
+
\ No newline at end of file
diff --git a/src/test/resources/spring/spring-cache.xml b/src/test/resources/spring/spring-cache.xml
index 7c9dfda9a..ea51df903 100644
--- a/src/test/resources/spring/spring-cache.xml
+++ b/src/test/resources/spring/spring-cache.xml
@@ -10,10 +10,10 @@
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
-
--->