66 */
77package org .gridsuite .modification .server .Impacts ;
88
9+ import com .fasterxml .jackson .core .JsonProcessingException ;
910import com .fasterxml .jackson .core .type .TypeReference ;
1011import com .fasterxml .jackson .databind .ObjectMapper ;
1112import com .powsybl .iidm .network .IdentifiableType ;
12- import lombok .SneakyThrows ;
1313import org .apache .commons .lang3 .tuple .Pair ;
1414import org .gridsuite .modification .server .dto .NetworkModificationResult ;
1515import org .gridsuite .modification .server .dto .NetworkModificationResult .ApplicationStatus ;
1616import org .gridsuite .modification .server .impacts .SimpleElementImpact ;
1717import org .gridsuite .modification .server .impacts .SimpleElementImpact .SimpleImpactType ;
18- import org .gridsuite .modification .server .utils .MatcherJson ;
19- import org .hamcrest .MatcherAssert ;
20- import org .skyscreamer .jsonassert .JSONAssert ;
21- import org .skyscreamer .jsonassert .JSONCompareMode ;
2218
2319import java .util .*;
2420import java .util .stream .Collectors ;
2521
26- import static org .hamcrest . MatcherAssert . assertThat ;
22+ import static org .gridsuite . modification . server . utils . assertions . Assertions .* ;
2723import static org .junit .Assert .assertEquals ;
2824import static org .junit .Assert .assertTrue ;
2925
3026/**
3127 * @author Slimane Amar <slimane.amar at rte-france.com>
3228 */
3329public final class TestImpactUtils {
34-
3530 private TestImpactUtils () {
3631 }
3732
38- @ SneakyThrows
39- public static void testEmptyImpacts (ObjectMapper mapper , String resultAsString ) {
40- Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() {
41- });
33+ public static void testEmptyImpacts (ObjectMapper mapper , String resultAsString ) throws JsonProcessingException {
34+ Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() { });
4235 assertTrue (networkModificationResult .isPresent ());
4336 testEmptyImpacts (mapper , networkModificationResult .get ());
4437 }
@@ -56,69 +49,60 @@ private static void testEmptyImpacts(ObjectMapper mapper, ApplicationStatus appl
5649 .applicationStatus (applicationStatusExpected )
5750 .networkImpacts (List .of ())
5851 .build ();
59-
60- MatcherAssert .assertThat (networkModificationResult , new MatcherJson <>(mapper , resultExpected ));
52+ assertThat (networkModificationResult ).recursivelyEquals (resultExpected );
6153 }
6254
63- @ SneakyThrows
64- public static void testElementImpacts (ObjectMapper mapper , String resultAsString , int nbImpacts , Set <String > substationIds ) {
65- Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() {
66- });
55+ public static void testElementImpacts (ObjectMapper mapper , String resultAsString , int nbImpacts , Set <String > substationIds ) throws JsonProcessingException {
56+ Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() { });
6757 assertTrue (networkModificationResult .isPresent ());
6858
6959 assertEquals (ApplicationStatus .ALL_OK , networkModificationResult .get ().getApplicationStatus ());
7060 assertEquals (new TreeSet <>(substationIds ), networkModificationResult .get ().getImpactedSubstationsIds ());
7161 assertEquals (nbImpacts , networkModificationResult .get ().getNetworkImpacts ().size ());
7262 }
7363
74- @ SneakyThrows
75- public static void testElementImpacts (ObjectMapper mapper , String resultAsString , List <SimpleElementImpact > elementImpactsExpected ) {
76- Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() {
77- });
64+ public static void testElementImpacts (ObjectMapper mapper , String resultAsString , List <SimpleElementImpact > elementImpactsExpected ) throws JsonProcessingException {
65+ Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() { });
7866 assertTrue (networkModificationResult .isPresent ());
7967 NetworkModificationResult resultExpected = NetworkModificationResult .builder ()
8068 .applicationStatus (ApplicationStatus .ALL_OK )
8169 .networkImpacts (elementImpactsExpected )
8270 .build ();
83- JSONAssert . assertEquals ( mapper . writeValueAsString ( resultExpected ), resultAsString , JSONCompareMode . NON_EXTENSIBLE );
71+ assertThat ( networkModificationResult . get ()). recursivelyEquals ( resultExpected );
8472 }
8573
86- public static void testElementCreationImpact (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) {
74+ public static void testElementCreationImpact (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) throws JsonProcessingException {
8775 testElementImpact (SimpleImpactType .CREATION , mapper , resultAsString , elementType , elementId , substationIds );
8876 }
8977
90- public static void testElementModificationImpact (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) {
78+ public static void testElementModificationImpact (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) throws JsonProcessingException {
9179 testElementImpact (SimpleImpactType .MODIFICATION , mapper , resultAsString , elementType , elementId , substationIds );
9280 }
9381
94- public static void testElementDeletionImpact (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) {
82+ public static void testElementDeletionImpact (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) throws JsonProcessingException {
9583 testElementImpact (SimpleImpactType .DELETION , mapper , resultAsString , elementType , elementId , substationIds );
9684 }
9785
98- @ SneakyThrows
99- public static void testElementImpact (SimpleImpactType impactType , ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) {
100- Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() {
101- });
86+ public static void testElementImpact (SimpleImpactType impactType , ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) throws JsonProcessingException {
87+ Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() { });
10288 assertTrue (networkModificationResult .isPresent ());
10389 NetworkModificationResult resultExpected = NetworkModificationResult .builder ()
10490 .applicationStatus (ApplicationStatus .ALL_OK )
105- .networkImpacts (List .of (createElementImpact (impactType , elementType , elementId , new TreeSet <>(substationIds ))))
91+ .networkImpacts (List .of (createElementImpact (impactType , elementType , elementId , new HashSet <>(substationIds ))))
10692 .build ();
107- assertThat (networkModificationResult .get (), new MatcherJson <>( mapper , resultExpected ) );
93+ assertThat (networkModificationResult .get ()). recursivelyEquals ( resultExpected );
10894 }
10995
110- @ SneakyThrows
11196 public static void testConnectableDeletionImpacts (ObjectMapper mapper , String resultAsString ,
11297 IdentifiableType connectableType , String connectableId ,
113- String breakerId , String disconnectorId , String substationId ) {
114- Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() {
115- });
98+ String breakerId , String disconnectorId , String substationId ) throws JsonProcessingException {
99+ Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() { });
116100 assertTrue (networkModificationResult .isPresent ());
117101 NetworkModificationResult resultExpected = NetworkModificationResult .builder ()
118102 .applicationStatus (ApplicationStatus .ALL_OK )
119103 .networkImpacts (createConnectableDeletionImpacts (connectableType , connectableId , breakerId , disconnectorId , substationId ))
120104 .build ();
121- assertThat (networkModificationResult .get (), new MatcherJson <>( mapper , resultExpected ) );
105+ assertThat (networkModificationResult .get ()). recursivelyEquals ( resultExpected );
122106 }
123107
124108 private static List <SimpleElementImpact > createConnectableDeletionImpacts (IdentifiableType connectableType , String connectableId ,
@@ -130,50 +114,45 @@ private static List<SimpleElementImpact> createConnectableDeletionImpacts(Identi
130114 );
131115 }
132116
133- @ SneakyThrows
134117 public static void testBranchCreationImpacts (ObjectMapper mapper , String resultAsString ,
135118 IdentifiableType branchType , String branchId ,
136119 String breakerId1 , String disconnectorId1 , String substationId1 ,
137- String breakerId2 , String disconnectorId2 , String substationId2 ) {
120+ String breakerId2 , String disconnectorId2 , String substationId2 ) throws JsonProcessingException {
138121 testBranchImpacts (mapper , SimpleImpactType .CREATION , resultAsString , branchType , branchId , breakerId1 , disconnectorId1 , substationId1 , breakerId2 , disconnectorId2 , substationId2 );
139122 }
140123
141- @ SneakyThrows
142- public static void testBranchCreationImpacts (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) {
124+ public static void testBranchCreationImpacts (ObjectMapper mapper , String resultAsString , IdentifiableType elementType , String elementId , Set <String > substationIds ) throws JsonProcessingException {
143125 List <SimpleElementImpact > impacts = List .of (
144126 createElementImpact (SimpleImpactType .CREATION , elementType , elementId , new TreeSet <>(substationIds )),
145127 createElementImpact (SimpleImpactType .MODIFICATION , elementType , elementId , new TreeSet <>(substationIds )) // case with newCurrentLimits1
146128 );
147129 testElementImpacts (mapper , resultAsString , impacts );
148130 }
149131
150- @ SneakyThrows
151132 public static void testBranchDeletionImpacts (ObjectMapper mapper , String resultAsString ,
152133 IdentifiableType branchType , String branchId ,
153134 String breakerId1 , String disconnectorId1 , String substationId1 ,
154- String breakerId2 , String disconnectorId2 , String substationId2 ) {
135+ String breakerId2 , String disconnectorId2 , String substationId2 ) throws JsonProcessingException {
155136 testBranchImpacts (mapper , SimpleImpactType .DELETION , resultAsString , branchType , branchId , breakerId1 , disconnectorId1 , substationId1 , breakerId2 , disconnectorId2 , substationId2 );
156137 }
157138
158- @ SneakyThrows
159139 public static void testBranchImpacts (ObjectMapper mapper , SimpleImpactType impactType , String resultAsString ,
160140 IdentifiableType branchType , String branchId ,
161141 String breakerId1 , String disconnectorId1 , String substationId1 ,
162- String breakerId2 , String disconnectorId2 , String substationId2 ) {
163- Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() {
164- });
142+ String breakerId2 , String disconnectorId2 , String substationId2 ) throws JsonProcessingException {
143+ Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() { });
165144 assertTrue (networkModificationResult .isPresent ());
166145 NetworkModificationResult resultExpected = NetworkModificationResult .builder ()
167146 .applicationStatus (ApplicationStatus .ALL_OK )
168147 .networkImpacts (createBranchImpacts (impactType , branchType , branchId , breakerId1 , disconnectorId1 , substationId1 , breakerId2 , disconnectorId2 , substationId2 ))
169148 .build ();
170- assertThat (networkModificationResult .get (), new MatcherJson <>( mapper , resultExpected ) );
149+ assertThat (networkModificationResult .get ()). recursivelyEquals ( resultExpected );
171150 }
172151
173152 private static List <SimpleElementImpact > createBranchImpacts (SimpleImpactType impactType , IdentifiableType branchType , String branchId ,
174153 String breakerId1 , String disconnectorId1 , String substationId1 ,
175154 String breakerId2 , String disconnectorId2 , String substationId2 ) {
176- LinkedList <SimpleElementImpact > impacts = new LinkedList <>(List .of (createElementImpact (impactType , branchType , branchId , new TreeSet <>(List .of (substationId1 , substationId2 )))));
155+ LinkedList <SimpleElementImpact > impacts = new LinkedList <>(List .of (createElementImpact (impactType , branchType , branchId , new HashSet <>(List .of (substationId1 , substationId2 )))));
177156 List <SimpleElementImpact > switchImpacts = List .of (
178157 createElementImpact (impactType , IdentifiableType .SWITCH , breakerId1 , Set .of (substationId1 )),
179158 createElementImpact (impactType , IdentifiableType .SWITCH , disconnectorId1 , Set .of (substationId1 )),
@@ -189,20 +168,18 @@ private static List<SimpleElementImpact> createBranchImpacts(SimpleImpactType im
189168 return impacts ;
190169 }
191170
192- @ SneakyThrows
193171 public static void test3WTDeletionImpacts (ObjectMapper mapper , String resultAsString , String w3tId ,
194172 String breakerId1 , String disconnectorId1 ,
195173 String breakerId2 , String disconnectorId2 ,
196174 String breakerId3 , String disconnectorId3 ,
197- String substationId ) {
198- Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() {
199- });
175+ String substationId ) throws JsonProcessingException {
176+ Optional <NetworkModificationResult > networkModificationResult = mapper .readValue (resultAsString , new TypeReference <>() { });
200177 assertTrue (networkModificationResult .isPresent ());
201178 NetworkModificationResult resultExpected = NetworkModificationResult .builder ()
202179 .applicationStatus (ApplicationStatus .ALL_OK )
203180 .networkImpacts (create3wtDeletionImpacts (w3tId , breakerId1 , disconnectorId1 , breakerId2 , disconnectorId2 , breakerId3 , disconnectorId3 , substationId ))
204181 .build ();
205- assertThat (networkModificationResult .get (), new MatcherJson <>( mapper , resultExpected ) );
182+ assertThat (networkModificationResult .get ()). recursivelyEquals ( resultExpected );
206183 }
207184
208185 private static List <SimpleElementImpact > create3wtDeletionImpacts (String w3tId ,
0 commit comments