diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsHandler.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsHandler.java index fa0575e50..a8353a259 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsHandler.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsHandler.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.ServiceLoader; +import java.util.stream.Collectors; /** * @author Laurent Issertial {@literal } @@ -37,11 +38,8 @@ public final class ModelConfigsHandler { new EventBuilderConfig(EventDisconnectionBuilder::of, EventDisconnectionBuilder.TAG), new EventBuilderConfig(NodeFaultEventBuilder::of, NodeFaultEventBuilder.TAG)); - private final Map eventBuilderConstructorByName = Map.of( - EventDisconnectionBuilder.TAG, EventDisconnectionBuilder::of, - NodeFaultEventBuilder.TAG, EventDisconnectionBuilder::of, - EventActivePowerVariationBuilder.TAG, EventActivePowerVariationBuilder::of - ); + private final Map eventBuilderConstructorByName = + eventBuilderConfigs.stream().collect(Collectors.toMap(EventBuilderConfig::getTag, EventBuilderConfig::getBuilderConstructor)); private ModelConfigsHandler() { List modelConfigLoaders = Lists.newArrayList(ServiceLoader.load(ModelConfigLoader.class)); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/BuilderConfigTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/BuilderConfigTest.java new file mode 100644 index 000000000..3e50da712 --- /dev/null +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/BuilderConfigTest.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com/) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * SPDX-License-Identifier: MPL-2.0 + */ +package com.powsybl.dynawaltz.builders; + +import com.powsybl.commons.report.ReportNode; +import com.powsybl.dynamicsimulation.DynamicModel; +import com.powsybl.dynamicsimulation.EventModel; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * @author Laurent Issertial {@literal } + */ +class BuilderConfigTest { + + private static Network NETWORK; + private static ModelConfigsHandler MODEL_CONFIGS_HANDLER; + + @BeforeAll + static void setup() { + NETWORK = EurostagTutorialExample1Factory.create(); + MODEL_CONFIGS_HANDLER = ModelConfigsHandler.getInstance(); + } + + @Test + void testModelBuilders() { + for (BuilderConfig builderConfig : MODEL_CONFIGS_HANDLER.getBuilderConfigs()) { + String lib = builderConfig.getLibs().iterator().next(); + ModelBuilder tagBuilder = MODEL_CONFIGS_HANDLER.getModelBuilder(NETWORK, lib, ReportNode.NO_OP); + ModelBuilder configBuilder = builderConfig.getBuilderConstructor().createBuilder(NETWORK, lib, ReportNode.NO_OP); + assertNotNull(tagBuilder); + assertEquals(tagBuilder.getClass(), configBuilder.getClass()); + } + } + + @Test + void testEventBuilders() { + for (EventBuilderConfig eventBuilderConfig : MODEL_CONFIGS_HANDLER.getEventBuilderConfigs()) { + ModelBuilder tagBuilder = MODEL_CONFIGS_HANDLER.getEventModelBuilder(NETWORK, eventBuilderConfig.getTag(), ReportNode.NO_OP); + ModelBuilder configBuilder = eventBuilderConfig.getBuilderConstructor().createBuilder(NETWORK, ReportNode.NO_OP); + assertNotNull(tagBuilder); + assertEquals(tagBuilder.getClass(), configBuilder.getClass()); + } + } +}