}
@Test
public void testGetParentStacksInOrder() throws Exception {
List<StackInfo> allStacks = metaInfo.getSupportedStacks();
StackInfo stackInfo = metaInfo.getStackInfo(STACK_NAME_HDP, EXT_STACK_NAME);
StackInfo newStack = new StackInfo();
newStack.setName(STACK_NAME_HDP);
newStack.setVersion("2.0.99");
newStack.setParentStackVersion(EXT_STACK_NAME);
newStack.setActive(true);
newStack.setRepositories(stackInfo.getRepositories());
allStacks.add(newStack);
Method method = StackExtensionHelper.class.getDeclaredMethod
("getParentStacksInOrder", Collection.class);
method.setAccessible(true);
StackExtensionHelper helper = new StackExtensionHelper(metaInfo.getStackRoot());
Map<String, List<StackInfo>> stacks = (Map<String, List<StackInfo>>)
method.invoke(helper, allStacks);
Assert.assertNotNull(stacks.get("2.0.99"));
// Verify order
LinkedList<String> target = new LinkedList<String>();
target.add("2.0.5");
target.add("2.0.6");
target.add("2.0.99");
LinkedList<String> actual = new LinkedList<String>();
LinkedList<StackInfo> parents = (LinkedList<StackInfo>) stacks.get("2.0.99");
parents.addFirst(newStack);
ListIterator lt = parents.listIterator(parents.size());
while (lt.hasPrevious()) {
StackInfo stack = (StackInfo) lt.previous();
actual.add(stack.getVersion());
}
org.junit.Assert.assertArrayEquals("Order of stack extension not " +
"preserved.", target.toArray(), actual.toArray());
}