org.apache.commons.io.output.NullWriter Java Examples
The following examples show how to use
org.apache.commons.io.output.NullWriter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatusTest.java From appstatus with Apache License 2.0 | 6 votes |
@Test public void testSuccess() throws UnsupportedEncodingException, IOException { final AppStatus appStatus = new AppStatus(); final StatusWebHandler statusWeb = new StatusWebHandler(); statusWeb.setAppStatus(appStatus); statusWeb.setApplicationName("test"); final Map<String, IPage> pages = new HashMap<String, IPage>(); final StatusPage page = new StatusPage(); pages.put(page.getId(), page); statusWeb.setPages(pages); statusWeb.init(); final HttpServletRequest servlet = mock(HttpServletRequest.class); final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final StubServletOutputStream sos = new StubServletOutputStream(); when(response.getWriter()).thenReturn(new PrintWriter(new NullWriter())); when(response.getOutputStream()).thenReturn(sos); page.doGet(statusWeb, request, response); verify(response).setStatus(200); }
Example #2
Source File: TransformersValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Test public void checkTwtsValues() { assertTrue(TransformersValidation.INSTANCE.checkTransformer("test", rho, rhoPreviousStep, rhoNextStep, tapPosition, lowTapPosition, highTapPosition, targetV, regulatedSide, v, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // Error >= -Max(UpIncrement, DownIncrement) assertFalse(TransformersValidation.INSTANCE.checkTransformer("test", rho, rhoPreviousStep, rhoNextStep, tapPosition, lowTapPosition, highTapPosition, targetV, regulatedSide, lowV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(TransformersValidation.INSTANCE.checkTransformer("test", rho, Float.NaN, rhoNextStep, lowTapPosition, lowTapPosition, highTapPosition, targetV, regulatedSide, lowV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // Error <= -Min(UpIncrement, DownIncrement) assertFalse(TransformersValidation.INSTANCE.checkTransformer("test", rho, rhoPreviousStep, rhoNextStep, tapPosition, lowTapPosition, highTapPosition, targetV, regulatedSide, highV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(TransformersValidation.INSTANCE.checkTransformer("test", rho, rhoPreviousStep, Float.NaN, highTapPosition, lowTapPosition, highTapPosition, targetV, regulatedSide, highV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // check NaN vales assertFalse(TransformersValidation.INSTANCE.checkTransformer("test", rho, rhoPreviousStep, rhoNextStep, tapPosition, lowTapPosition, highTapPosition, Float.NaN, regulatedSide, v, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(TransformersValidation.INSTANCE.checkTransformer("test", rho, rhoPreviousStep, rhoNextStep, tapPosition, lowTapPosition, highTapPosition, targetV, regulatedSide, Float.NaN, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); }
Example #3
Source File: BusesValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Test public void checkBusesValues() { assertTrue(BusesValidation.INSTANCE.checkBuses("test", loadP, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, twtQ, tltP, tltQ, mainComponent, looseConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.INSTANCE.checkBuses("test", loadP, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, twtQ, tltP, tltQ, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.INSTANCE.checkBuses("test", loadP, 174.4932, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, twtQ, tltP, tltQ, mainComponent, looseConfig, NullWriter.NULL_WRITER)); // check NaN values assertFalse(BusesValidation.INSTANCE.checkBuses("test", Double.NaN, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, twtQ, tltP, tltQ, mainComponent, looseConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.INSTANCE.checkBuses("test", loadP, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, Double.NaN, tltP, tltQ, mainComponent, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(true); assertTrue(BusesValidation.INSTANCE.checkBuses("test", Double.NaN, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, twtQ, tltP, tltQ, mainComponent, looseConfig, NullWriter.NULL_WRITER)); assertTrue(BusesValidation.INSTANCE.checkBuses("test", loadP, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, Double.NaN, tltP, tltQ, mainComponent, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(false); // check main component assertFalse(BusesValidation.INSTANCE.checkBuses("test", loadP, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, twtQ, tltP, tltQ, mainComponent, strictConfig, NullWriter.NULL_WRITER)); mainComponent = false; assertTrue(BusesValidation.INSTANCE.checkBuses("test", loadP, loadQ, genP, genQ, batP, batQ, shuntP, shuntQ, svcP, svcQ, vscCSP, vscCSQ, lineP, lineQ, danglingLineP, danglingLineQ, twtP, twtQ, tltP, tltQ, mainComponent, strictConfig, NullWriter.NULL_WRITER)); }
Example #4
Source File: BusesValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Test public void checkNetworkBuses() throws IOException { Network.BusView networkBusView = Mockito.mock(Network.BusView.class); Mockito.when(networkBusView.getBusStream()).thenAnswer(dummy -> Stream.of(bus)); Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getBusView()).thenReturn(networkBusView); assertTrue(BusesValidation.INSTANCE.checkBuses(network, looseConfig, data)); assertFalse(BusesValidation.INSTANCE.checkBuses(network, strictConfig, data)); assertTrue(ValidationType.BUSES.check(network, looseConfig, tmpDir)); assertFalse(ValidationType.BUSES.check(network, strictConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), looseConfig, NullWriter.NULL_WRITER, ValidationType.BUSES); assertTrue(ValidationType.BUSES.check(network, looseConfig, validationWriter)); }
Example #5
Source File: StaticVarCompensatorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkSvcs() { // active power should be equal to 0 assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs(svc, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(svcTerminal.getP()).thenReturn(-39.8); assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs(svc, strictConfig, NullWriter.NULL_WRITER)); // the unit is disconnected Mockito.when(svcBusView.getBus()).thenReturn(null); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs(svc, strictConfig, NullWriter.NULL_WRITER)); }
Example #6
Source File: DAOTestBase.java From incubator-pinot with Apache License 2.0 | 5 votes |
private void cleanUpJDBC() throws Exception { System.out.println("Cleaning database: start"); try (Connection conn = ds.getConnection()) { URL deleteSchemaUrl = getClass().getResource("/schema/drop-tables.sql"); ScriptRunner scriptRunner = new ScriptRunner(conn, false, false); scriptRunner.setLogWriter(new PrintWriter(new NullWriter())); scriptRunner.runScript(new FileReader(deleteSchemaUrl.getFile())); } new File(dbUrlId).delete(); System.out.println("Cleaning database: done!"); }
Example #7
Source File: StatusTest.java From appstatus with Apache License 2.0 | 5 votes |
@Test public void testMaintenance() throws UnsupportedEncodingException, IOException { final AppStatus appStatus = new AppStatus(); // Maintenance is on appStatus.setMaintenance(true); final StatusWebHandler statusWeb = new StatusWebHandler(); statusWeb.setAppStatus(appStatus); statusWeb.setApplicationName("test"); final Map<String, IPage> pages = new HashMap<String, IPage>(); final StatusPage page = new StatusPage(); pages.put(page.getId(), page); statusWeb.setPages(pages); statusWeb.init(); final HttpServletRequest servlet = mock(HttpServletRequest.class); final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final StubServletOutputStream sos = new StubServletOutputStream(); when(response.getWriter()).thenReturn(new PrintWriter(new NullWriter())); when(response.getOutputStream()).thenReturn(sos); page.doGet(statusWeb, request, response); verify(response).setStatus(503); }
Example #8
Source File: Is24CsvWritingExample.java From OpenEstate-IO with Apache License 2.0 | 5 votes |
/** * Start the example application. * * @param args command line arguments */ @SuppressWarnings("Duplicates") public static void main(String[] args) { // init logging PropertyConfigurator.configure( Is24CsvWritingExample.class.getResource(PACKAGE + "/log4j.properties")); // create some CSV records List<Is24CsvRecord> records = new ArrayList<>(); records.add(createHausKaufRecord()); records.add(createHausKaufRecord()); records.add(createWohnungMieteRecord()); records.add(createWohnungMieteRecord()); // write CSV records into a java.io.File try { write(records, File.createTempFile("output-", ".csv")); } catch (IOException ex) { LOGGER.error("Can't create temporary file!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); System.exit(1); } // write CSV records into a java.io.OutputStream write(records, new NullOutputStream()); // write CSV records into a java.io.Writer write(records, new NullWriter()); // write CSV records into a string and send it to the console writeToConsole(records); }
Example #9
Source File: IdxWritingExample.java From OpenEstate-IO with Apache License 2.0 | 5 votes |
/** * Start the example application. * * @param args command line arguments */ @SuppressWarnings("Duplicates") public static void main(String[] args) { // init logging PropertyConfigurator.configure( IdxWritingExample.class.getResource(PACKAGE + "/log4j.properties")); // create some CSV records List<IdxRecord> records = new ArrayList<>(); records.add(createRecord()); records.add(createRecord()); records.add(createRecord()); records.add(createRecord()); // write CSV records into a java.io.File try { write(records, File.createTempFile("output-", ".csv")); } catch (IOException ex) { LOGGER.error("Can't create temporary file!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); System.exit(1); } // write CSV records into a java.io.OutputStream write(records, new NullOutputStream()); // write CSV records into a java.io.Writer write(records, new NullWriter()); // write CSV records into a string and send it to the console writeToConsole(records); }
Example #10
Source File: FlowsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkTransformerFlows() { assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer1, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(transformer1, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(bus1.isInMainConnectedComponent()).thenReturn(false); Mockito.when(bus2.isInMainConnectedComponent()).thenReturn(false); assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer1, strictConfig, NullWriter.NULL_WRITER)); }
Example #11
Source File: FlowsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkLineFlows() { assertTrue(FlowsValidation.INSTANCE.checkFlows(line1, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(line1, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(bus1.isInMainConnectedComponent()).thenReturn(false); Mockito.when(bus2.isInMainConnectedComponent()).thenReturn(false); assertTrue(FlowsValidation.INSTANCE.checkFlows(line1, strictConfig, NullWriter.NULL_WRITER)); }
Example #12
Source File: ShuntCompensatorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkNetworkShunts() throws IOException { Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getShuntCompensatorStream()).thenAnswer(dummy -> Stream.of(shunt)); assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts(network, strictConfig, data)); assertTrue(ValidationType.SHUNTS.check(network, strictConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), strictConfig, NullWriter.NULL_WRITER, ValidationType.SHUNTS); assertTrue(ValidationType.SHUNTS.check(network, strictConfig, validationWriter)); }
Example #13
Source File: ShuntCompensatorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkShunts() { // “q” = - bPerSection * currentSectionCount * v^2 assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(shuntTerminal.getQ()).thenReturn(171.52); assertFalse(ShuntCompensatorsValidation.INSTANCE.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); // if the shunt is disconnected then either “q” is not defined or “q” is 0 Mockito.when(shuntBusView.getBus()).thenReturn(null); assertFalse(ShuntCompensatorsValidation.INSTANCE.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(shuntTerminal.getQ()).thenReturn(Double.NaN); assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts(shunt, strictConfig, NullWriter.NULL_WRITER)); }
Example #14
Source File: ShuntCompensatorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkShuntsValues() { // “p” is always NaN assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); p = 1; assertFalse(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); p = Float.NaN; // “q” = - bPerSection * currentSectionCount * v^2 assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); q = 170.52; assertFalse(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); q = 171.52; assertFalse(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); // check main component mainComponent = false; assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, v, qMax, nominalV, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); mainComponent = true; q = 170.50537; // check with NaN values assertFalse(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, Float.NaN, v, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, Float.NaN, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, Float.NaN, v, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(ShuntCompensatorsValidation.INSTANCE.checkShunts("test", p, q, currentSectionCount, maximumSectionCount, bPerSection, Float.NaN, qMax, nominalV, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); }
Example #15
Source File: GeneratorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkGenerators() { // active power should be equal to setpoint assertTrue(GeneratorsValidation.INSTANCE.checkGenerators(generator, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(genTerminal.getP()).thenReturn(-39.8); assertFalse(GeneratorsValidation.INSTANCE.checkGenerators(generator, strictConfig, NullWriter.NULL_WRITER)); // the unit is disconnected Mockito.when(genBusView.getBus()).thenReturn(null); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators(generator, strictConfig, NullWriter.NULL_WRITER)); }
Example #16
Source File: Transformers3WValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkNetworkTwts() throws IOException { Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getThreeWindingsTransformerStream()).thenAnswer(dummy -> Stream.of(twtValidationData.get3WTransformer())); assertFalse(Transformers3WValidation.INSTANCE.checkTransformers(network, strictConfig, data)); assertFalse(ValidationType.TWTS3W.check(network, strictConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), strictConfig, NullWriter.NULL_WRITER, ValidationType.TWTS); assertFalse(ValidationType.TWTS3W.check(network, strictConfig, validationWriter)); strictConfig.setThreshold(.3); assertTrue(Transformers3WValidation.INSTANCE.checkTransformers(network, strictConfig, NullWriter.NULL_WRITER)); }
Example #17
Source File: Transformers3WValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkTwts() { assertFalse(Transformers3WValidation.INSTANCE.checkTransformer(twtValidationData.get3WTransformer(), strictConfig, NullWriter.NULL_WRITER)); strictConfig.setThreshold(.3); assertTrue(Transformers3WValidation.INSTANCE.checkTransformer(twtValidationData.get3WTransformer(), strictConfig, NullWriter.NULL_WRITER)); // check NaN values twtValidationData.setNanLeg1P(); assertFalse(Transformers3WValidation.INSTANCE.checkTransformer(twtValidationData.get3WTransformer(), strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(Transformers3WValidation.INSTANCE.checkTransformer(twtValidationData.get3WTransformer(), strictConfig, NullWriter.NULL_WRITER)); }
Example #18
Source File: TransformersValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkNetworkTwts() throws IOException { Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getTwoWindingsTransformerStream()).thenAnswer(dummy -> Stream.of(transformer)); assertTrue(TransformersValidation.INSTANCE.checkTransformers(network, strictConfig, data)); assertTrue(ValidationType.TWTS.check(network, strictConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), strictConfig, NullWriter.NULL_WRITER, ValidationType.TWTS); assertTrue(ValidationType.TWTS.check(network, strictConfig, validationWriter)); }
Example #19
Source File: StaticVarCompensatorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Test public void checkNetworkSvcs() throws IOException { Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getStaticVarCompensatorStream()).thenAnswer(dummy -> Stream.of(svc)); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs(network, looseConfig, data)); assertTrue(ValidationType.SVCS.check(network, looseConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), looseConfig, NullWriter.NULL_WRITER, ValidationType.SVCS); assertTrue(ValidationType.SVCS.check(network, looseConfig, validationWriter)); }
Example #20
Source File: GeneratorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void checkNetworkGenerators() throws IOException { Bus genBus1 = Mockito.mock(Bus.class); Mockito.when(genBus1.getV()).thenReturn(v); Mockito.when(genBus1.isInMainConnectedComponent()).thenReturn(mainComponent); BusView genBusView1 = Mockito.mock(BusView.class); Mockito.when(genBusView1.getBus()).thenReturn(genBus1); Mockito.when(genBusView1.getConnectableBus()).thenReturn(genBus1); Terminal genTerminal1 = Mockito.mock(Terminal.class); Mockito.when(genTerminal1.getP()).thenReturn(p); Mockito.when(genTerminal1.getQ()).thenReturn(q); Mockito.when(genTerminal1.getBusView()).thenReturn(genBusView1); ReactiveLimits genReactiveLimits1 = Mockito.mock(ReactiveLimits.class); Mockito.when(genReactiveLimits1.getMinQ(Mockito.anyFloat())).thenReturn(minQ); Mockito.when(genReactiveLimits1.getMaxQ(Mockito.anyFloat())).thenReturn(maxQ); Generator generator1 = Mockito.mock(Generator.class); Mockito.when(generator1.getId()).thenReturn("gen1"); Mockito.when(generator1.getTerminal()).thenReturn(genTerminal1); Mockito.when(generator1.getTargetP()).thenReturn(targetP); Mockito.when(generator1.getTargetQ()).thenReturn(targetQ); Mockito.when(generator1.getTargetV()).thenReturn(targetV); Mockito.when(generator1.getMaxP()).thenReturn(maxP); Mockito.when(generator1.getMinP()).thenReturn(minP); Mockito.when(generator1.getReactiveLimits()).thenReturn(genReactiveLimits1); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators(generator1, strictConfig, NullWriter.NULL_WRITER)); Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getGeneratorStream()).thenAnswer(dummy -> Stream.of(generator, generator1)); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators(network, looseConfig, data)); assertTrue(ValidationType.GENERATORS.check(network, looseConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), looseConfig, NullWriter.NULL_WRITER, ValidationType.GENERATORS); assertTrue(ValidationType.GENERATORS.check(network, looseConfig, validationWriter)); // test generation adjustment Bus genBus2 = Mockito.mock(Bus.class); Mockito.when(genBus2.getV()).thenReturn(v); Mockito.when(genBus2.isInMainConnectedComponent()).thenReturn(mainComponent); BusView genBusView2 = Mockito.mock(BusView.class); Mockito.when(genBusView2.getBus()).thenReturn(genBus2); Mockito.when(genBusView2.getConnectableBus()).thenReturn(genBus2); Terminal genTerminal2 = Mockito.mock(Terminal.class); Mockito.when(genTerminal2.getP()).thenReturn(-155.236); Mockito.when(genTerminal2.getQ()).thenReturn(q); Mockito.when(genTerminal2.getBusView()).thenReturn(genBusView1); ReactiveLimits genReactiveLimits2 = Mockito.mock(ReactiveLimits.class); Mockito.when(genReactiveLimits2.getMinQ(Mockito.anyFloat())).thenReturn(minQ); Mockito.when(genReactiveLimits2.getMaxQ(Mockito.anyFloat())).thenReturn(maxQ); Generator generator2 = Mockito.mock(Generator.class); Mockito.when(generator2.getId()).thenReturn("gen2"); Mockito.when(generator2.getTerminal()).thenReturn(genTerminal2); Mockito.when(generator2.getTargetP()).thenReturn(155.107); Mockito.when(generator2.getTargetQ()).thenReturn(targetQ); Mockito.when(generator2.getTargetV()).thenReturn(targetV); Mockito.when(generator2.getMaxP()).thenReturn(227.5); Mockito.when(generator2.getMinP()).thenReturn(-227.5); Mockito.when(generator2.getReactiveLimits()).thenReturn(genReactiveLimits1); Mockito.when(network.getGeneratorStream()).thenAnswer(dummy -> Stream.of(generator, generator1, generator2)); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators(network, looseConfig, NullWriter.NULL_WRITER)); }
Example #21
Source File: GeneratorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void checkGeneratorsValues() { // active power should be equal to setpoint assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); p = -39.8; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); p = -39.5056; assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // check with NaN values assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, Float.NaN, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, Float.NaN, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(false); // if voltageRegulatorOn="false" then reactive power should be equal to setpoint voltageRegulatorOn = false; assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); q = 3.7; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); // check with NaN values assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, Float.NaN, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(true); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, Float.NaN, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(false); // if voltageRegulatorOn="true" then either V at the connected bus is equal to g.getTargetV() and the reactive bounds are satisfied voltageRegulatorOn = true; assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 400; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 380; q = 11; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // check main component mainComponent = false; assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); mainComponent = true; q = 3.7; // check with NaN values v = 380; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, Float.NaN, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, Float.NaN, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, Float.NaN, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, Float.NaN, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, Float.NaN, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, Float.NaN, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(false); // if voltageRegulatorOn="true" then either q is equal to g.getReactiveLimits().getMinQ(p) and v is higher than targetV q = 10; v = 360; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 400; assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); q = 5; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // when maxQ < minQ strictConfig.setNoRequirementIfReactiveBoundInversion(true); // if noRequirementIfReactiveBoundInversion return true assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, maxQ, minQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setNoRequirementIfReactiveBoundInversion(false); // the code switches the 2 values to go back to a situation where minQ < maxQ and the normal tests are done assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, maxQ, minQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // if voltageRegulatorOn="true" then either q is equal to g.getReactiveLimits().getMaxQ(p) and v is lower than targetV q = 0; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 360; assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); q = 5; v = 400; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // a validation error should be detected if there is both a voltage and a target but no p or q v = 380; p = Float.NaN; q = Float.NaN; assertFalse(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); targetP = 0; targetQ = 0; assertTrue(GeneratorsValidation.INSTANCE.checkGenerators("test", p, q, v, targetP, targetQ, targetV, voltageRegulatorOn, minP, maxP, minQ, maxQ, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); }
Example #22
Source File: BusesValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void checkBuses() { assertTrue(BusesValidation.INSTANCE.checkBuses(bus, looseConfig, NullWriter.NULL_WRITER)); assertFalse(BusesValidation.INSTANCE.checkBuses(bus, strictConfig, NullWriter.NULL_WRITER)); }
Example #23
Source File: FlowsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void checkTransformerFlowsSpecificCompatibility() { assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer1, looseConfigSpecificCompatibility, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(transformer1, strictConfigSpecificCompatibility, NullWriter.NULL_WRITER)); }
Example #24
Source File: FlowsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void checkNetworkFlows() throws IOException { Line line2 = Mockito.mock(Line.class); Mockito.when(line2.getId()).thenReturn("line2"); Mockito.when(line2.getTerminal1()).thenReturn(terminal1); Mockito.when(line2.getTerminal2()).thenReturn(terminal2); Mockito.when(line2.getR()).thenReturn(r); Mockito.when(line2.getX()).thenReturn(x); Mockito.when(line2.getG1()).thenReturn(g1); Mockito.when(line2.getG2()).thenReturn(g2); Mockito.when(line2.getB1()).thenReturn(b1); Mockito.when(line2.getB2()).thenReturn(b2); TwoWindingsTransformer transformer2 = Mockito.mock(TwoWindingsTransformer.class); Mockito.when(transformer2.getId()).thenReturn("transformer2"); Mockito.when(transformer2.getTerminal1()).thenReturn(terminal1); Mockito.when(transformer2.getTerminal2()).thenReturn(terminal2); Mockito.when(transformer2.getR()).thenReturn(r * (1 - r / 100)); Mockito.when(transformer2.getX()).thenReturn(x * (1 - x / 100)); Mockito.when(transformer2.getG()).thenReturn(g1 * (1 - g1 / 100)); Mockito.when(transformer2.getB()).thenReturn(b1 * 2 * (1 - b1 / 100)); Mockito.when(transformer2.getRatioTapChanger()).thenReturn(ratioTapChanger); Mockito.when(transformer2.getRatedU1()).thenReturn(ratedU1); Mockito.when(transformer2.getRatedU2()).thenReturn(ratedU2); assertTrue(FlowsValidation.INSTANCE.checkFlows(transformer2, looseConfig, NullWriter.NULL_WRITER)); assertFalse(FlowsValidation.INSTANCE.checkFlows(transformer2, strictConfig, NullWriter.NULL_WRITER)); Network network = Mockito.mock(Network.class); Mockito.when(network.getId()).thenReturn("network"); Mockito.when(network.getLineStream()).thenAnswer(dummy -> Stream.of(line2, line1)); Mockito.when(network.getTwoWindingsTransformerStream()).thenAnswer(dummy -> Stream.of(transformer2, transformer1)); assertTrue(FlowsValidation.INSTANCE.checkFlows(network, looseConfig, data)); assertFalse(FlowsValidation.INSTANCE.checkFlows(network, strictConfig, data)); assertTrue(ValidationType.FLOWS.check(network, looseConfig, tmpDir)); assertFalse(ValidationType.FLOWS.check(network, strictConfig, tmpDir)); ValidationWriter validationWriter = ValidationUtils.createValidationWriter(network.getId(), looseConfig, NullWriter.NULL_WRITER, ValidationType.FLOWS); assertTrue(ValidationType.FLOWS.check(network, looseConfig, validationWriter)); }
Example #25
Source File: SecurityAnalysisResultEquivalenceTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void equivalent() { SecurityAnalysisResultEquivalence resultEquivalence = new SecurityAnalysisResultEquivalence(0.1, NullWriter.NULL_WRITER); LimitViolation line1Violation1 = new LimitViolation("NHV1_NHV2_1", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.0, Branch.Side.ONE); LimitViolation similarLine1Violation1 = new LimitViolation("NHV1_NHV2_1", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.09, Branch.Side.ONE); LimitViolation differentLine1Violation1 = new LimitViolation("NHV1_NHV2_1", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1101.0, Branch.Side.ONE); LimitViolation smallLine1Violation1 = new LimitViolation("NHV1_NHV2_1", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 950.09, Branch.Side.ONE); LimitViolation line1Violation2 = new LimitViolation("NHV1_NHV2_1", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.0, Branch.Side.TWO); LimitViolation similarLine1Violation2 = new LimitViolation("NHV1_NHV2_1", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.09, Branch.Side.TWO); LimitViolation differentLine1Violation2 = new LimitViolation("NHV1_NHV2_1", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1101.0, Branch.Side.TWO); LimitViolation line2Violation = new LimitViolation("NHV1_NHV2_2", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.0, Branch.Side.ONE); LimitViolation similarLine2Violation = new LimitViolation("NHV1_NHV2_2", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.09, Branch.Side.ONE); LimitViolation smallLine2Violation = new LimitViolation("NHV1_NHV2_2", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 950.09, Branch.Side.ONE); LimitViolation line3Violation = new LimitViolation("NHV1_NHV2_3", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.0, Branch.Side.ONE); LimitViolation similarLine3Violation = new LimitViolation("NHV1_NHV2_3", LimitViolationType.CURRENT, null, Integer.MAX_VALUE, 1000.0, 0.95f, 1100.09, Branch.Side.ONE); Contingency contingency1 = Mockito.mock(Contingency.class); Mockito.when(contingency1.getId()).thenReturn("contingency1"); Contingency contingency2 = Mockito.mock(Contingency.class); Mockito.when(contingency2.getId()).thenReturn("contingency2"); Contingency contingency3 = Mockito.mock(Contingency.class); Mockito.when(contingency3.getId()).thenReturn("contingency3"); // similar pre and post contingency results LimitViolationsResult preContingencyResult1 = new LimitViolationsResult(true, Arrays.asList(line1Violation1)); PostContingencyResult postContingencyResult11 = new PostContingencyResult(contingency1, new LimitViolationsResult(true, Arrays.asList(line1Violation1, line1Violation2))); PostContingencyResult postContingencyResult12 = new PostContingencyResult(contingency2, new LimitViolationsResult(true, Arrays.asList(line1Violation1, line2Violation))); SecurityAnalysisResult result1 = new SecurityAnalysisResult(preContingencyResult1, Arrays.asList(postContingencyResult11, postContingencyResult12)); LimitViolationsResult preContingencyResult2 = new LimitViolationsResult(true, Arrays.asList(similarLine1Violation1)); PostContingencyResult postContingencyResult21 = new PostContingencyResult(contingency1, new LimitViolationsResult(true, Arrays.asList(similarLine1Violation1, similarLine1Violation2))); PostContingencyResult postContingencyResult22 = new PostContingencyResult(contingency2, new LimitViolationsResult(true, Arrays.asList(similarLine1Violation1, similarLine2Violation))); SecurityAnalysisResult result2 = new SecurityAnalysisResult(preContingencyResult2, Arrays.asList(postContingencyResult22, postContingencyResult21)); assertTrue(resultEquivalence.equivalent(result1, result2)); // different pre contingency results, similar post contingency results preContingencyResult2 = new LimitViolationsResult(true, Arrays.asList(differentLine1Violation1)); result2 = new SecurityAnalysisResult(preContingencyResult2, Arrays.asList(postContingencyResult22, postContingencyResult21)); assertFalse(resultEquivalence.equivalent(result1, result2)); // similar pre contingency results, different post contingency results preContingencyResult2 = new LimitViolationsResult(true, Arrays.asList(similarLine1Violation1)); postContingencyResult21 = new PostContingencyResult(contingency1, new LimitViolationsResult(true, Arrays.asList(similarLine1Violation1, differentLine1Violation2))); result2 = new SecurityAnalysisResult(preContingencyResult2, Arrays.asList(postContingencyResult22, postContingencyResult21)); assertFalse(resultEquivalence.equivalent(result1, result2)); // similar pre contingency results, different post contingency results: more contingencies at the end of result2 postContingencyResult21 = new PostContingencyResult(contingency1, new LimitViolationsResult(true, Arrays.asList(similarLine1Violation1, similarLine1Violation2))); PostContingencyResult postContingencyResult23 = new PostContingencyResult(contingency3, new LimitViolationsResult(true, Arrays.asList(similarLine1Violation1, similarLine3Violation))); result2 = new SecurityAnalysisResult(preContingencyResult2, Arrays.asList(postContingencyResult22, postContingencyResult21, postContingencyResult23)); assertFalse(resultEquivalence.equivalent(result1, result2)); // similar pre contingency results, different post contingency results: more contingencies in result2 PostContingencyResult postContingencyResult13 = new PostContingencyResult(contingency3, new LimitViolationsResult(true, Arrays.asList(line1Violation1, line3Violation))); result1 = new SecurityAnalysisResult(preContingencyResult1, Arrays.asList(postContingencyResult13, postContingencyResult12)); assertFalse(resultEquivalence.equivalent(result1, result2)); // similar pre contingency results, different post contingency results: more contingencies at the end of result1 result1 = new SecurityAnalysisResult(preContingencyResult1, Arrays.asList(postContingencyResult13, postContingencyResult11, postContingencyResult12)); result2 = new SecurityAnalysisResult(preContingencyResult2, Arrays.asList(postContingencyResult22, postContingencyResult21)); assertFalse(resultEquivalence.equivalent(result1, result2)); // similar pre contingency results, different post contingency results: more contingencies in result1 result2 = new SecurityAnalysisResult(preContingencyResult2, Arrays.asList(postContingencyResult23, postContingencyResult21)); assertFalse(resultEquivalence.equivalent(result1, result2)); // similar pre contingency results, similar post contingency results: more contingencies in result1, but small postContingencyResult12 = new PostContingencyResult(contingency2, new LimitViolationsResult(true, Arrays.asList(smallLine1Violation1, smallLine2Violation))); result1 = new SecurityAnalysisResult(preContingencyResult1, Arrays.asList(postContingencyResult13, postContingencyResult11, postContingencyResult12)); assertTrue(resultEquivalence.equivalent(result1, result2)); }
Example #26
Source File: TransformersValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void checkTwts() { assertTrue(TransformersValidation.INSTANCE.checkTransformer(transformer, strictConfig, NullWriter.NULL_WRITER)); Mockito.when(bus.getV()).thenReturn(highV); assertFalse(TransformersValidation.INSTANCE.checkTransformer(transformer, strictConfig, NullWriter.NULL_WRITER)); }
Example #27
Source File: StaticVarCompensatorsValidationTest.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Test public void checkSvcsValues() { // active power should be equal to 0 assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); p = -39.8; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); p = -0.01; assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // if regulationMode = OFF then reactive power should be equal to 0 regulationMode = RegulationMode.OFF; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // if regulationMode = REACTIVE_POWER if the setpoint is in [Qmin=bMin*V*V, Qmax=bMax*V*V] then then reactive power should be equal to setpoint regulationMode = RegulationMode.REACTIVE_POWER; assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); q = 3.7; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); // check with NaN values assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, Float.NaN, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, Float.NaN, bMax, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(true); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, Float.NaN, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, Float.NaN, bMax, connected, mainComponent, looseConfig, NullWriter.NULL_WRITER)); looseConfig.setOkMissingValues(false); // if regulationMode = VOLTAGE then either V at the connected bus is equal to voltageSetpoint and q is bounded within [-Qmax=bMax*V*V, -Qmin=bMin*V*V] regulationMode = RegulationMode.VOLTAGE; assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 400; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 380; q = 1445; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // check with NaN values q = 3.7; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, Float.NaN, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, Float.NaN, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, Float.NaN, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(true); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, Float.NaN, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, Float.NaN, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, Float.NaN, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); strictConfig.setOkMissingValues(false); // if regulationMode = VOLTAGE then either q is equal to -bMin * V * V and V is lower than voltageSetpoint q = 1296; v = 360; nominalV = 360; assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 340; nominalV = 340; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // if regulationMode = VOLTAGE then either q is equal to -bMax * V * V and V is higher than voltageSetpoint q = -16000; v = 400; nominalV = 400; assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); v = 420; nominalV = 420; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); // check main component mainComponent = false; assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); mainComponent = true; // a validation error should be detected if there is both a voltage and a target but no p or q v = 380; nominalV = 380; p = Float.NaN; q = Float.NaN; assertFalse(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); reactivePowerSetpoint = 0; assertTrue(StaticVarCompensatorsValidation.INSTANCE.checkSVCs("test", p, q, v, v, nominalV, reactivePowerSetpoint, voltageSetpoint, regulationMode, bMin, bMax, connected, mainComponent, strictConfig, NullWriter.NULL_WRITER)); }