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());
}
}
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());
}
}
Aggregations