Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Biasuzzi committed Jun 21, 2017
1 parent 69dfe3e commit 1aa3689
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ public EurostagEchExportConfig(boolean noGeneratorMinMaxQ, boolean noSwitch, Str
this.forbiddenCharactersReplacement = Objects.requireNonNull(forbiddenCharactersReplacement, "forbiddenCharactersReplacement (single char) string must not be null");
this.noGeneratorMinMaxQ = noGeneratorMinMaxQ;
this.noSwitch = noSwitch;
this.svcAsFixedInjectionInLF = svcAsFixedInjectionInLF;
this.specificCompatibility = specificCompatibility;
if (specificCompatibility) {
this.svcAsFixedInjectionInLF = true;
LOGGER.info("force svcAsFixedInjectionInLF to true (specificCompatibility is true)");
} else {
this.svcAsFixedInjectionInLF = svcAsFixedInjectionInLF;
}
if (forbiddenCharacters.contains(forbiddenCharactersReplacement.toString())) {
throw new IllegalArgumentException("forbiddenCharactersReplacement " + forbiddenCharactersReplacement + " must not appear also in the forbiddenCharacters string: " + forbiddenCharacters);
}
this.specificCompatibility = specificCompatibility;
}

public boolean isNoGeneratorMinMaxQ() {
Expand Down Expand Up @@ -99,18 +104,13 @@ public static EurostagEchExportConfig load(PlatformConfig platformConfig) {

// specificCompatibility parameter = true forces svcAsFixedInjectionInLF to true
ModuleConfig loadFlowModuleConfig = platformConfig.getModuleConfigIfExists("load-flow-default-parameters");
boolean specificCompatibility = (loadFlowModuleConfig != null) ? loadFlowModuleConfig.getBooleanProperty("specificCompatibility", false) : false;
LOGGER.info("load-flow-default-parameters/specificCompatibility: {}", specificCompatibility);
boolean specificCompatibility = (loadFlowModuleConfig != null) ? loadFlowModuleConfig.getBooleanProperty("specificCompatibility", DEFAULT_SPECIFIC_COMPATIBILITY) : DEFAULT_SPECIFIC_COMPATIBILITY;

if (platformConfig.moduleExists(EUROSTAG_ECH_EXPORT_CONFIG)) {
ModuleConfig config = platformConfig.getModuleConfig(EUROSTAG_ECH_EXPORT_CONFIG);
boolean noGeneratorMinMaxQ = config.getBooleanProperty("noGeneratorMinMaxQ", DEFAULT_NOGENERATORMINMAXQ);
boolean noSwitch = config.getBooleanProperty("noSwitch", DEFAULT_NOSWITCH);
boolean svcAsFixedInjectionInLF = config.getBooleanProperty("svcAsFixedInjectionInLF", DEFAULT_SVC_AS_FIXED_INJECTION_IN_LF);
if (specificCompatibility) {
svcAsFixedInjectionInLF = true;
LOGGER.info("force svcAsFixedInjectionInLF to true (specificCompatibility is true)");
}
String forbiddenCharacters = config.getStringProperty("forbiddenCharacters", DEFAULT_FORBIDDEN_CHARACTERS);
String replacementCharString = config.getStringProperty("forbiddenCharactersReplacement", DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT.toString());
if (replacementCharString.length() != 1) {
Expand All @@ -120,7 +120,7 @@ public static EurostagEchExportConfig load(PlatformConfig platformConfig) {
return new EurostagEchExportConfig(noGeneratorMinMaxQ, noSwitch, forbiddenCharacters, forbiddenCharactersReplacement, svcAsFixedInjectionInLF, specificCompatibility);
} else {
LOGGER.warn("no eurostag-ech-export config found: Using defaults.");
return new EurostagEchExportConfig(DEFAULT_NOGENERATORMINMAXQ, DEFAULT_NOSWITCH, DEFAULT_FORBIDDEN_CHARACTERS, DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT, DEFAULT_SVC_AS_FIXED_INJECTION_IN_LF, DEFAULT_SPECIFIC_COMPATIBILITY);
return new EurostagEchExportConfig(DEFAULT_NOGENERATORMINMAXQ, DEFAULT_NOSWITCH, DEFAULT_FORBIDDEN_CHARACTERS, DEFAULT_FORBIDDEN_CHARACTERS_REPLACEMENT, DEFAULT_SVC_AS_FIXED_INJECTION_IN_LF, specificCompatibility);
}
}

Expand All @@ -131,7 +131,7 @@ public String toString() {
", forbiddenCharacters=" + forbiddenCharacters +
", forbiddenCharactersReplacement=" + forbiddenCharactersReplacement +
", svcAsFixedInjectionInLF=" + svcAsFixedInjectionInLF +
", load-flow-default-parameters/specificCompatibility=" + specificCompatibility +
", specificCompatibility=" + specificCompatibility +
"]";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright (c) 2017, 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/.
*/
package eu.itesla_project.iidm.eurostag.export;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import eu.itesla_project.commons.config.InMemoryPlatformConfig;
import eu.itesla_project.commons.config.MapModuleConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.FileSystem;

import static org.junit.Assert.assertEquals;

/**
* @author Christian Biasuzzi <christian.biasuzzi@techrain.it>
*/
public class CheckEurostagEchExportConfigTest {

InMemoryPlatformConfig platformConfig;
FileSystem fileSystem;

@Before
public void setUp() {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
platformConfig = new InMemoryPlatformConfig(fileSystem);
MapModuleConfig defaultConfig = platformConfig.createModuleConfig("componentDefaultConfig");
}

@After
public void tearDown() throws Exception {
fileSystem.close();
}

private EurostagEchExportConfig getConfigFromFile(FileSystem fileSystem, boolean specificCompatibility) {
InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem);
MapModuleConfig moduleConfig = platformConfig.createModuleConfig("eurostag-ech-export");
moduleConfig.setStringProperty("svcAsFixedInjectionInLF", "false");

moduleConfig = platformConfig.createModuleConfig("load-flow-default-parameters");
moduleConfig.setStringProperty("specificCompatibility", Boolean.toString(specificCompatibility));

return EurostagEchExportConfig.load(platformConfig);
}


@Test
public void testConfig() throws IOException {
EurostagEchExportConfig config = new EurostagEchExportConfig();
assertEquals(false, config.isSvcAsFixedInjectionInLF());
}

@Test
public void testConfigFromFile() throws IOException {
EurostagEchExportConfig config = getConfigFromFile(fileSystem, false);
assertEquals(false, config.isSvcAsFixedInjectionInLF());
}

@Test
public void testConfigSpecificCompatibility() throws IOException {
EurostagEchExportConfig config = getConfigFromFile(fileSystem, true);
assertEquals(true, config.isSvcAsFixedInjectionInLF());
}


}

0 comments on commit 1aa3689

Please sign in to comment.