use of org.wso2.carbon.identity.oauth.scope.endpoint.exceptions.ScopeEndpointException 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.oauth.scope.endpoint.exceptions.ScopeEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopesApiServiceImplTest method testGetScopes.
@Test(dataProvider = "BuildgetScopes")
public void testGetScopes(Response.Status expectation) throws Exception {
Set<Scope> scopes = new HashSet<>();
scopes.add(new Scope(someScopeName, someScopeName, someScopeDescription));
int startIndex = 0;
int count = 1;
if (Response.Status.OK.equals(expectation)) {
when(oAuth2ScopeService.getScopes(any(Integer.class), any(Integer.class), any(Boolean.class), any(String.class))).thenReturn(scopes);
when(ScopeUtils.class, "getScopeDTOs", any(Set.class)).thenCallRealMethod();
Response response = scopesApiService.getScopes(startIndex, count);
assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), "Error occurred while getting scopes");
assertEquals(((HashSet) response.getEntity()).size(), count, "Cannot Retrieve Expected Scopes");
} else if (Response.Status.INTERNAL_SERVER_ERROR.equals(expectation)) {
when(oAuth2ScopeService.getScopes(any(Integer.class), any(Integer.class))).thenThrow(IdentityOAuth2ScopeException.class);
callRealMethod();
try {
scopesApiService.getScopes(startIndex, count);
} 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");
}
}
}
use of org.wso2.carbon.identity.oauth.scope.endpoint.exceptions.ScopeEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopesApiServiceImplTest method testRegisterScope.
@Test(dataProvider = "BuildRegisterScope")
public void testRegisterScope(Response.Status expectation, Throwable throwable) throws Exception {
ScopeDTO scopeDTO = new ScopeDTO();
scopeDTO.setDescription("some description");
scopeDTO.setBindings(Collections.<String>emptyList());
if (Response.Status.OK.equals(expectation)) {
when(oAuth2ScopeService.registerScope(any(Scope.class))).thenReturn(any(Scope.class));
assertEquals(scopesApiService.registerScope(scopeDTO).getStatus(), Response.Status.CREATED.getStatusCode(), "Error occurred while registering scopes");
} else if (Response.Status.BAD_REQUEST.equals(expectation)) {
when(oAuth2ScopeService.registerScope(any(Scope.class))).thenThrow(throwable);
callRealMethod();
try {
scopesApiService.registerScope(scopeDTO);
} 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.CONFLICT.equals(expectation)) {
((IdentityOAuth2ScopeException) throwable).setErrorCode(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_CONFLICT_REQUEST_EXISTING_SCOPE.getCode());
when(oAuth2ScopeService.registerScope(any(Scope.class))).thenThrow(throwable);
callRealMethod();
try {
scopesApiService.registerScope(scopeDTO);
} catch (ScopeEndpointException e) {
assertEquals(e.getResponse().getStatus(), Response.Status.CONFLICT.getStatusCode(), "Cannot find HTTP Response, Conflict in Case of " + "IdentityOAuth2ScopeClientException");
assertEquals(((ErrorDTO) (e.getResponse().getEntity())).getMessage(), Response.Status.CONFLICT.getReasonPhrase(), "Cannot find appropriate error message " + "for HTTP Response, Conflict");
} finally {
reset(oAuth2ScopeService);
}
} else if (Response.Status.INTERNAL_SERVER_ERROR.equals(expectation)) {
when(oAuth2ScopeService.registerScope(any(Scope.class))).thenThrow(IdentityOAuth2ScopeException.class);
callRealMethod();
try {
scopesApiService.registerScope(scopeDTO);
} 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);
}
}
}
Aggregations