From 57215964d77d6bf8461ce17ec851964487d6ac92 Mon Sep 17 00:00:00 2001 From: tanjaFrejaEid Date: Thu, 14 Dec 2023 09:47:23 +0100 Subject: [PATCH] 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); + } }