Search in sources :

Example 1 with PatchDomain

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

the class DomainServiceTest method shouldPatch_technicalException.

@Test
public void shouldPatch_technicalException() {
    PatchDomain patchDomain = Mockito.mock(PatchDomain.class);
    when(domainRepository.findById("my-domain")).thenReturn(Maybe.error(TechnicalException::new));
    TestObserver testObserver = domainService.patch("my-domain", patchDomain).test();
    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
    verify(domainRepository, times(1)).findById(anyString());
    verify(domainRepository, never()).update(any(Domain.class));
}
Also used : NewDomain(io.gravitee.am.service.model.NewDomain) PatchDomain(io.gravitee.am.service.model.PatchDomain) TestObserver(io.reactivex.observers.TestObserver) PatchDomain(io.gravitee.am.service.model.PatchDomain) Test(org.junit.Test)

Example 2 with PatchDomain

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

the class DomainServiceTest method shouldNoPatch_ResetPasswordMultiFields_InvalidFields.

@Test
public void shouldNoPatch_ResetPasswordMultiFields_InvalidFields() {
    PatchDomain patchDomain = Mockito.mock(PatchDomain.class);
    Domain domain = new Domain();
    domain.setId("my-domain");
    domain.setHrid("my-domain");
    domain.setReferenceType(ReferenceType.ENVIRONMENT);
    domain.setReferenceId(ENVIRONMENT_ID);
    domain.setName("my-domain");
    domain.setPath("/test");
    final AccountSettings accountSettings = new AccountSettings();
    final FormField formField = new FormField();
    formField.setKey("unknown");
    accountSettings.setResetPasswordCustomFormFields(Arrays.asList(formField));
    accountSettings.setResetPasswordCustomForm(true);
    domain.setAccountSettings(accountSettings);
    when(patchDomain.patch(any())).thenReturn(domain);
    when(domainRepository.findById("my-domain")).thenReturn(Maybe.just(domain));
    doReturn(false).when(accountSettingsValidator).validate(any());
    TestObserver testObserver = domainService.patch("my-domain", patchDomain).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertNotComplete();
    testObserver.assertError(InvalidParameterException.class);
    verify(domainRepository, times(1)).findById(anyString());
    verify(domainRepository, never()).update(any(Domain.class));
    verify(eventService, never()).create(any());
}
Also used : AccountSettings(io.gravitee.am.model.account.AccountSettings) NewDomain(io.gravitee.am.service.model.NewDomain) PatchDomain(io.gravitee.am.service.model.PatchDomain) FormField(io.gravitee.am.model.account.FormField) TestObserver(io.reactivex.observers.TestObserver) PatchDomain(io.gravitee.am.service.model.PatchDomain) Test(org.junit.Test)

Example 3 with PatchDomain

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

the class DomainServiceTest method shouldPatch_NoResetPasswordMultiFields.

@Test
public void shouldPatch_NoResetPasswordMultiFields() {
    PatchDomain patchDomain = Mockito.mock(PatchDomain.class);
    Domain domain = new Domain();
    domain.setId("my-domain");
    domain.setHrid("my-domain");
    domain.setReferenceType(ReferenceType.ENVIRONMENT);
    domain.setReferenceId(ENVIRONMENT_ID);
    domain.setName("my-domain");
    domain.setPath("/test");
    final AccountSettings accountSettings = new AccountSettings();
    accountSettings.setResetPasswordCustomForm(false);
    domain.setAccountSettings(accountSettings);
    when(patchDomain.patch(any())).thenReturn(domain);
    when(domainRepository.findById("my-domain")).thenReturn(Maybe.just(domain));
    when(domainRepository.findByHrid(ReferenceType.ENVIRONMENT, ENVIRONMENT_ID, domain.getHrid())).thenReturn(Maybe.just(domain));
    when(environmentService.findById(ENVIRONMENT_ID)).thenReturn(Single.just(new Environment()));
    when(domainRepository.findAll()).thenReturn(Flowable.empty());
    when(domainRepository.update(any(Domain.class))).thenReturn(Single.just(domain));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    doReturn(Single.just(List.of()).ignoreElement()).when(domainValidator).validate(any(), any());
    doReturn(Single.just(List.of()).ignoreElement()).when(virtualHostValidator).validateDomainVhosts(any(), any());
    doReturn(true).when(accountSettingsValidator).validate(any());
    TestObserver testObserver = domainService.patch("my-domain", patchDomain).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(domainRepository, times(1)).findById(anyString());
    verify(domainRepository, times(1)).update(any(Domain.class));
    verify(eventService, times(1)).create(any());
}
Also used : AccountSettings(io.gravitee.am.model.account.AccountSettings) Event(io.gravitee.am.model.common.event.Event) NewDomain(io.gravitee.am.service.model.NewDomain) PatchDomain(io.gravitee.am.service.model.PatchDomain) TestObserver(io.reactivex.observers.TestObserver) PatchDomain(io.gravitee.am.service.model.PatchDomain) Test(org.junit.Test)

