package org.jenkinsci.plugins.p4;

import static org.junit.Assert.*;

import hudson.matrix.DefaultMatrixExecutionStrategyImpl;
import hudson.matrix.MatrixProject;
import hudson.model.FreeStyleProject;
import hudson.scm.SCM;

import org.jenkinsci.plugins.p4.matrix.MatrixOptions;
import org.jenkinsci.plugins.p4.populate.AutoCleanImpl;
import org.jenkinsci.plugins.p4.populate.Populate;
import org.jenkinsci.plugins.p4.workspace.StaticWorkspaceImpl;
import org.jenkinsci.plugins.p4.workspace.Workspace;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;

public class PerforceScmTest {

	@Rule
	public JenkinsRule jenkins = new JenkinsRule();

	@Test
	public void testConfigBasic() throws Exception {
		FreeStyleProject project = jenkins.createFreeStyleProject();

		String credential = "123";
		Workspace workspace = new StaticWorkspaceImpl("none", false, "test.ws");
		Populate populate = new AutoCleanImpl();
		PerforceScm scm = new PerforceScm(credential, workspace, populate);

		project.setScm(scm);
		SCM testScm = project.getScm();
		assertEquals("org.jenkinsci.plugins.p4.PerforceScm", testScm.getType());

		assertTrue(testScm.supportsPolling());
		assertTrue(testScm.requiresWorkspaceForPolling());

		assertEquals(testScm, project.getScm());
	}

	@Test
	public void testIsBuildParent() throws IOException {
		MatrixProject project = new MatrixProject("MatrixTest");

		String credential = "123";
		Workspace workspace = new StaticWorkspaceImpl("none", false, "test.ws");
		Populate populate = new AutoCleanImpl();
		PerforceScm scm = new PerforceScm(credential, workspace, populate);
		project.setScm(scm);

		project.setExecutionStrategy(new DefaultMatrixExecutionStrategyImpl());
		assertFalse("isBuildParent should be false for default execution strategy",
				scm.isBuildParent(project));

		project.setExecutionStrategy(new MatrixOptions(true, false, false));
		assertTrue("isBuildParent should be true when MatrixOptions#buildParent is true",
				scm.isBuildParent(project));

		project.setExecutionStrategy(new MatrixOptions(false, true, true));
		assertFalse("isBuildParent should be false when MatrixOptions#buildParent is false",
				scm.isBuildParent(project));
	}

}

@@ -32,43 +32,8 @@
 4;%0A%0A
-import static org.junit.Assert.*;%0A%0A
 impo
@@ -81,24 +81,24 @@
 rategyImpl;%0A
+
 import hudso
@@ -182,17 +182,16 @@
 cm.SCM;%0A
-%0A
 import o
@@ -577,16 +577,149 @@
 ption;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0A%0A
 public c
@@ -1312,35 +1312,36 @@
 ing());%0A%09%09assert
-Tru
+Fals
 e(testScm.requir

Update test to reflect concurrent Polling.