@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 Client client = new Client(); client.setId("client-id"); client.setScopes(Collections.singletonList(clientScope.getKey())); 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.singleton(domain))); when(scopeService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.emptySet())) .thenReturn(Single.just(Collections.singleton(domainScope))); when(clientService.findByDomain(domain.getId())).thenReturn(Single.just(Collections.singleton(client))); 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()); verify(clientService, times(1)).findByDomain(domain.getId()); verify(roleService, times(1)).findByDomain(domain.getId()); verify(scopeService, times(2)).create(any(String.class), any(NewScope.class)); }
@Override public boolean upgrade() { logger.info("Applying scope upgrade"); domainService.findAll() .flatMapObservable(domains -> Observable.fromIterable(domains)) .flatMapSingle(domain -> upgradeDomain(domain)) .subscribe(); return true; }
ScopeUpgrader implements Upgrader, Ordered { @Override public boolean upgrade() { logger.info("Applying scope upgrade"); domainService.findAll() .flatMapObservable(domains -> Observable.fromIterable(domains)) .flatMapSingle(domain -> upgradeDomain(domain)) .subscribe(); return true; } }
ScopeUpgrader implements Upgrader, Ordered { @Override public boolean upgrade() { logger.info("Applying scope upgrade"); domainService.findAll() .flatMapObservable(domains -> Observable.fromIterable(domains)) .flatMapSingle(domain -> upgradeDomain(domain)) .subscribe(); return true; }  }
ScopeUpgrader implements Upgrader, Ordered { @Override public boolean upgrade() { logger.info("Applying scope upgrade"); domainService.findAll() .flatMapObservable(domains -> Observable.fromIterable(domains)) .flatMapSingle(domain -> upgradeDomain(domain)) .subscribe(); return true; }  @Override boolean upgrade(); @Override int getOrder(); }
ScopeUpgrader implements Upgrader, Ordered { @Override public boolean upgrade() { logger.info("Applying scope upgrade"); domainService.findAll() .flatMapObservable(domains -> Observable.fromIterable(domains)) .flatMapSingle(domain -> upgradeDomain(domain)) .subscribe(); return true; }  @Override boolean upgrade(); @Override int getOrder();  }