/*******************************************************************************
 * Copyright (c) 2012 Pivotal Software, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal Software, Inc. - initial API and implementation
 *******************************************************************************/
package org.springsource.ide.eclipse.commons.tests.util;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;

/**
 * Derived from AbstractBeansCoreTestCase
 * @author Steffen Pingel
 * @author Terry Denney
 */
public abstract class StsTestCase extends TestCase {

	protected IProject createPredefinedProject(final String projectName) throws CoreException, IOException {
		return StsTestUtil.createPredefinedProject(projectName, getBundleName());
	}

	protected IResource createPredefinedProjectAndGetResource(String projectName, String resourcePath)
			throws CoreException, IOException {
		IProject project = createPredefinedProject(projectName);
		// XXX do a second full build to ensure markers are up-to-date
		project.build(IncrementalProjectBuilder.FULL_BUILD, null);

		IResource resource = project.findMember(resourcePath);
		StsTestUtil.waitForResource(resource);
		return resource;
	}

	protected abstract String getBundleName();

	protected String getSourceWorkspacePath() {
		return StsTestUtil.getSourceWorkspacePath(getBundleName());
	}

	public static <T> void assertElements(T[] actual, T... expect) {
		assertElements(Arrays.asList(actual), expect);
	}

	public static <T> void assertElements(Collection<T> actual, T... expect) {
		Set<T> expectedSet = new HashSet<T>(Arrays.asList(expect));

		for (T propVal : actual) {
			if (!expectedSet.remove(propVal)) {
				fail("Unexpected element: "+propVal);
			}
		}

		if (!expectedSet.isEmpty()) {
			StringBuilder missing = new StringBuilder();
			for (T propVal : expectedSet) {
				missing.append(propVal+"\n");
			}
			fail("Missing elements: \n"+missing);
		}
	}

	@Override
	protected void tearDown() throws Exception {
		StsTestUtil.cleanUpProjects();
		super.tearDown();
	}

}

@@ -753,16 +753,57 @@
 tCase;%0A%0A
+import org.eclipse.core.resources.IFile;%0A
 import o
@@ -990,16 +990,193 @@
 ception;
+%0Aimport org.eclipse.core.runtime.NullProgressMonitor;%0Aimport org.eclipse.core.runtime.Path;%0Aimport org.springsource.ide.eclipse.commons.tests.util.StsTestUtil.StringInputStream;
 %0A%0A/**%0A *
@@ -2806,10 +2806,471 @@
 ();%0A%09%7D%0A%0A
+%09public static void createEmptyFile(IProject project, String path)%0A%09%09%09throws CoreException %7B%0A%09%09%09%09IFile file = project.getFile(new Path(path));%0A%09%09%09%09file.create(new StringInputStream(%22%22), true, new NullProgressMonitor());%0A%09%09%09%7D%0A%0A%09public static void createFile(IProject project, String path, String data)%0A%09%09%09throws CoreException %7B%0A%09%09%09%09IFile file = project.getFile(new Path(path));%0A%09%09%09%09file.create(new StringInputStream(data), true, new NullProgressMonitor());%0A%09%09%09%7D%0A
 %7D%0A

Add some stuff to StsTestCase