use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormRepositoryTest method shouldFindById.
@Test
public void shouldFindById() {
Form form = buildForm();
Form createdForm = repository.create(form).blockingGet();
TestObserver<Form> testObserver = repository.findById(createdForm.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
assertEqualsTo(form, createdForm.getId(), testObserver);
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormRepositoryTest method shouldUpdateEmail.
@Test
public void shouldUpdateEmail() {
Form form = buildForm();
Form createdForm = repository.create(form).blockingGet();
TestObserver<Form> testObserver = repository.findById(createdForm.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
assertEqualsTo(form, createdForm.getId(), testObserver);
Form updatableForm = buildForm();
updatableForm.setId(createdForm.getId());
TestObserver<Form> updatedForm = repository.update(updatableForm).test();
updatedForm.awaitTerminalEvent();
assertEqualsTo(updatableForm, createdForm.getId(), updatedForm);
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormsResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a form", notes = "User must have the DOMAIN_FORM[CREATE] permission on the specified domain " + "or DOMAIN_FORM[CREATE] permission on the specified environment " + "or DOMAIN_FORM[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Form successfully created"), @ApiResponse(code = 500, message = "Internal server error") })
public void create(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @ApiParam(name = "form", required = true) @Valid @NotNull final NewForm newForm, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, Permission.DOMAIN_FORM, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMapSingle(irrelevant -> formService.create(domain, newForm, authenticatedUser).map(form -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/forms/" + form.getId())).entity(form).build()))).subscribe(response::resume, response::resume);
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class ClientServiceTest method shouldDelete.
@Test
public void shouldDelete() {
when(applicationService.delete("my-client", null)).thenReturn(Completable.complete());
Form form = new Form();
form.setId("form-id");
Email email = new Email();
email.setId("email-id");
TestObserver testObserver = clientService.delete("my-client").test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
verify(applicationService, times(1)).delete("my-client", null);
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormServiceTest method copyFromClient.
@Test
public void copyFromClient() {
final String sourceUid = "sourceUid";
final String targetUid = "targetUid";
Form formOne = new Form();
formOne.setId("templateId");
formOne.setEnabled(true);
formOne.setReferenceType(ReferenceType.DOMAIN);
formOne.setReferenceId(DOMAIN);
formOne.setClient(sourceUid);
formOne.setTemplate("login");
formOne.setContent("formContent");
formOne.setAssets("formAsset");
Form formTwo = new Form(formOne);
formTwo.setTemplate("error");
when(formRepository.findByClientAndTemplate(ReferenceType.DOMAIN, DOMAIN, targetUid, "login")).thenReturn(Maybe.empty());
when(formRepository.findByClientAndTemplate(ReferenceType.DOMAIN, DOMAIN, targetUid, "error")).thenReturn(Maybe.empty());
when(formRepository.create(any())).thenAnswer(i -> Single.just(i.getArgument(0)));
when(formRepository.findByClient(ReferenceType.DOMAIN, DOMAIN, sourceUid)).thenReturn(Flowable.just(formOne, formTwo));
when(eventService.create(any())).thenReturn(Single.just(new Event()));
TestObserver<List<Form>> testObserver = formService.copyFromClient(DOMAIN, sourceUid, targetUid).test();
testObserver.assertComplete().assertNoErrors();
testObserver.assertValue(forms -> forms.size() == 2 && forms.stream().filter(form -> form.getReferenceId().equals(DOMAIN) && form.getClient().equals(targetUid) && !form.getId().equals("templateId") && Arrays.asList("login", "error").contains(form.getTemplate()) && form.getContent().equals("formContent") && form.getAssets().equals("formAsset")).count() == 2);
}
Aggregations