diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index 2efe00fdd..b7079a812 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -36,6 +36,7 @@ public class RestNetworkStoreClient implements NetworkStoreClient { private static final Logger LOGGER = LoggerFactory.getLogger(RestNetworkStoreClient.class); private static final int RESOURCES_CREATION_CHUNK_SIZE = 1000; + public static final String RETRYING = "Retrying..."; private static final String STR_NETWORK = "network"; private static final String URL_NETWORK_UUID = "/networks/{networkUuid}"; private static final String STR_SUBSTATION = "substation"; @@ -54,6 +55,9 @@ public class RestNetworkStoreClient implements NetworkStoreClient { private static final String STR_HVDC_LINE = "hvdc line"; private static final String STR_TIE_LINE = "tie line"; private static final String STR_GROUND = "ground"; + public static final String STR_LOAD = "load"; + public static final String STR_LINE = "line"; + public static final String STR_CONFIGURED_BUSES = "bus"; private final RestClient restClient; @@ -85,7 +89,7 @@ private void create(String target, String url } catch (ResourceAccessException e) { LOGGER.error(e.toString(), e); // retry only one time - LOGGER.info("Retrying..."); + LOGGER.info(RETRYING); restClient.createAll(url, resourcePartition, uriVariables); } stopwatch.stop(); @@ -184,7 +188,7 @@ private void updateAll(String target, String } catch (ResourceAccessException e) { LOGGER.error(e.toString(), e); // retry only one time - LOGGER.info("Retrying..."); + LOGGER.info(RETRYING); updatePartition(target, url, attributeFilter, resourcePartition, uriVariables); } stopwatch.stop(); @@ -209,7 +213,7 @@ private void removeAll(String target, String url, UUID networkUuid, int variantN } catch (ResourceAccessException e) { LOGGER.error(e.toString(), e); // retry only one time - LOGGER.info("Retrying..."); + LOGGER.info(RETRYING); restClient.deleteAll(url, idsPartition, networkUuid, variantNum); } stopwatch.stop(); @@ -392,7 +396,7 @@ public void removeBatteries(UUID networkUuid, int variantNum, List batte @Override public List> getVoltageLevelLoads(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("load", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/loads", networkUuid, variantNum, voltageLevelId); + return getAll(STR_LOAD, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/loads", networkUuid, variantNum, voltageLevelId); } @Override @@ -457,12 +461,12 @@ public void removeThreeWindingsTransformers(UUID networkUuid, int variantNum, Li @Override public List> getVoltageLevelLines(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("line", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/lines", networkUuid, variantNum, voltageLevelId); + return getAll(STR_LINE, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/lines", networkUuid, variantNum, voltageLevelId); } @Override public void removeLines(UUID networkUuid, int variantNum, List linesId) { - removeAll("line", "/networks/{networkUuid}/{variantNum}/lines", networkUuid, variantNum, linesId); + removeAll(STR_LINE, "/networks/{networkUuid}/{variantNum}/lines", networkUuid, variantNum, linesId); } @Override @@ -523,27 +527,27 @@ public void updateBusbarSections(UUID networkUuid, List> loadResources) { - create("load", "/networks/{networkUuid}/loads", loadResources, networkUuid); + create(STR_LOAD, "/networks/{networkUuid}/loads", loadResources, networkUuid); } @Override public List> getLoads(UUID networkUuid, int variantNum) { - return getAll("load", "/networks/{networkUuid}/{variantNum}/loads", networkUuid, variantNum); + return getAll(STR_LOAD, "/networks/{networkUuid}/{variantNum}/loads", networkUuid, variantNum); } @Override public Optional> getLoad(UUID networkUuid, int variantNum, String loadId) { - return get("load", "/networks/{networkUuid}/{variantNum}/loads/{loadId}", networkUuid, variantNum, loadId); + return get(STR_LOAD, "/networks/{networkUuid}/{variantNum}/loads/{loadId}", networkUuid, variantNum, loadId); } @Override public void updateLoads(UUID networkUuid, List> loadResources, AttributeFilter attributeFilter) { - updateAll("load", "/networks/{networkUuid}/loads", loadResources, attributeFilter, networkUuid); + updateAll(STR_LOAD, "/networks/{networkUuid}/loads", loadResources, attributeFilter, networkUuid); } @Override public void removeLoads(UUID networkUuid, int variantNum, List loadsId) { - removeAll("load", "/networks/{networkUuid}/{variantNum}/loads", networkUuid, variantNum, loadsId); + removeAll(STR_LOAD, "/networks/{networkUuid}/{variantNum}/loads", networkUuid, variantNum, loadsId); } // generator @@ -638,22 +642,22 @@ public void updateThreeWindingsTransformers(UUID networkUuid, List> lineResources) { - create("line", "/networks/{networkUuid}/lines", lineResources, networkUuid); + create(STR_LINE, "/networks/{networkUuid}/lines", lineResources, networkUuid); } @Override public List> getLines(UUID networkUuid, int variantNum) { - return getAll("line", "/networks/{networkUuid}/{variantNum}/lines", networkUuid, variantNum); + return getAll(STR_LINE, "/networks/{networkUuid}/{variantNum}/lines", networkUuid, variantNum); } @Override public Optional> getLine(UUID networkUuid, int variantNum, String lineId) { - return get("line", "/networks/{networkUuid}/{variantNum}/lines/{lineId}", networkUuid, variantNum, lineId); + return get(STR_LINE, "/networks/{networkUuid}/{variantNum}/lines/{lineId}", networkUuid, variantNum, lineId); } @Override public void updateLines(UUID networkUuid, List> lineResources, AttributeFilter attributeFilter) { - updateAll("line", "/networks/{networkUuid}/lines", lineResources, attributeFilter, networkUuid); + updateAll(STR_LINE, "/networks/{networkUuid}/lines", lineResources, attributeFilter, networkUuid); } // shunt compensator @@ -802,32 +806,32 @@ public void updateDanglingLines(UUID networkUuid, List> busesResources) { - create("bus", "/networks/{networkUuid}/configured-buses", busesResources, networkUuid); + create(STR_CONFIGURED_BUSES, "/networks/{networkUuid}/configured-buses", busesResources, networkUuid); } @Override public List> getConfiguredBuses(UUID networkUuid, int variantNum) { - return getAll("bus", "/networks/{networkUuid}/{variantNum}/configured-buses", networkUuid, variantNum); + return getAll(STR_CONFIGURED_BUSES, "/networks/{networkUuid}/{variantNum}/configured-buses", networkUuid, variantNum); } @Override public List> getVoltageLevelConfiguredBuses(UUID networkUuid, int variantNum, String voltageLevelId) { - return getAll("bus", "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/configured-buses", networkUuid, variantNum, voltageLevelId); + return getAll(STR_CONFIGURED_BUSES, "/networks/{networkUuid}/{variantNum}/voltage-levels/{voltageLevelId}/configured-buses", networkUuid, variantNum, voltageLevelId); } @Override public Optional> getConfiguredBus(UUID networkUuid, int variantNum, String busId) { - return get("bus", "/networks/{networkUuid}/{variantNum}/configured-buses/{busId}", networkUuid, variantNum, busId); + return get(STR_CONFIGURED_BUSES, "/networks/{networkUuid}/{variantNum}/configured-buses/{busId}", networkUuid, variantNum, busId); } @Override public void updateConfiguredBuses(UUID networkUuid, List> busesResources, AttributeFilter attributeFilter) { - updateAll("bus", "/networks/{networkUuid}/configured-buses", busesResources, attributeFilter, networkUuid); + updateAll(STR_CONFIGURED_BUSES, "/networks/{networkUuid}/configured-buses", busesResources, attributeFilter, networkUuid); } @Override public void removeConfiguredBuses(UUID networkUuid, int variantNum, List busesId) { - removeAll("bus", "/networks/{networkUuid}/{variantNum}/configured-buses", networkUuid, variantNum, busesId); + removeAll(STR_CONFIGURED_BUSES, "/networks/{networkUuid}/{variantNum}/configured-buses", networkUuid, variantNum, busesId); } @Override diff --git a/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java b/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java index 6f2d18179..5d279463f 100644 --- a/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java +++ b/network-store-client/src/test/java/com/powsybl/network/store/client/RestNetworkStoreClientTest.java @@ -25,7 +25,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.client.HttpClientErrorException; import java.io.IOException; import java.time.ZonedDateTime; @@ -233,16 +232,6 @@ public void setUp() throws IOException { server.expect(requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/tie-lines")) .andExpect(method(GET)) .andRespond(withSuccess(tieLineJson, MediaType.APPLICATION_JSON)); - - server.expect(requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/substations")) - .andExpect(method(DELETE)) - .andExpect(content().string("[\"s1\"]")) - .andRespond(withSuccess()); - - server.expect(requestTo("/networks/" + networkUuid + "/" + Resource.INITIAL_VARIANT_NUM + "/substations")) - .andExpect(method(DELETE)) - .andExpect(content().string("[]")) - .andRespond(withBadRequest()); } @Test @@ -309,10 +298,6 @@ public void test() { tieLines = network.getTieLineStream().collect(Collectors.toList()); assertEquals(1, tieLines.size()); assertEquals("tieLine2", tieLines.get(0).getNameOrId()); - - assertDoesNotThrow(() -> restClient.deleteAll("/networks/{networkUuid}/{variantNum}/substations", List.of("s1"), networkUuid, Resource.INITIAL_VARIANT_NUM)); - HttpClientErrorException httpClientErrorException = assertThrows(HttpClientErrorException.class, () -> restClient.deleteAll("/networks/{networkUuid}/{variantNum}/substations", List.of(), networkUuid, Resource.INITIAL_VARIANT_NUM)); - assertEquals("400 Bad Request", httpClientErrorException.getMessage()); } }