Search in sources :

Example 6 with Form

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);
}
Also used : Form(io.gravitee.am.model.Form) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 7 with Form

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);
}
Also used : Form(io.gravitee.am.model.Form) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 8 with Form

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);
}
Also used : Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) User(io.gravitee.am.identityprovider.api.User) Form(io.gravitee.am.model.Form) ReferenceType(io.gravitee.am.model.ReferenceType) io.swagger.annotations(io.swagger.annotations) URI(java.net.URI) NewForm(io.gravitee.am.service.model.NewForm) Context(javax.ws.rs.core.Context) Permissions.of(io.gravitee.am.management.service.permissions.Permissions.of) AsyncResponse(javax.ws.rs.container.AsyncResponse) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Template(io.gravitee.am.model.Template) ResourceContext(javax.ws.rs.container.ResourceContext) FormService(io.gravitee.am.service.FormService) Permissions.or(io.gravitee.am.management.service.permissions.Permissions.or) User(io.gravitee.am.identityprovider.api.User) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException)

Example 9 with Form

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);
}
Also used : Email(io.gravitee.am.model.Email) Form(io.gravitee.am.model.Form) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 10 with Form

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);
}
Also used : Form(io.gravitee.am.model.Form) Event(io.gravitee.am.model.common.event.Event) List(java.util.List) Test(org.junit.Test)

Aggregations

Form (io.gravitee.am.model.Form)22 Test (org.junit.Test)15 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)8 User (io.gravitee.am.identityprovider.api.User)5 NewForm (io.gravitee.am.service.model.NewForm)5 List (java.util.List)5 Response (javax.ws.rs.core.Response)5 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)3 Domain (io.gravitee.am.model.Domain)3 ReferenceType (io.gravitee.am.model.ReferenceType)3 Template (io.gravitee.am.model.Template)3 FormService (io.gravitee.am.service.FormService)3 Maybe (io.reactivex.Maybe)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)2 Acl (io.gravitee.am.model.Acl)2 Event (io.gravitee.am.model.common.event.Event)2 Permission (io.gravitee.am.model.permissions.Permission)2 DomainService (io.gravitee.am.service.DomainService)2 DomainNotFoundException (io.gravitee.am.service.exception.DomainNotFoundException)2