forked from Realhedin/topjava02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtil.java
More file actions
38 lines (31 loc) · 1.22 KB
/
TestUtil.java
File metadata and controls
38 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package ru.javawebinar.topjava;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import ru.javawebinar.topjava.matcher.ModelMatcher;
import ru.javawebinar.topjava.model.User;
import java.io.UnsupportedEncodingException;
/**
* GKislin
* 05.01.2015.
*/
public class TestUtil {
public static ResultActions print(ResultActions action) throws UnsupportedEncodingException {
System.out.println(getContent(action));
return action;
}
public static String getContent(ResultActions action) throws UnsupportedEncodingException {
return action.andReturn().getResponse().getContentAsString();
}
public static RequestPostProcessor userHttpBasic(User user) {
return SecurityMockMvcRequestPostProcessors.httpBasic(user.getEmail(), user.getPassword());
}
/**
* Compare entities using toString
*/
public static class ToStringModelMatcher<T> extends ModelMatcher<T, String> {
public ToStringModelMatcher(Class<T> entityClass) {
super(Object::toString, entityClass);
}
}
}