Example 4 with PatchDomain

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

the class DomainServiceTest method shouldPatch_domainNotFound.

@Test
public void shouldPatch_domainNotFound() {
    PatchDomain patchDomain = Mockito.mock(PatchDomain.class);
    when(domainRepository.findById("my-domain")).thenReturn(Maybe.empty());
    TestObserver testObserver = domainService.patch("my-domain", patchDomain).test();
    testObserver.assertError(DomainNotFoundException.class);
    testObserver.assertNotComplete();
    verify(domainRepository, times(1)).findById(anyString());
    verify(domainRepository, never()).update(any(Domain.class));
}
Also used : NewDomain(io.gravitee.am.service.model.NewDomain) PatchDomain(io.gravitee.am.service.model.PatchDomain) TestObserver(io.reactivex.observers.TestObserver) PatchDomain(io.gravitee.am.service.model.PatchDomain) Test(org.junit.Test)

Example 5 with PatchDomain

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

the class DomainResourceTest method shouldUpdateFilteredDomain.

@Test
public void shouldUpdateFilteredDomain() {
    Domain mockDomain = buildDomainMock();
    PatchDomain patchDomain = new PatchDomain();
    patchDomain.setDescription(Optional.of("New description"));
    doReturn(Single.just(true)).when(permissionService).hasPermission(any(User.class), any(PermissionAcls.class));
    // only domain read permission
    doReturn(Single.just(Permission.of(Permission.DOMAIN, Acl.READ))).when(permissionService).findAllPermissions(any(User.class), any(ReferenceType.class), anyString());
    doReturn(Single.just(mockDomain)).when(domainService).patch(eq(mockDomain.getId()), any(PatchDomain.class), any(User.class));
    final Response response = put(target("domains").path(mockDomain.getId()), patchDomain);
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    final Domain domain = readEntity(response, Domain.class);
    assertEquals(mockDomain.getId(), domain.getId());
    assertEquals(mockDomain.getName(), domain.getName());
    assertEquals(mockDomain.getDescription(), domain.getDescription());
    assertEquals(mockDomain.isEnabled(), domain.isEnabled());
    assertEquals(mockDomain.getCreatedAt(), domain.getCreatedAt());
    assertEquals(mockDomain.getUpdatedAt(), domain.getUpdatedAt());
    assertEquals(mockDomain.getPath(), domain.getPath());
    assertEquals(mockDomain.getReferenceType(), domain.getReferenceType());
    assertEquals(mockDomain.getReferenceId(), domain.getReferenceId());
    assertNull(domain.getOidc());
    assertNull(domain.getScim());
    assertNull(domain.getLoginSettings());
    assertNull(domain.getAccountSettings());
    assertNull(domain.getTags());
}
Also used : Response(javax.ws.rs.core.Response) User(io.gravitee.am.identityprovider.api.User) PatchDomain(io.gravitee.am.service.model.PatchDomain) PermissionAcls(io.gravitee.am.management.service.permissions.PermissionAcls) PatchDomain(io.gravitee.am.service.model.PatchDomain) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Aggregations

PatchDomain (io.gravitee.am.service.model.PatchDomain)14 Test (org.junit.Test)12 NewDomain (io.gravitee.am.service.model.NewDomain)7 TestObserver (io.reactivex.observers.TestObserver)7 Response (javax.ws.rs.core.Response)6 User (io.gravitee.am.identityprovider.api.User)5 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)5 PermissionAcls (io.gravitee.am.management.service.permissions.PermissionAcls)4 AccountSettings (io.gravitee.am.model.account.AccountSettings)3 Event (io.gravitee.am.model.common.event.Event)3 FormField (io.gravitee.am.model.account.FormField)2 Acl (io.gravitee.am.model.Acl)1 Domain (io.gravitee.am.model.Domain)1 Entrypoint (io.gravitee.am.model.Entrypoint)1 Permission (io.gravitee.am.model.permissions.Permission)1 EntrypointService (io.gravitee.am.service.EntrypointService)1 DomainNotFoundException (io.gravitee.am.service.exception.DomainNotFoundException)1 PatchClientRegistrationSettings (io.gravitee.am.service.model.openid.PatchClientRegistrationSettings)1 PatchOIDCSettings (io.gravitee.am.service.model.openid.PatchOIDCSettings)1 MediaType (io.gravitee.common.http.MediaType)1