diff --git a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java index 5805d111..6da24f16 100644 --- a/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java +++ b/src/test/java/org/gridsuite/filter/server/FilterEntityControllerTest.java @@ -22,7 +22,6 @@ import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; -import jakarta.servlet.ServletException; import org.apache.commons.collections4.OrderedMap; import org.apache.commons.collections4.map.LinkedMap; import org.gridsuite.filter.AbstractFilter; @@ -64,11 +63,8 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.util.CollectionUtils; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import java.util.*; -import java.util.stream.Stream; import static org.apache.commons.lang3.StringUtils.join; import static org.gridsuite.filter.server.repositories.proxies.AbstractFilterRepositoryProxy.WRONG_FILTER_TYPE; @@ -220,240 +216,12 @@ public String joinWithComma(Object... array) { return join(array, ","); } - @Test - public void testLineFilter() throws Exception { - String userId = "userId"; - UUID filterId1 = UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"); - UUID filterId2 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"); - Date modificationDate = new Date(); - - LineFilter lineFilter = LineFilter.builder().equipmentID("NHV1_NHV2_1") - .substationName1("P1") - .substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))) - .countries2(new TreeSet<>(Set.of("FR"))) - .freeProperties2(Map.of("region", List.of("north"))) - .freeProperties1(Map.of("region", List.of("south"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)) - .nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)) - .build(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - filterId1, - modificationDate, - lineFilter - ); - insertFilter(filterId1, lineCriteriaFilter); - checkFormFilter(filterId1, lineCriteriaFilter); - - // export - assertThrows("Network '" + NETWORK_NOT_FOUND_UUID + "' not found", ServletException.class, () -> mvc.perform(get(URL_TEMPLATE + "/" + filterId1 + "/export?networkUuid=" + NETWORK_NOT_FOUND_UUID) - .contentType(APPLICATION_JSON))); - - mvc.perform(get(URL_TEMPLATE + "/" + filterId1 + "/export").param("networkUuid", NETWORK_UUID.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)) - .andExpect(content().json("[{\"id\":\"NHV1_NHV2_1\",\"type\":\"LINE\"}]")); - - List filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", filterId1.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - - Date dateModification = filterAttributes.get(0).getModificationDate(); - - CriteriaFilter hvdcLineCriteriaFilter = new CriteriaFilter( - filterId1, - dateModification, - HvdcLineFilter.builder() - .equipmentID("equipmentID") - .equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2") - .countries1(COUNTRIES1) - .countries2(COUNTRIES2) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 50., null)) - .build() - ); - modifyFormFilter(filterId1, hvdcLineCriteriaFilter, userId); - checkFormFilter(filterId1, hvdcLineCriteriaFilter); - - var res = mvc.perform(get(URL_TEMPLATE)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(); - filterAttributes = objectMapper.readValue(res, new TypeReference<>() { - }); - assertEquals(1, filterAttributes.size()); - if (!filterAttributes.get(0).getId().equals(filterId1)) { - Collections.reverse(filterAttributes); - } - - matchFilterInfos(filterAttributes.get(0), filterId1, FilterType.CRITERIA, EquipmentType.HVDC_LINE, modificationDate); - - filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", filterId1.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - assertEquals(1, filterAttributes.size()); - matchFilterInfos(filterAttributes.get(0), filterId1, FilterType.CRITERIA, EquipmentType.HVDC_LINE, modificationDate); - - // test replace line filter with other filter type - AbstractFilter generatorFormFilter = new CriteriaFilter( - filterId1, - modificationDate, - new GeneratorFilter("eqId1", "gen1", "s1", new TreeSet<>(Set.of("FR", "BE")), null, null, new NumericalFilter(RangeType.RANGE, 50., null), null) - ); - - modifyFormFilter(filterId1, generatorFormFilter, userId); - - filterAttributes = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/metadata").param("ids", filterId1.toString()) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - assertEquals(1, filterAttributes.size()); - matchFilterInfos(filterAttributes.get(0), filterId1, FilterType.CRITERIA, EquipmentType.GENERATOR, modificationDate); - - // update with same type filter - AbstractFilter generatorFormFilter2 = new CriteriaFilter( - filterId1, - modificationDate, - new GeneratorFilter("eqId2", "gen2", "s2", new TreeSet<>(Set.of("FR", "BE")), null, null, new NumericalFilter(RangeType.RANGE, 50., null), null) - ); - modifyFormFilter(filterId1, generatorFormFilter2, userId); - - // delete - mvc.perform(delete(URL_TEMPLATE + "/" + filterId2)).andExpect(status().isNotFound()); - - mvc.perform(get(URL_TEMPLATE + "/" + filterId2)).andExpect(status().isNotFound()); - - filterService.deleteAll(); - } - - @Test - public void testLineFilter2() throws Exception { - String userId = "userId"; - UUID filterId3 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300c"); - UUID filterId4 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300d"); - Date modificationDate = new Date(); - - // a 2-country network (one substation FR, one BE) - final double p2NominalVoltage = 63.; - network6.getLine("NHV1_NHV2_2").getTerminal2().getVoltageLevel().setNominalV(p2NominalVoltage); // patch just for better coverage - final String noMatch = "[]"; - final String bothMatch = "[{\"id\":\"NHV1_NHV2_1\",\"type\":\"LINE\"},{\"id\":\"NHV1_NHV2_2\",\"type\":\"LINE\"}]"; - - List rangeTypes = new ArrayList<>(); - rangeTypes.add(RangeType.EQUALITY); - List values1 = new ArrayList<>(); - values1.add(p2NominalVoltage); - List values2 = new ArrayList<>(); - values2.add(null); - - CriteriaFilter lineCriteriaFilterBEFR = insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("BE")), new TreeSet<>(Set.of("FR")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, bothMatch, false); - - // more country filters - rangeTypes.add(RangeType.GREATER_OR_EQUAL); - rangeTypes.set(0, RangeType.GREATER_OR_EQUAL); - values1.set(0, 0.); - values1.add(0.); - values2.add(null); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("BE")), new TreeSet<>(Set.of("FR")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, bothMatch, true); - - network6.getSubstation("P2").setCountry(Country.FR); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("IT")), new TreeSet<>(Set.of("FR")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, noMatch, true); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of()), new TreeSet<>(Set.of("IT")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, noMatch, true); - network6.getSubstation("P1").setCountry(Country.IT); - insertLineFilter(filterId3, null, null, null, new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("IT")), - rangeTypes, values1, values2, NETWORK_UUID_6, null, bothMatch, true); - - filterService.deleteAll(); - } - - @Test - public void testGeneratorFilter() throws Exception { - final String generatorUuid = "42b70a4d-e0c4-413a-8e3e-78e9027d300f"; - final String noMatch = "[]"; - final String oneMatch = "[{\"id\":\"GEN\",\"type\":\"GENERATOR\"}]"; - final String bothMatch = "[{\"id\":\"GEN\",\"type\":\"GENERATOR\"}, {\"id\":\"GEN2\",\"type\":\"GENERATOR\"}]"; - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, oneMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, oneMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "nameNotFound", "P1", null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", null, null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, oneMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "substationNameNotFound", null, RangeType.RANGE, 15., 30., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.EQUALITY, 145., null, null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 19., 22., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 27., 30., null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 34.30, 35.70, null, NETWORK_UUID, null, noMatch); - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - "GEN", "GEN", "P1", Set.of("FR", "IT"), RangeType.RANGE, 14.55, 15.45, null, NETWORK_UUID, null, noMatch); - // no filter at all - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - null, null, null, null, null, 0., 0., null, NETWORK_UUID, null, bothMatch); - // no SOLAR generator - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - null, null, null, null, null, 0., 0., EnergySource.SOLAR, NETWORK_UUID, null, noMatch); - // 2 OTHER generators in our network - insertInjectionFilter(EquipmentType.GENERATOR, UUID.fromString(generatorUuid), - null, null, null, null, null, 0., 0., EnergySource.OTHER, NETWORK_UUID, null, bothMatch); - } - - @Test - public void testLoadFilter() throws Exception { - insertInjectionFilter(EquipmentType.LOAD, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "LOAD", null, "P2", Set.of("FR"), RangeType.RANGE, 144., 176., null, NETWORK_UUID, VARIANT_ID_1, "[{\"id\":\"LOAD\",\"type\":\"LOAD\"}]"); - } - - @Test - public void testShuntCompensatorFilter() throws Exception { - insertInjectionFilter(EquipmentType.SHUNT_COMPENSATOR, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "SHUNT", null, "S1", Set.of("FR"), RangeType.EQUALITY, 380., null, null, NETWORK_UUID_4, null, "[{\"id\":\"SHUNT\",\"type\":\"SHUNT_COMPENSATOR\"}]"); - } - - @Test - public void testStaticVarCompensatorFilter() throws Exception { - insertInjectionFilter(EquipmentType.STATIC_VAR_COMPENSATOR, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "SVC3", null, "S2", null, null, null, null, null, NETWORK_UUID_3, null, "[{\"id\":\"SVC3\",\"type\":\"STATIC_VAR_COMPENSATOR\"}]"); - } - - @Test - public void testBatteryFilter() throws Exception { - insertInjectionFilter(EquipmentType.BATTERY, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "batteryId1", "batteryName", null, Set.of("FR"), RangeType.RANGE, 45., 65., null, NETWORK_UUID, null, "[]"); - } - @Test public void testBusBarSectionFilter() throws Exception { insertInjectionFilter(EquipmentType.BUSBAR_SECTION, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), null, "batteryName", null, Set.of("DE"), RangeType.EQUALITY, 380., null, null, NETWORK_UUID, null, "[]"); } - @Test - public void testDanglingLineFilter() throws Exception { - insertInjectionFilter(EquipmentType.DANGLING_LINE, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "danglingLineId1", null, "s2", Set.of("FR"), RangeType.RANGE, 138., 162., null, NETWORK_UUID, null, "[]"); - } @Test public void testLccConverterStationFilter() throws Exception { @@ -467,318 +235,6 @@ public void testVscConverterStationFilter() throws Exception { "vscId1", "vscName1", "s2", null, RangeType.EQUALITY, 225., null, null, NETWORK_UUID, null, "[]"); } - @Test - public void testHvdcLineFilter() throws Exception { - final String noMatch = "[]"; - final String matchHVDCLine = "[{\"id\":\"L\",\"type\":\"HVDC_LINE\"}]"; - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("FR", "BE")), new TreeSet<>(Set.of("FR", "IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, matchHVDCLine); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "substationNameNotFound", new TreeSet<>(Set.of("FR", "BE")), new TreeSet<>(Set.of("FR", "IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "substationNameNotFound", "S1", new TreeSet<>(Set.of("FR", "BE")), new TreeSet<>(Set.of("FR", "IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("IT")), new TreeSet<>(Set.of("FR")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, noMatch); - network2.getSubstation("S1").setCountry(Country.IT); - insertHvdcLineFilter(UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, "HVDC", "S1", "S2", new TreeSet<>(Set.of("FR")), new TreeSet<>(Set.of("IT")), RangeType.RANGE, 380., 420., NETWORK_UUID_2, null, matchHVDCLine); - } - - @Test - public void testTwoWindingsTransformerFilter() throws Exception { - List rangeTypes = new ArrayList<>(); - rangeTypes.add(RangeType.EQUALITY); - rangeTypes.add(RangeType.RANGE); - List values1 = new ArrayList<>(); - values1.add(380.); - values1.add(142.5); - List values2 = new ArrayList<>(); - values2.add(null); - values2.add(157.5); - - // with this network (EurostagTutorialExample1Factory::create), we have 2 2WT Transfos: - // - NGEN_NHV1 term1: 24 kV term2: 380 kV - // - NHV2_NLOAD term1: 380 kV term2: 150 kV - final String noMatch = "[]"; - final String matchNHV2NLOAD = "[{\"id\":\"NHV2_NLOAD\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"}]"; - final String matchNGENNHV1 = "[{\"id\":\"NGEN_NHV1\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"}]"; - final String bothMatch = "[{\"id\":\"NHV2_NLOAD\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"},{\"id\":\"NGEN_NHV1\",\"type\":\"TWO_WINDINGS_TRANSFORMER\"}]"; - - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "NHV2_NLOAD", null, "P2", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - // no eqpt/substation filter: only NHV2_NLOAD match because of RANGE filter - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - // bad substationName - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "NHV2_NLOAD", null, "substationNameNotFound", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, noMatch); - // this network has only FR substations: IT does not match: - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "NHV2_NLOAD", null, "P2", Set.of("IT"), rangeTypes, values1, values2, null, NETWORK_UUID, null, noMatch); - - // change RANGE into "> 24" - rangeTypes.set(1, RangeType.GREATER_THAN); - values1.set(1, 24.); - values2.set(1, null); - // NGEN_NHV1 still does not match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - - // change "> 24" into ">= 24" - rangeTypes.set(1, RangeType.GREATER_OR_EQUAL); - // both transfos now match both filters - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, bothMatch); - - // change "== 380" into ">= 0" - // change ">= 24" into "< 380" - rangeTypes.set(0, RangeType.GREATER_OR_EQUAL); - values1.set(0, 0.); - rangeTypes.set(1, RangeType.LESS_THAN); - values1.set(1, 380.); - // both match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, bothMatch); - // add substation filter on P1 => NGENNHV1 - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, "P1", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNGENNHV1); - // add substation filter on P2 => NHV2NLOAD - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, "P2", Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNHV2NLOAD); - - // change "< 380" into "< 150" - values1.set(1, 150.); - // only NGEN_NHV1 match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, matchNGENNHV1); - - // change "< 150" into "<= 150" - rangeTypes.set(1, RangeType.LESS_OR_EQUAL); - // both match - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, bothMatch); - - // match second terminal property - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, Map.of("region", List.of("south")), NETWORK_UUID, null, matchNHV2NLOAD); - - // change ">=0" into "> 400" - rangeTypes.set(0, RangeType.GREATER_OR_EQUAL); - values1.set(0, 400.); - // [400..150] not possible - insertTransformerFilter(EquipmentType.TWO_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR"), rangeTypes, values1, values2, null, NETWORK_UUID, null, noMatch); - } - - @Test - public void testThreeWindingsTransformerFilter() throws Exception { - List rangeTypes = new ArrayList<>(); - rangeTypes.add(RangeType.RANGE); - rangeTypes.add(RangeType.EQUALITY); - rangeTypes.add(RangeType.EQUALITY); - List values1 = new ArrayList<>(); - values1.add(127.); - values1.add(33.); - values1.add(11.); - List values2 = new ArrayList<>(); - values2.add(134.); - values2.add(null); - values2.add(null); - - // with this network (ThreeWindingsTransformerNetworkFactory.create), we have a single 3WT: - // - 3WT term1: 132 kV term2: 33 kV term3: 11 kV - final String noMatch = "[]"; - final String match3WT = "[{\"id\":\"3WT\",\"type\":\"THREE_WINDINGS_TRANSFORMER\"}]"; - - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "3WT", null, "SUBSTATION", Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // same without eqpt / sybstation - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // bad substationName - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "3WT", null, "substationNameNotFound", Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - // IT does not match - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - "3WT", null, "SUBSTATION", Set.of("IT"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Current filters have covered OR #1/6 in get3WTransformerList - - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #2/6 - values1.set(1, 11.); - values1.set(2, 33.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #3/6 - values1.set(0, 33.); - values2.set(0, 33.); - values1.set(1, 132.); - values1.set(2, 11.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #4/6 - values1.set(1, 11.); - values1.set(2, 132.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #5/6 - values1.set(0, 10.); - values2.set(0, 12.); - values1.set(1, 132.); - values1.set(2, 33.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - - // Update filters to cover OR #6/6 - values1.set(1, 33.); - values1.set(2, 132.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, match3WT); - - // variant to increase coverage - values1.set(2, 500.); - insertTransformerFilter(EquipmentType.THREE_WINDINGS_TRANSFORMER, UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"), - null, null, null, Set.of("FR", "CH"), rangeTypes, values1, values2, null, NETWORK_UUID_5, null, noMatch); - } - - @Test - public void testVoltageLevelFilter() throws Exception { - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("FR", "IT"), RangeType.RANGE, 15., 30., NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", null, RangeType.RANGE, 15., 30., NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "nameNotFound", null, RangeType.RANGE, 15., 30., NETWORK_UUID, null, "[]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", null, RangeType.RANGE, 20., 27., NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", null, RangeType.RANGE, 29., 36., NETWORK_UUID, null, "[]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("FR", "IT"), RangeType.EQUALITY, 150., null, NETWORK_UUID, null, "[]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("FR", "IT"), RangeType.EQUALITY, 24., null, NETWORK_UUID, null, "[{\"id\":\"VLGEN\",\"type\":\"VOLTAGE_LEVEL\"}]"); - insertVoltageLevelFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "VLGEN", "VLGEN", Set.of("ES", "PT"), null, null, null, NETWORK_UUID, null, "[]"); - } - - @Test - public void testSubstationFilter() throws Exception { - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "P1", Set.of("FR", "IT"), NETWORK_UUID, null, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"}]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "P1", null, NETWORK_UUID, null, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"}]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "nameNotFound", null, NETWORK_UUID, null, "[]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P1", "P1", Set.of("ES", "PT"), NETWORK_UUID, null, "[]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P2", null, Set.of("FR", "IT"), NETWORK_UUID, null, "[{\"id\":\"P2\",\"type\":\"SUBSTATION\"}]"); - insertSubstationFilter(UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300f"), - "P2", null, Set.of("ES", "PT"), NETWORK_UUID, null, "[]"); - } - - @Test - public void testLineFilterCrud() throws Exception { - UUID filterId1 = UUID.fromString("99999999-e0c4-413a-8e3e-78e9027d300f"); - LineFilter lineFilter = LineFilter.builder().equipmentID("equipmentID").equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES1).countries2(COUNTRIES2) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 5., 8.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 6., null)) - .build(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - null, - new Date(), - lineFilter - ); - - // --- insert filter --- // - insertFilter(filterId1, lineCriteriaFilter); - - // check the inserted filter - lineCriteriaFilter.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter); - - // --- duplicate filter -- // - UUID newFilterId1 = duplicateFilter(filterId1); - - // check the duplicated filter whether it is matched to the original - lineCriteriaFilter.setId(newFilterId1); - checkFormFilter(newFilterId1, lineCriteriaFilter); - - // --- modify filter --- // - LineFilter lineFilter2 = LineFilter.builder().equipmentID("equipmentID").equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES2).countries2(COUNTRIES1) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 4., 9.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 5., null)) - .build(); - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - null, - new Date(), - lineFilter2 - ); - updateFilter(filterId1, lineCriteriaFilter2, "userId"); - - // check the modified filter - lineCriteriaFilter2.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter2); - - // --- modify filter with equipment type changed --- // - GeneratorFilter generatorFilter = GeneratorFilter.builder().equipmentID("eqId1").equipmentName("gen1") - .substationName("s1") - .countries(new TreeSet<>(Set.of("FR", "BE"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 50., null)) - .build(); - CriteriaFilter generatorCriteriaFilter = new CriteriaFilter( - null, - new Date(), - generatorFilter - ); - updateFilter(filterId1, generatorCriteriaFilter, "userId"); - - // check the modified filter - generatorCriteriaFilter.setId(filterId1); - checkFormFilter(filterId1, generatorCriteriaFilter); - - // --- delete filters --- // - deleteFilter(filterId1); - deleteFilter(newFilterId1); - - // check empty after delete all - List allFilters = getAllFilters(); - Assertions.assertThat(allFilters).isEmpty(); - } - @Test public void testIdentifierListFilter() throws Exception { UUID filterId = UUID.fromString("77614d91-c168-4f89-8fb9-77a23729e88e"); @@ -847,182 +303,6 @@ public void testIdentifierListFilter() throws Exception { checkIdentifierListFilterExportAndMetadata(substationFilterId, "[{\"id\":\"P1\",\"type\":\"SUBSTATION\"},{\"id\":\"P2\",\"type\":\"SUBSTATION\"}]\n", EquipmentType.SUBSTATION); } - @Test - public void testGetFiltersByIds() throws Exception { - UUID filterId3 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300c"); - UUID filterId4 = UUID.fromString("42b70a4d-e0c4-413a-8e3e-78e9027d300d"); - - LineFilter lineFilter = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - filterId3, - new Date(), - lineFilter - ); - insertFilter(filterId3, lineCriteriaFilter); - checkFormFilter(filterId3, lineCriteriaFilter); - - LineFilter lineFilter2 = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - filterId4, - new Date(), - lineFilter2 - ); - - insertFilter(filterId4, lineCriteriaFilter2); - checkFormFilter(filterId4, lineCriteriaFilter2); - } - - @Test - public void testExportFilters() throws Exception { - UUID filterId = UUID.randomUUID(); - UUID filterId2 = UUID.randomUUID(); - UUID filterId3 = UUID.randomUUID(); - - LineFilter lineFilter = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - Date date = new Date(); - CriteriaFilter lineCriteriaFilter = new CriteriaFilter( - filterId2, - date, - lineFilter - ); - insertFilter(filterId2, lineCriteriaFilter); - checkFormFilter(filterId2, lineCriteriaFilter); - - LineFilter lineFilter2 = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - filterId3, - date, - lineFilter2 - ); - - insertFilter(filterId3, lineCriteriaFilter2); - checkFormFilter(filterId3, lineCriteriaFilter2); - - IdentifierListFilterEquipmentAttributes attribute1 = new IdentifierListFilterEquipmentAttributes("GEN", 1.0); - IdentifierListFilterEquipmentAttributes attribute2 = new IdentifierListFilterEquipmentAttributes("wrongId", 2.0); - IdentifierListFilterEquipmentAttributes attribute3 = new IdentifierListFilterEquipmentAttributes("wrongId2", 3.0); - - IdentifierListFilter identifierListFilter = new IdentifierListFilter(filterId, - date, - EquipmentType.GENERATOR, - List.of(attribute1, attribute2, attribute3)); - insertFilter(filterId, identifierListFilter); - checkIdentifierListFilter(filterId, identifierListFilter); - - List values = Arrays.asList(filterId.toString(), filterId2.toString(), filterId3.toString()); - MultiValueMap params = new LinkedMultiValueMap<>(); - params.addAll("ids", values); - params.add("networkUuid", NETWORK_UUID.toString()); - params.add("variantId", VARIANT_ID_1); - - List filterEquipments = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/export").params(params) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - IdentifiableAttributes identifiableAttributes = new IdentifiableAttributes("GEN", IdentifiableType.GENERATOR, 1.0); - IdentifiableAttributes identifiableAttributes4 = new IdentifiableAttributes("NHV1_NHV2_1", IdentifiableType.LINE, null); - - FilterEquipments filterEquipment1 = FilterEquipments.builder() - .filterId(filterId) - .identifiableAttributes(List.of(identifiableAttributes)) - .notFoundEquipments(List.of("wrongId", "wrongId2")) - .build(); - - FilterEquipments filterEquipment2 = FilterEquipments.builder() - .filterId(filterId2) - .identifiableAttributes(List.of(identifiableAttributes4)) - .build(); - - FilterEquipments filterEquipment3 = FilterEquipments.builder() - .filterId(filterId3) - .identifiableAttributes(List.of(identifiableAttributes4)) - .build(); - - assertEquals(3, filterEquipments.size()); - List expected = new ArrayList<>(List.of(filterEquipment1, filterEquipment2, filterEquipment3)); - checkFilterEquipments(expected, filterEquipments); - - } - - @Test - public void testGetIdentifiablesCount() throws Exception { - UUID filterId1 = UUID.randomUUID(); - UUID filterId2 = UUID.randomUUID(); - UUID filterId3 = UUID.randomUUID(); - - LineFilter lineFilter1 = LineFilter.builder().equipmentID("NHV1_NHV2_1").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - CriteriaFilter lineCriteriaFilter1 = new CriteriaFilter( - filterId1, - new Date(), - lineFilter1 - ); - insertFilter(filterId1, lineCriteriaFilter1); - checkFormFilter(filterId1, lineCriteriaFilter1); - - LineFilter lineFilter2 = LineFilter.builder().equipmentID("NHV1_NHV2_2").substationName1("P1").substationName2("P2") - .countries1(new TreeSet<>(Set.of("FR"))).countries2(new TreeSet<>(Set.of("FR"))) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 360., 400.)).nominalVoltage2(new NumericalFilter(RangeType.RANGE, 356.25, 393.75)).build(); - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - filterId2, - new Date(), - lineFilter2 - ); - insertFilter(filterId2, lineCriteriaFilter2); - checkFormFilter(filterId2, lineCriteriaFilter2); - - Date modificationDate = new Date(); - CriteriaFilter hvdcLineFilter = new CriteriaFilter( - filterId3, - modificationDate, - HvdcLineFilter.builder().equipmentID("NHV1_NHV2_3").equipmentName("equipmentName_3") - .substationName1("substationName1").substationName2("substationName2") - .countries1(new TreeSet<>(Set.of("FR", "BE"))).countries2(new TreeSet<>(Set.of("FR", "IT"))) - .freeProperties2(Map.of("region", List.of("north"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 380., 420.)) - .build() - ); - insertFilter(filterId3, hvdcLineFilter); - checkFormFilter(filterId3, hvdcLineFilter); - - MultiValueMap params = new LinkedMultiValueMap<>(Map.of( - "networkUuid", List.of(NETWORK_UUID.toString()), - "variantId", List.of(VARIANT_ID_1), - "ids[g1]", List.of(filterId1.toString()), - "ids[g2]", List.of(filterId2.toString()), - "ids[g3]", List.of(filterId3.toString()), - "ids[g4]", List.of(UUID.randomUUID().toString()) - )); - Map identifiablesCount = objectMapper.readValue( - mvc.perform(get(URL_TEMPLATE + "/identifiables-count") - .params(params) - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn().getResponse().getContentAsString(), - new TypeReference<>() { - }); - assertEquals(1, identifiablesCount.get("g1").longValue()); - assertEquals(1, identifiablesCount.get("g2").longValue()); - assertEquals(0, identifiablesCount.get("g3").longValue()); - assertEquals(0, identifiablesCount.get("g4").longValue()); - - assertEquals(4, identifiablesCount.size()); - } - private void checkFilterEquipments(List filterEquipments1, List filterEquipments2) { assertEquals(CollectionUtils.isEmpty(filterEquipments1), CollectionUtils.isEmpty(filterEquipments2)); assertEquals(filterEquipments1.size(), filterEquipments2.size()); @@ -2148,120 +1428,4 @@ public void testExpertFilterLoadLinkToOtherFilterWithIsPartOfOperator() throws E checkFilterEvaluating(expertFilter, expectedResultJson); } - @Test - public void testLineFiltersCrudInBatch() throws Exception { - UUID filterId1 = UUID.randomUUID(); - LineFilter lineFilter1 = LineFilter.builder().equipmentID("equipmentID1").equipmentName("equipmentName1") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES1).countries2(COUNTRIES2) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 5., 8.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 6., null)) - .build(); - CriteriaFilter lineCriteriaFilter1 = new CriteriaFilter( - null, - new Date(), - lineFilter1 - ); - - UUID filterId2 = UUID.randomUUID(); - LineFilter lineFilter2 = LineFilter.builder().equipmentID("equipmentID2").equipmentName("equipmentName2") - .substationName1("substationName3").countries1(COUNTRIES1).countries2(COUNTRIES2) - .substationName2("substationName4") - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 4., 9.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 5., null)) - .build(); - CriteriaFilter lineCriteriaFilter2 = new CriteriaFilter( - null, - new Date(), - lineFilter2 - ); - - Map filtersToCreateMap = Map.of( - filterId1, lineCriteriaFilter1, - filterId2, lineCriteriaFilter2 - ); - - // --- insert in batch --- // - insertFilters(filtersToCreateMap); - - // check inserted filters - lineCriteriaFilter1.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter1); - lineCriteriaFilter2.setId(filterId2); - checkFormFilter(filterId2, lineCriteriaFilter2); - - // --- duplicate in batch --- // - Map sourceAndNewUuidMap = duplicateFilters(List.of(filterId1, filterId2)); - - sourceAndNewUuidMap.forEach((sourceUuid, newUuid) -> filtersToCreateMap.get(sourceUuid).setId(newUuid)); - - // check each duplicated filter whether it is matched to the original - for (Map.Entry entry : sourceAndNewUuidMap.entrySet()) { - UUID sourceUuid = entry.getKey(); - UUID newUuid = entry.getValue(); - checkFormFilter(newUuid, (CriteriaFilter) filtersToCreateMap.get(sourceUuid)); - } - - // --- modify filters in batch --- // - LineFilter lineFilter3 = LineFilter.builder().equipmentID("equipmentID").equipmentName("equipmentName") - .substationName1("substationName1") - .substationName2("substationName2").countries1(COUNTRIES2).countries2(COUNTRIES1) - .nominalVoltage1(new NumericalFilter(RangeType.RANGE, 3., 10.)) - .nominalVoltage2(new NumericalFilter(RangeType.EQUALITY, 4., null)) - .build(); - CriteriaFilter lineCriteriaFilter3 = new CriteriaFilter( - null, - new Date(), - lineFilter3 - ); - GeneratorFilter generatorFilter = GeneratorFilter.builder().equipmentID("eqId1").equipmentName("gen1") - .substationName("s1") - .countries(new TreeSet<>(Set.of("FR", "BE"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 50., null)) - .build(); - CriteriaFilter generatorCriteriaFilter = new CriteriaFilter( - null, - new Date(), - generatorFilter - ); - Map filtersToUpdateMap = Map.of( - filterId1, lineCriteriaFilter3, - filterId2, generatorCriteriaFilter - ); - updateFilters(filtersToUpdateMap); - - // check modified filters - lineCriteriaFilter3.setId(filterId1); - checkFormFilter(filterId1, lineCriteriaFilter3); - generatorCriteriaFilter.setId(filterId2); - checkFormFilter(filterId2, generatorCriteriaFilter); - - // --- modify filters in batch with a none existing id --- // - GeneratorFilter generatorFilter2 = GeneratorFilter.builder().equipmentID("eqId1").equipmentName("gen1") - .substationName("s1") - .countries(new TreeSet<>(Set.of("FR", "BE"))) - .nominalVoltage(new NumericalFilter(RangeType.RANGE, 60., null)) - .build(); - CriteriaFilter generatorCriteriaFilter2 = new CriteriaFilter( - null, - new Date(), - generatorFilter2 - ); - - Map filtersToUpdateMap2 = Map.of( - UUID.randomUUID(), lineCriteriaFilter3, - filterId2, generatorCriteriaFilter2 - ); - updateFiltersWithNoneExistingId(filtersToUpdateMap2); - // check modified filters => filter with filterId2 should not be changed - checkFormFilter(filterId2, generatorCriteriaFilter); - - // --- delete filters in batch -- // - deleteFilters(Stream.concat(sourceAndNewUuidMap.keySet().stream(), sourceAndNewUuidMap.values().stream()).toList()); - - // check empty after delete all - List allFilters = getAllFilters(); - Assertions.assertThat(allFilters).isEmpty(); - } - }