/*
 * This file is part of COMPASS. It is subject to the license terms in
 * the LICENSE file found in the top-level directory of this distribution.
 * (Also available at http://www.apache.org/licenses/LICENSE-2.0.txt)
 * You may not use this file except in compliance with the License.
 */
package de.dfki.asr.compass.model;

import java.io.IOException;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class PrefabSetDeepCopyTest {

	@Test
	public void deepCopyPrefabSetShouldCreateCopy() throws IOException, ClassNotFoundException {
		PrefabSet originalSet = initializePrefabSet();
		PrefabSet clone = (PrefabSet) originalSet.deepCopy();
		assertEquals(originalSet.getName(), clone.getName());
	}

	@Test
	public void deepCopyPrefabSetShouldCopyChildren() throws IOException, ClassNotFoundException {
		Boolean childrenCopied = true;
		PrefabSet originalSet = initializePrefabSet();
		PrefabSet clone = (PrefabSet) originalSet.deepCopy();
		if (originalSet.getChildren().size() != clone.getChildren().size()) {
			childrenCopied = false;
		}
		for (PrefabSet child: originalSet.getChildren()) {
			int childIndex = originalSet.getChildren().indexOf(child);
			if (!(clone.getChildren().get(childIndex).getName().equals(child.getName()))) {
				childrenCopied = false;
			}
		}
		assertTrue(childrenCopied);
	}

	@Test
	public void deepCopyPrefabSetShouldCopyPrefabs() throws IOException, ClassNotFoundException {
		Boolean copiedPrefabs = true;
		PrefabSet originalSet = initializePrefabSet();
		PrefabSet clone = (PrefabSet) originalSet.deepCopy();
		if (originalSet.getPrefabs().size() != clone.getPrefabs().size()) {
			copiedPrefabs = false;
		}
		for (SceneNode prefab: originalSet.getPrefabs()) {
			int prefabIndex = originalSet.getPrefabs().indexOf(prefab);
			if (!(clone.getPrefabs().get(prefabIndex).getName().equals(prefab.getName()))) {
				copiedPrefabs =  false;
			}
		}
		assertTrue(copiedPrefabs);
	}

	private PrefabSet initializePrefabSet() {
		PrefabSet originalSet = new PrefabSet();
		PrefabSet childSetA = new PrefabSet();
		PrefabSet childSetB = new PrefabSet();
		childSetA.setName("childA");
		childSetB.setName("childB");
		childSetA.setParent(originalSet);
		childSetB.setParent(originalSet);
		SceneNode prefabA = new SceneNode();
		SceneNode prefabB = new SceneNode();
		prefabA.setName("TestPrefabA");
		prefabB.setName("TestPrefabB");
		originalSet.addPrefab(prefabA);
		originalSet.addPrefab(prefabB);
		originalSet.setName("PrefabSetTest");
		return originalSet;
	}
}

@@ -1333,24 +1333,543 @@
 opied);%0A%09%7D%0A%0A
+%09@Test%0A%09public void deepCopyPrefabSetShouldClearIds() throws IOException, ClassNotFoundException %7B%0A%09%09Boolean clearedIds = true;%0A%09%09PrefabSet originalSet = initializePrefabSet();%0A%09%09PrefabSet clone = (PrefabSet) originalSet.deepCopy();%0A%09%09if (clone.getId() != 0) %7B%0A%09%09%09clearedIds = false;%0A%09%09%7D%0A%09%09for (PrefabSet c: clone.getChildren()) %7B%0A%09%09%09if (c.getId() != 0) %7B%0A%09%09%09%09clearedIds = false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09for (SceneNode p: clone.getPrefabs()) %7B%0A%09%09%09if (p.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%0A
 %09@Test%0A%09publ
@@ -1950,32 +1950,32 @@
 oundException %7B%0A
-
 %09%09Boolean copied
@@ -2633,16 +2633,40 @@
 bSet();%0A
+%09%09originalSet.setId(1);%0A
 %09%09childS
@@ -2715,24 +2715,68 @@
 (%22childB%22);%0A
+%09%09childSetA.setId(2);%0A%09%09childSetB.setId(3);%0A
 %09%09childSetA.
@@ -2947,16 +2947,16 @@
 fabA%22);%0A
-
 %09%09prefab
@@ -2981,16 +2981,56 @@
 fabB%22);%0A
+%09%09prefabA.setId(4);%0A%09%09prefabB.setId(5);%0A
 %09%09origin

Check for cleared IDs when deep copying prefab sets