Search in sources :

Example 21 with Scope

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 ScopeServiceTest method shouldUpdate_nonSystemScope_discoveryReplaced.

@Test
public void shouldUpdate_nonSystemScope_discoveryReplaced() {
    UpdateScope updateScope = new UpdateScope();
    updateScope.setDiscovery(true);
    updateScope.setName("name");
    final String scopeId = "toUpdateId";
    Scope toUpdate = new Scope();
    toUpdate.setId(scopeId);
    toUpdate.setSystem(false);
    toUpdate.setDiscovery(false);
    toUpdate.setName("oldName");
    toUpdate.setDescription("oldDescription");
    ArgumentCaptor<Scope> argument = ArgumentCaptor.forClass(Scope.class);
    when(scopeRepository.findById(scopeId)).thenReturn(Maybe.just(toUpdate));
    when(scopeRepository.update(argument.capture())).thenReturn(Single.just(new Scope()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    TestObserver testObserver = scopeService.update(DOMAIN, scopeId, updateScope).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(scopeRepository, times(1)).update(any(Scope.class));
    assertNotNull(argument.getValue());
    assertEquals("name", argument.getValue().getName());
    assertNull(argument.getValue().getDescription());
    assertTrue(argument.getValue().isDiscovery());
}
Also used : Scope(io.gravitee.am.model.oauth2.Scope) Event(io.gravitee.am.model.common.event.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 22 with Scope

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 ScopeServiceTest method shouldNotDeleteSystemScope.

@Test
public void shouldNotDeleteSystemScope() throws TechnicalException {
    Scope scope = new Scope();
    scope.setKey("scope-key");
    scope.setSystem(true);
    when(scopeRepository.findById("scope-id")).thenReturn(Maybe.just(scope));
    TestObserver testObserver = scopeService.delete("scope-id", false).test();
    testObserver.assertError(SystemScopeDeleteException.class);
    testObserver.assertNotComplete();
}
Also used : Scope(io.gravitee.am.model.oauth2.Scope) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 23 with Scope

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 ScopeServiceTest method shouldNotCreate_malformedIconUri.

@Test
public void shouldNotCreate_malformedIconUri() {
    NewScope newScope = Mockito.mock(NewScope.class);
    when(newScope.getKey()).thenReturn("my-scope");
    when(newScope.getIconUri()).thenReturn("malformedIconUri");
    when(scopeRepository.findByDomainAndKey(DOMAIN, "my-scope")).thenReturn(Maybe.empty());
    TestObserver testObserver = new TestObserver();
    scopeService.create(DOMAIN, newScope).subscribe(testObserver);
    testObserver.assertError(MalformedIconUriException.class);
    testObserver.assertNotComplete();
    verify(scopeRepository, times(1)).findByDomainAndKey(DOMAIN, "my-scope");
    verify(scopeRepository, never()).create(any(Scope.class));
}
Also used : Scope(io.gravitee.am.model.oauth2.Scope) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 24 with Scope

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 ScopeServiceTest method shouldPatch_systemScope_discoveryNotReplaced.

@Test
public void shouldPatch_systemScope_discoveryNotReplaced() {
    PatchScope patch = new PatchScope();
    patch.setDiscovery(Optional.of(true));
    patch.setName(Optional.of("name"));
    final String scopeId = "toPatchId";
    Scope toPatch = new Scope();
    toPatch.setId(scopeId);
    toPatch.setSystem(true);
    toPatch.setDiscovery(false);
    toPatch.setName("oldName");
    toPatch.setDescription("oldDescription");
    ArgumentCaptor<Scope> argument = ArgumentCaptor.forClass(Scope.class);
    when(scopeRepository.findById(scopeId)).thenReturn(Maybe.just(toPatch));
    when(scopeRepository.update(argument.capture())).thenReturn(Single.just(new Scope()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    TestObserver testObserver = scopeService.patch(DOMAIN, scopeId, patch).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(scopeRepository, times(1)).update(any(Scope.class));
    assertNotNull(argument.getValue());
    assertEquals("name", argument.getValue().getName());
    assertEquals("oldDescription", argument.getValue().getDescription());
    assertFalse(argument.getValue().isDiscovery());
}
Also used : Scope(io.gravitee.am.model.oauth2.Scope) Event(io.gravitee.am.model.common.event.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 25 with Scope

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 ScopeServiceTest method shouldUpdateSystemScope.

@Test
public void shouldUpdateSystemScope() {
    UpdateSystemScope updateScope = new UpdateSystemScope();
    updateScope.setDiscovery(true);
    updateScope.setName("name");
    final String scopeId = "toUpdateId";
    Scope toUpdate = new Scope();
    toUpdate.setId(scopeId);
    toUpdate.setSystem(true);
    toUpdate.setDiscovery(false);
    toUpdate.setName("oldName");
    toUpdate.setDescription("oldDescription");
    ArgumentCaptor<Scope> argument = ArgumentCaptor.forClass(Scope.class);
    when(scopeRepository.findById(scopeId)).thenReturn(Maybe.just(toUpdate));
    when(scopeRepository.update(argument.capture())).thenReturn(Single.just(new Scope()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    TestObserver testObserver = scopeService.update(DOMAIN, scopeId, updateScope).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(scopeRepository, times(1)).update(any(Scope.class));
    assertNotNull(argument.getValue());
    assertEquals("name", argument.getValue().getName());
    assertNull(argument.getValue().getDescription());
    assertTrue(argument.getValue().isDiscovery());
}
Also used : Scope(io.gravitee.am.model.oauth2.Scope) Event(io.gravitee.am.model.common.event.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Aggregations

Scope (io.gravitee.am.model.oauth2.Scope)63 Test (org.junit.Test)43 TestObserver (io.reactivex.observers.TestObserver)25 Event (io.gravitee.am.model.common.event.Event)16 Page (io.gravitee.am.model.common.Page)15 Domain (io.gravitee.am.model.Domain)10 NewScope (io.gravitee.am.service.model.NewScope)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)8 Maybe (io.reactivex.Maybe)8 Single (io.reactivex.Single)8 RandomString (io.gravitee.am.common.utils.RandomString)7 ScopeRepository (io.gravitee.am.repository.management.api.ScopeRepository)7 Completable (io.reactivex.Completable)7 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)6 ApplicationOAuthSettings (io.gravitee.am.model.application.ApplicationOAuthSettings)6 Observable (io.reactivex.Observable)6 User (io.gravitee.am.identityprovider.api.User)5 ReferenceType (io.gravitee.am.model.ReferenceType)5 ApplicationScopeSettings (io.gravitee.am.model.application.ApplicationScopeSettings)5