use of com.bakdata.conquery.models.forms.frontendconfiguration.FormType in project conquery by bakdata.
the class FormConfigTest method getConfigs.
@Test
public void getConfigs() {
// PREPARE
user.addPermission(dataset.createPermission(Ability.READ.asSet()));
user.addPermission(FormPermission.onInstance(Ability.CREATE, form.getFormType()));
ExportForm form2 = new ExportForm();
RelativeMode mode3 = new RelativeMode();
form2.setTimeMode(mode3);
mode3.setForm(form);
mode3.setFeatures(List.of(new CQConcept()));
mode3.setOutcomes(List.of(new CQConcept()));
TestForm form3 = new TestForm();
ObjectMapper mapper = FormConfigProcessor.getMAPPER();
FormConfigAPI formConfig = FormConfigAPI.builder().formType(form.getFormType()).values(mapper.valueToTree(form)).build();
FormConfigAPI formConfig2 = FormConfigAPI.builder().formType(form2.getFormType()).values(mapper.valueToTree(form2)).build();
// This should not be retrieved by the user because it does not hold the Permission to create TestForms
FormConfigAPI formConfig3 = FormConfigAPI.builder().formType(form3.getFormType()).values(mapper.valueToTree(form2)).build();
FormConfigId formId = processor.addConfig(user, dataset, formConfig).getId();
FormConfigId formId2 = processor.addConfig(user, dataset, formConfig2).getId();
FormConfigId _formId3 = processor.addConfig(user, dataset, formConfig3).getId();
FormScanner.FRONTEND_FORM_CONFIGS = Map.of(form.getFormType(), new FormType(form.getFormType(), new TextNode("dummy")));
// EXECUTE
Stream<FormConfigOverviewRepresentation> response = processor.getConfigsByFormType(user, dataset, Collections.emptySet());
// CHECK
assertThat(response).containsExactlyInAnyOrder(FormConfigOverviewRepresentation.builder().formType(form.getClass().getAnnotation(CPSType.class).id()).id(formId).label(formConfig.getLabel()).own(true).ownerName(user.getLabel()).shared(false).system(false).tags(formConfig.getTags()).createdAt(formConfig.getCreationTime().atZone(ZoneId.systemDefault())).build(), FormConfigOverviewRepresentation.builder().formType(form2.getClass().getAnnotation(CPSType.class).id()).id(formId2).label(formConfig2.getLabel()).own(true).ownerName(user.getLabel()).shared(false).system(false).tags(formConfig2.getTags()).createdAt(formConfig2.getCreationTime().atZone(ZoneId.systemDefault())).build());
}
Aggregations