Search in sources :

Example 81 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testDeleteSubscriptionException.

@Test(description = "Exception when deleting subscription", expectedExceptions = APIManagementException.class)
public void testDeleteSubscriptionException() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO);
    Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting api subscription " + UUID, new SQLException())).when(apiSubscriptionDAO).deleteAPISubscription(UUID);
    apiStore.deleteAPISubscription(UUID);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SQLException(java.sql.SQLException) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 82 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetLastUpdatedTimeOfApplication.

@Test(description = "Getting last updated time of Application")
public void testGetLastUpdatedTimeOfApplication() throws APIManagementException {
    ApplicationDAO applicationDAO = mock(ApplicationDAO.class);
    AbstractAPIManager apiStore = getAPIStoreImpl(applicationDAO);
    when(applicationDAO.getLastUpdatedTimeOfApplication(UUID)).thenReturn(LAST_UPDATED_TIME);
    apiStore.getLastUpdatedTimeOfApplication(UUID);
    verify(applicationDAO, times(1)).getLastUpdatedTimeOfApplication(UUID);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Test(org.testng.annotations.Test)

Example 83 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class AbstractAPIManagerTestCase method testGetApplicationByUuid.

@Test(description = "Retrieve an application by uuid")
public void testGetApplicationByUuid() throws APIManagementException {
    ApplicationDAO applicationDAO = mock(ApplicationDAO.class);
    AbstractAPIManager apiStore = getAPIStoreImpl(applicationDAO);
    Application applicationFromDAO = new Application(APP_NAME, USER_NAME);
    when(applicationDAO.getApplication(UUID)).thenReturn(applicationFromDAO);
    Application application = apiStore.getApplication(UUID, USER_NAME);
    Assert.assertNotNull(application);
    verify(applicationDAO, times(1)).getApplication(UUID);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 84 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method updateApplicationByResourceId.

@Override
public void updateApplicationByResourceId(String resourceId, ServiceProvider updatedApp, String tenantDomain, String username) throws IdentityApplicationManagementException {
    validateApplicationConfigurations(updatedApp, tenantDomain, username);
    updatedApp.setApplicationResourceId(resourceId);
    setDisplayNamesOfLocalAuthenticators(updatedApp, tenantDomain);
    Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
    for (ApplicationResourceManagementListener listener : listeners) {
        if (listener.isEnabled() && !listener.doPreUpdateApplicationByResourceId(updatedApp, resourceId, tenantDomain, username)) {
            throw buildServerException("Pre Update application operation of listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
        }
    }
    try {
        startTenantFlow(tenantDomain);
        ApplicationBasicInfo storedAppInfo = getApplicationBasicInfo(resourceId, tenantDomain);
        if (storedAppInfo == null) {
            String msg = "Cannot find an application for " + "resourceId: " + resourceId + " in tenantDomain: " + tenantDomain;
            throw buildClientException(APPLICATION_NOT_FOUND, msg);
        }
        String updatedAppName = updatedApp.getApplicationName();
        String storedAppName = storedAppInfo.getApplicationName();
        doPreUpdateChecks(storedAppName, updatedApp, tenantDomain, username);
        ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        appDAO.updateApplicationByResourceId(resourceId, tenantDomain, updatedApp);
        if (isOwnerUpdateRequest(storedAppInfo.getAppOwner(), updatedApp.getOwner())) {
            // User existence check is already done in appDAO.updateApplicationByResourceId() method.
            assignApplicationRole(updatedApp.getApplicationName(), updatedApp.getOwner().getUserName());
        }
        updateApplicationPermissions(updatedApp, updatedAppName, storedAppName);
    } catch (RegistryException e) {
        String message = "Error while updating application with resourceId: " + resourceId + " in tenantDomain: " + tenantDomain;
        throw buildServerException(message, e);
    } finally {
        endTenantFlow();
    }
    for (ApplicationResourceManagementListener listener : listeners) {
        if (listener.isEnabled() && !listener.doPostUpdateApplicationByResourceId(updatedApp, resourceId, tenantDomain, username)) {
            log.error("Post Update application operation of listener: " + getName(listener) + " failed for " + "application with resourceId: " + resourceId);
            return;
        }
    }
    triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.UPDATE_APPLICATION.getEventId(), getAppId(updatedApp), getApplicationName(updatedApp), TARGET_APPLICATION, buildSPData(updatedApp));
}
Also used : ApplicationResourceManagementListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 85 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method doPreAddApplicationChecks.

private void doPreAddApplicationChecks(ServiceProvider serviceProvider, String tenantDomain, String username) throws IdentityApplicationManagementException {
    String appName = serviceProvider.getApplicationName();
    if (StringUtils.isBlank(appName)) {
        // check for required attributes.
        throw buildClientException(INVALID_REQUEST, "Application name cannot be empty.");
    }
    ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
    if (appDAO.isApplicationExists(appName, tenantDomain)) {
        String msg = "An application with name: '" + appName + "' already exists in tenantDomain: " + tenantDomain;
        throw new IdentityApplicationRegistrationFailureException(APPLICATION_ALREADY_EXISTS.getCode(), msg);
    }
    if (ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(appName)) {
        String msg = "Application with name: '" + appName + "' already loaded from the file system.";
        throw buildClientException(APPLICATION_ALREADY_EXISTS, msg);
    }
    if (!isRegexValidated(appName)) {
        String message = "The Application name: '" + appName + "' is not valid! It is not adhering to the regex: " + ApplicationMgtUtil.getSPValidatorRegex();
        throw buildClientException(INVALID_REQUEST, message);
    }
    addUserIdAsDefaultSubject(serviceProvider);
    validateApplicationConfigurations(serviceProvider, tenantDomain, username);
}
Also used : PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) IdentityApplicationRegistrationFailureException(org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException)

Aggregations

ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)62 Test (org.testng.annotations.Test)59 Application (org.wso2.carbon.apimgt.core.models.Application)50 BeforeTest (org.testng.annotations.BeforeTest)33 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)32 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)31 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)25 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)25 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)18 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)18 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)15 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)15 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)13 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)13 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)13 API (org.wso2.carbon.apimgt.core.models.API)12 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)11 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)10