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 5721596 commit 8b8d36e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +30,7 @@ public class OrganisationIdUpdateTest {
private static final List<OrganisationIdAttribute> 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;
Expand All @@ -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));
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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<OrganisationIdAttribute> 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;
Expand Down Expand Up @@ -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.");
}
}

}

0 comments on commit 8b8d36e

Please sign in to comment.