|
| 1 | +/** |
| 2 | + * Copyright (c) 2025, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | +package org.gridsuite.mapping.server; |
| 8 | + |
| 9 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 10 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 11 | +import org.gridsuite.mapping.server.model.RuleEntity; |
| 12 | +import org.gridsuite.mapping.server.repository.RuleRepository; |
| 13 | +import org.gridsuite.mapping.server.utils.EquipmentType; |
| 14 | +import org.gridsuite.mapping.server.utils.SetGroupType; |
| 15 | +import org.junit.Before; |
| 16 | +import org.junit.Test; |
| 17 | +import org.junit.runner.RunWith; |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; |
| 19 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| 20 | +import org.springframework.boot.test.context.SpringBootTest; |
| 21 | +import org.springframework.test.context.ContextConfiguration; |
| 22 | +import org.springframework.test.context.junit4.SpringRunner; |
| 23 | +import org.springframework.test.web.servlet.MockMvc; |
| 24 | +import org.springframework.test.web.servlet.MvcResult; |
| 25 | +import org.springframework.transaction.annotation.Transactional; |
| 26 | + |
| 27 | +import java.util.List; |
| 28 | +import java.util.UUID; |
| 29 | + |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 32 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 33 | + |
| 34 | +/** |
| 35 | + * @author Mathieu Deharbe <mathieu.deharbe at rte-france.com> |
| 36 | + */ |
| 37 | +@RunWith(SpringRunner.class) |
| 38 | +@SpringBootTest |
| 39 | +@AutoConfigureMockMvc |
| 40 | +@ContextConfiguration(classes = {MappingApplication.class}) |
| 41 | +public class SupervisionControllerTest { |
| 42 | + |
| 43 | + @Autowired |
| 44 | + private RuleRepository ruleRepository; |
| 45 | + |
| 46 | + @Autowired |
| 47 | + private MockMvc mvc; |
| 48 | + |
| 49 | + @Autowired |
| 50 | + private ObjectMapper objectMapper; |
| 51 | + |
| 52 | + private final UUID filter1Uuid = UUID.randomUUID(); |
| 53 | + private final UUID filter2Uuid = UUID.randomUUID(); |
| 54 | + |
| 55 | + @Before |
| 56 | + public void setUp() { |
| 57 | + cleanDB(); |
| 58 | + RuleEntity rule1 = new RuleEntity(UUID.randomUUID(), EquipmentType.LINE, "null", "setGroup", SetGroupType.FIXED, filter1Uuid, null); |
| 59 | + RuleEntity rule2 = new RuleEntity(UUID.randomUUID(), EquipmentType.LINE, "null", "setGroup", SetGroupType.FIXED, filter2Uuid, null); |
| 60 | + ruleRepository.save(rule1); |
| 61 | + ruleRepository.save(rule2); |
| 62 | + } |
| 63 | + |
| 64 | + private void cleanDB() { |
| 65 | + ruleRepository.deleteAll(); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + @Transactional |
| 70 | + public void testGetFiltersList() throws Exception { |
| 71 | + MvcResult result = mvc.perform(get("/supervision/filters")) |
| 72 | + .andExpect(status().isOk()) |
| 73 | + .andReturn(); |
| 74 | + |
| 75 | + // check result |
| 76 | + String filtersJson = result.getResponse().getContentAsString(); |
| 77 | + List<UUID> filters = objectMapper.readValue(filtersJson, new TypeReference<>() { }); |
| 78 | + assertThat(filters).containsExactlyInAnyOrder(filter1Uuid, filter2Uuid); |
| 79 | + } |
| 80 | +} |
0 commit comments