-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sven Strittmatter <[email protected]>
- Loading branch information
1 parent
eb42a7b
commit 67f9f52
Showing
1 changed file
with
36 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,45 +27,45 @@ | |
// but the generic code assumes every endpoint returns a list | ||
class UserProfileServiceTest { | ||
|
||
private Config config; | ||
private UserProfileService underTest; | ||
private MockRestServiceServer mockServer; | ||
private Config config; | ||
private UserProfileService underTest; | ||
private MockRestServiceServer mockServer; | ||
|
||
// This string does not contain every field of the api response as those are not implemented | ||
private String apiResponse = """ | ||
{ | ||
"user": { | ||
"id": 0, | ||
"username": "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", | ||
"first_name": "string", | ||
"last_name": "string", | ||
"email": "[email protected]", | ||
"last_login": "2022-11-01T16:20:19.373Z", | ||
"is_active": true, | ||
"is_superuser": true, | ||
"configuration_permissions": [0] | ||
} | ||
} | ||
"""; | ||
|
||
@BeforeEach | ||
void setup() { | ||
config = new Config("https://defectdojo.example.com", "abc", 42); | ||
underTest = new UserProfileService(config); | ||
mockServer = MockRestServiceServer.createServer(underTest.getRestTemplate()); | ||
// This string does not contain every field of the api response as those are not implemented | ||
private String apiResponse = """ | ||
{ | ||
"user": { | ||
"id": 0, | ||
"username": "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", | ||
"first_name": "string", | ||
"last_name": "string", | ||
"email": "[email protected]", | ||
"last_login": "2022-11-01T16:20:19.373Z", | ||
"is_active": true, | ||
"is_superuser": true, | ||
"configuration_permissions": [0] | ||
} | ||
} | ||
"""; | ||
|
||
@Test | ||
void testSearch() throws JsonProcessingException, URISyntaxException { | ||
var url = config.getUrl() + "/api/v2/" + underTest.getUrlPath() + "/?offset=0&limit=100"; | ||
mockServer.expect(requestTo(url)).andRespond(withSuccess(apiResponse, MediaType.APPLICATION_JSON)); | ||
@BeforeEach | ||
void setup() { | ||
config = new Config("https://defectdojo.example.com", "abc", 42); | ||
underTest = new UserProfileService(config); | ||
mockServer = MockRestServiceServer.createServer(underTest.getRestTemplate()); | ||
} | ||
|
||
var user = new User(0L, "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", "string", "string"); | ||
var userProfile = new UserProfile(user); | ||
var expected = Arrays.asList(userProfile); | ||
var actual = underTest.search(); | ||
@Test | ||
void testSearch() throws JsonProcessingException, URISyntaxException { | ||
var url = config.getUrl() + "/api/v2/" + underTest.getUrlPath() + "/?offset=0&limit=100"; | ||
mockServer.expect(requestTo(url)).andRespond(withSuccess(apiResponse, MediaType.APPLICATION_JSON)); | ||
|
||
mockServer.verify(); | ||
assertIterableEquals(expected, actual); | ||
} | ||
var user = new User(0L, "GdqmXprK.j7R+OYE49SzL3mM2U6I0DyLRHnDg87i9It0AfP-kxvswW3qOI2i+31-@0", "string", "string"); | ||
var userProfile = new UserProfile(user); | ||
var expected = Arrays.asList(userProfile); | ||
var actual = underTest.search(); | ||
|
||
mockServer.verify(); | ||
assertIterableEquals(expected, actual); | ||
} | ||
} |