use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormServiceTest method copyFromClient_duplicateFound.
@Test
public void copyFromClient_duplicateFound() {
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");
when(formRepository.findByClientAndTemplate(ReferenceType.DOMAIN, DOMAIN, targetUid, "login")).thenReturn(Maybe.just(new Form()));
when(formRepository.findByClient(ReferenceType.DOMAIN, DOMAIN, sourceUid)).thenReturn(Flowable.just(formOne));
TestObserver<List<Form>> testObserver = formService.copyFromClient(DOMAIN, sourceUid, targetUid).test();
testObserver.assertNotComplete();
testObserver.assertError(FormAlreadyExistsException.class);
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class ApplicationFormsResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a form for an application", notes = "User must have APPLICATION_FORM[CREATE] permission on the specified application " + "or APPLICATION_FORM[CREATE] permission on the specified domain " + "or APPLICATION_FORM[CREATE] permission on the specified environment " + "or APPLICATION_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, @PathParam("application") String application, @ApiParam(name = "email", required = true) @Valid @NotNull final NewForm newForm, @Suspended final AsyncResponse response) {
final User authenticatedUser = getAuthenticatedUser();
checkAnyPermission(organizationId, environmentId, domain, application, Permission.APPLICATION_FORM, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMap(irrelevant -> applicationService.findById(application)).switchIfEmpty(Maybe.error(new ApplicationNotFoundException(application))).flatMapSingle(irrelevant -> formService.create(domain, application, newForm, authenticatedUser)).map(form -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/applications/" + application + "/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 MongoFormRepository method convert.
private Form convert(FormMongo pageMongo) {
if (pageMongo == null) {
return null;
}
Form page = new Form();
page.setId(pageMongo.getId());
page.setEnabled(pageMongo.isEnabled());
page.setReferenceType(ReferenceType.valueOf(pageMongo.getReferenceType()));
page.setReferenceId(pageMongo.getReferenceId());
page.setClient(pageMongo.getClient());
page.setTemplate(pageMongo.getTemplate());
page.setContent(pageMongo.getContent());
page.setAssets(pageMongo.getAssets());
page.setCreatedAt(pageMongo.getCreatedAt());
page.setUpdatedAt(pageMongo.getUpdatedAt());
return page;
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormsResourceTest method shouldCreate.
@Test
@Ignore
public void shouldCreate() {
final String domainId = "domain-1";
final Domain mockDomain = new Domain();
mockDomain.setId(domainId);
NewForm newForm = new NewForm();
newForm.setTemplate(Template.LOGIN);
newForm.setContent("content");
doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
doReturn(Single.just(new Form())).when(formService).create(eq(domainId), any(), any(User.class));
final Response response = target("domains").path(domainId).path("forms").request().post(Entity.json(newForm));
assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormRepositoryTest method shouldFindByClientAndTemplate.
@Test
public void shouldFindByClientAndTemplate() {
final int loop = 10;
for (int i = 0; i < loop; i++) {
final Form form = buildForm();
form.setReferenceId(FIXED_REF_ID);
form.setClient(FIXED_CLI_ID);
repository.create(form).blockingGet();
}
final Form form = buildForm();
form.setReferenceId(FIXED_REF_ID);
form.setClient(FIXED_CLI_ID);
form.setTemplate("MyTemplateId");
Form templateForm = repository.create(form).blockingGet();
TestObserver<Form> testMaybe = repository.findByClientAndTemplate(ReferenceType.DOMAIN, FIXED_REF_ID, FIXED_CLI_ID, "MyTemplateId").test();
testMaybe.awaitTerminalEvent();
testMaybe.assertNoErrors();
assertEqualsTo(templateForm, templateForm.getId(), testMaybe);
}
Aggregations