[jboss-svn-commits] JBL Code SVN: r35663 - in labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src: test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Oct 22 04:30:53 EDT 2010
Author: velias
Date: 2010-10-22 04:30:53 -0400 (Fri, 22 Oct 2010)
New Revision: 35663
Added:
labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/resources/log4j.properties
Modified:
labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java
labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java
labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java
labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java
Log:
JIRAValueSource and JIRAValueSource unit and integration tests done
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java 2010-10-22 03:44:32 UTC (rev 35662)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSource.java 2010-10-22 08:30:53 UTC (rev 35663)
@@ -25,8 +25,9 @@
* System Config parameters used by this value source:
* <ul>
* <li><code>org.jboss.community.sbs.plugin.reports.monthly.fisheye.url</code> - String - http/s url to fisheye server
- * where is <a href="https://docspace.corp.redhat.com/docs/DOC-36206#API" target="_blank">"Red Hat Contributors report"
- * plugin API</a>.
+ * where is <a href="https://docspace.corp.redhat.com/docs/DOC-36206#Remote_API"
+ * target="_blank">"Red Hat Contributors report" plugin remote API</a>. Typical value:
+ * <code>http://fisheye.jboss.org/plugins/servlet/contributors-stat</code>
* <li><code>org.jboss.community.sbs.plugin.reports.monthly.fisheye.u</code> - String - username used to call FishEye
* <li><code>org.jboss.community.sbs.plugin.reports.monthly.fisheye.p</code> - String - password used to call FishEye
* <li><code>org.jboss.community.sbs.plugin.reports.monthly.fisheye.debug</code> - Boolean - if set to <code>true</code>
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java 2010-10-22 03:44:32 UTC (rev 35662)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/main/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSource.java 2010-10-22 08:30:53 UTC (rev 35663)
@@ -2,21 +2,24 @@
import java.io.IOException;
import java.io.StringReader;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
import org.jboss.community.sbs.plugin.reports.monthly.SystemConfigProvider;
import org.jboss.community.sbs.plugin.reports.monthly.aggregator.AggregatorUtils;
@@ -30,46 +33,47 @@
* System Config parameters used by this value source:
* <ul>
* <li><code>org.jboss.community.sbs.plugin.reports.monthly.jira.url</code> - String - http/s url to JIRA server where
- * is <a href="https://docspace.corp.redhat.com/docs/DOC-38712#Company_Contributions_Report"
- * target="_blank">"Red Hat Contributors report" plugin</a>.
- * <li><code>org.jboss.community.sbs.plugin.reports.monthly.jira.u</code> - String - username used to call JIRA
- * <li><code>org.jboss.community.sbs.plugin.reports.monthly.jira.p</code> - String - password used to call JIRA
+ * is <a href="https://docspace.corp.redhat.com/docs/DOC-38712#Company_Contributions_Report". Typical value
+ * <code>http://jira.jboss.org/secure/ConfigureReport.jspa</code>. target="_blank">"Red Hat Contributors report"
+ * plugin</a>.
* <li><code>org.jboss.community.sbs.plugin.reports.monthly.jira.debug</code> - Boolean - if set to <code>true</code> no
* http/s calls to JIRA are performed, generator returns mock value only (all zero)
* </ul>
*
- * TODO unit tests
*
* @author Vlastimil Elias (velias at redhat dot com)
*/
public class JIRAValueSource extends ValueSourceBase<String> {
+ private static final Logger log = LogManager.getLogger(JIRAValueSource.class);
+
/**
- * TODO JIRA call parameter name for Maximal date.
+ * JIRA call parameter name for Maximal date.
*/
- protected static final String JIRA_PARAM_NAME_MAXDATE = "mad";
+ protected static final String JIRA_PARAM_NAME_MAXDATE = "to";
/**
- * TODO JIRA call parameter name for Minimal date.
+ * JIRA call parameter name for Minimal date.
*/
- protected static final String JIRA_PARAM_NAME_MINDATE = "mid";
+ protected static final String JIRA_PARAM_NAME_MINDATE = "from";
/**
- * TODO Date parameters format used on FishEye call.
+ * Date parameters format used on JIRA call.
*/
- protected static final String JIRA_PARAM_DATE_FORMAT = "yyyy-M-d";
+ protected static final String JIRA_PARAM_DATE_FORMAT = "d/MMM/yy";
+ protected static final Locale JIRA_PARAM_DATE_LOCALE = Locale.ENGLISH;
+ protected static final String JIRA_PARAM_REPORTSRC = "reportsrc";
+
+ protected static final String JIRA_PARAM_REPORT_KEY = "reportKey";
+
public static final String CONFIG_KEY_URL = "org.jboss.community.sbs.plugin.reports.monthly.jira.url";
- public static final String CONFIG_KEY_USERNAME = "org.jboss.community.sbs.plugin.reports.monthly.jira.u";
- public static final String CONFIG_KEY_PWD = "org.jboss.community.sbs.plugin.reports.monthly.jira.p";
public static final String CONFIG_KEY_DEBUG = "org.jboss.community.sbs.plugin.reports.monthly.jira.debug";
protected boolean debug = false;
protected HttpClient client;
- protected boolean doAuthentication = false;
-
protected Map<String, String[]> cache = null;
protected Exception cacheE = null;
@@ -104,13 +108,7 @@
}
client = new HttpClient();
- String un = StringUtils.trimToNull(this.sysConfig.getStringProperty(CONFIG_KEY_USERNAME));
- String pwd = StringUtils.trimToEmpty(this.sysConfig.getStringProperty(CONFIG_KEY_PWD));
- if (un != null) {
- client.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
- new UsernamePasswordCredentials(un, pwd));
- doAuthentication = true;
- }
+
}
@Override
@@ -146,7 +144,7 @@
protected Map<String, String[]> loadData() throws IOException {
HttpMethod method = new GetMethod(StringUtils.trimToNull(sysConfig.getStringProperty(CONFIG_KEY_URL)));
- method.setDoAuthentication(doAuthentication);
+ method.setDoAuthentication(false);
method.setFollowRedirects(true);
method.setQueryString(prepareParams());
try {
@@ -172,17 +170,70 @@
*/
protected NameValuePair[] prepareParams() {
List<NameValuePair> params = new ArrayList<NameValuePair>();
- SimpleDateFormat sdf = new SimpleDateFormat(JIRA_PARAM_DATE_FORMAT);
+ SimpleDateFormat sdf = new SimpleDateFormat(JIRA_PARAM_DATE_FORMAT, JIRA_PARAM_DATE_LOCALE);
+ String df = null;
+ String dt = null;
if (dateFrom != null) {
- params.add(new NameValuePair(JIRA_PARAM_NAME_MINDATE, sdf.format(dateFrom)));
+ df = sdf.format(dateFrom);
+ params.add(new NameValuePair(JIRA_PARAM_NAME_MINDATE, df));
}
if (dateTo != null) {
- params.add(new NameValuePair(JIRA_PARAM_NAME_MAXDATE, sdf.format(dateTo)));
+ dt = sdf.format(dateTo);
+ params.add(new NameValuePair(JIRA_PARAM_NAME_MAXDATE, dt));
}
+ params.add(new NameValuePair(JIRA_PARAM_REPORTSRC, "-2-" + generateJiraToken(df, dt)));
+ params.add(new NameValuePair(JIRA_PARAM_REPORT_KEY,
+ "org.jboss.labs.jira.plugin.patch-contributions-report-plugin:companyContributionsReport"));
return params.toArray(new NameValuePair[] {});
}
+ protected String generateJiraToken(String df, String dt) {
+ df = StringUtils.trimToEmpty(df);
+ dt = StringUtils.trimToEmpty(dt);
+ String tokenbase = "eqweterkefjiewjwoe" + df + dt;
+ return toHexString(md5(tokenbase));
+ }
+
/**
+ * Convert byte array To hex string.
+ *
+ * @param bytes the bytes
+ * @return the string
+ */
+ protected static String toHexString(byte[] bytes) {
+ if (bytes == null) {
+ throw new IllegalArgumentException("byte array must not be null");
+ }
+ StringBuffer hex = new StringBuffer(bytes.length * 2);
+ for (byte aByte : bytes) {
+ hex.append(Character.forDigit((aByte & 0XF0) >> 4, 16));
+ hex.append(Character.forDigit((aByte & 0X0F), 16));
+ }
+ return hex.toString();
+ }
+
+ /**
+ * Get Md5 checksum of given String.
+ *
+ * @param text the text
+ * @return the byte[]
+ */
+ protected static byte[] md5(String text) {
+ // arguments check
+ if (text == null) {
+ throw new NullPointerException("null text for MD5");
+ }
+
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(text.getBytes());
+ return md.digest();
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("Cannot find MD5 algorithm");
+ }
+ }
+
+ /**
* Proces response from JIRA server.
*
* @param responseBody to process
@@ -197,11 +248,18 @@
String response = (new String(responseBody)).trim();
int idx = response.indexOf("id=\"jira_cont_rep_csv\"");
+ if (idx < 0) {
+ log.error("JIRA HTTP call failed: Bad response, no csv file part found in returned data: " + response);
+ throw new IOException(
+ "JIRA HTTP call failed: Bad response, no csv file part found in returned data. See logfile for returned content.");
+ }
int startIdx = response.indexOf(">", idx) + 1;
int endIdx = response.indexOf("<", startIdx);
if (startIdx == -1 || endIdx == -1 || startIdx > endIdx) {
- throw new IOException("JIRA HTTP call failed: Bad response, no csv file part found in returned data.");
+ log.error("JIRA HTTP call failed: Bad response, no csv file part found in returned data: " + response);
+ throw new IOException(
+ "JIRA HTTP call failed: Bad response, no csv file part found in returned data. See logfile for returned content.");
}
String csvcontent = response.substring(startIdx, endIdx).trim();
@@ -214,14 +272,39 @@
boolean first = true;
while ((row = reader.readNext()) != null) {
+ if (row.length < 6) {
+ log.error("JIRA HTTP call failed: Bad response, short line in returned data: " + csvcontent);
+ throw new IOException(
+ "JIRA HTTP call failed: Bad response, short line in returned data. See logfile for returned content.");
+ }
// skip header
if (first) {
first = false;
} else {
- ret.put(row[0], (String[]) ArrayUtils.subarray(row, 2, 6));
+ String[] data = (String[]) ArrayUtils.subarray(row, 2, 6);
+ checkCSVValue(csvcontent, row[0]);
+ for (String v : data) {
+ checkCSVValue(csvcontent, v);
+ }
+ ret.put(row[0], data);
}
}
+ return ret;
- return ret;
}
+
+ /**
+ * Check value from csv file.
+ *
+ * @param csvcontent used to log
+ * @param value to check
+ * @throws IOException
+ */
+ protected void checkCSVValue(String csvcontent, String value) throws IOException {
+ if (StringUtils.trimToNull(value) == null) {
+ log.error("JIRA HTTP call failed: Bad response, no value on some line of in returned data: " + csvcontent);
+ throw new IOException(
+ "JIRA HTTP call failed: Bad response, no value on some line of in returned data. See logfile for returned content.");
+ }
+ }
}
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java 2010-10-22 03:44:32 UTC (rev 35662)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/FISHEYEValueSourceTest.java 2010-10-22 08:30:53 UTC (rev 35663)
@@ -19,6 +19,20 @@
*/
public class FISHEYEValueSourceTest {
+ /**
+ * URL value used for integration test {@link #getValues_INTEGRATION_AUTH()}
+ */
+ protected static final String INT_TEST_URL = "http://localhost:8060/plugins/servlet/contributors-stat";
+ protected static final String INT_TEST_U = "admin";
+ protected static final String INT_TEST_P = "admin";
+
+ /**
+ * Disable integration test ({@link #loadData_INTEGRATION()}) here.
+ */
+ protected static boolean INT_TEST_PERFORM = false;
+
+ protected SimpleDateFormat UTIL_DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");
+
@Test
public void processResponse() throws IOException {
@@ -159,7 +173,7 @@
}
@Test
- public void getValues_REMOTE_NOAUTH() throws Exception {
+ public void getValues_REMOTEMOCK_NOAUTH() throws Exception {
HttpFISHEYEMockServer server = new HttpFISHEYEMockServer();
try {
@@ -213,7 +227,7 @@
}
@Test
- public void getValues_REMOTE_AUTH() throws Exception {
+ public void getValues_REMOTEMOCK_AUTH() throws Exception {
HttpFISHEYEMockServer server = new HttpFISHEYEMockServer();
server.doauth = true;
try {
@@ -244,6 +258,30 @@
} finally {
server.disconnect();
}
+ }
+ @Test
+ public void getValues_INTEGRATION_AUTH() throws Exception {
+ if (INT_TEST_PERFORM) {
+ MapBasedSystemConfigProvider config = new MapBasedSystemConfigProvider();
+ config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_DEBUG, "false");
+ config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_URL, INT_TEST_URL);
+ config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_USERNAME, INT_TEST_U);
+ config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_PWD, INT_TEST_P);
+
+ FISHEYEValueSource tested = new FISHEYEValueSource(config, null, null);
+
+ FishEyeRepositoryConfig id = new FishEyeRepositoryConfig("CheckstyleSVN");
+
+ String[] val = tested.getValues(id);
+ Assert.assertEquals(2, val.length);
+
+ tested.dateFrom = UTIL_DATE_FORMAT.parse("1.10.2001");
+ tested.dateTo = UTIL_DATE_FORMAT.parse("31.10.2010");
+ val = tested.getValues(id);
+ Assert.assertEquals(2, val.length);
+
+ }
}
+
}
Modified: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java 2010-10-22 03:44:32 UTC (rev 35662)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/java/org/jboss/community/sbs/plugin/reports/monthly/valuesource/JIRAValueSourceTest.java 2010-10-22 08:30:53 UTC (rev 35663)
@@ -1,21 +1,17 @@
package org.jboss.community.sbs.plugin.reports.monthly.valuesource;
import java.io.IOException;
+import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.auth.AuthScope;
import org.jboss.community.sbs.plugin.reports.monthly.MapBasedSystemConfigProvider;
import org.jboss.community.sbs.plugin.reports.monthly.SystemConfigProvider;
import org.jboss.community.sbs.plugin.reports.monthly.aggregator.AggregatorUtils;
-import org.jboss.community.sbs.plugin.reports.monthly.config.FishEyeRepositoryConfig;
import org.junit.Assert;
import org.junit.Test;
-import com.ibm.icu.text.SimpleDateFormat;
-
/**
* Unit test for {@link FISHEYEValueSource}.
*
@@ -23,8 +19,23 @@
*/
public class JIRAValueSourceTest {
+ /**
+ * URL value used for integration test {@link #loadData_INTEGRATION()}
+ */
+ protected static final String INT_TEST_URL = "http://localhost:8080/secure/ConfigureReport.jspa";
+
+ /**
+ * Disable integration test ({@link #loadData_INTEGRATION()}) here.
+ */
+ protected static boolean INT_TEST_PERFORM = false;
+
+ /**
+ * If change this, check all tests where used!!
+ */
protected static final int ROW_SIZE = 4;
+ protected SimpleDateFormat UTIL_DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");
+
@Test
public void getValues_caches() throws Exception {
@@ -84,16 +95,38 @@
// OK
}
Assert.assertEquals(0, tested.checkCallCount());
+ }
+ @Test
+ public void getValues_DEBUG() throws Exception {
+
+ // test debug mode of provider
+ MapBasedSystemConfigProvider config = new MapBasedSystemConfigProvider();
+ config.addConfigProperty(JIRAValueSource.CONFIG_KEY_DEBUG, "true");
+
+ JIRAValueSource tested = new JIRAValueSource(config, null, null);
+
+ String[] val = null;
+ try {
+ val = tested.getValues(null);
+ Assert.fail();
+ } catch (IllegalArgumentException e) {
+ // OK
+ }
+
+ val = tested.getValues("PROJ");
+ Assert.assertEquals(ROW_SIZE, val.length);
+ Assert.assertEquals("0", val[0]);
+ Assert.assertEquals("0", val[1]);
+ Assert.assertEquals("0", val[2]);
+ Assert.assertEquals("0", val[3]);
}
@Test
public void processResponse() throws IOException {
- // TODO unit test
+ JIRAValueSource tested = new JIRAValueSource(null, null, null);
- FISHEYEValueSource tested = new FISHEYEValueSource(null, null, null);
-
- String[] ret = null;
+ Map<String, String[]> ret = null;
try {
ret = tested.processResponse(null);
Assert.fail("No exception thrown");
@@ -109,49 +142,97 @@
}
try {
- ret = tested.processResponse("fault:Erro xxxx".getBytes());
+ ret = tested.processResponse("strange not correct content".getBytes());
Assert.fail("No exception thrown");
} catch (IOException e) {
// OK
}
+ // correct data
+ ret = tested
+ .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
+ + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
+ + "ORG,JBoss.org,10,9,15,14\n" + "JBAS,JBoss AS,1,2,3,4\n" + "</textarea> cosi dalsi <b>/n</textarea>")
+ .getBytes());
+ Assert.assertEquals(2, ret.size());
+ Assert.assertNotNull(ret.get("ORG"));
+ Assert.assertArrayEquals(new String[] { "10", "9", "15", "14" }, ret.get("ORG"));
+ Assert.assertNotNull(ret.get("JBAS"));
+ Assert.assertArrayEquals(new String[] { "1", "2", "3", "4" }, ret.get("JBAS"));
+
+ // empty data is correct
+ ret = tested
+ .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
+ + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
+ + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
+ Assert.assertEquals(0, ret.size());
+
+ // longer lines of data are correct
+ ret = tested
+ .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
+ + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
+ + "ORG,JBoss.org,10,9,15,14,22\n" + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
+ Assert.assertEquals(1, ret.size());
+ Assert.assertNotNull(ret.get("ORG"));
+ Assert.assertArrayEquals(new String[] { "10", "9", "15", "14" }, ret.get("ORG"));
+
+ // shorter lines of data ends with exception
try {
- ret = tested.processResponse("ok:1".getBytes());
- Assert.fail("No exception thrown");
+ ret = tested
+ .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
+ + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
+ + "ORG,JBoss.org,10,9,15\n" + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
+ Assert.fail("Exception not thrown");
} catch (IOException e) {
// OK
}
+ // shorter lines (comma at the end) of data ends with exception
try {
- ret = tested.processResponse("nook:1:10".getBytes());
- Assert.fail("No exception thrown");
+ ret = tested
+ .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
+ + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
+ + "ORG,JBoss.org,10,9,15,\n" + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
+ Assert.fail("Exception not thrown");
} catch (IOException e) {
// OK
}
- ret = tested.processResponse("ok:1:10".getBytes());
- Assert.assertEquals("1", ret[0]);
- Assert.assertEquals("10", ret[1]);
+ // no project key on line ends with exception
+ try {
+ ret = tested
+ .processResponse(("test <h1> <h1> aha <textarea rows=\"40\" cols=\"60\" readonly=\"readonly\" id=\"jira_cont_rep_csv\">\n"
+ + "Project key,Project name,Number of issues reported by Red Hat,Number of issues reported by Community,Number of issues resolved by Red Hat,Number of issues resolved by Community\n"
+ + ",JBoss.org,10,9,15,22\n" + "</textarea> cosi dalsi <b>/n</textarea>").getBytes());
+ Assert.fail("Exception not thrown");
+ } catch (IOException e) {
+ // OK
+ }
+
}
@Test
public void prepareParams() throws Exception {
JIRAValueSource tested = new JIRAValueSource(null, null, null);
- SimpleDateFormat sdf = new SimpleDateFormat(JIRAValueSource.JIRA_PARAM_DATE_FORMAT);
-
// no params
NameValuePair[] val = tested.prepareParams();
Assert.assertNull(getParameter(val, JIRAValueSource.JIRA_PARAM_NAME_MINDATE));
Assert.assertNull(getParameter(val, JIRAValueSource.JIRA_PARAM_NAME_MAXDATE));
+ Assert.assertEquals("org.jboss.labs.jira.plugin.patch-contributions-report-plugin:companyContributionsReport",
+ getParameter(val, JIRAValueSource.JIRA_PARAM_REPORT_KEY));
+ Assert.assertTrue(getParameter(val, JIRAValueSource.JIRA_PARAM_REPORTSRC).startsWith("-2-"));
// all params set
- tested.dateFrom = sdf.parse("2010-10-01");
- tested.dateTo = sdf.parse("2010-10-31");
+ tested.dateFrom = UTIL_DATE_FORMAT.parse("1.10.2010");
+ tested.dateTo = UTIL_DATE_FORMAT.parse("31.10.2010");
val = tested.prepareParams();
- Assert.assertEquals("2010-10-1", getParameter(val, JIRAValueSource.JIRA_PARAM_NAME_MINDATE));
- Assert.assertEquals("2010-10-31", getParameter(val, JIRAValueSource.JIRA_PARAM_NAME_MAXDATE));
+ Assert.assertEquals("1/Oct/10", getParameter(val, JIRAValueSource.JIRA_PARAM_NAME_MINDATE));
+ Assert.assertEquals("31/Oct/10", getParameter(val, JIRAValueSource.JIRA_PARAM_NAME_MAXDATE));
+ Assert.assertTrue(getParameter(val, JIRAValueSource.JIRA_PARAM_REPORTSRC).startsWith("-2-"));
+ Assert.assertEquals("org.jboss.labs.jira.plugin.patch-contributions-report-plugin:companyContributionsReport",
+ getParameter(val, JIRAValueSource.JIRA_PARAM_REPORT_KEY));
}
protected String getParameter(NameValuePair[] val, String name) {
@@ -176,143 +257,42 @@
// OK
}
- // no authentication
config.addConfigProperty(JIRAValueSource.CONFIG_KEY_URL, "http://test.jboss.org");
tested = new JIRAValueSource(config, null, null);
Assert.assertNotNull(tested.client);
Assert.assertFalse(tested.debug);
- Assert.assertFalse(tested.doAuthentication);
- // with authentication
- config.addConfigProperty(JIRAValueSource.CONFIG_KEY_USERNAME, "un");
- config.addConfigProperty(JIRAValueSource.CONFIG_KEY_PWD, "pw");
- tested = new JIRAValueSource(config, null, null);
- Assert.assertNotNull(tested.client);
- Assert.assertFalse(tested.debug);
- Assert.assertTrue(tested.doAuthentication);
- UsernamePasswordCredentials cr = (UsernamePasswordCredentials) tested.client.getState().getCredentials(
- new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM));
- Assert.assertEquals("un", cr.getUserName());
- Assert.assertEquals("pw", cr.getPassword());
-
}
@Test
- public void getValues_DEBUG() throws Exception {
-
- // test debug mode of provider
- MapBasedSystemConfigProvider config = new MapBasedSystemConfigProvider();
- config.addConfigProperty(JIRAValueSource.CONFIG_KEY_DEBUG, "true");
-
- JIRAValueSource tested = new JIRAValueSource(config, null, null);
-
- String[] val = null;
- try {
- val = tested.getValues(null);
- Assert.fail();
- } catch (IllegalArgumentException e) {
- // OK
- }
-
- val = tested.getValues("PROJ");
- Assert.assertEquals(ROW_SIZE, val.length);
- Assert.assertEquals("0", val[0]);
- Assert.assertEquals("0", val[1]);
- Assert.assertEquals("0", val[2]);
- Assert.assertEquals("0", val[3]);
+ public void loadData_REMOTEMOCK() throws Exception {
+ // TODO unit test like in FISHEYEValueSource?
}
@Test
- public void loadData_REMOTE_NOAUTH() throws Exception {
- // TODO unit test
- HttpFISHEYEMockServer server = new HttpFISHEYEMockServer();
- try {
+ public void loadData_INTEGRATION() throws Exception {
+ if (INT_TEST_PERFORM) {
MapBasedSystemConfigProvider config = new MapBasedSystemConfigProvider();
- config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_DEBUG, "false");
- config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_URL, "http://localhost:" + HttpFISHEYEMockServer.PORT);
+ config.addConfigProperty(JIRAValueSource.CONFIG_KEY_DEBUG, "false");
+ config.addConfigProperty(JIRAValueSource.CONFIG_KEY_URL, INT_TEST_URL);
- FISHEYEValueSource tested = new FISHEYEValueSource(config, null, null);
+ JIRAValueSource tested = new JIRAValueSource(config, null, null);
- // all ok
- server.connect();
- FishEyeRepositoryConfig id = new FishEyeRepositoryConfig("REPO");
- String[] val = tested.getValues(id);
- server.disconnect();
- Assert.assertEquals(2, val.length);
- Assert.assertEquals("10", val[0]);
- Assert.assertEquals("100", val[1]);
- Assert.assertEquals("REPO", server.p_repo);
- Assert.assertNull(server.p_path);
- Assert.assertNull(server.p_mindate);
- Assert.assertNull(server.p_maxdate);
- Assert.assertNull(server.h_auth);
+ Map<String, String[]> val = tested.loadData();
+ Assert.assertNotNull(val);
- // data error from server
- try {
- server.dataok = false;
- server.connect();
- val = tested.getValues(id);
- Assert.fail();
- } catch (IOException e) {
- // ok
- } finally {
- server.disconnect();
- }
+ tested.dateFrom = UTIL_DATE_FORMAT.parse("1.10.2001");
+ tested.dateTo = UTIL_DATE_FORMAT.parse("31.10.2010");
+ val = tested.loadData();
+ Assert.assertNotNull(val);
- try {
- server.dataok = true;
- server.statusok = false;
- server.connect();
- val = tested.getValues(id);
- Assert.fail();
- } catch (IOException e) {
- // ok
- } finally {
- server.disconnect();
- }
-
- } finally {
- server.disconnect();
}
}
- @Test
- public void loadData_REMOTE_AUTH() throws Exception {
- // TODO unit test
- HttpFISHEYEMockServer server = new HttpFISHEYEMockServer();
- server.doauth = true;
- try {
-
- MapBasedSystemConfigProvider config = new MapBasedSystemConfigProvider();
- config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_DEBUG, "false");
- config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_URL, "http://localhost:" + HttpFISHEYEMockServer.PORT);
- config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_USERNAME, "user");
- config.addConfigProperty(FISHEYEValueSource.CONFIG_KEY_PWD, "pwd");
-
- FISHEYEValueSource tested = new FISHEYEValueSource(config, null, null);
-
- // all ok
- server.connect();
- FishEyeRepositoryConfig id = new FishEyeRepositoryConfig("REPO");
- id.setPath("/path");
- String[] val = tested.getValues(id);
- server.disconnect();
- Assert.assertEquals(2, val.length);
- Assert.assertEquals("10", val[0]);
- Assert.assertEquals("100", val[1]);
- Assert.assertEquals("REPO", server.p_repo);
- Assert.assertEquals("/path", server.p_path);
- Assert.assertNull(server.p_mindate);
- Assert.assertNull(server.p_maxdate);
- Assert.assertNotNull(server.h_auth);
-
- } finally {
- server.disconnect();
- }
-
- }
-
+ /**
+ * Mock class used to test {@link JIRAValueSource#getValues(String)} without real load of data.
+ */
protected static class JIRAValueSourceMock extends JIRAValueSource {
private boolean exception = false;
Added: labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/resources/log4j.properties
===================================================================
--- labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/resources/log4j.properties (rev 0)
+++ labs/jbosslabs/labs-3.0-build/integration/sbs/reports/trunk/src/test/resources/log4j.properties 2010-10-22 08:30:53 UTC (rev 35663)
@@ -0,0 +1,7 @@
+log4j.rootLogger=error, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+
+# Pattern to output identifiable messages.
+log4j.appender.stdout.layout.ConversionPattern=LogFromTestedMethod: %5p [%t] (%F:%L) - %m%n
More information about the jboss-svn-commits
mailing list