|
9 | 9 | import com.powsybl.iidm.network.Network; |
10 | 10 | import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; |
11 | 11 | import com.powsybl.iidm.network.util.LimitViolationUtils; |
| 12 | +import com.powsybl.loadflow.LoadFlowParameters; |
| 13 | +import com.powsybl.network.store.client.NetworkStoreService; |
12 | 14 | import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl; |
13 | 15 | import com.powsybl.security.LimitViolationType; |
| 16 | +import org.gridsuite.computation.service.AbstractResultContext; |
14 | 17 | import org.gridsuite.loadflow.server.dto.LimitViolationInfos; |
| 18 | +import org.gridsuite.loadflow.server.dto.parameters.LoadFlowParametersValues; |
| 19 | +import org.gridsuite.loadflow.server.service.LoadFlowResultService; |
| 20 | +import org.gridsuite.loadflow.server.service.LoadFlowRunContext; |
15 | 21 | import org.gridsuite.loadflow.server.service.LoadFlowWorkerService; |
16 | 22 | import org.junit.jupiter.api.Assertions; |
17 | 23 | import org.junit.jupiter.api.Test; |
| 24 | +import org.mockito.InOrder; |
| 25 | +import org.springframework.beans.factory.annotation.Autowired; |
18 | 26 | import org.springframework.boot.test.context.SpringBootTest; |
| 27 | +import org.springframework.boot.test.mock.mockito.MockBean; |
| 28 | + |
| 29 | +import java.util.UUID; |
| 30 | + |
| 31 | +import static org.mockito.Mockito.*; |
19 | 32 |
|
20 | 33 | /** |
21 | 34 | * @author Kevin Le Saulnier <kevin.le-saulnier at rte-france.com> |
22 | 35 | */ |
23 | 36 | @SpringBootTest |
24 | 37 | class LoadFlowWorkerServiceTest { |
| 38 | + |
| 39 | + @MockBean |
| 40 | + private NetworkStoreService networkStoreService; |
| 41 | + |
| 42 | + @MockBean |
| 43 | + private LoadFlowResultService loadFlowResultService; |
| 44 | + |
| 45 | + @Autowired |
| 46 | + private LoadFlowWorkerService loadFlowWorkerService; |
| 47 | + |
25 | 48 | @Test |
26 | 49 | void testGetNextLimitName() { |
27 | 50 | Network network = EurostagTutorialExample1Factory.createWithFixedCurrentLimits(new NetworkFactoryImpl()); |
@@ -83,4 +106,28 @@ void testGetNoTemporaryLimitNextLimitName() { |
83 | 106 | String expectedNextLimitName = null; |
84 | 107 | Assertions.assertEquals(expectedNextLimitName, nextLimitName); |
85 | 108 | } |
| 109 | + |
| 110 | + @Test |
| 111 | + void testFlushIsCalledBeforeInsertResults() { |
| 112 | + Network network = mock(Network.class); |
| 113 | + LoadFlowRunContext runContext = mock(LoadFlowRunContext.class); |
| 114 | + AbstractResultContext<LoadFlowRunContext> resultContext = mock(AbstractResultContext.class); |
| 115 | + com.powsybl.loadflow.LoadFlowResult result = mock(com.powsybl.loadflow.LoadFlowResult.class); |
| 116 | + LoadFlowParametersValues parametersValues = mock(LoadFlowParametersValues.class); |
| 117 | + when(resultContext.getRunContext()).thenReturn(runContext); |
| 118 | + when(resultContext.getResultUuid()).thenReturn(UUID.randomUUID()); |
| 119 | + when(runContext.isApplySolvedValues()).thenReturn(false); |
| 120 | + when(runContext.getNetwork()).thenReturn(network); |
| 121 | + when(runContext.buildParameters()).thenReturn(mock(LoadFlowParameters.class)); |
| 122 | + when(runContext.getParameters()).thenReturn(parametersValues); |
| 123 | + when(parametersValues.getLimitReduction()).thenReturn(0.8f); |
| 124 | + when(result.isFailed()).thenReturn(false); |
| 125 | + |
| 126 | + loadFlowWorkerService.saveResult(network, resultContext, result); |
| 127 | + |
| 128 | + // Verify results save (flush) is done before inserting results in DB |
| 129 | + InOrder inOrder = inOrder(networkStoreService, loadFlowResultService); |
| 130 | + inOrder.verify(networkStoreService).flush(resultContext.getRunContext().getNetwork()); |
| 131 | + inOrder.verify(loadFlowResultService).insert(any(UUID.class), eq(result), any(), any(), any()); |
| 132 | + } |
86 | 133 | } |
0 commit comments