maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denn...@apache.org
Subject svn commit: r1379884 - in /maven/plugins/trunk/maven-changes-plugin/src: main/java/org/apache/maven/plugin/jira/ test/java/org/apache/maven/plugin/jira/
Date Sat, 01 Sep 2012 22:32:02 GMT
Author: dennisl
Date: Sat Sep  1 22:32:02 2012
New Revision: 1379884

URL: http://svn.apache.org/viewvc?rev=1379884&view=rev
Log:
[MCHANGES-285] SAXException parsing JIRA XML from JIRA 5.1 

Submitted by: Ton Swieb
Reviewed by: Dennis Lundberg

I have reformated the code to follow our code style and added a license header that was missing.

Added:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JqlQueryBuilder.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/UrlBuilder.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JqlQueryBuilderTest.java
  (with props)
    maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/UrlBuilderTest.java
  (with props)
Modified:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/AbstractJiraDownloader.java
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
    maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JiraHelperTestCase.java

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/AbstractJiraDownloader.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/AbstractJiraDownloader.java?rev=1379884&r1=1379883&r2=1379884&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/AbstractJiraDownloader.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/AbstractJiraDownloader.java
Sat Sep  1 22:32:02 2012
@@ -19,7 +19,6 @@ package org.apache.maven.plugin.jira;
  * under the License.
  */
 
-import org.apache.commons.httpclient.cookie.CookiePolicy;
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HostConfiguration;
@@ -29,9 +28,10 @@ import org.apache.commons.httpclient.Htt
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.StatusLine;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.params.HttpClientParams;
 import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.cookie.CookiePolicy;
 import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpClientParams;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.issues.Issue;
 import org.apache.maven.plugin.logging.Log;
@@ -51,9 +51,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLEncoder;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -103,6 +101,8 @@ public abstract class AbstractJiraDownlo
     private MavenProject project;
     /** The maven settings. */
     private Settings settings;
+    /** Use JQL, JIRA query language, instead of URL parameter based queries */
+    private boolean useJql;
     /** The pattern used to parse dates from the JIRA xml file. */
     protected String jiraDatePattern;
 
@@ -132,7 +132,15 @@ public abstract class AbstractJiraDownlo
             client.setState( state );
 
             String fullUrl = null;
-            fullUrl = getParameterBasedQueryURL( client );
+
+            if ( useJql )
+            {
+                fullUrl = getJqlQueryURL();
+            }
+            else
+            {
+                fullUrl = getParameterBasedQueryURL( client );
+            }
             String baseUrl = JiraHelper.getBaseUrl( fullUrl );
 
             getLog().debug( "JIRA lives at: " + baseUrl );
@@ -171,6 +179,42 @@ public abstract class AbstractJiraDownlo
         }
     }
 
