use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.
the class ScopeUpgraderTest method shouldNotCreateScopes_clientsAndRolesHaveNoScopes.
@Test
public void shouldNotCreateScopes_clientsAndRolesHaveNoScopes() {
final Scope domainScope = new Scope();
domainScope.setId("domain-scope-key");
domainScope.setKey("domain-scope-key");
final String domainId = "domain-id";
final String domainName = "domain-name";
final Domain domain = new Domain();
domain.setId(domainId);
domain.setName(domainName);
final Application app = new Application();
app.setId("client-id");
final Role role = new Role();
role.setId("role-id");
role.setPermissionAcls(null);
when(domainService.findAll()).thenReturn(Single.just(Collections.singletonList(domain)));
when(scopeService.findByDomain(domain.getId(), 0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page<>(Collections.emptySet(), 0, Integer.MAX_VALUE))).thenReturn(Single.just(new Page<>(Collections.singleton(domainScope), 0, Integer.MAX_VALUE)));
when(applicationService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(app)));
when(roleService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(role)));
scopeUpgrader.upgrade();
verify(domainService, times(1)).findAll();
verify(scopeService, times(1)).findByDomain(domain.getId(), 0, Integer.MAX_VALUE);
verify(applicationService, times(1)).findByDomain(domain.getId());
verify(roleService, times(1)).findByDomain(domain.getId());
verify(scopeService, never()).create(any(String.class), any(NewScope.class));
}
use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.
the class ScopeUpgraderTest method shouldCreateScopes_withRoleAndClientScopes.
@Test
public void shouldCreateScopes_withRoleAndClientScopes() {
final Scope domainScope = new Scope();
domainScope.setId("domain-scope-key");
domainScope.setKey("domain-scope-key");
final String domainId = "domain-id";
final String domainName = "domain-name";
final Domain domain = new Domain();
domain.setId(domainId);
domain.setName(domainName);
final Scope clientScope = new Scope();
clientScope.setId("client-scope-key");
clientScope.setKey("client-scope-key");
final Application app = new Application();
app.setId("client-id");
ApplicationSettings settings = new ApplicationSettings();
ApplicationOAuthSettings oauth = new ApplicationOAuthSettings();
oauth.setScopes(Collections.singletonList(clientScope.getKey()));
settings.setOauth(oauth);
app.setSettings(settings);
final Scope roleScope = new Scope();
roleScope.setId("role-scope-key");
roleScope.setKey("role-scope-key");
final Role role = new Role();
role.setId("role-id");
role.setOauthScopes(Collections.singletonList(roleScope.getKey()));
when(domainService.findAll()).thenReturn(Single.just(Collections.singletonList(domain)));
when(scopeService.findByDomain(domain.getId(), 0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page<>(Collections.emptySet(), 0, 0))).thenReturn(Single.just(new Page<>(Collections.singleton(domainScope), 0, 1)));
when(applicationService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(app)));
when(roleService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(role)));
when(scopeService.create(any(String.class), any(NewScope.class))).thenReturn(Single.just(new Scope()));
scopeUpgrader.upgrade();
verify(domainService, times(1)).findAll();
verify(scopeService, times(3)).findByDomain(domain.getId(), 0, Integer.MAX_VALUE);
verify(applicationService, times(1)).findByDomain(domain.getId());
verify(roleService, times(1)).findByDomain(domain.getId());
verify(scopeService, times(2)).create(any(String.class), any(NewScope.class));
}
use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.
the class ScopeUpgraderTest method shouldNotCreateScopes_domainHasScopes.
@Test
public void shouldNotCreateScopes_domainHasScopes() {
final Scope domainScope = new Scope();
domainScope.setId("domain-scope-key");
domainScope.setKey("domain-scope-key");
final String domainId = "domain-id";
final String domainName = "domain-name";
final Domain domain = new Domain();
domain.setId(domainId);
domain.setName(domainName);
when(domainService.findAll()).thenReturn(Single.just(Collections.singletonList(domain)));
when(scopeService.findByDomain(domain.getId(), 0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page<>(Collections.singleton(domainScope), 0, 1)));
scopeUpgrader.upgrade();
verify(domainService, times(1)).findAll();
verify(scopeService, times(1)).findByDomain(domain.getId(), 0, Integer.MAX_VALUE);
verify(applicationService, never()).findByDomain(domain.getId());
verify(roleService, never()).findByDomain(domain.getId());
verify(scopeService, never()).create(any(String.class), any(NewScope.class));
}
use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.
the class ScopeRepositoryTest method testFindByDomainAndKey.
@Test
public void testFindByDomainAndKey() {
// create scope
Scope scope = new Scope();
scope.setName("firstOne");
scope.setKey("one");
scope.setDomain("testDomain");
scopeRepository.create(scope).blockingGet();
scope.setId(null);
scope.setName("anotherOne");
scope.setDomain("another");
scopeRepository.create(scope).blockingGet();
// fetch scopes
TestObserver<Scope> testObserver = scopeRepository.findByDomainAndKey("testDomain", "one").test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
testObserver.assertValue(result -> "firstOne".equals(result.getName()));
}
use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.CreateDataChangeEventSubscriptionInput1.Scope in project gravitee-access-management by gravitee-io.
the class ScopeRepositoryTest method testFindById.
@Test
public void testFindById() {
// create scope
Scope scope = buildScope();
Scope scopeCreated = scopeRepository.create(scope).blockingGet();
// fetch scope
TestObserver<Scope> testObserver = scopeRepository.findById(scopeCreated.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
assertEqualsTo(scope, testObserver);
}
Aggregations