Skip to content
Snippets Groups Projects
Commit 8887f5c7 authored by Tobias Bruns's avatar Tobias Bruns
Browse files

OZG-6988 add reporint settings

parent 54ceeac3
No related branches found
No related tags found
1 merge request!3Ozg 6988 add reporting
package de.ozgcloud.admin.reporting;
import java.util.List;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.TypeAlias;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.jackson.Jacksonized;
@Document("settings")
@TypeAlias("reporting")
@Jacksonized
@Builder
@Getter
public class ReportingSetting {
@Id
private String id;
@Builder.Default
private String name = "reporting";
@NotBlank
private String formEngineName;
@NotBlank
private String formId;
@NotEmpty
private List<FieldMapping> mappings;
@Builder
@Getter
static class FieldMapping {
private String sourcePath;
private String targetPath;
}
}
package de.ozgcloud.admin.reporting;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource
public interface ReportingSettingRepository extends MongoRepository<ReportingSetting, String> {
}
package de.ozgcloud.admin.reporting;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import de.ozgcloud.common.test.DataITCase;
import lombok.SneakyThrows;
@AutoConfigureMockMvc
@WithMockUser(roles = "ADMIN_ADMIN")
@DataITCase
class ReportingSettingsITCase {
@Autowired
private MockMvc mockMvc;
@Autowired
private MongoOperations mongoOperations;
@BeforeEach
void clearDatabase() {
mongoOperations.dropCollection("settings");
}
@Test
@SneakyThrows
void shouldHaveLinkToReporting() {
mockMvc.perform(get("/api/configuration"))
.andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("$._links.reportingSettings").exists());
}
@Test
@SneakyThrows
void shouldDenyWhileMissingFields() {
mockMvc.perform(post("/api/configuration/reportingSettings").with(csrf())
.contentType(MediaType.APPLICATION_JSON).content("{}"))
.andExpect(status().isUnprocessableEntity());
}
@Disabled
@Test
@SneakyThrows
void shouldAddReportingSetting() {
mockMvc.perform(post("/api/configuration/reportingSettings").with(csrf())
.contentType(MediaType.APPLICATION_JSON).content("{}"))
.andExpect(status().isCreated());
var collection = mongoOperations.getCollection("settings");
assertThat(collection.countDocuments()).isEqualTo(1);
}
@Test
@SneakyThrows
void shouldListReportings() {
mockMvc.perform(get("/api/configuration/reportingSettings"))
.andExpect(status().is2xxSuccessful());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment