<commit_before>package com.hp.octane.plugins.jenkins.actions.project;

import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.hp.nga.integrations.dto.DTOFactory;
import com.hp.nga.integrations.dto.parameters.ParameterConfig;
import com.hp.nga.integrations.dto.parameters.ParameterType;
import com.hp.nga.integrations.dto.pipelines.PipelineNode;
import com.hp.nga.integrations.dto.pipelines.PipelinePhase;
import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.*;
import hudson.plugins.parameterizedtrigger.*;
import hudson.tasks.BuildTrigger;
import hudson.tasks.Fingerprinter;
import hudson.tasks.Shell;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Created with IntelliJ IDEA.
 * User: gullery
 * Date: 13/01/15
 * Time: 11:42
 * To change this template use File | Settings | File Templates.
 */

public class ProjectActionsMavenTest {
	private static final DTOFactory dtoFactory = DTOFactory.getInstance();
	private static final String projectName = "root-job";

	@Rule
	final public JenkinsRule rule = new JenkinsRule();

	//  Structure test: maven, no params, no children
	//
	@Test
	public void testStructureMavenNoParamsNoChildren() throws IOException, SAXException {
		rule.createMavenProject(projectName);

		JenkinsRule.WebClient client = rule.createWebClient();
		Page page;
		PipelineNode pipeline;

		page = client.goTo("nga/api/v1/jobs/" + projectName, "application/json");
		pipeline = dtoFactory.dtoFromJson(page.getWebResponse().getContentAsString(), PipelineNode.class);
		assertEquals(projectName, pipeline.getCiId());
		assertEquals(projectName, pipeline.getName());
		assertEquals(0, pipeline.getParameters().size());
		assertEquals(0, pipeline.getPhasesInternal().size());
		assertEquals(0, pipeline.getPhasesPostBuild().size());
	}

	@Test
	//@Ignore
	public void testDoRun() throws IOException, SAXException, InterruptedException {
		int retries = 0;
		MavenModuleSet p = rule.createMavenProject(projectName);
		JenkinsRule.WebClient client = rule.createWebClient();
		WebRequestSettings wrs = new WebRequestSettings(new URL(client.getContextPath() + "nga/jobs/" + projectName + "/run"), HttpMethod.POST);
		wrs = client.addCrumb(wrs);
		WebResponse wr = client.loadWebResponse(wrs);
		while ((p.getLastBuild() == null || p.getLastBuild().isBuilding()) && ++retries < 20) {
			Thread.sleep(1000);
		}
		assertEquals(p.getBuilds().toArray().length, 1);
	}

	//  Structure test: maven, with params, no children
	//<commit_msg>tech: fixing the unit test<commit_after>package com.hp.octane.plugins.jenkins.actions.project;

import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.hp.nga.integrations.dto.DTOFactory;
import com.hp.nga.integrations.dto.parameters.ParameterConfig;
import com.hp.nga.integrations.dto.parameters.ParameterType;
import com.hp.nga.integrations.dto.pipelines.PipelineNode;
import com.hp.nga.integrations.dto.pipelines.PipelinePhase;
import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.*;
import hudson.plugins.parameterizedtrigger.*;
import hudson.tasks.BuildTrigger;
import hudson.tasks.Fingerprinter;
import hudson.tasks.Shell;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Created with IntelliJ IDEA.
 * User: gullery
 * Date: 13/01/15
 * Time: 11:42
 * To change this template use File | Settings | File Templates.
 */

public class ProjectActionsMavenTest {
	private static final DTOFactory dtoFactory = DTOFactory.getInstance();
	private static final String projectName = "root-job";

	@Rule
	final public JenkinsRule rule = new JenkinsRule();

	//  Structure test: maven, no params, no children
	//
	@Test
	public void testStructureMavenNoParamsNoChildren() throws IOException, SAXException {
		rule.createMavenProject(projectName);

		JenkinsRule.WebClient client = rule.createWebClient();
		Page page;
		PipelineNode pipeline;

		page = client.goTo("nga/api/v1/jobs/" + projectName, "application/json");
		pipeline = dtoFactory.dtoFromJson(page.getWebResponse().getContentAsString(), PipelineNode.class);
		assertEquals(projectName, pipeline.getCiId());
		assertEquals(projectName, pipeline.getName());
		assertEquals(0, pipeline.getParameters().size());
		assertEquals(0, pipeline.getPhasesInternal().size());
		assertEquals(0, pipeline.getPhasesPostBuild().size());
	}

	@Test
	//@Ignore
	public void testDoRun() throws IOException, SAXException, InterruptedException {
		int retries = 0;
		MavenModuleSet p = rule.createMavenProject(projectName);
		JenkinsRule.WebClient client = rule.createWebClient();
		WebRequestSettings wrs = new WebRequestSettings(new URL(client.getContextPath() + "nga/api/v1/jobs/" + projectName + "/run"), HttpMethod.POST);
		wrs = client.addCrumb(wrs);
		WebResponse wr = client.loadWebResponse(wrs);
		while ((p.getLastBuild() == null || p.getLastBuild().isBuilding()) && ++retries < 20) {
			Thread.sleep(1000);
		}
		assertEquals(p.getBuilds().toArray().length, 1);
	}

	//  Structure test: maven, with params, no children
	//
{'fraction_non_alphanumeric': 0.12264480111653873, 'fraction_numerical': 0.0078506629448709, 'mean_word_length': 5.507377979568672, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1924758', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1804, 'n_words': 366}