UcteAliasesCreation { public static void createAliases(Network network) { Set<String> duplicatedAliases = new HashSet<>(); network.getBranchStream().forEach(branch -> { if (branch instanceof TieLine) { TieLine tieLine = (TieLine) branch; tieLine.addAlias(tieLine.getHalf1().getId()); tieLine.addAlias(tieLine.getHalf2().getId()); addHalfElementNameAliases(tieLine, duplicatedAliases); } addElementNameAlias(branch, duplicatedAliases); }); network.getSwitchStream().forEach(switchEl -> addElementNameAlias(switchEl, duplicatedAliases)); network.getDanglingLineStream().forEach(dl -> addElementNameAlias(dl, duplicatedAliases)); } private  UcteAliasesCreation(); static void createAliases(Network network);  }
@Test public void checkAliasesCreationWhenImportingMergedFile() { Network network = loadNetworkFromResourceFile("/uxTestGridForMerging.uct"); assertNull(network.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertNull(network.getIdentifiable("FFFFFF11 XXXXXX11 1")); assertNull(network.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE")); assertNull(network.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertNull(network.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertNull(network.getIdentifiable("FFFFFF11 XXXXXX11 1")); UcteAliasesCreation.createAliases(network); assertNotNull(network.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE")); assertNotNull(network.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertNotNull(network.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertNotNull(network.getIdentifiable("FFFFFF11 XXXXXX11 1")); assertEquals(network.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE"), network.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertEquals(network.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE"), network.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertEquals(network.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE"), network.getIdentifiable("FFFFFF11 XXXXXX11 1")); }
@Test public void checkAliasesCreationBeforeIidmMerging() { Network networkFR = loadNetworkFromResourceFile("/frTestGridForMerging.uct"); Network networkBE = loadNetworkFromResourceFile("/beTestGridForMerging.uct"); UcteAliasesCreation.createAliases(networkBE); UcteAliasesCreation.createAliases(networkFR); assertNotNull(networkBE.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE")); assertNotNull(networkFR.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); Network merge = Network.create("merge", "UCT"); merge.merge(networkBE, networkFR); assertNotNull(merge.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE")); assertNotNull(merge.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertNotNull(merge.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertNotNull(merge.getIdentifiable("FFFFFF11 XXXXXX11 1")); assertEquals(merge.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE"), merge.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertEquals(merge.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE"), merge.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertEquals(merge.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE"), merge.getIdentifiable("FFFFFF11 XXXXXX11 1")); }
@Test public void checkAliasesCreationAfterIidmMerging() { Network networkFR = loadNetworkFromResourceFile("/frTestGridForMerging.uct"); Network networkBE = loadNetworkFromResourceFile("/beTestGridForMerging.uct"); Network merge = Network.create("merge", "UCT"); merge.merge(networkBE, networkFR); assertNull(merge.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE")); assertNull(merge.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertNotNull(merge.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertNotNull(merge.getIdentifiable("FFFFFF11 XXXXXX11 1")); assertNotEquals("BBBBBB11 XXXXXX11 1", merge.getIdentifiable("BBBBBB11 XXXXXX11 1").getId()); assertNotEquals("FFFFFF11 XXXXXX11 1", merge.getIdentifiable("FFFFFF11 XXXXXX11 1").getId()); UcteAliasesCreation.createAliases(merge); assertNotNull(merge.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE")); assertNotNull(merge.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertNotNull(merge.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertNotNull(merge.getIdentifiable("FFFFFF11 XXXXXX11 1")); assertEquals(merge.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE"), merge.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE")); assertEquals(merge.getIdentifiable("BBBBBB11 XXXXXX11 ABCDE"), merge.getIdentifiable("BBBBBB11 XXXXXX11 1")); assertEquals(merge.getIdentifiable("FFFFFF11 XXXXXX11 ABCDE"), merge.getIdentifiable("FFFFFF11 XXXXXX11 1")); }
@Test public void checkThatItDoesNotCreateDuplicatedAliasesNorThrow() { Network network = loadNetworkFromResourceFile("/aliasesDuplicationTest.uct"); UcteAliasesCreation.createAliases(network); assertNotNull(network.getIdentifiable("FFFFFF11 FFFFFF12 1")); assertNotNull(network.getIdentifiable("FFFFFF11 FFFFFF12 2")); assertNotNull(network.getIdentifiable("FFFFFF11 FFFFFF12 3")); assertNull(network.getIdentifiable("FFFFFF11 FFFFFF12 N/A")); assertNotNull(network.getIdentifiable("FFFFFF11 FFFFFF12 Unique")); }