/*******************************************************************************
 * 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
 * https://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal Software, Inc. - initial API and implementation
 *******************************************************************************/
package com.vmware.vfabric.ide.eclipse.tcserver.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.Collection;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.wst.server.core.IServer;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.vmware.vfabric.ide.eclipse.tcserver.tests.support.TcServerFixture;
import com.vmware.vfabric.ide.eclipse.tcserver.tests.support.TcServerHarness;

/**
 * @author Steffen Pingel
 * @author Tomasz Zarna
 */
@RunWith(Parameterized.class)
public class TcServerProvisioningTest {

	private final TcServerFixture fixture;

	public TcServerProvisioningTest(TcServerFixture fixture) {
		this.fixture = fixture;
	}

	@Parameters
	public static Collection<Object[]> data() {
		Object[][] data = new Object[TcServerFixture.ALL.length][1];
		for (int i = 0; i < TcServerFixture.ALL.length; i++) {
			data[i][0] = TcServerFixture.ALL[i];
		}
		return Arrays.asList(data);
	}

	private TcServerHarness harness;

	@Before
	public void setUp() throws Exception {
		harness = fixture.createHarness();
	}

	@After
	public void tearDown() throws Exception {
		harness.dispose();
	}

	@Test
	public void testCreateServer() throws Exception {
		Assume.assumeNotNull(fixture.getDownloadUrl());
		try {
			if (harness == null) {
				System.out.println("!!! No harness for " + fixture.getDownloadUrl() + " description=" + fixture.getDescription() + " type=" + fixture.getServerType());
			}
			IServer server = harness.createServer(null);
			assertNotNull(server);
		}
		catch (CoreException e) {
			// on Java 1.5 provisioning is expected to fail with tc Server v2.5
			// or later
			if (e.getMessage()
					.equals("tc Server v2.5 or later requires Java SE 6 or later.  Change the JRE to one that meets this requirement.")) {
				assertTrue("Expected Java version < 1.6, got: " + System.getProperty("java.version"), System
						.getProperty("java.version").compareTo("1.6") < 0);
			}
			else {
				throw e;
			}
		}
	}

}

@@ -675,16 +675,53 @@
 ertTrue;
+%0Aimport static org.junit.Assert.fail;
 %0A%0Aimport
@@ -2064,16 +2064,18 @@
 Url());%0A
+//
 %09%09try %7B%0A
@@ -2280,16 +2280,44 @@
 server =
+ null;%0A%09%09%09try %7B%0A%09%09%09%09server =
  harness
@@ -2337,16 +2337,99 @@
 (null);%0A
+%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%09fail(e.getMessage());%0A%09%09%09%7D%0A
 %09%09%09asser
@@ -2450,16 +2450,18 @@
 r);%0A%09%09%7D%0A
+//
 %09%09catch 
@@ -2480,16 +2480,18 @@
 on e) %7B%0A
+//
 %09%09%09// on
@@ -2553,16 +2553,18 @@
 er v2.5%0A
+//
 %09%09%09// or
@@ -2570,16 +2570,18 @@
 r later%0A
+//
 %09%09%09if (e
@@ -2594,16 +2594,18 @@
 ssage()%0A
+//
 %09%09%09%09%09.eq
@@ -2716,24 +2716,26 @@
 ement.%22)) %7B%0A
+//
 %09%09%09%09assertTr
@@ -2819,16 +2819,18 @@
  System%0A
+//
 %09%09%09%09%09%09.g
@@ -2879,21 +2879,25 @@
 ) %3C 0);%0A
+//
 %09%09%09%7D%0A
+//
 %09%09%09else 
@@ -2898,16 +2898,18 @@
 %09else %7B%0A
+//
 %09%09%09%09thro
@@ -2917,17 +2917,23 @@
  e;%0A
+//
 %09%09%09%7D%0A
+//
 %09%09%7D%0A
+//
 %09%7D%0A%0A

Debug failing test