From 72dd337adb2e16ab0b0d0d7bfa990e50a7f53043 Mon Sep 17 00:00:00 2001
From: Sonali Goyal <sonaligoyal654321@gmail.com>
Date: Sun, 17 Jan 2016 23:11:04 +0530
Subject: [PATCH] Add Test Selector Plugin support

Change-Id: If5637bff0ce312946ff1f9e10a6b49e25b9aca8b
---
 jenkins_jobs/modules/publishers.py            | 56 +++++++++++++++++++
 tests/publishers/fixtures/testselector001.xml | 15 +++++
 .../publishers/fixtures/testselector001.yaml  | 10 ++++
 3 files changed, 81 insertions(+)
 create mode 100644 tests/publishers/fixtures/testselector001.xml
 create mode 100644 tests/publishers/fixtures/testselector001.yaml

diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py
index 1af2e2251..f0fcc6df3 100644
--- a/jenkins_jobs/modules/publishers.py
+++ b/jenkins_jobs/modules/publishers.py
@@ -5329,6 +5329,62 @@ def clamav(parser, xml_parent, data):
         data.get('excludes', ''))
 
 
+def testselector(parser, xml_parent, data):
+    """yaml: testselector
+    This plugin allows you to choose specific tests you want to run.
+
+    Requires the Jenkins :jenkins-wiki:`Tests Selector Plugin
+    <Tests+Selector+Plugin>`.
+
+    :arg str name: Environment variable in which selected tests are saved
+      (required)
+    :arg str description: Description
+      (default "")
+    :arg str properties-file: Contain all your tests
+      (required)
+    :arg str enable-field: Imply if the test is enabled or not
+      (default "")
+    :arg str groupby: Plugin will group the tests by
+      (default "")
+    :arg str field-sperator: Separate between the fields in the tests tree
+      (default "")
+    :arg str show-fields: Shown in the tests tree
+      (default "")
+    :arg str multiplicity-field: Amount of times the test should run
+      (default "")
+
+    Example:
+
+    .. literalinclude:: /../../tests/publishers/fixtures/testselector001.yaml
+       :language: yaml
+    """
+
+    testselector = XML.SubElement(xml_parent, 'il.ac.technion.jenkins.plugins'
+                                              'TestExecuter')
+    try:
+        name = str(data['name'])
+    except KeyError as e:
+        raise MissingAttributeError(e.args[0])
+    try:
+        propertiesfile = str(data['properties-file'])
+    except KeyError as e:
+        raise MissingAttributeError(e.args[0])
+    XML.SubElement(testselector, 'name').text = name
+    XML.SubElement(testselector, 'description').text = data.get(
+        'description', '')
+    XML.SubElement(testselector, 'propertiesFilePath').text = propertiesfile
+    XML.SubElement(testselector, 'enableField').text = data.get(
+        'enable-field', '')
+    XML.SubElement(testselector, 'groupBy').text = data.get(
+        'groupby', '')
+    XML.SubElement(testselector, 'fieldSeparator').text = data.get(
+        'field-separator', '')
+    XML.SubElement(testselector, 'showFields').text = data.get(
+        'show-fields', '')
+    XML.SubElement(testselector, 'multiplicityField').text = data.get(
+        'multiplicity-field', '')
+
+
 def cloudformation(parser, xml_parent, data):
     """yaml: cloudformation
     Create cloudformation stacks before running a build and optionally
diff --git a/tests/publishers/fixtures/testselector001.xml b/tests/publishers/fixtures/testselector001.xml
new file mode 100644
index 000000000..81e27a504
--- /dev/null
+++ b/tests/publishers/fixtures/testselector001.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+  <publishers>
+    <il.ac.technion.jenkins.pluginsTestExecuter>
+      <name>tests</name>
+      <description>integration</description>
+      <propertiesFilePath>example.properties</propertiesFilePath>
+      <enableField>enabled</enableField>
+      <groupBy>testgroup</groupBy>
+      <fieldSeparator>.</fieldSeparator>
+      <showFields>testsuite,testcase</showFields>
+      <multiplicityField>multiplicity</multiplicityField>
+    </il.ac.technion.jenkins.pluginsTestExecuter>
+  </publishers>
+</project>
diff --git a/tests/publishers/fixtures/testselector001.yaml b/tests/publishers/fixtures/testselector001.yaml
new file mode 100644
index 000000000..3652f710d
--- /dev/null
+++ b/tests/publishers/fixtures/testselector001.yaml
@@ -0,0 +1,10 @@
+publishers:
+  - testselector:
+      name: tests
+      description: integration
+      properties-file: example.properties
+      enable-field: enabled
+      groupby: testgroup
+      field-separator: .
+      show-fields: testsuite,testcase
+      multiplicity-field: multiplicity