From 5ed9cc3d1f9ec7d66c85c3939484dde771e0c0ae Mon Sep 17 00:00:00 2001 From: Tanja Zivkovic Date: Wed, 13 Dec 2023 13:52:57 +0100 Subject: [PATCH 1/7] FE-17823 Added support for updating issued organisation ids --- .../client/beans/general/UpdateStatus.java | 50 ++++++++++++++ .../update/UpdateOrganisationIdRequest.java | 65 +++++++++++++++++++ .../update/UpdateOrganisationIdResponse.java | 39 +++++++++++ .../client/api/OrganisationIdClientApi.java | 9 ++- .../client/impl/OrganisationIdClient.java | 13 +++- .../service/CustomIdentifierService.java | 2 +- .../client/service/OrganisationIdService.java | 13 +++- .../service/RequestValidationService.java | 8 +++ .../frejaeid/client/util/MethodUrl.java | 1 + .../frejaeid/client/util/RequestTemplate.java | 5 +- .../impl/CustomIdentifierClientTest.java | 8 +-- ...ationIdClientDeleteOrganisationIdTest.java | 6 +- 12 files changed, 205 insertions(+), 14 deletions(-) create mode 100644 FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java create mode 100644 FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java create mode 100644 FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java new file mode 100644 index 0000000..d18f194 --- /dev/null +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java @@ -0,0 +1,50 @@ +package com.verisec.frejaeid.client.beans.general; + +import java.util.Objects; + +public class UpdateStatus { + + private final int added; + private final int updated; + private final int deleted; + + public UpdateStatus(int added, int updated, int deleted) { + this.added = added; + this.updated = updated; + this.deleted = deleted; + } + + public int getAdded() { + return added; + } + + public int getUpdated() { + return updated; + } + + public int getDeleted() { + return deleted; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof UpdateStatus)) return false; + UpdateStatus that = (UpdateStatus) o; + return added == that.added && updated == that.updated && deleted == that.deleted; + } + + @Override + public int hashCode() { + return Objects.hash(added, updated, deleted); + } + + @Override + public String toString() { + return "UpdateStatus{" + + "added=" + added + + ", updated=" + updated + + ", deleted=" + deleted + + '}'; + } +} diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java new file mode 100644 index 0000000..e473fa2 --- /dev/null +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java @@ -0,0 +1,65 @@ +package com.verisec.frejaeid.client.beans.organisationid.update; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest; +import com.verisec.frejaeid.client.beans.general.OrganisationIdAttribute; + +import java.util.List; +import java.util.Objects; + +public class UpdateOrganisationIdRequest implements RelyingPartyRequest { + + private final String identifier; + private final List additionalAttributes; + private final String relyingPartyId; + + + public UpdateOrganisationIdRequest(String identifier, List additionalAttributes) { + this.identifier = identifier; + this.additionalAttributes = additionalAttributes; + this.relyingPartyId = null; + } + + public UpdateOrganisationIdRequest(String identifier, List additionalAttributes, + String relyingPartyId) { + this.identifier = identifier; + this.additionalAttributes = additionalAttributes; + this.relyingPartyId = relyingPartyId; + } + + public String getIdentifier() { + return identifier; + } + + public List getAdditionalAttributes() { + return additionalAttributes; + } + + public String getRelyingPartyId() { + return relyingPartyId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof UpdateOrganisationIdRequest)) return false; + UpdateOrganisationIdRequest that = (UpdateOrganisationIdRequest) o; + return Objects.equals(identifier, that.identifier) && + Objects.equals(additionalAttributes, that.additionalAttributes) && + Objects.equals(relyingPartyId, that.relyingPartyId); + } + + @Override + public int hashCode() { + return Objects.hash(identifier, additionalAttributes, relyingPartyId); + } + + @Override + public String toString() { + return "UpdateOrganisationIdRequest{" + + "identifier='" + identifier + '\'' + + ", additionalAttributes=" + additionalAttributes + + ", relyingPartyId='" + relyingPartyId + '\'' + + '}'; + } +} diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java new file mode 100644 index 0000000..9e6c3e2 --- /dev/null +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java @@ -0,0 +1,39 @@ +package com.verisec.frejaeid.client.beans.organisationid.update; + +import com.verisec.frejaeid.client.beans.common.FrejaHttpResponse; +import com.verisec.frejaeid.client.beans.general.UpdateStatus; + +import java.util.Objects; + +public class UpdateOrganisationIdResponse implements FrejaHttpResponse { + + private final UpdateStatus updateStatus; + + public UpdateOrganisationIdResponse(UpdateStatus updateStatus) { + this.updateStatus = updateStatus; + } + + public UpdateStatus getUpdateStatus() { + return updateStatus; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof UpdateOrganisationIdResponse)) return false; + UpdateOrganisationIdResponse that = (UpdateOrganisationIdResponse) o; + return Objects.equals(updateStatus, that.updateStatus); + } + + @Override + public int hashCode() { + return Objects.hash(updateStatus); + } + + @Override + public String toString() { + return "UpdateOrganisationIdResponse{" + + "updateStatus=" + updateStatus + + '}'; + } +} diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java index 93dbe5a..6eea345 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java @@ -3,10 +3,12 @@ import com.verisec.frejaeid.client.beans.general.OrganisationIdUserInfo; import com.verisec.frejaeid.client.beans.organisationid.cancel.CancelAddOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest; -import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResultRequest; import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResult; +import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResultRequest; import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersRequest; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse; import com.verisec.frejaeid.client.enums.TransactionStatus; import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; import com.verisec.frejaeid.client.exceptions.FrejaEidClientPollingException; @@ -100,4 +102,9 @@ public void delete(DeleteOrganisationIdRequest deleteOrganisationIdRequest) */ public List getAllUsers(GetAllOrganisationIdUsersRequest getAllOrganisationIdUsersRequest) throws FrejaEidClientInternalException, FrejaEidException; + +//@Stop + public UpdateOrganisationIdResponse update(UpdateOrganisationIdRequest updateOrganisationIdRequest) + throws FrejaEidClientInternalException, FrejaEidException; + } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClient.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClient.java index b73400b..3053fac 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClient.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClient.java @@ -8,6 +8,8 @@ import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResultRequest; import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersRequest; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse; import com.verisec.frejaeid.client.client.api.OrganisationIdClientApi; import com.verisec.frejaeid.client.enums.FrejaEnvironment; import com.verisec.frejaeid.client.enums.TransactionContext; @@ -135,6 +137,16 @@ public List getAllUsers(GetAllOrganisationIdUsersRequest return organisationIdUserInfos; } + @Override + public UpdateOrganisationIdResponse update(UpdateOrganisationIdRequest updateOrganisationIdRequest) + throws FrejaEidClientInternalException, FrejaEidException { + requestValidationService.validateUpdateOrganisationIdRequest(updateOrganisationIdRequest); + LOG.debug("Updating organisation ID with identifier {}. ", updateOrganisationIdRequest.getIdentifier()); + UpdateOrganisationIdResponse response = organisationIdService.update(updateOrganisationIdRequest); + LOG.debug("Successfully updated organisation ID with identifier {}.", updateOrganisationIdRequest.getIdentifier()); + return response; + } + public static class Builder extends GenericBuilder { public static final Logger LOG = LogManager.getLogger(Builder.class); @@ -178,5 +190,4 @@ public OrganisationIdClient build() throws FrejaEidClientInternalException { } } - } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/CustomIdentifierService.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/CustomIdentifierService.java index dc991af..18af516 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/CustomIdentifierService.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/CustomIdentifierService.java @@ -18,7 +18,7 @@ public CustomIdentifierService(String serverAddress, HttpServiceApi httpService, public void set(SetCustomIdentifierRequest customIdentifierRequest) throws FrejaEidClientInternalException, FrejaEidException { httpService.send(getUrl(serverAddress, MethodUrl.CUSTOM_IDENTIFIER_SET), - RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, customIdentifierRequest, + RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, customIdentifierRequest, EmptyFrejaResponse.class, customIdentifierRequest.getRelyingPartyId()); } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/OrganisationIdService.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/OrganisationIdService.java index 59eac1a..48926c0 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/OrganisationIdService.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/OrganisationIdService.java @@ -9,6 +9,8 @@ import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersResponse; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdResponse; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse; import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; import com.verisec.frejaeid.client.exceptions.FrejaEidClientPollingException; import com.verisec.frejaeid.client.exceptions.FrejaEidException; @@ -28,7 +30,7 @@ public OrganisationIdService(String serverAddress, int pollingTimeoutInMilliseco this.pollingTimeoutInMilliseconds = pollingTimeoutInMilliseconds; } - public OrganisationIdService(String serverAddress, HttpServiceApi httpService, String resourceServiceUrl) { + public OrganisationIdService(String serverAddress, HttpServiceApi httpService, String resourceServiceUrl) { super(serverAddress, httpService, resourceServiceUrl); this.pollingTimeoutInMilliseconds = 0; } @@ -73,7 +75,7 @@ public OrganisationIdResult pollForResult(OrganisationIdResultRequest organisati public EmptyFrejaResponse delete(DeleteOrganisationIdRequest deleteOrganisationIdRequest) throws FrejaEidClientInternalException, FrejaEidException { return httpService.send(getUrl(serverAddress, MethodUrl.ORGANISATION_ID_DELETE), - RequestTemplate.DELETE_ORGANINSATION_ID_TEMPLATE, deleteOrganisationIdRequest, + RequestTemplate.DELETE_ORGANISATION_ID_TEMPLATE, deleteOrganisationIdRequest, EmptyFrejaResponse.class, deleteOrganisationIdRequest.getRelyingPartyId()); } @@ -92,6 +94,13 @@ public GetAllOrganisationIdUsersResponse getAllUsers( getAllOrganisationIdUsersRequest.getRelyingPartyId()); } + public UpdateOrganisationIdResponse update(UpdateOrganisationIdRequest updateOrganisationIdRequest) + throws FrejaEidClientInternalException, FrejaEidException { + return httpService.send(getUrl(serverAddress, MethodUrl.ORGANISATION_ID_UPDATE), + RequestTemplate.UPDATE_ORGANISATION_ID_TEMPLATE, updateOrganisationIdRequest, + UpdateOrganisationIdResponse.class, updateOrganisationIdRequest.getRelyingPartyId()); + } + private boolean isPollingTimeExpired(long pollingEndTime) { return (System.currentTimeMillis() + pollingTimeoutInMilliseconds) < pollingEndTime; } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/RequestValidationService.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/RequestValidationService.java index 01816f6..2d2c0f4 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/RequestValidationService.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/service/RequestValidationService.java @@ -10,6 +10,7 @@ import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersRequest; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; import com.verisec.frejaeid.client.beans.sign.init.InitiateSignRequest; import com.verisec.frejaeid.client.beans.usermanagement.customidentifier.delete.DeleteCustomIdentifierRequest; import com.verisec.frejaeid.client.beans.usermanagement.customidentifier.set.SetCustomIdentifierRequest; @@ -130,6 +131,13 @@ public void validateGetAllOrganisationIdUsersRequest( validateRelyingPartyIdIsEmpty(getAllOrganisationIdUsersRequest.getRelyingPartyId()); } + public void validateUpdateOrganisationIdRequest(UpdateOrganisationIdRequest updateOrganisationIdRequest) + throws FrejaEidClientInternalException { + validateRequest(updateOrganisationIdRequest); + validateIdentifier(updateOrganisationIdRequest.getIdentifier()); + validateRelyingPartyIdIsEmpty(updateOrganisationIdRequest.getRelyingPartyId()); + } + private void validateRequest(RelyingPartyRequest relyingPartyRequest) throws FrejaEidClientInternalException { if (relyingPartyRequest == null) { throw new FrejaEidClientInternalException("Request cannot be null value."); diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/MethodUrl.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/MethodUrl.java index 69d089e..55d28b5 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/MethodUrl.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/MethodUrl.java @@ -23,6 +23,7 @@ public enum MethodUrl { ORGANISATION_ID_DELETE("/organisation/management/orgId/1.0/delete"), ORGANISATION_ID_CANCEL_ADD("/organisation/management/orgId/1.0/cancelAdd"), ORGANISATION_ID_GET_ALL_USERS("/organisation/management/orgId/1.0/users/getAll"), + ORGANISATION_ID_UPDATE("/organisation/management/orgId/1.0/update"), CUSTOM_IDENTIFIER_SET("/user/manage/1.0/setCustomIdentifier"), CUSTOM_IDENTIFIER_DELETE("/user/manage/1.0/deleteCustomIdentifier"), QR_CODE_GENERATE("/qrcode/generate"), diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/RequestTemplate.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/RequestTemplate.java index 9e59dd5..dd90542 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/RequestTemplate.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/util/RequestTemplate.java @@ -12,11 +12,12 @@ public enum RequestTemplate { CANCEL_SIGN_TEMPLATE("cancelSignRequest={0}"), INIT_ADD_ORGANISATION_ID_TEMPLATE("initAddOrganisationIdRequest={0}"), ORGANISATION_ID_RESULT_TEMPLATE("getOneOrganisationIdResultRequest={0}"), - DELETE_ORGANINSATION_ID_TEMPLATE("deleteOrganisationIdRequest={0}"), + DELETE_ORGANISATION_ID_TEMPLATE("deleteOrganisationIdRequest={0}"), CANCEL_ADD_ORGANISATION_ID_TEMPLATE("cancelAddOrganisationIdRequest={0}"), GET_ALL_ORGANISATION_ID_USERS_TEMPLATE("getAllOrganisationIdUsersRequest={0}"), + UPDATE_ORGANISATION_ID_TEMPLATE("updateOrganisationIdRequest={0}"), RELYING_PARTY_ID("relyingPartyId={0}"), - SET_CUSTOM_IDENITIFIER_TEMPLATE("setCustomIdentifierRequest={0}"), + SET_CUSTOM_IDENTIFIER_TEMPLATE("setCustomIdentifierRequest={0}"), DELETE_CUSTOM_IDENTIFIER_TEMPLATE("deleteCustomIdentifierRequest={0}"), GET_CUSTODIANSHIP_STATUS_TEMPLATE("getCustodianshipStatusRequest={0}"); diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/CustomIdentifierClientTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/CustomIdentifierClientTest.java index c0e47d5..99431a1 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/CustomIdentifierClientTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/CustomIdentifierClientTest.java @@ -50,14 +50,14 @@ public void setCustomIdentifier_success() throws FrejaEidClientInternalException SetCustomIdentifierRequest.createDefaultWithEmail(EMAIL, CUSTOM_IDENTIFIER); customIdentifierClient.set(setCustomIdentifierRequestDefaultEmail); Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET, - RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, + RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, setCustomIdentifierRequestDefaultEmail, EmptyFrejaResponse.class, null); SetCustomIdentifierRequest setCustomIdentifierRequestDefaultSsn = SetCustomIdentifierRequest.createDefaultWithSsn(SsnUserInfo.create(Country.NORWAY, SSN), CUSTOM_IDENTIFIER); customIdentifierClient.set(setCustomIdentifierRequestDefaultSsn); Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET, - RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, + RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, setCustomIdentifierRequestDefaultSsn, EmptyFrejaResponse.class, null); } @@ -84,7 +84,7 @@ public void setCustomIdentifier_relyingPartyIdFromRequest_expectedSuccess() for (SetCustomIdentifierRequest request : requests) { customIdentifierClient.set(request); Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET, - RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, request, + RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, request, EmptyFrejaResponse.class, RELYING_PARTY_ID); } @@ -108,7 +108,7 @@ public void setCustomIdentifier_customIdentifierAlreadySetForUser_expectCustomId } catch (FrejaEidException rpEx) { Mockito.verify(httpServiceMock) .send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.CUSTOM_IDENTIFIER_SET, - RequestTemplate.SET_CUSTOM_IDENITIFIER_TEMPLATE, setCustomIdentifierRequest, + RequestTemplate.SET_CUSTOM_IDENTIFIER_TEMPLATE, setCustomIdentifierRequest, EmptyFrejaResponse.class, null); Assert.assertEquals(5002, rpEx.getErrorCode()); Assert.assertEquals("You have already used this custom identifier.", rpEx.getLocalizedMessage()); diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientDeleteOrganisationIdTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientDeleteOrganisationIdTest.java index 4cc48f0..57e2b46 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientDeleteOrganisationIdTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdClientDeleteOrganisationIdTest.java @@ -40,7 +40,7 @@ public void deleteOrganisationId_success() throws FrejaEidClientInternalExceptio .thenReturn(EmptyFrejaResponse.INSTANCE); organisationIdClient.delete(deleteOrganisationIdRequest); Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_DELETE, - RequestTemplate.DELETE_ORGANINSATION_ID_TEMPLATE, + RequestTemplate.DELETE_ORGANISATION_ID_TEMPLATE, deleteOrganisationIdRequest, EmptyFrejaResponse.class, null); } @@ -55,7 +55,7 @@ public void deleteOrganisationId_relyingPartyIdFromRequest_expectedSuccess() .thenReturn(EmptyFrejaResponse.INSTANCE); organisationIdClient.delete(deleteOrganisationIdRequest); Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_DELETE, - RequestTemplate.DELETE_ORGANINSATION_ID_TEMPLATE, + RequestTemplate.DELETE_ORGANISATION_ID_TEMPLATE, deleteOrganisationIdRequest, EmptyFrejaResponse.class, RELYING_PARTY_ID); } @@ -75,7 +75,7 @@ public void deleteOrganisationId_nonexistentCustomIdentifier_expectNoUserForCust Assert.fail("Test should throw exception!"); } catch (FrejaEidException rpEx) { Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_DELETE, - RequestTemplate.DELETE_ORGANINSATION_ID_TEMPLATE, + RequestTemplate.DELETE_ORGANISATION_ID_TEMPLATE, deleteOrganisationIdRequest, EmptyFrejaResponse.class, null); Assert.assertEquals(5001, rpEx.getErrorCode()); Assert.assertEquals("There is no user for given custom identifier.", rpEx.getLocalizedMessage()); From 57215964d77d6bf8461ce17ec851964487d6ac92 Mon Sep 17 00:00:00 2001 From: tanjaFrejaEid Date: Thu, 14 Dec 2023 09:47:23 +0100 Subject: [PATCH 2/7] added tests --- .../client/beans/general/UpdateStatus.java | 8 ++- .../update/UpdateOrganisationIdRequest.java | 36 +++++++++++- .../update/UpdateOrganisationIdResponse.java | 5 +- .../client/api/OrganisationIdClientApi.java | 12 +++- .../client/impl/OrganisationIdUpdateTest.java | 58 +++++++++++++++++++ .../http/OrganisationIdClientHttpTest.java | 33 ++++++++++- 6 files changed, 144 insertions(+), 8 deletions(-) create mode 100644 FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java index d18f194..65296bb 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java @@ -1,5 +1,8 @@ package com.verisec.frejaeid.client.beans.general; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.Objects; public class UpdateStatus { @@ -8,7 +11,10 @@ public class UpdateStatus { private final int updated; private final int deleted; - public UpdateStatus(int added, int updated, int deleted) { + @JsonCreator + public UpdateStatus(@JsonProperty("added") int added, + @JsonProperty("updated") int updated, + @JsonProperty("deleted") int deleted) { this.added = added; this.updated = updated; this.deleted = deleted; diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java index e473fa2..d8bd46f 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java @@ -1,6 +1,8 @@ package com.verisec.frejaeid.client.beans.organisationid.update; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest; import com.verisec.frejaeid.client.beans.general.OrganisationIdAttribute; @@ -11,16 +13,46 @@ public class UpdateOrganisationIdRequest implements RelyingPartyRequest { private final String identifier; private final List additionalAttributes; +// @JsonIgnore ??? private final String relyingPartyId; + public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes){ + return new UpdateOrganisationIdRequest(identifier, additionalAttributes); + } + + public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes, String relyingPartyId){ + return new UpdateOrganisationIdRequest(identifier, additionalAttributes, relyingPartyId); + } - public UpdateOrganisationIdRequest(String identifier, List additionalAttributes) { + /** + * Returns instance of {@linkplain UpdateOrganisationIdRequest} + * + * @param identifier identifier to be updated for the end user. It cannot be + * {@code null} or empty. + * @param additionalAttributes additional attributes related to the identifier. + * It can be {@code null} or empty. + * @return request + */ + @JsonCreator + private UpdateOrganisationIdRequest(@JsonProperty("identifier") String identifier, + @JsonProperty("additionalAttributes") List additionalAttributes) { this.identifier = identifier; this.additionalAttributes = additionalAttributes; this.relyingPartyId = null; } - public UpdateOrganisationIdRequest(String identifier, List additionalAttributes, + /** + * Returns instance of {@linkplain UpdateOrganisationIdRequest} + * + * @param identifier identifier to be updated for the end user. It cannot be + * {@code null} or empty. + * @param additionalAttributes additional attributes related to the identifier. + * It can be {@code null} or empty. + * @param relyingPartyId specifies relying party id for which transaction is + * initiated. It cannot be {@code null} or empty. + * @return request + */ + private UpdateOrganisationIdRequest(String identifier, List additionalAttributes, String relyingPartyId) { this.identifier = identifier; this.additionalAttributes = additionalAttributes; diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java index 9e6c3e2..2e2b6b7 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java @@ -1,5 +1,7 @@ package com.verisec.frejaeid.client.beans.organisationid.update; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.verisec.frejaeid.client.beans.common.FrejaHttpResponse; import com.verisec.frejaeid.client.beans.general.UpdateStatus; @@ -9,7 +11,8 @@ public class UpdateOrganisationIdResponse implements FrejaHttpResponse { private final UpdateStatus updateStatus; - public UpdateOrganisationIdResponse(UpdateStatus updateStatus) { + @JsonCreator + public UpdateOrganisationIdResponse(@JsonProperty("updateStatus") UpdateStatus updateStatus) { this.updateStatus = updateStatus; } diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java index 6eea345..777b813 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/client/api/OrganisationIdClientApi.java @@ -103,7 +103,17 @@ public void delete(DeleteOrganisationIdRequest deleteOrganisationIdRequest) public List getAllUsers(GetAllOrganisationIdUsersRequest getAllOrganisationIdUsersRequest) throws FrejaEidClientInternalException, FrejaEidException; -//@Stop + /** + * Updates issued organisation id for a specific person. + * + * @param updateOrganisationIdRequest instance of + * {@linkplain UpdateOrganisationIdRequest} with corresponding + * parameters + * @return {@linkplain UpdateOrganisationIdResponse} + * @throws FrejaEidClientInternalException if internal validation of request + * fails. + * @throws FrejaEidException if server returns an error. + */ public UpdateOrganisationIdResponse update(UpdateOrganisationIdRequest updateOrganisationIdRequest) throws FrejaEidClientInternalException, FrejaEidException; diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java new file mode 100644 index 0000000..ae578a9 --- /dev/null +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java @@ -0,0 +1,58 @@ +package com.verisec.frejaeid.client.client.impl; + +import com.verisec.frejaeid.client.beans.common.EmptyFrejaResponse; +import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest; +import com.verisec.frejaeid.client.beans.general.OrganisationIdAttribute; +import com.verisec.frejaeid.client.beans.general.UpdateStatus; +import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse; +import com.verisec.frejaeid.client.client.api.OrganisationIdClientApi; +import com.verisec.frejaeid.client.client.util.TestUtil; +import com.verisec.frejaeid.client.enums.FrejaEnvironment; +import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; +import com.verisec.frejaeid.client.exceptions.FrejaEidException; +import com.verisec.frejaeid.client.http.HttpServiceApi; +import com.verisec.frejaeid.client.util.MethodUrl; +import com.verisec.frejaeid.client.util.RequestTemplate; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.Arrays; +import java.util.List; + +public class OrganisationIdUpdateTest { + + private static final String IDENTIFIER = "identifier"; + private static final List ADDITIONAL_ATTRIBUTES = + Arrays.asList(OrganisationIdAttribute.create("key", "friendly name", "value"), + OrganisationIdAttribute.create("attribute_id", "attribute name", "attribute value")); + + private final HttpServiceApi httpServiceMock = Mockito.mock(HttpServiceApi.class); + private OrganisationIdClientApi organisationIdClient; + + @Before + public void initialiseClient() throws FrejaEidClientInternalException { + organisationIdClient = OrganisationIdClient.create(TestUtil.getDefaultSslSettings(), FrejaEnvironment.TEST) + .setHttpService(httpServiceMock) + .build(); + } + + @Test + public void updateOrgId_success() throws FrejaEidClientInternalException, FrejaEidException { + UpdateOrganisationIdRequest updateOrganisationIdRequest = + UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(0, 2, 0)); + Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), + Mockito.any(RelyingPartyRequest.class), + Mockito.eq(UpdateOrganisationIdResponse.class), (String) Mockito.isNull())) + .thenReturn(expectedResponse); + UpdateOrganisationIdResponse receivedResponse = organisationIdClient.update(updateOrganisationIdRequest); + Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_UPDATE, + RequestTemplate.UPDATE_ORGANISATION_ID_TEMPLATE, + updateOrganisationIdRequest, UpdateOrganisationIdResponse.class, null); + Assert.assertEquals(expectedResponse, receivedResponse); + } +} diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java index d2653c4..7e1db9f 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java @@ -1,9 +1,7 @@ package com.verisec.frejaeid.client.http; import com.verisec.frejaeid.client.beans.common.EmptyFrejaResponse; -import com.verisec.frejaeid.client.beans.general.OrganisationId; -import com.verisec.frejaeid.client.beans.general.OrganisationIdUserInfo; -import com.verisec.frejaeid.client.beans.general.SsnUserInfo; +import com.verisec.frejaeid.client.beans.general.*; import com.verisec.frejaeid.client.beans.organisationid.cancel.CancelAddOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResult; @@ -12,6 +10,8 @@ import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersResponse; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdResponse; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse; import com.verisec.frejaeid.client.client.api.OrganisationIdClientApi; import com.verisec.frejaeid.client.client.impl.OrganisationIdClient; import com.verisec.frejaeid.client.client.util.TestUtil; @@ -36,6 +36,9 @@ public class OrganisationIdClientHttpTest extends CommonHttpTest { private static final String ORGANISATION_ID_TITLE = "OrganisationId title"; private static final String IDENTIFIER_NAME = "Identifier name"; private static final String IDENTIFIER = "identifier"; + private static final List ADDITIONAL_ATTRIBUTES = + Arrays.asList(OrganisationIdAttribute.create("key", "friendly name", "value"), + OrganisationIdAttribute.create("attribute_id", "attribute name", "attribute value")); @BeforeClass public static void init() throws FrejaEidClientInternalException { @@ -246,4 +249,28 @@ public void getAllOrganisationIdUsers_sendRequestWithRelyingPartyId_success() organisationIdClient.getAllUsers(getAllOrganisationIdUsersRequest); Assert.assertEquals(getAllOrganisationIdUsersResponse.getUserInfos(), actualListOfOrganisationIdUserInfos); } + + @Test + public void updateOrganisationId_sendRequestWithoutRelyingPartyId_success() + throws FrejaEidClientInternalException, IOException, FrejaEidException { + UpdateOrganisationIdRequest updateOrganisationIdRequest = + UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(1, 1, 0)); + String responseString = jsonService.serializeToJson(expectedResponse); + startMockServer(updateOrganisationIdRequest, HttpStatusCode.OK.getCode(), responseString); + UpdateOrganisationIdResponse receivedResponse = organisationIdClient.update(updateOrganisationIdRequest); + Assert.assertEquals(expectedResponse, receivedResponse); + } + + @Test + public void updateOrganisationId_sendRequestWithRelyingPartyId_success() + throws FrejaEidClientInternalException, IOException, FrejaEidException { + UpdateOrganisationIdRequest updateOrganisationIdRequest = + UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES, RELYING_PARTY_ID); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(0, 2, 0)); + String responseString = jsonService.serializeToJson(expectedResponse); + startMockServer(updateOrganisationIdRequest, HttpStatusCode.OK.getCode(), responseString); + UpdateOrganisationIdResponse receivedResponse = organisationIdClient.update(updateOrganisationIdRequest); + Assert.assertEquals(expectedResponse, receivedResponse); + } } From 8b8d36ec62964d2a8208b64757c83d43b85a702e Mon Sep 17 00:00:00 2001 From: tanjaFrejaEid Date: Thu, 14 Dec 2023 11:21:33 +0100 Subject: [PATCH 3/7] added tests --- .../client/impl/OrganisationIdUpdateTest.java | 42 ++++++++++++++++++- .../service/RequestValidationServiceTest.java | 36 ++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java index ae578a9..ea6b3cf 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java @@ -9,6 +9,7 @@ import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse; import com.verisec.frejaeid.client.client.api.OrganisationIdClientApi; import com.verisec.frejaeid.client.client.util.TestUtil; +import com.verisec.frejaeid.client.enums.FrejaEidErrorCode; import com.verisec.frejaeid.client.enums.FrejaEnvironment; import com.verisec.frejaeid.client.exceptions.FrejaEidClientInternalException; import com.verisec.frejaeid.client.exceptions.FrejaEidException; @@ -29,6 +30,7 @@ public class OrganisationIdUpdateTest { private static final List ADDITIONAL_ATTRIBUTES = Arrays.asList(OrganisationIdAttribute.create("key", "friendly name", "value"), OrganisationIdAttribute.create("attribute_id", "attribute name", "attribute value")); + private static final String RELYING_PARTY_ID = "relyingPartyId"; private final HttpServiceApi httpServiceMock = Mockito.mock(HttpServiceApi.class); private OrganisationIdClientApi organisationIdClient; @@ -41,7 +43,7 @@ public void initialiseClient() throws FrejaEidClientInternalException { } @Test - public void updateOrgId_success() throws FrejaEidClientInternalException, FrejaEidException { + public void updateOrgId_withoutRelyingPartyId_success() throws FrejaEidClientInternalException, FrejaEidException { UpdateOrganisationIdRequest updateOrganisationIdRequest = UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES); UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(0, 2, 0)); @@ -55,4 +57,42 @@ public void updateOrgId_success() throws FrejaEidClientInternalException, FrejaE updateOrganisationIdRequest, UpdateOrganisationIdResponse.class, null); Assert.assertEquals(expectedResponse, receivedResponse); } + + @Test + public void updateOrgId_withRelyingPartyId_success() throws FrejaEidClientInternalException, FrejaEidException { + UpdateOrganisationIdRequest updateOrganisationIdRequest = + UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES, RELYING_PARTY_ID); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(1, 0, 1)); + Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), + Mockito.any(RelyingPartyRequest.class), + Mockito.eq(UpdateOrganisationIdResponse.class), Mockito.eq(RELYING_PARTY_ID))) + .thenReturn(expectedResponse); + UpdateOrganisationIdResponse receivedResponse = organisationIdClient.update(updateOrganisationIdRequest); + Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_UPDATE, + RequestTemplate.UPDATE_ORGANISATION_ID_TEMPLATE, updateOrganisationIdRequest, + UpdateOrganisationIdResponse.class, RELYING_PARTY_ID); + Assert.assertEquals(expectedResponse, receivedResponse); + } + + @Test + public void updateOrgId_nonExistentCustomIdentifier() throws FrejaEidClientInternalException, FrejaEidException { + UpdateOrganisationIdRequest updateOrganisationIdRequest = + UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES); + FrejaEidException expectedException = new FrejaEidException( + FrejaEidErrorCode.ORGANISATION_ID_IDENTIFIER_DOES_NOT_EXIST.getMessage(), + FrejaEidErrorCode.ORGANISATION_ID_IDENTIFIER_DOES_NOT_EXIST.getCode()); + Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), + Mockito.any(RelyingPartyRequest.class), + Mockito.eq(UpdateOrganisationIdResponse.class), (String) Mockito.isNull())) + .thenThrow(expectedException); + try { + organisationIdClient.update(updateOrganisationIdRequest); + Assert.fail("Test unexpectedly passed."); + } catch (FrejaEidException fex) { + Mockito.verify(httpServiceMock).send(FrejaEnvironment.TEST.getServiceUrl() + MethodUrl.ORGANISATION_ID_UPDATE, + RequestTemplate.UPDATE_ORGANISATION_ID_TEMPLATE, updateOrganisationIdRequest, + UpdateOrganisationIdResponse.class, null); + Assert.assertEquals(expectedException, fex); + } + } } diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/service/RequestValidationServiceTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/service/RequestValidationServiceTest.java index 708bcc8..a18eac6 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/service/RequestValidationServiceTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/service/RequestValidationServiceTest.java @@ -6,11 +6,13 @@ import com.verisec.frejaeid.client.beans.authentication.init.InitiateAuthenticationRequest; import com.verisec.frejaeid.client.beans.custodianship.get.GetUserCustodianshipStatusRequest; import com.verisec.frejaeid.client.beans.general.OrganisationId; +import com.verisec.frejaeid.client.beans.general.OrganisationIdAttribute; import com.verisec.frejaeid.client.beans.organisationid.cancel.CancelAddOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.get.OrganisationIdResultRequest; import com.verisec.frejaeid.client.beans.organisationid.getall.GetAllOrganisationIdUsersRequest; import com.verisec.frejaeid.client.beans.organisationid.init.InitiateAddOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; import com.verisec.frejaeid.client.beans.sign.cancel.CancelSignRequest; import com.verisec.frejaeid.client.beans.sign.get.SignResultRequest; import com.verisec.frejaeid.client.beans.sign.get.SignResultsRequest; @@ -29,6 +31,9 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.util.Arrays; +import java.util.List; + public class RequestValidationServiceTest { private static final String ORGANISATION_ID_TITLE = "OrganisationId title"; @@ -42,6 +47,9 @@ public class RequestValidationServiceTest { private static final String ORG_ID_ISSUER = "orgIdIssuer"; private static final String RELYING_PARTY_ID = "relyingPartyId"; private static final String USER_COUNTRY_ID_AND_CRN = "SE12345678"; + private static final List ADDITIONAL_ATTRIBUTES = + Arrays.asList(OrganisationIdAttribute.create("key", "friendly name", "value"), + OrganisationIdAttribute.create("attribute_id", "attribute name", "attribute value")); private static AuthenticationClientApi authenticationClient; private static SignClientApi signClient; @@ -918,4 +926,32 @@ public void getCustodianshipStatus_emptyCountryIdAndCrn_expectError() throws Fre } } + @Test + public void updateOrganisationIdRequest_emptyIdentifier() { + try { + UpdateOrganisationIdRequest updateOrganisationIdRequest = + UpdateOrganisationIdRequest.create("", ADDITIONAL_ATTRIBUTES); + organisationIdClient.update(updateOrganisationIdRequest); + Assert.fail("Test unexpectedly passed."); + } catch (FrejaEidClientInternalException ex) { + Assert.assertEquals("Identifier cannot be null or empty.", ex.getLocalizedMessage()); + } catch (FrejaEidException e) { + Assert.fail("Unexpected error occurred."); + } + } + + @Test + public void updateOrganisationIdRequest_emptyRelyingPartyId() { + try { + UpdateOrganisationIdRequest updateOrganisationIdRequest = + UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES, ""); + organisationIdClient.update(updateOrganisationIdRequest); + Assert.fail("Test unexpectedly passed."); + } catch (FrejaEidClientInternalException ex) { + Assert.assertEquals("RelyingPartyId cannot be empty.", ex.getLocalizedMessage()); + } catch (FrejaEidException e) { + Assert.fail("Unexpected error occurred."); + } + } + } From 4c0b0f61be0b408508fc383c8d3009136d067213 Mon Sep 17 00:00:00 2001 From: tanjaFrejaEid Date: Thu, 14 Dec 2023 11:51:00 +0100 Subject: [PATCH 4/7] removed comment --- .../beans/organisationid/update/UpdateOrganisationIdRequest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java index d8bd46f..26d88b0 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java @@ -13,7 +13,6 @@ public class UpdateOrganisationIdRequest implements RelyingPartyRequest { private final String identifier; private final List additionalAttributes; -// @JsonIgnore ??? private final String relyingPartyId; public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes){ From bf0e124a7328b04fc25b6d9e098cfe171393ffb1 Mon Sep 17 00:00:00 2001 From: tanjaFrejaEid Date: Thu, 14 Dec 2023 13:21:46 +0100 Subject: [PATCH 5/7] PR comments - removed unnecessary constructor --- .../update/UpdateOrganisationIdRequest.java | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java index 26d88b0..b4506b2 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdRequest.java @@ -1,7 +1,6 @@ package com.verisec.frejaeid.client.beans.organisationid.update; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest; import com.verisec.frejaeid.client.beans.general.OrganisationIdAttribute; @@ -15,14 +14,15 @@ public class UpdateOrganisationIdRequest implements RelyingPartyRequest { private final List additionalAttributes; private final String relyingPartyId; - public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes){ - return new UpdateOrganisationIdRequest(identifier, additionalAttributes); + public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes) { + return new UpdateOrganisationIdRequest(identifier, additionalAttributes, null); } - public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes, String relyingPartyId){ + public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes, String relyingPartyId) { return new UpdateOrganisationIdRequest(identifier, additionalAttributes, relyingPartyId); } + /** * Returns instance of {@linkplain UpdateOrganisationIdRequest} * @@ -30,29 +30,15 @@ public static UpdateOrganisationIdRequest create(String identifier, List additionalAttributes) { - this.identifier = identifier; - this.additionalAttributes = additionalAttributes; - this.relyingPartyId = null; - } - - /** - * Returns instance of {@linkplain UpdateOrganisationIdRequest} - * - * @param identifier identifier to be updated for the end user. It cannot be - * {@code null} or empty. - * @param additionalAttributes additional attributes related to the identifier. - * It can be {@code null} or empty. - * @param relyingPartyId specifies relying party id for which transaction is - * initiated. It cannot be {@code null} or empty. - * @return request - */ - private UpdateOrganisationIdRequest(String identifier, List additionalAttributes, - String relyingPartyId) { + private UpdateOrganisationIdRequest( + @JsonProperty("identifier") String identifier, + @JsonProperty("additionalAttributes") List additionalAttributes, + @JsonProperty("relyingPartyId") String relyingPartyId) { this.identifier = identifier; this.additionalAttributes = additionalAttributes; this.relyingPartyId = relyingPartyId; From b46b08e5c63fcbfb29011a6b0077ef6e5aad39c2 Mon Sep 17 00:00:00 2001 From: tanjaFrejaEid Date: Thu, 14 Dec 2023 14:24:34 +0100 Subject: [PATCH 6/7] renamed bean --- ...s.java => UpdateOrganisationIdStatus.java} | 14 +++++++------- .../update/UpdateOrganisationIdResponse.java | 19 ++++++++++--------- .../client/impl/OrganisationIdUpdateTest.java | 8 +++----- .../http/OrganisationIdClientHttpTest.java | 4 ++-- 4 files changed, 22 insertions(+), 23 deletions(-) rename FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/{UpdateStatus.java => UpdateOrganisationIdStatus.java} (69%) diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateOrganisationIdStatus.java similarity index 69% rename from FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java rename to FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateOrganisationIdStatus.java index 65296bb..4e08d8b 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateStatus.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/general/UpdateOrganisationIdStatus.java @@ -5,16 +5,16 @@ import java.util.Objects; -public class UpdateStatus { +public class UpdateOrganisationIdStatus { private final int added; private final int updated; private final int deleted; @JsonCreator - public UpdateStatus(@JsonProperty("added") int added, - @JsonProperty("updated") int updated, - @JsonProperty("deleted") int deleted) { + public UpdateOrganisationIdStatus(@JsonProperty("added") int added, + @JsonProperty("updated") int updated, + @JsonProperty("deleted") int deleted) { this.added = added; this.updated = updated; this.deleted = deleted; @@ -35,8 +35,8 @@ public int getDeleted() { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof UpdateStatus)) return false; - UpdateStatus that = (UpdateStatus) o; + if (!(o instanceof UpdateOrganisationIdStatus)) return false; + UpdateOrganisationIdStatus that = (UpdateOrganisationIdStatus) o; return added == that.added && updated == that.updated && deleted == that.deleted; } @@ -47,7 +47,7 @@ public int hashCode() { @Override public String toString() { - return "UpdateStatus{" + + return "UpdateOrganisationIdStatus{" + "added=" + added + ", updated=" + updated + ", deleted=" + deleted + diff --git a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java index 2e2b6b7..05b49b5 100644 --- a/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java +++ b/FrejaEidClient/src/main/java/com/verisec/frejaeid/client/beans/organisationid/update/UpdateOrganisationIdResponse.java @@ -3,21 +3,22 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.verisec.frejaeid.client.beans.common.FrejaHttpResponse; -import com.verisec.frejaeid.client.beans.general.UpdateStatus; +import com.verisec.frejaeid.client.beans.general.UpdateOrganisationIdStatus; import java.util.Objects; public class UpdateOrganisationIdResponse implements FrejaHttpResponse { - private final UpdateStatus updateStatus; + private final UpdateOrganisationIdStatus updateOrganisationIdStatus; @JsonCreator - public UpdateOrganisationIdResponse(@JsonProperty("updateStatus") UpdateStatus updateStatus) { - this.updateStatus = updateStatus; + public UpdateOrganisationIdResponse( + @JsonProperty("updateOrganisationIdStatus") UpdateOrganisationIdStatus updateOrganisationIdStatus) { + this.updateOrganisationIdStatus = updateOrganisationIdStatus; } - public UpdateStatus getUpdateStatus() { - return updateStatus; + public UpdateOrganisationIdStatus getUpdateOrganisationIdStatus() { + return updateOrganisationIdStatus; } @Override @@ -25,18 +26,18 @@ public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof UpdateOrganisationIdResponse)) return false; UpdateOrganisationIdResponse that = (UpdateOrganisationIdResponse) o; - return Objects.equals(updateStatus, that.updateStatus); + return Objects.equals(updateOrganisationIdStatus, that.updateOrganisationIdStatus); } @Override public int hashCode() { - return Objects.hash(updateStatus); + return Objects.hash(updateOrganisationIdStatus); } @Override public String toString() { return "UpdateOrganisationIdResponse{" + - "updateStatus=" + updateStatus + + "updateOrganisationIdStatus=" + updateOrganisationIdStatus + '}'; } } diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java index ea6b3cf..ee12d5d 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/client/impl/OrganisationIdUpdateTest.java @@ -1,10 +1,8 @@ package com.verisec.frejaeid.client.client.impl; -import com.verisec.frejaeid.client.beans.common.EmptyFrejaResponse; import com.verisec.frejaeid.client.beans.common.RelyingPartyRequest; import com.verisec.frejaeid.client.beans.general.OrganisationIdAttribute; -import com.verisec.frejaeid.client.beans.general.UpdateStatus; -import com.verisec.frejaeid.client.beans.organisationid.delete.DeleteOrganisationIdRequest; +import com.verisec.frejaeid.client.beans.general.UpdateOrganisationIdStatus; import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdRequest; import com.verisec.frejaeid.client.beans.organisationid.update.UpdateOrganisationIdResponse; import com.verisec.frejaeid.client.client.api.OrganisationIdClientApi; @@ -46,7 +44,7 @@ public void initialiseClient() throws FrejaEidClientInternalException { public void updateOrgId_withoutRelyingPartyId_success() throws FrejaEidClientInternalException, FrejaEidException { UpdateOrganisationIdRequest updateOrganisationIdRequest = UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES); - UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(0, 2, 0)); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateOrganisationIdStatus(0, 2, 0)); Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), Mockito.any(RelyingPartyRequest.class), Mockito.eq(UpdateOrganisationIdResponse.class), (String) Mockito.isNull())) @@ -62,7 +60,7 @@ public void updateOrgId_withoutRelyingPartyId_success() throws FrejaEidClientInt public void updateOrgId_withRelyingPartyId_success() throws FrejaEidClientInternalException, FrejaEidException { UpdateOrganisationIdRequest updateOrganisationIdRequest = UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES, RELYING_PARTY_ID); - UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(1, 0, 1)); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateOrganisationIdStatus(1, 0, 1)); Mockito.when(httpServiceMock.send(Mockito.anyString(), Mockito.any(RequestTemplate.class), Mockito.any(RelyingPartyRequest.class), Mockito.eq(UpdateOrganisationIdResponse.class), Mockito.eq(RELYING_PARTY_ID))) diff --git a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java index 7e1db9f..7ae38f9 100644 --- a/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java +++ b/FrejaEidClient/src/test/java/com/verisec/frejaeid/client/http/OrganisationIdClientHttpTest.java @@ -255,7 +255,7 @@ public void updateOrganisationId_sendRequestWithoutRelyingPartyId_success() throws FrejaEidClientInternalException, IOException, FrejaEidException { UpdateOrganisationIdRequest updateOrganisationIdRequest = UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES); - UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(1, 1, 0)); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateOrganisationIdStatus(1, 1, 0)); String responseString = jsonService.serializeToJson(expectedResponse); startMockServer(updateOrganisationIdRequest, HttpStatusCode.OK.getCode(), responseString); UpdateOrganisationIdResponse receivedResponse = organisationIdClient.update(updateOrganisationIdRequest); @@ -267,7 +267,7 @@ public void updateOrganisationId_sendRequestWithRelyingPartyId_success() throws FrejaEidClientInternalException, IOException, FrejaEidException { UpdateOrganisationIdRequest updateOrganisationIdRequest = UpdateOrganisationIdRequest.create(IDENTIFIER, ADDITIONAL_ATTRIBUTES, RELYING_PARTY_ID); - UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateStatus(0, 2, 0)); + UpdateOrganisationIdResponse expectedResponse = new UpdateOrganisationIdResponse(new UpdateOrganisationIdStatus(0, 2, 0)); String responseString = jsonService.serializeToJson(expectedResponse); startMockServer(updateOrganisationIdRequest, HttpStatusCode.OK.getCode(), responseString); UpdateOrganisationIdResponse receivedResponse = organisationIdClient.update(updateOrganisationIdRequest); From ef1c0e89ec8eb6124e9b92e64adb21dd4ffae397 Mon Sep 17 00:00:00 2001 From: tanjaFrejaEid Date: Thu, 14 Dec 2023 14:41:35 +0100 Subject: [PATCH 7/7] increased version --- FrejaEidClient/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FrejaEidClient/pom.xml b/FrejaEidClient/pom.xml index 182c558..d322224 100644 --- a/FrejaEidClient/pom.xml +++ b/FrejaEidClient/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.verisec.frejaeid FrejaEidClient - 2.19.1-SNAPSHOT + 2.20.0-SNAPSHOT jar FrejaEidClient