+    private String getJqlQueryURL()
+    {
+        // JQL is based on project names instead of project ID's
+        Map<String, String> urlMap = JiraHelper.getJiraUrlAndProjectName( project.getIssueManagement().getUrl()
);
+        String jiraUrl = urlMap.get( "url" );
+        String jiraProject = urlMap.get( "project" );
+
+        if ( jiraProject == null )
+        {
+            throw new RuntimeException( "The issue management URL in the POM does not include
a JIRA project name" );
+        }
+        else
+        {
+            // create the URL for getting the proper issues from JIRA
+            String jqlQuery = new JqlQueryBuilder( log )
+                    .project( jiraProject )
+                    .fixVersion( getFixFor() )
+                    .fixVersionIds( fixVersionIds )
+                    .statusIds( statusIds )
+                    .priorityIds( priorityIds )
+                    .resolutionIds( resolutionIds )
+                    .components( component )
+                    .typeIds( typeIds )
+                    .sortColumnNames( sortColumnNames )
+                    .build();
+
+            String url = new UrlBuilder( jiraUrl, "sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml"
)
+                    .addParameter( "tempMax", nbEntriesMax )
+                    .addParameter( "reset", "true" )
+                    .addParameter( "jqlQuery", jqlQuery )
+                    .build();
+
+            return url;
+        }
+    }
+
     private String getParameterBasedQueryURL( HttpClient client )
     {
         Map<String, String> urlMap = JiraHelper.getJiraUrlAndProjectId( project.getIssueManagement().getUrl()
);
@@ -715,4 +759,14 @@ public abstract class AbstractJiraDownlo
     {
         this.settings = settings;
     }
+
+	public boolean isUseJql()
+	{
+		return useJql;
+	}
+
+	public void setUseJql(boolean useJql)
+	{
+		this.useJql = useJql;
+	}
 }

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java?rev=1379884&r1=1379883&r2=1379884&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java
Sat Sep  1 22:32:02 2012
@@ -192,6 +192,53 @@ public class JiraHelper
     }
 
     /**
+     * Parse out the base URL for JIRA and the JIRA project name from the issue
+     * management URL.
+     * The issue management URL is assumed to be of the format http(s)://host:port/browse/{projectname}
+     *
+     * @param issueManagementUrl The URL to the issue management system
+     * @return A <code>Map</code> containing the URL and project name
+     * @since 2.8
+     */
+    public static Map<String, String> getJiraUrlAndProjectName( String issueManagementUrl
)
+    {
+        final int indexBrowse = issueManagementUrl.indexOf( "/browse/" );
+
+        String jiraUrl = "";
+        String project = "";
+
+        if ( indexBrowse != -1 )
+        {
+            jiraUrl = issueManagementUrl.substring( 0, indexBrowse );
+
+            final int indexBrowseEnd = indexBrowse + "/browse/".length();
+
+            final int indexProject = issueManagementUrl.indexOf( "/", indexBrowseEnd );
+
+            if ( indexProject != -1 )
+            {
+                //Project name has trailing '/'
+                project = issueManagementUrl.substring( indexBrowseEnd, indexProject );
+            }
+            else
+            {
+                //Project name without trailing '/'
+                project = issueManagementUrl.substring( indexBrowseEnd );
+            }
+        }
+        else
+        {
+            throw new IllegalArgumentException( "Invalid browse URL" );
+        }
+
+        HashMap<String, String> urlMap = new HashMap<String, String>( 4 );
+        urlMap.put( "url", jiraUrl );
+        urlMap.put( "project", project );
+
+        return urlMap;
+    }
+
+    /**
      * @since 2.8
      */
     public static String getBaseUrl( String url )

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java?rev=1379884&r1=1379883&r2=1379884&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
Sat Sep  1 22:32:02 2012
@@ -90,6 +90,14 @@ public class JiraMojo
     private String columnNames;
 
     /**
+     * Use the JIRA query language instead of the JIRA query based on HTTP parameters. 
+     * From JIRA 5.1 and up only JQL is supported. JIRA 4.4 supports both JQL and URL parameter
based queries.
+     * @since 2.8
+     */
+    @Parameter( defaultValue = "false" )
+    private boolean useJql;
+    
+    /**
      * Sets the component(s) that you want to limit your report to include.
      * Multiple values can be separated by commas (such as 10011,10012).
      * If this is set to empty - that means all components will be included.
@@ -425,6 +433,8 @@ public class JiraMojo
         issueDownloader.setWebPassword( webPassword );
 
         issueDownloader.setSettings( settings );
+
+        issueDownloader.setUseJql( useJql );
     }
 
     public void setMockDownloader( AbstractJiraDownloader mockDownloader )

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JqlQueryBuilder.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JqlQueryBuilder.java?rev=1379884&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JqlQueryBuilder.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JqlQueryBuilder.java
Sat Sep  1 22:32:02 2012
@@ -0,0 +1,241 @@
+package org.apache.maven.plugin.jira;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Locale;
+
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * Builder for a JIRA query using the JIRA query language.
+ * Only a limited set of JQL is supported.
+ *
+ * @author ton.swieb@finalist.com
+ * @since 2.8
+ */
+public class JqlQueryBuilder
+{
+    /**
+     * Log for debug output.
+     */
+    protected Log log;
+
+    private StringBuilder query = new StringBuilder();
+
+    private StringBuilder orderBy = new StringBuilder();
+
+    private String filter = "";
+
+    public JqlQueryBuilder( Log log )
+    {
+        this.log = log;
+    }
+
+    public JqlQueryBuilder project( String project )
+    {
+        AddSingleValue( "project", project );
+        return this;
+    }
+
+    /**
+     * When both {@link #fixVersion(String)} and {@link #fixVersionIds(String)} are used
then you will probably
+     * end up with a JQL query that is valid, but returns nothing. Unless they both only
reference the same fixVersion
+     *
+     * @param fixVersionIds
+     * @return
+     */
+    public JqlQueryBuilder fixVersionIds( String fixVersionIds )
+    {
+        AddCommaSeparatedValues( "fixVersion", fixVersionIds );
+        return this;
+    }
+
+    public JqlQueryBuilder statusIds( String statusIds )
+    {
+        AddCommaSeparatedValues( "status", statusIds );
+        return this;
+    }
+
+    public JqlQueryBuilder priorityIds( String priorityIds )
+    {
+        AddCommaSeparatedValues( "priority", priorityIds );
+        return this;
+    }
+
+    public JqlQueryBuilder resolutionIds( String resolutionIds )
+    {
+        AddCommaSeparatedValues( "resolution", resolutionIds );
+        return this;
+    }
+
+    public JqlQueryBuilder components( String components )
+    {
+        AddCommaSeparatedValues( "component", components );
+        return this;
+    }
+
+    public JqlQueryBuilder typeIds( String typeIds )
+    {
+        AddCommaSeparatedValues( "type", typeIds );
+        return this;
+    }
+
+    public JqlQueryBuilder filter( String filter )
+    {
+        this.filter = filter;
+        return this;
+    }
+
+    /**
+     * When both {@link #fixVersion(String)} and {@link #fixVersionIds(String)} are used
then you will probably
+     * end up with a JQL query that is valid, but returns nothing. Unless they both only
reference the same fixVersion
+     *
+     * @param fixVersion
+     * @return
+     */
+    public JqlQueryBuilder fixVersion( String fixVersion )
+    {
+        AddSingleValue( "fixVersion", fixVersion );
+        return this;
+    }
+
+    public JqlQueryBuilder sortColumnNames( String sortColumnNames )
+    {
+        if ( sortColumnNames != null )
+        {
+
+            orderBy.append( " ORDER BY " );
+
+            String[] sortColumnNamesArray = sortColumnNames.split( "," );
+
+            for ( int i = 0; i < sortColumnNamesArray.length - 1; i++ )
+            {
+                addSingleSortColumn( sortColumnNamesArray[i] );
+                orderBy.append( ", " );
+            }
+            addSingleSortColumn( sortColumnNamesArray[sortColumnNamesArray.length - 1] );
+        }
+        return this;
+    }
+
+    private void addSingleSortColumn( String name )
+    {
+
+        boolean descending = false;
+        name = name.trim().toLowerCase( Locale.ENGLISH );
+        if ( name.endsWith( "desc" ) )
+        {
+            descending = true;
+            name = name.substring( 0, name.length() - 4 ).trim();
+        }
+        else if ( name.endsWith( "asc" ) )
+        {
+            descending = false;
+            name = name.substring( 0, name.length() - 3 ).trim();
+        }
+        orderBy.append( name );
+        orderBy.append( descending ? " DESC" : " ASC" );
+    }
+
+
+    private void AddSingleValue( String key, String value )
+    {
+        if ( value != null )
+        {
+            if ( query.length() > 0 )
+            {
+                query.append( " AND " );
+            }
+            query.append( key ).append( " = " );
+            TrimAndQuoteValue( value );
+        }
+    }
+
+    private void AddCommaSeparatedValues( String key, String values )
+    {
+        if ( values != null )
+        {
+            if ( query.length() > 0 )
+            {
+                query.append( " AND " );
+            }
+
+            query.append( key + " in (" );
+
+            String[] valuesArr = values.split( "," );
+
+            for ( int i = 0; i < ( valuesArr.length - 1 ); i++ )
+            {
+                TrimAndQuoteValue( valuesArr[i] );
+                query.append( ", " );
+            }
+            TrimAndQuoteValue( valuesArr[valuesArr.length - 1] );
+            query.append( ")" );
+        }
+    }
+
+    private void TrimAndQuoteValue( String value )
+    {
+
+        String trimmedValue = value.trim();
+        if ( trimmedValue.contains( " " ) || trimmedValue.contains( "." ) )
+        {
+            query.append( "\"" ).append( trimmedValue ).append( "\"" );
+        }
+        else
+        {
+            query.append( trimmedValue );
+        }
+    }
+
+    public String build()
+    {
+
+        try
+        {
+            String jqlQuery;
+            // If the user has defined a filter - use that
+            if ( ( this.filter != null ) && ( this.filter.length() > 0 ) )
+            {
+                jqlQuery = filter;
+            }
+            else
+            {
+                jqlQuery = query.toString() + orderBy.toString();
+            }
+            getLog().debug( "Encoding JBL query " + jqlQuery );
+            String encodedQuery = URLEncoder.encode( jqlQuery, "UTF-8" );
+            getLog().debug( "Encoded JBL query " + encodedQuery );
+            return encodedQuery;
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            getLog().error( "Unable to encode JBL query with UTF-8", e );
+            throw new RuntimeException( e );
+        }
+    }
+
+    public Log getLog()
+    {
+        return log;
+    }
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JqlQueryBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/UrlBuilder.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/UrlBuilder.java?rev=1379884&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/UrlBuilder.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/UrlBuilder.java
Sat Sep  1 22:32:02 2012
@@ -0,0 +1,67 @@
+package org.apache.maven.plugin.jira;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Builder for a URL which build up of host part, a context part and 0 or more parameters.
+ *
+ * @author ton.swieb@finalist.com
+ * @since 2.8
+ */
+public class UrlBuilder
+{
+    private static final String AMPERSAND = "&";
+    private static final String QUESTION_MARK = "?";
+
+    StringBuilder query = new StringBuilder();
+
+    public UrlBuilder( String url, String context )
+    {
+        query.append( url ).append( "/" ).append( context );
+    }
+
+    public UrlBuilder addParameter( String key, String value )
+    {
+        if ( key != null && value != null )
+        {
+            if ( query.toString().contains( QUESTION_MARK ) )
+            {
+                query.append( AMPERSAND );
+            }
+            else
+            {
+                query.append( QUESTION_MARK );
+            }
+            query.append( key + "=" + value );
+        }
+        return this;
+    }
+
+    public UrlBuilder addParameter( String key, int value )
+    {
+        addParameter( key, String.valueOf( value ) );
+        return this;
+    }
+
+    public String build()
+    {
+        return query.toString();
+    }
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/UrlBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JiraHelperTestCase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JiraHelperTestCase.java?rev=1379884&r1=1379883&r2=1379884&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JiraHelperTestCase.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JiraHelperTestCase.java
Sat Sep  1 22:32:02 2012
@@ -51,6 +51,18 @@ public class JiraHelperTestCase
         assertEquals( "http://jira.codehaus.org", map.get( "url" ) );
     }
 
+    public void testGetJiraUrlAndProjectName()
+    {
+        Map<String, String> map;
+        map = JiraHelper.getJiraUrlAndProjectName( "http://jira.codehaus.org/browse/DOXIA/"
);
+        assertEquals( "http://jira.codehaus.org", map.get( "url" ) );
+        assertEquals( "DOXIA", map.get( "project" ) );
+
+        map = JiraHelper.getJiraUrlAndProjectName( "http://jira.codehaus.org/browse/DOXIA"
);
+        assertEquals( "http://jira.codehaus.org", map.get( "url" ) );
+        assertEquals( "DOXIA", map.get( "project" ) );
+    }
+
     public void testGetBaseUrl()
     {
         String expected = "http://www.jira.com";

Added: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JqlQueryBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JqlQueryBuilderTest.java?rev=1379884&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JqlQueryBuilderTest.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JqlQueryBuilderTest.java
Sat Sep  1 22:32:02 2012
@@ -0,0 +1,174 @@
+package org.apache.maven.plugin.jira;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+/**
+ * Test class for {@link JqlQueryBuilder}
+ *
+ * @author ton.swieb@finalist.com
+ * @since 2.8
+ */
+public class JqlQueryBuilderTest
+    extends TestCase
+{
+
+    public static final String ENCODING = "UTF-8";
+
+    public void testEmptyQuery()
+    {
+        String actual = new JqlQueryBuilder( new SystemStreamLog() ).build();
+        String expected = "";
+        assertEquals( expected, actual );
+    }
+
+    public void testSingleParameterValue()
+        throws UnsupportedEncodingException
+    {
+        String expected = URLEncoder.encode( "project = DOXIA", ENCODING );
+
+        String actual = createBuilder().project( "DOXIA" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testFixVersion()
+        throws UnsupportedEncodingException
+    {
+
+        String expected = URLEncoder.encode( "fixVersion = \"1.0\"", ENCODING );
+
+        String actual = createBuilder().fixVersion( "1.0" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testFixVersionCombinedWithOtherParameters()
+        throws UnsupportedEncodingException
+    {
+        String expected = URLEncoder.encode( "project = DOXIA AND fixVersion = \"1.0\"",
ENCODING );
+
+        String actual = createBuilder().project( "DOXIA" ).fixVersion( "1.0" ).build();
+        assertEquals( expected, actual );
+
+    }
+
+    public void testSingleParameterSingleValue()
+        throws UnsupportedEncodingException
+    {
+        String expected = URLEncoder.encode( "priority in (Blocker)", ENCODING );
+
+        String actual = createBuilder().priorityIds( "Blocker" ).build();
+        assertEquals( expected, actual );
+
+        actual = createBuilder().priorityIds( "  Blocker   " ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testSingleParameterMultipleValues()
+        throws UnsupportedEncodingException
+    {
+
+        String expected = URLEncoder.encode( "priority in (Blocker, Critical, Major)", ENCODING
);
+
+        String actual = createBuilder().priorityIds( "Blocker,Critical,Major" ).build();
+        assertEquals( expected, actual );
+
+        actual = createBuilder().priorityIds( "  Blocker  ,  Critical,  Major" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testMultipleParameterCombinedWithAND()
+        throws UnsupportedEncodingException
+    {
+
+        String expected = URLEncoder.encode( "priority in (Blocker) AND status in (Resolved)",
ENCODING );
+
+        String actual = createBuilder().priorityIds( "Blocker" ).statusIds( "Resolved" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testValueWithSpacesAreQuoted()
+        throws UnsupportedEncodingException
+    {
+
+        String expected = URLEncoder.encode( "status in (\"In Progress\")", ENCODING );
+
+        String actual = createBuilder().statusIds( "In Progress" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testSortSingleRowAscending()
+        throws UnsupportedEncodingException
+    {
+        String expected = URLEncoder.encode( "project = DOXIA ORDER BY key ASC", ENCODING
);
+
+        String actual = createBuilder().project( "DOXIA" ).sortColumnNames( "key" ).build();
+        assertEquals( expected, actual );
+
+        actual = createBuilder().project( "DOXIA" ).sortColumnNames( "key ASC" ).build();
+        assertEquals( expected, actual );
+
+        actual = createBuilder().project( "DOXIA" ).sortColumnNames( "     key    ASC   
" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testSortSingleDescending()
+        throws UnsupportedEncodingException
+    {
+        String expected = URLEncoder.encode( "project = DOXIA ORDER BY key DESC", ENCODING
);
+
+        String actual = createBuilder().project( "DOXIA" ).sortColumnNames( "key DESC" ).build();
+        assertEquals( expected, actual );
+
+        actual = createBuilder().project( "DOXIA" ).sortColumnNames( "     key    DESC  
 " ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testSortMultipleColumns()
+        throws UnsupportedEncodingException
+    {
+        String expected =
+            URLEncoder.encode( "project = DOXIA ORDER BY key ASC, assignee DESC, reporter
ASC", ENCODING );
+
+        String actual =
+            createBuilder().project( "DOXIA" ).sortColumnNames( "key ASC,assignee DESC, reporter
ASC" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testOrderByIsLastElement()
+        throws UnsupportedEncodingException
+    {
+        String expected =
+            URLEncoder.encode( "project = DOXIA ORDER BY key ASC, assignee DESC, reporter
ASC", ENCODING );
+
+        String actual =
+            createBuilder().sortColumnNames( "key ASC,assignee DESC, reporter ASC" ).project(
"DOXIA" ).build();
+        assertEquals( expected, actual );
+    }
+
+    private JqlQueryBuilder createBuilder()
+    {
+        return new JqlQueryBuilder( new SystemStreamLog() );
+    }
+}
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/JqlQueryBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/UrlBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/UrlBuilderTest.java?rev=1379884&view=auto
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/UrlBuilderTest.java
(added)
+++ maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/UrlBuilderTest.java
Sat Sep  1 22:32:02 2012
@@ -0,0 +1,64 @@
+package org.apache.maven.plugin.jira;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link UrlBuilder}
+ *
+ * @author ton.swieb@finalist.com
+ * @since 2.8
+ */
+public class UrlBuilderTest
+    extends TestCase
+{
+
+    public void testUrlWithoutParameters()
+    {
+        String expected = "http://www.jira.com/context";
+        String actual = new UrlBuilder( "http://www.jira.com", "context" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testUrlWithSingleParameter()
+    {
+        String expected = "http://www.jira.com/context?key1=value1";
+        String actual = new UrlBuilder( "http://www.jira.com", "context" ).addParameter(
"key1", "value1" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testUrlWithMultipleParameters()
+    {
+        String expected = "http://www.jira.com/context?key1=value1&key2=value2";
+        String actual =
+            new UrlBuilder( "http://www.jira.com", "context" ).addParameter( "key1", "value1"
).addParameter( "key2",
+                                                                                        
                     "value2" ).build();
+        assertEquals( expected, actual );
+    }
+
+    public void testUrlWithIntParameter()
+    {
+        String expected = "http://www.jira.com/context?key1=1";
+        String actual = new UrlBuilder( "http://www.jira.com", "context" ).addParameter(
"key1", 1 ).build();
+        assertEquals( expected, actual );
+    }
+
+}

Propchange: maven/plugins/trunk/maven-changes-plugin/src/test/java/org/apache/maven/plugin/jira/UrlBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message