@@ -0,0 +1,2598 @@
+/*%0A * This file is part of COMPASS. It is subject to the license terms in%0A * the LICENSE file found in the top-level directory of this distribution.%0A * (Also available at http://www.apache.org/licenses/LICENSE-2.0.txt)%0A * You may not use this file except in compliance with the License.%0A */%0Apackage de.dfki.asr.compass.model;%0A%0Aimport java.io.IOException;%0Aimport org.testng.annotations.Test;%0Aimport static org.testng.Assert.*;%0A%0Apublic class ProjectDeepCopyTest %7B%0A%0A%09@Test%0A%09public void deepCopyProjectDeepCopies() throws IOException, ClassNotFoundException %7B%0A%09%09Project originalProject = initializeProject();%0A%09%09Project copiedProject = (Project) originalProject.deepCopy();%0A%09%09assertTrue(projectIsCopy(originalProject, copiedProject));%0A%09%7D%0A%0A%09@Test%0A%09public void deepCopyProjectClearedIDs() throws IOException, ClassNotFoundException %7B%0A%09%09Boolean clearedIDs = true;%0A%09%09Project originalProject = initializeProject();%0A%09%09Project copiedProject = (Project) originalProject.deepCopy();%0A%09%09if (copiedProject.getId() != 0) %7B%0A%09%09%09clearedIDs = false;%0A%09%09%7D%0A%09%09for (Scenario s: copiedProject.getScenarios()) %7B%0A%09%09%09if (s.getId() != 0) %7B%0A%09%09%09%09clearedIDs = false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09assertTrue(clearedIDs);%0A%09%7D%0A%09private Project initializeProject() %7B%0A%09%09Project originalProject = new Project(%22testProject%22);%0A%09%09Scenario scenarioA = new Scenario();%0A%09%09Scenario scenarioB = new Scenario();%0A%0A%09%09scenarioA.setName(%22scenarioA%22);%0A%09%09scenarioB.setName(%22scenarioB%22);%0A%0A%09%09scenarioA.getRoot().setName(%22rootA%22);%0A%09%09scenarioB.getRoot().setName(%22rootB%22);%0A%0A%09%09originalProject.addScenario(scenarioA);%0A%09%09originalProject.addScenario(scenarioB);%0A%0A%09%09return originalProject;%0A%09%7D%0A%0A%09private Boolean projectIsCopy(final Project original, final Project copy ) %7B%0A%09%09if (!(original.getName().equals(copy.getName()))) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09if (original.getScenarios().size() != copy.getScenarios().size()) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09for (Scenario s: original.getScenarios()) %7B%0A%09%09%09int scenarioIndex = original.getScenarios().indexOf(s);%0A%09%09%09Scenario c = copy.getScenarios().get(scenarioIndex);%0A%09%09%09if (!scenarioIsCopy(s, c)) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return true;%0A%09%7D%0A%0A%09private Boolean scenarioIsCopy(final Scenario original, final Scenario copy) %7B%0A%09%09//Just check whether scenarios have been copied by comparing their name.%0A%09%09//DeepCopy for sceneNodes working correctly is tested seperately and can%0A%09%09//be assumed to be true here%0A%09%09if (!(original.getName().equals(copy.getName()))) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09SceneNode rootA = original.getRoot();%0A%09%09SceneNode rootB = copy.getRoot();%0A%0A%09%09if (!(rootA.getName().equals(rootB.getName()))) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09return true;%0A%09%7D%0A%7D%0A

Test for deep copying projects