use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopesApiServiceImplTest method testUpdateScope.
@Test(dataProvider = "BuildUpdateScope")
public void testUpdateScope(Response.Status expectation, Throwable throwable) throws Exception {
ScopeToUpdateDTO scopeToUpdateDTO = new ScopeToUpdateDTO();
scopeToUpdateDTO.setDescription("some description");
scopeToUpdateDTO.setBindings(Collections.<String>emptyList());
if (Response.Status.OK.equals(expectation)) {
when(ScopeUtils.getScopeDTO(any(Scope.class))).thenReturn(any(ScopeDTO.class));
assertEquals(scopesApiService.updateScope(scopeToUpdateDTO, someScopeName).getStatus(), Response.Status.OK.getStatusCode(), "Error occurred while updating scopes");
} else if (Response.Status.BAD_REQUEST.equals(expectation)) {
when(oAuth2ScopeService.updateScope(any(Scope.class))).thenThrow(IdentityOAuth2ScopeClientException.class);
callRealMethod();
try {
scopesApiService.updateScope(scopeToUpdateDTO, someScopeName);
} catch (ScopeEndpointException e) {
assertEquals(e.getResponse().getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), "Cannot find HTTP Response, Bad Request in Case of " + "IdentityOAuth2ScopeClientException");
assertEquals(((ErrorDTO) (e.getResponse().getEntity())).getMessage(), Response.Status.BAD_REQUEST.getReasonPhrase(), "Cannot find appropriate error message " + "for HTTP Response, Bad Request");
} finally {
reset(oAuth2ScopeService);
}
} else if (Response.Status.NOT_FOUND.equals(expectation)) {
((IdentityOAuth2ScopeException) throwable).setErrorCode(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_NOT_FOUND_SCOPE.getCode());
when(oAuth2ScopeService.updateScope(any(Scope.class))).thenThrow(throwable);
callRealMethod();
try {
scopesApiService.updateScope(scopeToUpdateDTO, someScopeName);
} catch (ScopeEndpointException e) {
assertEquals(e.getResponse().getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "Cannot find HTTP Response, Not Found in Case of " + "IdentityOAuth2ScopeClientException");
assertEquals(((ErrorDTO) (e.getResponse().getEntity())).getMessage(), Response.Status.NOT_FOUND.getReasonPhrase(), "Cannot find appropriate error message " + "for HTTP Response, Not Found");
} finally {
reset(oAuth2ScopeService);
}
} else if (Response.Status.INTERNAL_SERVER_ERROR.equals(expectation)) {
when(oAuth2ScopeService.updateScope(any(Scope.class))).thenThrow(IdentityOAuth2ScopeException.class);
callRealMethod();
try {
scopesApiService.updateScope(scopeToUpdateDTO, someScopeName);
} catch (ScopeEndpointException e) {
assertEquals(e.getResponse().getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Cannot find HTTP Response, Internal Server Error in case of " + "IdentityOAuth2ScopeException");
assertNull(e.getResponse().getEntity(), "Do not include error message in case of " + "Server Exception");
} finally {
reset(oAuth2ScopeService);
}
}
}
use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopesApiServiceImplTest method buildUpdateApplication.
@DataProvider(name = "BuildUpdateScope")
public Object[][] buildUpdateApplication() {
IdentityOAuth2ScopeClientException identityOAuth2ScopeClientException = new IdentityOAuth2ScopeClientException("Oauth2 Scope Client Exception");
IdentityOAuth2ScopeException identityOAuth2ScopeException = new IdentityOAuth2ScopeException("Oauth2 Scope " + "Exception");
return new Object[][] { { Response.Status.OK, null }, { Response.Status.BAD_REQUEST, identityOAuth2ScopeClientException }, { Response.Status.NOT_FOUND, identityOAuth2ScopeClientException }, { Response.Status.INTERNAL_SERVER_ERROR, identityOAuth2ScopeException } };
}
use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeMgtDAOTest method getAllScopes.
@Test(dataProvider = "getAllScopesDataProvider")
public void getAllScopes(List<Object> scopes, int tenantId) throws SQLException, IdentityOAuth2ScopeException {
try (Connection connection = DAOUtils.getConnection(DB_NAME)) {
mockStatic(IdentityDatabaseUtil.class);
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection);
assertTrue(scopes != null && !scopes.isEmpty(), "Failed to retrieve scopes.");
addScopes(scopes, tenantId);
// Clean after test
deleteScopes(scopes, tenantId);
}
}
use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeMgtDAOTest method getScopeIDByName.
@Test(dataProvider = "getScopeIDByNameDataProvider")
public void getScopeIDByName(Object scope, int tenantId) throws IdentityOAuth2ScopeException, SQLException {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME)) {
mockStatic(IdentityDatabaseUtil.class);
addScopes(Collections.singletonList(scope), tenantId);
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection1);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection1);
assertTrue(oAuthScopeDAO.getScopeIDByName(((Scope) scope).getName(), tenantId) != Oauth2ScopeConstants.INVALID_SCOPE_ID, "Failed to retrieve the scope id.");
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection2);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection2);
assertTrue(oAuthScopeDAO.getScopeIDByName("invalidScopeName", tenantId) == Oauth2ScopeConstants.INVALID_SCOPE_ID, "Failed to retrieve the scope id.");
// Clean after test
deleteScopes(Collections.singletonList(scope), tenantId);
}
}
use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeMgtDAOTest method deleteScopeByName.
@Test(dataProvider = "deleteScopeByNameDataProvider")
public void deleteScopeByName(Object scope, int tenantId) throws IdentityOAuth2ScopeException, SQLException {
try (Connection connection1 = DAOUtils.getConnection(DB_NAME);
Connection connection2 = DAOUtils.getConnection(DB_NAME)) {
mockStatic(IdentityDatabaseUtil.class);
addScopes(Collections.singletonList(scope), tenantId);
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection1);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection1);
oAuthScopeDAO.deleteScopeByName(((Scope) scope).getName(), tenantId);
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection2);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection2);
assertNull(oAuthScopeDAO.getScopeByName(((Scope) scope).getName(), tenantId), "Failed to delete the scope" + " by name.");
}
}
Aggregations