-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix ErrorHandling and LocalDateTime json serialization
- Loading branch information
1 parent
4f48418
commit 10c12ea
Showing
4 changed files
with
48 additions
and
40 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
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
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 |
---|---|---|
|
@@ -62,10 +62,8 @@ class AuthzControllerNoOrganizzationAccessModeTest { | |
@Test | ||
void givenUnauthorizedUserWhenCreateOrganizationOperatorThenOk() throws Exception { | ||
String organizationIpaCode = "IPACODE"; | ||
CreateOperatorRequest request = new CreateOperatorRequest(); | ||
request.setExternalUserId("EXTERNALUSERID"); | ||
Gson gson = new Gson(); | ||
String body = gson.toJson(request); | ||
String body = buildCreateOperatorRequest(); | ||
|
||
Mockito.when(authnServiceMock.getUserInfo("accessToken")) | ||
.thenReturn(UserInfo.builder() | ||
.organizations(List.of(UserOrganizationRoles.builder() | ||
|
@@ -86,16 +84,7 @@ void givenUnauthorizedUserWhenCreateOrganizationOperatorThenOk() throws Exceptio | |
@Test | ||
void givenAuthorizedUserWhenCreateOrganizationOperatorThenOk() throws Exception { | ||
String organizationIpaCode = "IPACODE"; | ||
CreateOperatorRequest createOperatorRequest = new CreateOperatorRequest(); | ||
createOperatorRequest.setExternalUserId("externalUserId"); | ||
createOperatorRequest.setFiscalCode("fiscalCode"); | ||
createOperatorRequest.setFirstName("firstName"); | ||
createOperatorRequest.setLastName("lastName"); | ||
createOperatorRequest.setEmail("[email protected]"); | ||
createOperatorRequest.setRoles(List.of("ROLE_ADMIN")); | ||
Gson gson = new Gson(); | ||
String body = gson.toJson(createOperatorRequest); | ||
|
||
String body = buildCreateOperatorRequest(); | ||
|
||
Mockito.when(authnServiceMock.getUserInfo("accessToken")) | ||
.thenReturn(UserInfo.builder() | ||
|
@@ -113,17 +102,25 @@ void givenAuthorizedUserWhenCreateOrganizationOperatorThenOk() throws Exception | |
.content(body) | ||
).andExpect(status().isOk()); | ||
} | ||
|
||
public static String buildCreateOperatorRequest() { | ||
CreateOperatorRequest createOperatorRequest = new CreateOperatorRequest(); | ||
createOperatorRequest.setExternalUserId("externalUserId"); | ||
createOperatorRequest.setFiscalCode("fiscalCode"); | ||
createOperatorRequest.setFirstName("firstName"); | ||
createOperatorRequest.setLastName("lastName"); | ||
createOperatorRequest.setEmail("[email protected]"); | ||
createOperatorRequest.setRoles(List.of("ROLE_ADMIN")); | ||
Gson gson = new Gson(); | ||
return gson.toJson(createOperatorRequest); | ||
} | ||
|
||
// end region | ||
|
||
//createUser region | ||
@Test | ||
void givenAuthorizedUserWhenCreateUserThenOk() throws Exception { | ||
UserDTO user = new UserDTO(); | ||
user.setExternalUserId("EXTERNALUSERID"); | ||
user.setFiscalCode("FISCALCODE"); | ||
user.setFirstName("FIRSTNAME"); | ||
user.setLastName("LASTNAME"); | ||
Gson gson = new Gson(); | ||
String body = gson.toJson(user); | ||
String body = buildCreateUserRequest(); | ||
|
||
Mockito.when(authnServiceMock.getUserInfo("accessToken")) | ||
.thenReturn(UserInfo.builder() | ||
|
@@ -144,10 +141,8 @@ void givenAuthorizedUserWhenCreateUserThenOk() throws Exception { | |
|
||
@Test | ||
void givenUnauthorizedUserWhenCreateUserThenOk() throws Exception { | ||
UserDTO request = new UserDTO(); | ||
request.setExternalUserId("EXTERNALUSERID"); | ||
Gson gson = new Gson(); | ||
String body = gson.toJson(request); | ||
String body = buildCreateUserRequest(); | ||
|
||
Mockito.when(authnServiceMock.getUserInfo("accessToken")) | ||
.thenReturn(UserInfo.builder() | ||
.organizations(List.of(UserOrganizationRoles.builder() | ||
|
@@ -164,13 +159,23 @@ void givenUnauthorizedUserWhenCreateUserThenOk() throws Exception { | |
.content(String.valueOf((body))) | ||
).andExpect(status().isUnauthorized()); | ||
} | ||
|
||
public static String buildCreateUserRequest() { | ||
UserDTO user = new UserDTO(); | ||
user.setExternalUserId("EXTERNALUSERID"); | ||
user.setFiscalCode("FISCALCODE"); | ||
user.setFirstName("FIRSTNAME"); | ||
user.setLastName("LASTNAME"); | ||
Gson gson = new Gson(); | ||
return gson.toJson(user); | ||
} | ||
//end region | ||
|
||
//region createClient | ||
@Test | ||
void givenUnauthorizedUserWhenRegisterClientThenUnauthorizedException() throws Exception { | ||
String organizationIpaCode = "IPACODE"; | ||
CreateClientRequest request = new CreateClientRequest(); | ||
request.setClientName("CLIENTNAME"); | ||
CreateClientRequest request = buildCreateClientRequest(); | ||
Gson gson = new Gson(); | ||
String body = gson.toJson(request); | ||
Mockito.when(authnServiceMock.getUserInfo("accessToken")) | ||
|
@@ -196,8 +201,7 @@ void givenAuthorizedUserWhenRegisterClientThenOk() throws Exception { | |
String uuidRegex = | ||
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"; | ||
String organizationIpaCode = "IPA_TEST_2"; | ||
CreateClientRequest createClientRequest = new CreateClientRequest(); | ||
createClientRequest.setClientName("CLIENTNAME"); | ||
CreateClientRequest createClientRequest = buildCreateClientRequest(); | ||
|
||
UserInfo expectedUser = UserInfo.builder() | ||
.userId("USERID") | ||
|
@@ -233,6 +237,14 @@ void givenAuthorizedUserWhenRegisterClientThenOk() throws Exception { | |
assertEquals(uuidRandomForSecret, clientDTO.getClientSecret()); | ||
} | ||
|
||
private static CreateClientRequest buildCreateClientRequest() { | ||
CreateClientRequest createClientRequest = new CreateClientRequest(); | ||
createClientRequest.setClientName("CLIENTNAME"); | ||
return createClientRequest; | ||
} | ||
//endregion | ||
|
||
//region getClientSecret | ||
@Test | ||
void givenAuthorizedUserWhenGetClientSecretThenOk() throws Exception { | ||
String uuidRandomForClientSecret = UUID.randomUUID().toString(); | ||
|
@@ -263,5 +275,6 @@ void givenAuthorizedUserWhenGetClientSecretThenOk() throws Exception { | |
|
||
assertEquals(uuidRandomForClientSecret, result.getResponse().getContentAsString()); | ||
} | ||
//endregion | ||
|
||
} |
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