| /* |
| * |
| * Copyright (c) 2011 - 2018 - Loetz GmbH & Co KG, 69115 Heidelberg, Germany |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Initial contribution: |
| * Loetz GmbH & Co. KG |
| * |
| */ |
| package org.eclipse.osbp.xtext.datainterchange.jvmmodel; |
| |
| import static org.junit.Assert.assertEquals; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.junit.Test; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| /** |
| * The Class TestManageJoins. |
| */ |
| public class TestManageJoins { |
| private static final Logger LOGGER = LoggerFactory.getLogger(TestManageJoins.class); |
| |
| /** |
| * Test. |
| */ |
| @Test |
| public void test() { |
| JoinGraph<String> joinGraph = new JoinGraph<>(); |
| joinGraph.addNode("A"); |
| joinGraph.addNode("B"); |
| joinGraph.addNode("C"); |
| joinGraph.addNode("D"); |
| |
| joinGraph.addJoin("A", "B", "ab"); |
| joinGraph.addJoin("A", "C", "ac"); |
| joinGraph.addJoin("B", "D", "bd"); |
| joinGraph.addJoin("C", "D", "cd"); |
| |
| joinGraph.addJoin("B", "C", "bc"); |
| joinGraph.addJoin("C", "B", "cb"); |
| |
| ManageJoins<String> findAllPaths = new ManageJoins<>(joinGraph); |
| List<List<String>> paths = new ArrayList<>(); |
| |
| List<String> path1 = new ArrayList<>(); |
| path1.add("A"); |
| path1.add("B"); |
| path1.add("D"); |
| |
| List<String> path2 = new ArrayList<>(); |
| path2.add("A"); |
| path2.add("B"); |
| path2.add("C"); |
| path2.add("D"); |
| |
| List<String> path3 = new ArrayList<>(); |
| path3.add("A"); |
| path3.add("C"); |
| path3.add("D"); |
| |
| List<String> path4 = new ArrayList<>(); |
| path4.add("A"); |
| path4.add("C"); |
| path4.add("B"); |
| path4.add("D"); |
| |
| paths.add(path2); |
| paths.add(path1); |
| paths.add(path4); |
| paths.add(path3); |
| |
| LOGGER.error("all paths from A to D----------------------"); |
| findAllPaths.getAllPathsToDestination("A", "D").stream().forEach(r->LOGGER.error(r.toString())); |
| assertEquals(paths, findAllPaths.getAllPaths("A")); |
| LOGGER.error("all paths from A ----------------------"); |
| findAllPaths.getAllPaths("A").stream().forEach(r->LOGGER.error(r.toString())); |
| assertEquals(paths, findAllPaths.getAllPaths("A")); |
| LOGGER.error("all joins from A ----------------------"); |
| findAllPaths.getAllJoins("A").stream().forEach(r->LOGGER.error(r.toString())); |
| } |
| } |