Search in sources :

Example 26 with IdentityOAuth2ScopeException

use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2ScopeServiceTest method testRegisterWithInvalidScopeName.

@Test(dataProvider = "invalidScopeNameProvider")
public void testRegisterWithInvalidScopeName(String scopeName, String expected) {
    try {
        Scope scope = new Scope(scopeName, "displayName", "description");
        oAuth2ScopeService.registerScope(scope);
    } catch (IdentityOAuth2ScopeException ex) {
        assertEquals(ex.getMessage(), String.format(expected, scopeName));
        return;
    }
    fail("Expected IdentityOAuth2ScopeClientException was not thrown by registerScope method");
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope) Test(org.testng.annotations.Test)

Example 27 with IdentityOAuth2ScopeException

use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException 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");
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ScopeEndpointException(org.wso2.carbon.identity.oauth.scope.endpoint.exceptions.ScopeEndpointException) Scope(org.wso2.carbon.identity.oauth2.bean.Scope) IdentityOAuth2ScopeException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException) ScopeUtils(org.wso2.carbon.identity.oauth.scope.endpoint.util.ScopeUtils) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 28 with IdentityOAuth2ScopeException

use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.

the class ScopesApiServiceImplTest method buildRegisterApplication.

@DataProvider(name = "BuildRegisterScope")
public Object[][] buildRegisterApplication() {
    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.CONFLICT, identityOAuth2ScopeClientException }, { Response.Status.INTERNAL_SERVER_ERROR, identityOAuth2ScopeException } };
}
Also used : IdentityOAuth2ScopeClientException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeClientException) IdentityOAuth2ScopeException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException) DataProvider(org.testng.annotations.DataProvider)

Example 29 with IdentityOAuth2ScopeException

use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.

the class ScopesApiServiceImplTest method checkScopeException.

@DataProvider(name = "checkisScopeException")
public Object[][] checkScopeException() {
    IdentityOAuth2ScopeClientException identityOAuth2ScopeClientException = new IdentityOAuth2ScopeClientException("Oauth2 Scope Client Exception");
    IdentityOAuth2ScopeException identityOAuth2ScopeException = new IdentityOAuth2ScopeException("Oauth2 Scope Exception");
    return new Object[][] { { Response.Status.OK, null }, { Response.Status.NOT_FOUND, null }, { Response.Status.BAD_REQUEST, identityOAuth2ScopeClientException }, { Response.Status.INTERNAL_SERVER_ERROR, identityOAuth2ScopeException } };
}
Also used : IdentityOAuth2ScopeClientException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeClientException) IdentityOAuth2ScopeException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException) DataProvider(org.testng.annotations.DataProvider)

Example 30 with IdentityOAuth2ScopeException

use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException in project identity-inbound-auth-oauth by wso2-extensions.

the class ScopesApiServiceImplTest method buildGetApplication.

@DataProvider(name = "BuildGetScope")
public Object[][] buildGetApplication() {
    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 } };
}
Also used : IdentityOAuth2ScopeClientException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeClientException) IdentityOAuth2ScopeException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException) DataProvider(org.testng.annotations.DataProvider)

Aggregations

Scope (org.wso2.carbon.identity.oauth2.bean.Scope)14 Test (org.testng.annotations.Test)12 IdentityOAuth2ScopeException (org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeException)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 Connection (java.sql.Connection)9 IdentityOAuth2ScopeClientException (org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeClientException)8 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)8 OAuthScopeCacheKey (org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey)6 DataProvider (org.testng.annotations.DataProvider)5 UserApplicationScopeConsentDO (org.wso2.carbon.identity.oauth2.model.UserApplicationScopeConsentDO)5 ScopeDTO (org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO)3 ScopeEndpointException (org.wso2.carbon.identity.oauth.scope.endpoint.exceptions.ScopeEndpointException)3 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)3 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)2 ErrorDTO (org.wso2.carbon.identity.oauth.scope.endpoint.dto.ErrorDTO)2 OAuth2ScopeConsentResponse (org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse)2 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1