Search in sources :

Example 1 with SystemTask

use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.

the class SystemTaskRepositoryTest method testDelete.

@Test
public void testDelete() {
    SystemTask task = buildSystemTask();
    SystemTask systemTaskCreated = taskRepository.create(task).blockingGet();
    // fetch SystemTask
    TestObserver<SystemTask> testObserver = taskRepository.findById(systemTaskCreated.getId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(s -> s.getId().equals(systemTaskCreated.getId()));
    // delete SystemTask
    TestObserver testObserver1 = taskRepository.delete(systemTaskCreated.getId()).test();
    testObserver1.awaitTerminalEvent();
    // fetch SystemTask
    taskRepository.findById(systemTaskCreated.getId()).test().assertEmpty();
}
Also used : SystemTask(io.gravitee.am.model.SystemTask) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 2 with SystemTask

use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.

the class SystemTaskRepositoryTest method testFindById.

@Test
public void testFindById() {
    // create task
    SystemTask task = buildSystemTask();
    SystemTask systemTaskCreated = taskRepository.create(task).blockingGet();
    // fetch task
    TestObserver<SystemTask> testObserver = taskRepository.findById(systemTaskCreated.getId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    assertEqualsTo(task, task.getOperationId(), testObserver);
}
Also used : SystemTask(io.gravitee.am.model.SystemTask) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 3 with SystemTask

use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.

the class SystemTaskRepositoryTest method testUpdateIf.

@Test
public void testUpdateIf() {
    SystemTask task = buildSystemTask();
    SystemTask systemTaskCreated = taskRepository.create(task).blockingGet();
    SystemTask updatedSystemTask = buildSystemTask();
    updatedSystemTask.setId(systemTaskCreated.getId());
    TestObserver<SystemTask> testObserver = taskRepository.updateIf(updatedSystemTask, systemTaskCreated.getOperationId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    assertEqualsTo(updatedSystemTask, updatedSystemTask.getOperationId(), testObserver);
}
Also used : SystemTask(io.gravitee.am.model.SystemTask) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 4 with SystemTask

use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.

the class SystemTaskRepositoryTest method buildSystemTask.

private SystemTask buildSystemTask() {
    SystemTask task = new SystemTask();
    String rand = UUID.randomUUID().toString();
    task.setId(rand);
    task.setType(rand);
    task.setStatus(rand);
    task.setOperationId(rand);
    task.setCreatedAt(new Date());
    task.setUpdatedAt(new Date());
    return task;
}
Also used : SystemTask(io.gravitee.am.model.SystemTask) Date(java.util.Date)

Example 5 with SystemTask

use of io.gravitee.am.model.SystemTask in project gravitee-access-management by gravitee-io.

the class ApplicationScopeSettingsUpgrader method migrateScopeSettings.

private Single<Boolean> migrateScopeSettings(SystemTask task) {
    return applicationService.findAll().flatMapPublisher(apps -> Flowable.fromIterable(apps)).flatMapSingle(app -> {
        logger.debug("Process application '{}'", app.getId());
        if (app.getSettings() != null && app.getSettings().getOauth() != null) {
            final ApplicationOAuthSettings oauthSettings = app.getSettings().getOauth();
            List<ApplicationScopeSettings> scopeSettings = new ArrayList<>();
            if (oauthSettings.getScopes() != null && !oauthSettings.getScopes().isEmpty()) {
                logger.debug("Process scope options for application '{}'", app.getId());
                for (String scope : oauthSettings.getScopes()) {
                    ApplicationScopeSettings setting = new ApplicationScopeSettings();
                    setting.setScope(scope);
                    setting.setDefaultScope(oauthSettings.getDefaultScopes() != null && oauthSettings.getDefaultScopes().contains(scope));
                    if (oauthSettings.getScopeApprovals() != null && oauthSettings.getScopeApprovals().containsKey(scope)) {
                        setting.setScopeApproval(oauthSettings.getScopeApprovals().get(scope));
                    }
                    scopeSettings.add(setting);
                }
                oauthSettings.setScopeSettings(scopeSettings);
                // remove old values
                oauthSettings.setScopes(null);
                oauthSettings.setDefaultScopes(null);
                oauthSettings.setScopeApprovals(null);
                logger.debug("Update settings for application '{}'", app.getId());
                return applicationService.update(app);
            } else {
                logger.debug("No scope to process for application '{}'", app.getId());
            }
        } else {
            logger.debug("No scope to process for application '{}'", app.getId());
        }
        return Single.just(app);
    }).ignoreElements().doOnError(err -> updateSystemTask(task, (SystemTaskStatus.FAILURE), task.getOperationId()).subscribe()).andThen(updateSystemTask(task, SystemTaskStatus.SUCCESS, task.getOperationId()).map(__ -> true).onErrorResumeNext((err) -> {
        logger.error("Unable to update status for migrate scope options task: {}", err.getMessage());
        return Single.just(false);
    })).onErrorResumeNext((err) -> {
        logger.error("Unable to migrate scope options for applications: {}", err.getMessage());
        return Single.just(false);
    });
}
Also used : ApplicationService(io.gravitee.am.service.ApplicationService) Ordered(org.springframework.core.Ordered) SystemTask(io.gravitee.am.model.SystemTask) Logger(org.slf4j.Logger) ApplicationOAuthSettings(io.gravitee.am.model.application.ApplicationOAuthSettings) NonNull(io.reactivex.annotations.NonNull) Date(java.util.Date) Publisher(org.reactivestreams.Publisher) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SystemTaskRepository(io.gravitee.am.repository.management.api.SystemTaskRepository) UUID(java.util.UUID) SystemTaskStatus(io.gravitee.am.model.SystemTaskStatus) Single(io.reactivex.Single) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) List(java.util.List) Flowable(io.reactivex.Flowable) SystemTaskTypes(io.gravitee.am.model.SystemTaskTypes) Function(io.reactivex.functions.Function) ApplicationScopeSettings(io.gravitee.am.model.application.ApplicationScopeSettings) Lazy(org.springframework.context.annotation.Lazy) APPLICATION_SCOPE_SETTINGS_UPGRADER(io.gravitee.am.management.service.impl.upgrades.UpgraderOrder.APPLICATION_SCOPE_SETTINGS_UPGRADER) ApplicationOAuthSettings(io.gravitee.am.model.application.ApplicationOAuthSettings) ApplicationScopeSettings(io.gravitee.am.model.application.ApplicationScopeSettings) ArrayList(java.util.ArrayList)

Aggregations

SystemTask (io.gravitee.am.model.SystemTask)11 Test (org.junit.Test)7 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)4 SystemTaskStatus (io.gravitee.am.model.SystemTaskStatus)3 ApplicationOAuthSettings (io.gravitee.am.model.application.ApplicationOAuthSettings)3 SystemTaskRepository (io.gravitee.am.repository.management.api.SystemTaskRepository)3 ApplicationService (io.gravitee.am.service.ApplicationService)3 Single (io.reactivex.Single)3 Date (java.util.Date)3 UUID (java.util.UUID)3 Application (io.gravitee.am.model.Application)2 ApplicationSettings (io.gravitee.am.model.application.ApplicationSettings)2 Maps (io.gravitee.common.util.Maps)2 Maybe (io.reactivex.Maybe)2 Arrays (java.util.Arrays)2 Set (java.util.Set)2 RunWith (org.junit.runner.RunWith)2 InjectMocks (org.mockito.InjectMocks)2 Mock (org.mockito.Mock)2 Mockito (org.mockito.Mockito)2