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));
}
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());
}
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());
}
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));
}
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());
}
Aggregations