Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tanjaFrejaEid committed Dec 14, 2023
1 parent 5ed9cc3 commit 5721596
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -11,16 +13,46 @@ public class UpdateOrganisationIdRequest implements RelyingPartyRequest {

private final String identifier;
private final List<OrganisationIdAttribute> additionalAttributes;
// @JsonIgnore ???
private final String relyingPartyId;

public static UpdateOrganisationIdRequest create(String identifier, List<OrganisationIdAttribute> additionalAttributes){
return new UpdateOrganisationIdRequest(identifier, additionalAttributes);
}

public static UpdateOrganisationIdRequest create(String identifier, List<OrganisationIdAttribute> additionalAttributes, String relyingPartyId){
return new UpdateOrganisationIdRequest(identifier, additionalAttributes, relyingPartyId);
}

public UpdateOrganisationIdRequest(String identifier, List<OrganisationIdAttribute> 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<OrganisationIdAttribute> additionalAttributes) {
this.identifier = identifier;
this.additionalAttributes = additionalAttributes;
this.relyingPartyId = null;
}

public UpdateOrganisationIdRequest(String identifier, List<OrganisationIdAttribute> 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<OrganisationIdAttribute> additionalAttributes,
String relyingPartyId) {
this.identifier = identifier;
this.additionalAttributes = additionalAttributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,17 @@ public void delete(DeleteOrganisationIdRequest deleteOrganisationIdRequest)
public List<OrganisationIdUserInfo> 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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<OrganisationIdAttribute> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<OrganisationIdAttribute> 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 {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 5721596

Please sign in to comment.