Search in sources :

Example 16 with StyxException

use of net.petafuel.styx.api.exception.StyxException in project styx by petafuel.

the class AccessTokenFilterUnitTest method testAccessTokenHasServiceTheMasterTokenDoesNotHaveAnymore.

@Test
void testAccessTokenHasServiceTheMasterTokenDoesNotHaveAnymore() {
    AccessToken accessToken = new AccessToken();
    accessToken.setServiceType("ais");
    MasterToken masterToken = prepareMasterToken("pis", 2);
    AccessTokenFilter accessTokenFilter = new AccessTokenFilter();
    Assertions.assertThrows(StyxException.class, () -> accessTokenFilter.checkMaxUsages(masterToken, accessToken));
    try {
        accessTokenFilter.checkMaxUsages(masterToken, accessToken);
    } catch (StyxException exception) {
        ResponseEntity response = exception.getResponseEntity();
        Assertions.assertEquals(ResponseConstant.STYX_MASTER_TOKEN_RESTRICTED.getReasonPhrase(), response.getMessage());
        Assertions.assertEquals(ResponseConstant.STYX_MASTER_TOKEN_RESTRICTED.getStatusCode(), response.getCode().getStatusCode());
        Assertions.assertEquals(ResponseCategory.ERROR, response.getCategory());
        Assertions.assertEquals(ResponseOrigin.STYX, response.getOrigin());
    }
}
Also used : MasterToken(net.petafuel.styx.core.persistence.models.MasterToken) ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) AccessToken(net.petafuel.styx.core.persistence.models.AccessToken) StyxException(net.petafuel.styx.api.exception.StyxException) Test(org.junit.jupiter.api.Test)

Example 17 with StyxException

use of net.petafuel.styx.api.exception.StyxException in project styx by petafuel.

the class AccessTokenFilterUnitTest method testMasterTokenRestrictionsNotSet.

@Test
void testMasterTokenRestrictionsNotSet() {
    MasterToken masterToken = new MasterToken();
    AccessTokenFilter accessTokenFilter = new AccessTokenFilter();
    Assertions.assertThrows(StyxException.class, () -> accessTokenFilter.checkRestrictions(masterToken, "pis"));
    try {
        accessTokenFilter.checkRestrictions(masterToken, "pis");
    } catch (StyxException exception) {
        ResponseEntity response = exception.getResponseEntity();
        Assertions.assertEquals(ResponseConstant.STYX_MASTER_TOKEN_RESTRICTED.getReasonPhrase(), response.getMessage());
        Assertions.assertEquals(ResponseConstant.STYX_MASTER_TOKEN_RESTRICTED.getStatusCode(), response.getCode().getStatusCode());
        Assertions.assertEquals(ResponseCategory.ERROR, response.getCategory());
        Assertions.assertEquals(ResponseOrigin.STYX, response.getOrigin());
    }
}
Also used : MasterToken(net.petafuel.styx.core.persistence.models.MasterToken) ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) StyxException(net.petafuel.styx.api.exception.StyxException) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseEntity (net.petafuel.styx.api.exception.ResponseEntity)17 StyxException (net.petafuel.styx.api.exception.StyxException)17 MasterToken (net.petafuel.styx.core.persistence.models.MasterToken)6 Test (org.junit.jupiter.api.Test)5 Path (javax.ws.rs.Path)4 POST (javax.ws.rs.POST)3 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)3 AbstractTokenFilter (net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter)3 RequiresMandatoryHeader (net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader)3 AspspUrlMapper (net.petafuel.styx.api.util.AspspUrlMapper)3 PaymentResponse (net.petafuel.styx.api.v1.payment.entity.PaymentResponse)3 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)3 PersistenceEmptyResultSetException (net.petafuel.styx.core.persistence.PersistenceEmptyResultSetException)3 AccessToken (net.petafuel.styx.core.persistence.models.AccessToken)3 PISRequest (net.petafuel.styx.core.xs2a.contracts.PISRequest)3 InitiatedPayment (net.petafuel.styx.core.xs2a.entities.InitiatedPayment)3 SinglePayment (net.petafuel.styx.core.xs2a.entities.SinglePayment)3 PISRequestFactory (net.petafuel.styx.core.xs2a.factory.PISRequestFactory)3 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)3 OAuth2 (net.petafuel.styx.core.xs2a.sca.OAuth2)3