|
27 | 27 | // but the generic code assumes every endpoint returns a list
|
28 | 28 | class UserProfileServiceTest {
|
29 | 29 |
|
30 |
| - private Config config; |
31 |
| - private UserProfileService underTest; |
32 |
| - private MockRestServiceServer mockServer; |
| 30 | + private Config config; |
| 31 | + private UserProfileService underTest; |
| 32 | + private MockRestServiceServer mockServer; |
33 | 33 |
|
34 |
| - // This string does not contain every field of the api response as those are not implemented |
35 |
| - private String apiResponse = """ |
36 |
| - { |
37 |
| - "user": { |
38 |
| - "id": 0, |
39 |
| - "username": "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", |
40 |
| - "first_name": "string", |
41 |
| - "last_name": "string", |
42 |
| - "email": "user@example.com", |
43 |
| - "last_login": "2022-11-01T16:20:19.373Z", |
44 |
| - "is_active": true, |
45 |
| - "is_superuser": true, |
46 |
| - "configuration_permissions": [0] |
47 |
| - } |
48 |
| - } |
49 |
| - """; |
50 |
| - |
51 |
| - @BeforeEach |
52 |
| - void setup() { |
53 |
| - config = new Config("https://defectdojo.example.com", "abc", 42); |
54 |
| - underTest = new UserProfileService(config); |
55 |
| - mockServer = MockRestServiceServer.createServer(underTest.getRestTemplate()); |
| 34 | + // This string does not contain every field of the api response as those are not implemented |
| 35 | + private String apiResponse = """ |
| 36 | + { |
| 37 | + "user": { |
| 38 | + "id": 0, |
| 39 | + "username": "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", |
| 40 | + "first_name": "string", |
| 41 | + "last_name": "string", |
| 42 | + "email": "user@example.com", |
| 43 | + "last_login": "2022-11-01T16:20:19.373Z", |
| 44 | + "is_active": true, |
| 45 | + "is_superuser": true, |
| 46 | + "configuration_permissions": [0] |
| 47 | + } |
56 | 48 | }
|
| 49 | + """; |
57 | 50 |
|
58 |
| - @Test |
59 |
| - void testSearch() throws JsonProcessingException, URISyntaxException { |
60 |
| - var url = config.getUrl() + "/api/v2/" + underTest.getUrlPath() + "/?offset=0&limit=100"; |
61 |
| - mockServer.expect(requestTo(url)).andRespond(withSuccess(apiResponse, MediaType.APPLICATION_JSON)); |
| 51 | + @BeforeEach |
| 52 | + void setup() { |
| 53 | + config = new Config("https://defectdojo.example.com", "abc", 42); |
| 54 | + underTest = new UserProfileService(config); |
| 55 | + mockServer = MockRestServiceServer.createServer(underTest.getRestTemplate()); |
| 56 | + } |
62 | 57 |
|
63 |
| - var user = new User(0L, "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", "string", "string"); |
64 |
| - var userProfile = new UserProfile(user); |
65 |
| - var expected = Arrays.asList(userProfile); |
66 |
| - var actual = underTest.search(); |
| 58 | + @Test |
| 59 | + void testSearch() throws JsonProcessingException, URISyntaxException { |
| 60 | + var url = config.getUrl() + "/api/v2/" + underTest.getUrlPath() + "/?offset=0&limit=100"; |
| 61 | + mockServer.expect(requestTo(url)).andRespond(withSuccess(apiResponse, MediaType.APPLICATION_JSON)); |
67 | 62 |
|
68 |
| - mockServer.verify(); |
69 |
| - assertIterableEquals(expected, actual); |
70 |
| - } |
| 63 | + var user = new User(0L, "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", "string", "string"); |
| 64 | + var userProfile = new UserProfile(user); |
| 65 | + var expected = Arrays.asList(userProfile); |
| 66 | + var actual = underTest.search(); |
| 67 | + |
| 68 | + mockServer.verify(); |
| 69 | + assertIterableEquals(expected, actual); |
| 70 | + } |
71 | 71 | }
|
0 commit comments