Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EventModelBuilder getter #361

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <laurent.issertial at rte-france.com>}
Expand All @@ -37,11 +38,8 @@ public final class ModelConfigsHandler {
new EventBuilderConfig(EventDisconnectionBuilder::of, EventDisconnectionBuilder.TAG),
new EventBuilderConfig(NodeFaultEventBuilder::of, NodeFaultEventBuilder.TAG));

private final Map<String, EventBuilderConfig.EventModelBuilderConstructor> eventBuilderConstructorByName = Map.of(
EventDisconnectionBuilder.TAG, EventDisconnectionBuilder::of,
NodeFaultEventBuilder.TAG, EventDisconnectionBuilder::of,
EventActivePowerVariationBuilder.TAG, EventActivePowerVariationBuilder::of
);
private final Map<String, EventBuilderConfig.EventModelBuilderConstructor> eventBuilderConstructorByName =
eventBuilderConfigs.stream().collect(Collectors.toMap(EventBuilderConfig::getTag, EventBuilderConfig::getBuilderConstructor));

private ModelConfigsHandler() {
List<ModelConfigLoader> modelConfigLoaders = Lists.newArrayList(ServiceLoader.load(ModelConfigLoader.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <laurent.issertial at rte-france.com>}
*/
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<DynamicModel> tagBuilder = MODEL_CONFIGS_HANDLER.getModelBuilder(NETWORK, lib, ReportNode.NO_OP);
ModelBuilder<DynamicModel> 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<EventModel> tagBuilder = MODEL_CONFIGS_HANDLER.getEventModelBuilder(NETWORK, eventBuilderConfig.getTag(), ReportNode.NO_OP);
ModelBuilder<EventModel> configBuilder = eventBuilderConfig.getBuilderConstructor().createBuilder(NETWORK, ReportNode.NO_OP);
assertNotNull(tagBuilder);
assertEquals(tagBuilder.getClass(), configBuilder.getClass());
}
}
}
Loading