Author: tchemit Date: 2012-07-15 21:08:28 +0200 (Sun, 15 Jul 2012) New Revision: 307 Url: http://nuiton.org/repositories/revision/jredmine/307 Log: fixes #2188: Make possible to use redmine service or any api without plexus container fixes #2189: Improve RedmineService design refs #937: Maven test utilise les properties de test de la distribution (improve test design) Added: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServer.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java Removed: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java Modified: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/model/io/xpp3/RedmineXpp3HelperTest.java branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java Modified: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java 2012-07-15 19:08:28 UTC (rev 307) @@ -26,7 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.io.rest.RestClient; import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.model.Attachment; import org.nuiton.jredmine.model.Issue; @@ -44,8 +43,6 @@ /** * Default implementation of {@link RedmineAnonymousService}. * <p/> - * This implementation just make sure that the rest client is anonnymous. - * <p/> * Created: 2 janv. 2010 * * @author tchemit <chemit@codelutin.com> @@ -53,152 +50,195 @@ * @see RestClientConfiguration#isAnonymous() * @since 1.0.3 */ -public class DefaultRedmineAnonymousService implements RedmineServiceImplementor, RedmineAnonymousService { +public class DefaultRedmineAnonymousService implements RedmineAnonymousService { /** Logger. */ private static final Log log = LogFactory.getLog(DefaultRedmineAnonymousService.class); - /** @plexus.requirement role="org.nuiton.jredmine.RedmineServiceImplementor" role-hint="default" */ - protected RedmineServiceImplementor delegateImplementor; + /** + * Delegate all the technical layer to an implementor. + * + * @see RedmineServiceImplementor + */ + protected final RedmineServiceImplementor delegateImplementor; + /** + * Default constructor. + * <p/> + * Make this service use the default {@link RedmineServiceImplementor}. + * + * @see DefaultRedmineServiceImplementor + * @since 1.4 + */ public DefaultRedmineAnonymousService() { + this(new DefaultRedmineServiceImplementor()); } + /** + * Service constructor using the givne implementator to deal this technical layer. + * + * @param delegateImplementor the implementator to use + * @since 1.4 + */ + public DefaultRedmineAnonymousService(RedmineServiceImplementor delegateImplementor) { + this.delegateImplementor = delegateImplementor; + } + /////////////////////////////////////////////////////////////////////////// /// RedmineAnonymousService implementation /////////////////////////////////////////////////////////////////////////// @Override + public void init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + // Force to not be loggued + configuration.setAnonymous(true); + if (log.isDebugEnabled()) { + log.debug("init service with configuration: " + configuration); + } + delegateImplementor.init(configuration); + } + + @Override + public void destroy() throws RedmineServiceException { + delegateImplementor.destroy(); + } + + @Override + public RedmineServiceImplementor getDelegateImplementor() { + return delegateImplementor; + } + + @Override public IssueStatus[] getIssueStatuses() throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME, - IssueStatus.class + return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME, + IssueStatus.class ); } @Override public IssuePriority[] getIssuePriorities() throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME, - IssuePriority.class + return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME, + IssuePriority.class ); } @Override public Project[] getProjects() throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME, Project.class); + return delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME, Project.class); } @Override public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, - IssueCategory.class, - projectName + return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, + IssueCategory.class, + projectName ); } @Override public Project getProject(String projectName) throws RedmineServiceException { - return getData(ModelHelper.GET_PROJECT_REQUEST_NAME, - Project.class, - projectName + return delegateImplementor.getData(ModelHelper.GET_PROJECT_REQUEST_NAME, + Project.class, + projectName ); } @Override public Tracker[] getTrackers(String projectName) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, - Tracker.class, - projectName + return delegateImplementor.getDatas(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, + Tracker.class, + projectName ); } @Override public News[] getNews(String projectName) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, - News.class, - projectName + return delegateImplementor.getDatas(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, + News.class, + projectName ); } @Override public User[] getProjectMembers(String projectName) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_USER_REQUEST_NAME, - User.class, - projectName + return delegateImplementor.getDatas(ModelHelper.GET_ALL_USER_REQUEST_NAME, + User.class, + projectName ); } @Override public Version[] getVersions(String projectName) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, - Version.class, - projectName + return delegateImplementor.getDatas(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, + Version.class, + projectName ); } @Override public Version getVersion(String projectName, String versionName) throws RedmineServiceException { - return getData(ModelHelper.GET_VERSION_REQUEST_NAME, - Version.class, - projectName, - versionName + return delegateImplementor.getData(ModelHelper.GET_VERSION_REQUEST_NAME, + Version.class, + projectName, + versionName ); } @Override public Attachment[] getAttachments(String projectName, String versionName) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, - Attachment.class, - projectName, - versionName + return delegateImplementor.getDatas(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, + Attachment.class, + projectName, + versionName ); } @Override public Issue[] getIssues(String projectName, String versionName) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, - Issue.class, - projectName, - versionName + return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, + Issue.class, + projectName, + versionName ); } @Override public TimeEntry[] getIssueTimeEntries(String projectName, String issueId) throws RedmineServiceException { - return getDatas(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, - TimeEntry.class, - projectName, - issueId + return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, + TimeEntry.class, + projectName, + issueId ); } @Override public Issue[] getIssues(String projectName) throws RedmineServiceException { - Issue[] result = getDatas(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, - Issue.class, - projectName + Issue[] result = delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, + Issue.class, + projectName ); return result; } @Override public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { - Issue[] result = getDatas(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, - Issue.class, - projectName + Issue[] result = delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, + Issue.class, + projectName ); return result; } @Override public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { - Issue[] result = getDatas(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, - Issue.class, - projectName + Issue[] result = delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, + Issue.class, + projectName ); return result; } @@ -206,72 +246,63 @@ /////////////////////////////////////////////////////////////////////////// /// RedmineServiceImplementor implementation /////////////////////////////////////////////////////////////////////////// - @Override - public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { - // Force to not be loggued - configuration.setAnonymous(true); - if (log.isDebugEnabled()) { - log.debug("init configuration for " + this); - } - RedmineServiceImplementor result = delegateImplementor.init(configuration); - return result; - } - @Override - public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { - if (log.isDebugEnabled()) { - log.debug("init session for " + this); - } - checkNotLoggued(session); - return delegateImplementor.init(session); - } +// @Override +// public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { +// // Force to not be loggued +// configuration.setAnonymous(true); +// if (log.isDebugEnabled()) { +// log.debug("init configuration for " + this); +// } +// return delegateImplementor.init(configuration); +// } +// +// @Override +// public <T> T getData(String requestName, +// Class<T> type, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.getData(requestName, type, args); +// } +// +// @Override +// public <T> T[] getDatas(String requestName, +// Class<T> type, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.getDatas(requestName, type, args); +// } +// +// @Override +// public <T> T sendData(String requestName, +// Class<T> klazz, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.sendData(requestName, klazz, args); +// } +// +// @Override +// public <T> T[] sendDatas(String requestName, +// Class<T> klazz, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.sendDatas(requestName, klazz, args); +// } +// +// @Override +// public boolean isInit() { +// return delegateImplementor.isInit(); +// } +// +// @Override +// public void destroy() throws RedmineServiceException { +// delegateImplementor.destroy(); +// } +// +// @Override +// public void checkNotLoggued(RestClient session) throws IllegalStateException, RedmineServiceLoginException, NullPointerException { +// delegateImplementor.checkNotLoggued(session); +// } +// +// @Override +// public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { +// delegateImplementor.checkLoggued(); +// } - @Override - public <T> T getData(String requestName, - Class<T> type, - Object... args) throws RedmineServiceException { - return delegateImplementor.getData(requestName, type, args); - } - - @Override - public <T> T[] getDatas(String requestName, - Class<T> type, - Object... args) throws RedmineServiceException { - return delegateImplementor.getDatas(requestName, type, args); - } - - @Override - public <T> T sendData(String requestName, - Class<T> klazz, - Object... args) throws RedmineServiceException { - return delegateImplementor.sendData(requestName, klazz, args); - } - - @Override - public <T> T[] sendDatas(String requestName, - Class<T> klazz, - Object... args) throws RedmineServiceException { - return delegateImplementor.sendDatas(requestName, klazz, args); - } - - @Override - public boolean isInit() { - return delegateImplementor.isInit(); - } - - @Override - public void destroy() throws RedmineServiceException { - delegateImplementor.destroy(); - } - - @Override - public void checkNotLoggued(RestClient session) throws IllegalStateException, RedmineServiceLoginException, NullPointerException { - delegateImplementor.checkNotLoggued(session); - } - - @Override - public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { - delegateImplementor.checkLoggued(); - } - } Modified: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2012-07-15 19:08:28 UTC (rev 307) @@ -26,49 +26,200 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.io.rest.RestClient; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; import org.nuiton.jredmine.model.ModelHelper; import org.nuiton.jredmine.model.News; import org.nuiton.jredmine.model.Project; import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; import org.nuiton.jredmine.model.Version; /** - * Default {@link RedmineService} implementation based on a {@link RestClient} + * Default {@link RedmineService} implementation. * * @author tchemit <chemit@codelutin.com> * @plexus.component role="org.nuiton.jredmine.RedmineService" role-hint="default" * @since 1.0.0 */ -public class DefaultRedmineService extends DefaultRedmineAnonymousService implements RedmineService { +public class DefaultRedmineService implements RedmineService { protected static final Log log = LogFactory.getLog(DefaultRedmineService.class); + /** + * Delegate all the technical layer to a implementor. + * + * @see RedmineServiceImplementor + * @since 1.4 + */ + protected final RedmineServiceImplementor delegateImplementor; + + /** + * Delegate all anonymous call to the anonymous service. + * + * @see RedmineAnonymousService + * @since 1.4 + */ + protected final RedmineAnonymousService anonymousService; + + /** + * Default constructor. + * <p/> + * Make this service use the default {@link RedmineServiceImplementor}. + * + * @see DefaultRedmineServiceImplementor + * @since 1.4 + */ + public DefaultRedmineService() { + this(new DefaultRedmineServiceImplementor()); + } + + /** + * Service constructor using the givne implementator to deal this technical layer. + * + * @param delegateImplementor the implementator to use + * @since 1.4 + */ + public DefaultRedmineService(RedmineServiceImplementor delegateImplementor) { + this.delegateImplementor = delegateImplementor; + this.anonymousService = new DefaultRedmineAnonymousService(delegateImplementor); + } + /////////////////////////////////////////////////////////////////////////// - /// RedmineServiceImplementor implementation + /// RedmineAnonymousService implementation /////////////////////////////////////////////////////////////////////////// + @Override - public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { - RedmineServiceImplementor result = delegateImplementor.init(configuration); + public void init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + if (log.isDebugEnabled()) { + log.debug("init service with configuration: " + configuration); + } + delegateImplementor.init(configuration); + } + + @Override + public void destroy() throws RedmineServiceException { + delegateImplementor.destroy(); + } + + @Override + public RedmineServiceImplementor getDelegateImplementor() { + return delegateImplementor; + } + + @Override + public IssueStatus[] getIssueStatuses() throws RedmineServiceException { + IssueStatus[] result = anonymousService.getIssueStatuses(); return result; } @Override - public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { - return delegateImplementor.init(session); + public IssuePriority[] getIssuePriorities() throws RedmineServiceException { + IssuePriority[] result = anonymousService.getIssuePriorities(); + return result; } + @Override + public Project[] getProjects() throws RedmineServiceException { + Project[] result = anonymousService.getProjects(); + return result; + } + + @Override + public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { + IssueCategory[] result = anonymousService.getIssueCategories(projectName); + return result; + } + + @Override + public Project getProject(String projectName) throws RedmineServiceException { + Project result = anonymousService.getProject(projectName); + return result; + } + + @Override + public Tracker[] getTrackers(String projectName) throws RedmineServiceException { + Tracker[] result = anonymousService.getTrackers(projectName); + return result; + } + + @Override + public News[] getNews(String projectName) throws RedmineServiceException { + News[] result = anonymousService.getNews(projectName); + return result; + } + + @Override + public User[] getProjectMembers(String projectName) throws RedmineServiceException { + User[] result = anonymousService.getProjectMembers(projectName); + return result; + } + + @Override + public Version[] getVersions(String projectName) throws RedmineServiceException { + Version[] result = anonymousService.getVersions(projectName); + return result; + } + + @Override + public Version getVersion(String projectName, + String versionName) throws RedmineServiceException { + Version result = anonymousService.getVersion(projectName, versionName); + return result; + } + + @Override + public Attachment[] getAttachments(String projectName, + String versionName) throws RedmineServiceException { + Attachment[] result = anonymousService.getAttachments(projectName, versionName); + return result; + } + + @Override + public Issue[] getIssues(String projectName, + String versionName) throws RedmineServiceException { + Issue[] result = anonymousService.getIssues(projectName, versionName); + return result; + } + + @Override + public TimeEntry[] getIssueTimeEntries(String projectName, + String issueId) throws RedmineServiceException { + TimeEntry[] result = anonymousService.getIssueTimeEntries(projectName, issueId); + return result; + } + + @Override + public Issue[] getIssues(String projectName) throws RedmineServiceException { + Issue[] result = anonymousService.getIssues(projectName); + return result; + } + + @Override + public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { + Issue[] result = anonymousService.getOpenedIssues(projectName); + return result; + } + + @Override + public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { + Issue[] result = anonymousService.getClosedIssues(projectName); + return result; + } + /////////////////////////////////////////////////////////////////////////// /// RedmineLogguedService implementation /////////////////////////////////////////////////////////////////////////// @Override public Project[] getUserProjects() throws RedmineServiceException { - checkLoggued(); - Project[] result = getDatas(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME, - Project.class); + delegateImplementor.checkLoggued(); + Project[] result = delegateImplementor.getDatas(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME, + Project.class); return result; } @@ -77,10 +228,10 @@ Version version) throws RedmineServiceException { // send data and obtain created version - Version result = sendData(ModelHelper.ADD_VERSION_REQUEST_NAME, - Version.class, - projectName, - version + Version result = delegateImplementor.sendData(ModelHelper.ADD_VERSION_REQUEST_NAME, + Version.class, + projectName, + version ); return result; } @@ -90,10 +241,10 @@ Version version) throws RedmineServiceException { // send data and obtain updated version - Version result = sendData(ModelHelper.UPDATE_VERSION_REQUEST_NAME, - Version.class, - projectName, - version + Version result = delegateImplementor.sendData(ModelHelper.UPDATE_VERSION_REQUEST_NAME, + Version.class, + projectName, + version ); return result; } @@ -104,11 +255,11 @@ Version newVersion) throws RedmineServiceException { // send data and obtain updated or created new version - Version result = sendData(ModelHelper.NEXT_VERSION_REQUEST_NAME, - Version.class, - projectName, - newVersion, - oldVersionName + Version result = delegateImplementor.sendData(ModelHelper.NEXT_VERSION_REQUEST_NAME, + Version.class, + projectName, + newVersion, + oldVersionName ); return result; } @@ -119,11 +270,11 @@ Attachment attachement) throws RedmineServiceException { // send data and obtain created attachment - Attachment result = sendData(ModelHelper.ADD_ATTACHMENT_REQUEST_NAME, - Attachment.class, - projectName, - versionName, - attachement + Attachment result = delegateImplementor.sendData(ModelHelper.ADD_ATTACHMENT_REQUEST_NAME, + Attachment.class, + projectName, + versionName, + attachement ); return result; } @@ -131,11 +282,12 @@ @Override public News addNews(String projectName, News news) throws RedmineServiceException { + // send data and obtain created news - News result = sendData(ModelHelper.ADD_NEWS_REQUEST_NAME, - News.class, - projectName, - news + News result = delegateImplementor.sendData(ModelHelper.ADD_NEWS_REQUEST_NAME, + News.class, + projectName, + news ); return result; } @@ -144,13 +296,74 @@ public TimeEntry addIssueTimeEntry(String projectName, String issueId, TimeEntry entry) throws RedmineServiceException { - // send data and obtain updated version - TimeEntry result = sendData(ModelHelper.ADD_ISSUE_TIME_ENTRY_REQUEST_NAME, - TimeEntry.class, - projectName, - issueId, - entry + + // send data and obtain created time entry + TimeEntry result = delegateImplementor.sendData(ModelHelper.ADD_ISSUE_TIME_ENTRY_REQUEST_NAME, + TimeEntry.class, + projectName, + issueId, + entry ); return result; } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineServiceImplementor implementation + /////////////////////////////////////////////////////////////////////////// + +// @Override +// public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { +// if (log.isDebugEnabled()) { +// log.debug("init configuration for " + this); +// } +// return delegateImplementor.init(configuration); +// } +// +// @Override +// public <T> T getData(String requestName, +// Class<T> type, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.getData(requestName, type, args); +// } +// +// @Override +// public <T> T[] getDatas(String requestName, +// Class<T> type, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.getDatas(requestName, type, args); +// } +// +// @Override +// public <T> T sendData(String requestName, +// Class<T> klazz, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.sendData(requestName, klazz, args); +// } +// +// @Override +// public <T> T[] sendDatas(String requestName, +// Class<T> klazz, +// Object... args) throws RedmineServiceException { +// return delegateImplementor.sendDatas(requestName, klazz, args); +// } +// +// @Override +// public boolean isInit() { +// return delegateImplementor.isInit(); +// } +// +// @Override +// public void destroy() throws RedmineServiceException { +// delegateImplementor.destroy(); +// } +// +// @Override +// public void checkNotLoggued(RestClient session) throws IllegalStateException, RedmineServiceLoginException, NullPointerException { +// delegateImplementor.checkNotLoggued(session); +// } +// +// @Override +// public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { +// delegateImplementor.checkLoggued(); +// } } Modified: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-07-15 19:08:28 UTC (rev 307) @@ -24,10 +24,8 @@ */ package org.nuiton.jredmine; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import com.google.common.base.Preconditions; import org.nuiton.io.rest.RestClient; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.io.rest.RestException; import org.nuiton.io.rest.RestRequest; import org.nuiton.jredmine.model.io.xpp3.RedmineXpp3Helper; @@ -41,21 +39,12 @@ * Created: 2 janv. 2010 * * @author tchemit <chemit@codelutin.com> - * @plexus.component role="org.nuiton.jredmine.RedmineServiceImplementor" role-hint="default" * @see RedmineServiceImplementor * @since 1.0.3 */ public class DefaultRedmineServiceImplementor implements RedmineServiceImplementor { - /** Logger */ - private static final Log log = - LogFactory.getLog(DefaultRedmineServiceImplementor.class); - - /** - * Client Rest. - * - * @plexus.requirement role="org.nuiton.io.rest.RestClient" role-hint="redmine" - */ + /** Redmine Client Rest. */ protected RestClient session; /** xpp3 xpp3Helper to transform xml stream to pojo */ @@ -66,10 +55,6 @@ public DefaultRedmineServiceImplementor() { xpp3Helper = new RedmineXpp3Helper(); - if (log.isDebugEnabled()) { - log.debug("new " + this); - } - session = new RedmineRestClient(); } /////////////////////////////////////////////////////////////////////////// @@ -82,20 +67,12 @@ } @Override - public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { + public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + Preconditions.checkNotNull(configuration, "the client configuration was not be null!"); + Preconditions.checkState(!init, "the client " + this + " was already init!"); + session = new RedmineRestClient(); session.setConfiguration(configuration); - RedmineServiceImplementor result = init(session); - return result; - } - - @Override - public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { - if (init) { - throw new IllegalStateException( - "the client " + this + " was already init!"); - } try { - this.session = session; if (!session.isOpen()) { session.open(); @@ -111,23 +88,23 @@ @Override public void destroy() throws RedmineServiceException { - checkInit(); - try { - if (session.isOpen()) { - try { - session.close(); - } catch (RestException ex) { - throw new RedmineServiceException( - "has problem while closing Rest client " + - ex.getMessage(), ex); + if (isInit()) { + try { + if (session.isOpen()) { + try { + session.close(); + } catch (RestException ex) { + throw new RedmineServiceException( + "has problem while closing Rest client " + + ex.getMessage(), ex); + } } + } finally { + if (session != null) { + session = null; + } + init = false; } - } finally { - // can't remove the reference since plexus injects it -// if (session != null) { -// session = null; -// } - init = false; } } Modified: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java 2012-07-15 19:08:28 UTC (rev 307) @@ -50,6 +50,29 @@ public interface RedmineAnonymousService { /** + * Initialize the service. + * + * @param configuration the configuration to be used to init the internal redmine client + * @throws RedmineServiceException if any pb + */ + void init(RedmineServiceConfiguration configuration) throws RedmineServiceException; + + /** + * Close the service and destroy any connexion to the redmine service. + * + * @throws RedmineServiceException if any pb + */ + void destroy() throws RedmineServiceException; + + /** + * Get the technical layer. + * + * @return the technical layer. + * @since 1.4 + */ + RedmineServiceImplementor getDelegateImplementor(); + + /** * Obtain all accessible projects. * * @return all the projects Added: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,14 @@ +package org.nuiton.jredmine; + +import org.nuiton.io.rest.RestClientConfiguration; + +/** + * Contract of a redmine service configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public interface RedmineServiceConfiguration extends RestClientConfiguration { + + +} \ No newline at end of file Property changes on: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-07-15 19:08:28 UTC (rev 307) @@ -25,7 +25,6 @@ package org.nuiton.jredmine; import org.nuiton.io.rest.RestClient; -import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.rest.RedmineRestClient; /** @@ -50,15 +49,15 @@ */ boolean isInit(); - /** - * Initialize the service given a redmine client already initialized. - * - * @param session the redmine client to be used by the service - * @return the initialized service - * @throws RedmineServiceException if any pb - * @see RedmineRestClient - */ - RedmineServiceImplementor init(RestClient session) throws RedmineServiceException; +// /** +// * Initialize the service given a redmine client already initialized. +// * +// * @param session the redmine client to be used by the service +// * @return the initialized service +// * @throws RedmineServiceException if any pb +// * @see RedmineRestClient +// */ +// RedmineServiceImplementor init(RestClient session) throws RedmineServiceException; /** * Initialize the service given a client configuration. @@ -67,7 +66,7 @@ * @return the initialized service * @throws RedmineServiceException if any pb */ - RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException; + RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException; /** * Close the service and destroy any connexion to the redmine service. Deleted: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -1,290 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.nuiton.io.rest.RestClientConfiguration; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.IssueCategory; -import org.nuiton.jredmine.model.IssuePriority; -import org.nuiton.jredmine.model.IssueStatus; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Tracker; -import org.nuiton.jredmine.model.User; -import org.nuiton.jredmine.model.Version; -import org.nuiton.jredmine.rest.RedmineRestClient; - -import java.io.IOException; - -/** - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.4, will be rethink in version 2.0 (avoid inheritance on tests). - */ -@Deprecated -public abstract class AbstractRedmineServiceTest<S extends RedmineAnonymousService> implements RedmineTestContract { - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractRedmineServiceTest.class); - - /** shared rest client (open only one session for all the test). */ - static RedmineRestClient client; - - /** service to test. */ - private S service; - - protected static RedmineFixtures fixtures; - - protected Project[] projects; - - protected Project project; - - protected Version[] versions; - - protected Version version; - - protected User[] users; - - protected Issue[] issues; - - protected IssuePriority[] issuePriorities; - - protected IssueStatus[] issueStatuses; - - protected IssueCategory[] issueCategories; - - protected Tracker[] trackers; - - protected News newz; - - protected News[] news; - - protected Attachment attachment; - - protected Attachment[] attachments; - - protected TimeEntry timeEntry; - - protected TimeEntry[] timeEntries; - - private final Class<S> serviceType; - - public AbstractRedmineServiceTest(Class<S> serviceType) { - this.serviceType = serviceType; - } - - protected S getService() { - return service; - } - - @BeforeClass - public static void setUpClass() throws Exception { - // make sure client is null before starting the test - - client = null; - fixtures = new RedmineFixtures(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - fixtures = null; - if (client != null) { - client.close(); - client = null; - } - } - - protected final S newService() throws Exception { - S s = serviceType.newInstance(); - ((DefaultRedmineAnonymousService) s).delegateImplementor = new DefaultRedmineServiceImplementor(); - return s; - } - - @Before - public void setUp() throws Exception { - - if (client == null) { - - RestClientConfiguration configuration = getConfiguration(); - try { - client = new RedmineRestClient(configuration); - - client.open(); - } catch (Exception e) { - - // could not log - if (log.isErrorEnabled()) { - log.error("can not connect to server " + configuration.getRestUrl() + ", will skip test " + DefaultRedmineServiceTest.class.getName()); - } -// System.out.println("can not connect to server " + configuration.getRestUrl() + ", will skip test " + DefaultRedmineServiceTest.class.getName()); - client = null; - } finally { - Assume.assumeTrue(client != null && client.isOpen()); - } - } - - service = newService(); - - ((RedmineServiceImplementor) service).init(client); - } - - protected abstract RestClientConfiguration getConfiguration() throws IOException; - - @After - public void tearDown() throws Exception { - service = null; - project = null; - projects = null; - version = null; - versions = null; - users = null; - issues = null; - issueCategories = null; - issuePriorities = null; - issueStatuses = null; - trackers = null; - newz = null; - news = null; - attachment = null; - attachments = null; - timeEntry = null; - timeEntries = null; - } - - - @Test - public void isInit() throws Exception { - - Assert.assertFalse(((RedmineServiceImplementor) newService()).isInit()); - } - - @Test - @Override - public void getProjects() throws Exception { - projects = getService().getProjects(); - } - - @Test - @Override - public void getIssuePriorities() throws Exception { - issuePriorities = getService().getIssuePriorities(); - } - - @Test - @Override - public void getIssueStatuses() throws Exception { - issueStatuses = getService().getIssueStatuses(); - } - - @Test - @Override - public void getProject() throws Exception { - project = getService().getProject(PROJECT_NAME); - } - - @Test - @Override - public void getIssueCategories() throws Exception { - issueCategories = getService().getIssueCategories(PROJECT_NAME); - } - - @Test - @Override - public void getTrackers() throws Exception { - trackers = getService().getTrackers(PROJECT_NAME); - } - - @Test - @Override - public void getNews() throws Exception { - news = getService().getNews(PROJECT_NAME); - } - - @Test - @Override - public void getProjectMembers() throws Exception { - users = getService().getProjectMembers(PROJECT_NAME); - } - - @Test - @Override - public void getProjectIssues() throws Exception { - issues = getService().getIssues(PROJECT_NAME); - } - - @Test - @Override - public void getVersions() throws Exception { - versions = getService().getVersions(PROJECT_NAME); - } - - @Test - @Override - public void getVersion() throws Exception { - version = getService().getVersion(PROJECT_NAME, VERSION_NAME); - } - - @Test - @Override - public void getVersionIssues() throws Exception { - issues = getService().getIssues(PROJECT_NAME, VERSION_NAME); - } - - @Test - @Override - public void getOpenedIssues() throws Exception { - issues = getService().getOpenedIssues(PROJECT_NAME); - } - - @Test - @Override - public void getClosedIssues() throws Exception { - issues = getService().getClosedIssues(PROJECT_NAME); - } - - @Test - @Override - public void getIssueTimeEntries() throws Exception { - timeEntries = getService().getIssueTimeEntries(PROJECT_NAME, ISSUE_ID); - } - - @Test - @Override - public void getAttachments() throws Exception { - attachments = getService().getAttachments(PROJECT_NAME, VERSION_NAME); - } -} Deleted: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -1,93 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.junit.Test; -import org.nuiton.io.rest.RestClientConfiguration; - -import java.io.IOException; - -/** - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.4, will be rethink in version 2.0 (avoid inheritance on tests). - */ -@Deprecated -public class DefaultRedmineAnonymousServiceTest extends AbstractRedmineServiceTest<DefaultRedmineAnonymousService> { - - public DefaultRedmineAnonymousServiceTest() { - super(DefaultRedmineAnonymousService.class); - } - - @Override - protected RestClientConfiguration getConfiguration() throws IOException { - return fixtures.newAnonymousConfiguration(); - } - - @Test - @Override - public void getUserProjects() throws Exception { - // not for anonymous service - } - - @Test - @Override - public void addVersion() throws Exception { - // not for anonymous service - } - - @Test - @Override - public void addAttachment() throws Exception { - // not for anonymous service - } - - @Test - @Override - public void addNews() throws Exception { - // not for anonymous service - } - - @Test - @Override - public void updateVersion() throws Exception { - // not for anonymous service - } - - @Test - @Override - public void nextVersion() throws Exception { - // not for anonymous service - } - - @Test - @Override - public void addIssueTime() throws Exception { - // not for anonymous service - } - - -} Deleted: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -1,105 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.junit.Test; -import org.nuiton.io.rest.RestClientConfiguration; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Version; - -import java.io.IOException; - -/** - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.4, will be rethink in version 2.0 (avoid inheritance on tests). - */ -@Deprecated -public class DefaultRedmineServiceAsAnonymousTest extends AbstractRedmineServiceTest<DefaultRedmineService> { - - public DefaultRedmineServiceAsAnonymousTest() { - super(DefaultRedmineService.class); - } - - @Override - protected RestClientConfiguration getConfiguration() throws IOException { - RestClientConfiguration configuration = fixtures.newLogguedConfiguration(); - configuration.setAnonymous(true); - return configuration; - } - - @Test(expected = RedmineServiceLoginException.class) - @Override - public void getUserProjects() throws Exception { - projects = getService().getUserProjects(); - } - - @Test(expected = RedmineServiceLoginException.class) - @Override - public void addVersion() throws Exception { - version = new Version(); - getService().addVersion(PROJECT_NAME, version); - } - - @Test(expected = RedmineServiceLoginException.class) - @Override - public void addAttachment() throws Exception { - attachment = new Attachment(); - getService().addAttachment(PROJECT_NAME, VERSION_NAME, attachment); - } - - @Test(expected = RedmineServiceLoginException.class) - @Override - public void addNews() throws Exception { - newz = new News(); - getService().addNews(PROJECT_NAME, newz); - } - - @Test(expected = RedmineServiceLoginException.class) - @Override - public void updateVersion() throws Exception { - version = new Version(); - getService().updateVersion(PROJECT_NAME, version); - } - - @Test(expected = RedmineServiceLoginException.class) - @Override - public void nextVersion() throws Exception { - - version = new Version(); - getService().nextVersion(PROJECT_NAME, VERSION_NAME, version); - } - - @Test(expected = RedmineServiceLoginException.class) - @Override - public void addIssueTime() throws Exception { - timeEntry = new TimeEntry(); - getService().addIssueTimeEntry(PROJECT_NAME, ISSUE_ID, timeEntry); - } - -} \ No newline at end of file Deleted: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -1,95 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.junit.Test; -import org.nuiton.io.rest.RestClientConfiguration; - -import java.io.IOException; - -/** - * @author tchemit <chemit@codelutin.com> - * @deprecated since 1.4, will be rethink in version 2.0 (avoid inheritance on tests). - */ - -@Deprecated -public class DefaultRedmineServiceTest extends AbstractRedmineServiceTest<DefaultRedmineService> { - - public DefaultRedmineServiceTest() { - super(DefaultRedmineService.class); - } - - @Override - protected RestClientConfiguration getConfiguration() throws IOException { - return fixtures.newLogguedConfiguration(); - } - - @Test - @Override - public void getUserProjects() throws Exception { - projects = getService().getUserProjects(); - } - - @Test - @Override - public void addVersion() throws Exception { - // TODO - } - - @Test - @Override - public void addAttachment() throws Exception { - // TODO - } - - @Test - @Override - public void addNews() throws Exception { - // TODO - } - - @Test - @Override - public void updateVersion() throws Exception { - // TODO - } - - @Test - @Override - public void nextVersion() throws Exception { - // TODO - } - - @Test - @Override - public void addIssueTime() throws Exception { -// TimeEntry timeEntry = new TimeEntry(); -// timeEntry.setActivityId(9); -// timeEntry.setComments("ajout time"); -// timeEntry.setHours(3.5f); -//// timeEntry.setSpentOn(new Date()); -// getService().addIssueTimeEntry(PROJECT_NAME, ISSUE_ID, timeEntry); - } -} Added: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,63 @@ +package org.nuiton.jredmine; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assume; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.io.IOException; + +/** + * A class rule that provider the {@link RedmineFixtures} and check that the + * valid anonymous configuration is found. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineAnonymousFixtureClassRule implements TestRule { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(RedmineAnonymousFixtureClassRule.class); + + RedmineFixtures fixtures = new RedmineFixtures(); + + RedmineServiceConfiguration conf; + + @Override + public Statement apply(Statement base, Description description) { + + Class<?> testClass = description.getTestClass(); + + try { + conf = fixtures.obtainRedmineConfiguration(); + + if (conf == null) { + + // could not find any configuration + if (log.isWarnEnabled()) { + log.warn("could not connect to server " + + fixtures.newAnonymousConfiguration() + ", will skip test " + + testClass.getName()); + } + Assume.assumeTrue(false); + } + // since having a configuration available, is by force anonymous + + } catch (IOException e) { + throw new IllegalStateException("Could not check jredmine configuration in test " + testClass.getName(), e); + + } + return base; + } + + public RedmineFixtures getFixtures() { + return fixtures; + } + + public RedmineServiceConfiguration getConf() { + return conf; + } +} Added: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,170 @@ +package org.nuiton.jredmine; + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; + +import java.io.IOException; + +/** + * Tests the {@link RedmineAnonymousService} service. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineAnonymousServiceTest { + + @ClassRule + public static final RedmineAnonymousFixtureClassRule classRule = + new RedmineAnonymousFixtureClassRule(); + + @Rule + public final RedmineServer<RedmineAnonymousService> server = new RedmineServer<RedmineAnonymousService>(classRule.getFixtures()) { + + @Override + protected RedmineAnonymousService createService( + RedmineServiceConfiguration configuration) throws IOException, RedmineServiceException { + + return fixtures.newRedmineAnonymousService(configuration); + } + + @Override + protected RedmineServiceConfiguration createConfiguration() throws IOException { + RedmineServiceConfiguration conf = fixtures.newAnonymousConfiguration(); + return conf; + } + }; + + protected RedmineFixtures getFixtures() { + return server.getFixtures(); + } + + protected RedmineAnonymousService getService() { + return server.getService(); + } + + @Test + public void getProjects() throws Exception { + Project[] projects = getService().getProjects(); + Assert.assertNotNull(projects); + Assert.assertTrue(projects.length > 0); + } + + @Test + public void getProject() throws Exception { + Project project = getService().getProject(getFixtures().projectName()); + Assert.assertNotNull(project); + } + + @Test + public void getNews() throws Exception { + News[] news = getService().getNews(getFixtures().projectName()); + Assert.assertNotNull(news); + Assert.assertTrue(news.length > 0); + } + + @Test + public void getProjectIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getVersions() throws Exception { + Version[] versions = getService().getVersions(getFixtures().projectName()); + Assert.assertNotNull(versions); + Assert.assertTrue(versions.length > 0); + } + + @Test + public void getVersion() throws Exception { + Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(version); + } + + @Test + public void getIssueCategories() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); + Assert.assertNotNull(issueCategories); + Assert.assertTrue(issueCategories.length > 0); + } + + @Test + public void getProjectMembers() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + User[] users = getService().getProjectMembers(getFixtures().projectName()); + Assert.assertNotNull(users); + Assert.assertTrue(users.length > 0); + } + + @Test + public void getOpenedIssues() throws Exception { + Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getClosedIssues() throws Exception { + Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getIssueTimeEntries() throws Exception { + TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); + Assert.assertNotNull(timeEntries); + Assert.assertTrue(timeEntries.length > 0); + } + + @Test + public void getIssuePriorities() throws Exception { + IssuePriority[] issuePriorities = getService().getIssuePriorities(); + Assert.assertNotNull(issuePriorities); + Assert.assertTrue(issuePriorities.length > 0); + } + + @Test + public void getIssueStatuses() throws Exception { + IssueStatus[] issueStatuses = getService().getIssueStatuses(); + Assert.assertNotNull(issueStatuses); + Assert.assertTrue(issueStatuses.length > 0); + } + + @Test + public void getTrackers() throws Exception { + Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); + Assert.assertNotNull(trackers); + Assert.assertTrue(trackers.length > 0); + } + + @Test + public void getVersionIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getAttachments() throws Exception { + Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(attachments); + Assert.assertTrue(attachments.length > 0); + } + +} \ No newline at end of file Modified: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.java 2012-07-15 19:08:28 UTC (rev 307) @@ -6,9 +6,11 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.io.rest.RestClientConfiguration; +import org.nuiton.io.rest.RestException; import org.nuiton.jredmine.model.Attachment; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.model.IssueCategory; @@ -21,6 +23,7 @@ import org.nuiton.jredmine.model.User; import org.nuiton.jredmine.model.Version; import org.nuiton.jredmine.model.io.xpp3.RedmineDataConverter; +import org.nuiton.jredmine.rest.RedmineRestClient; import java.io.File; import java.io.IOException; @@ -38,20 +41,9 @@ */ public class RedmineFixtures { - /** Logger. */ private static final Log log = LogFactory.getLog(RedmineFixtures.class); - public static final String FILE_TO_UPLOAD_CONTENT = "Fichier à uploader"; -// -// public static final String PROJECT_NAME = "jredmine"; -// -// public static final String VERSION_NAME = "1.3"; -// -// public static final String ISSUE_ID = "1925"; - - private Project JRedmineProject; - private ArrayListMultimap<Class<?>, Object> model; private RestClientConfiguration anonymousConfiguration; @@ -74,30 +66,94 @@ return "1925"; } - public RestClientConfiguration newAnonymousConfiguration() + + protected RedmineServiceConfiguration obtainRedmineConfiguration() throws IOException { + + RedmineServiceConfiguration conf = newLogguedConfiguration(); + + boolean ok = false; + + RedmineRestClient client = new RedmineRestClient(conf); + + try { + + client.open(); + ok = client.isOpen(); + } catch (Exception e) { + + if (log.isDebugEnabled()) { + log.debug("Could not connect to redmine with configuration: " + conf, e); + } + + } finally { + try { + client.close(); + } catch (RestException e) { + if (log.isErrorEnabled()) { + log.error("Could not close session", e); + } + } + } + + if (!ok) { + + // try to connect anonymous + conf = newAnonymousConfiguration(); + + client = new RedmineRestClient(conf); + + try { + + client.open(); + ok = client.isOpen(); + } catch (Exception e) { + + if (log.isDebugEnabled()) { + log.debug("Could not connect to redmine with configuration: " + conf, e); + } + } finally { + try { + client.close(); + } catch (RestException e) { + if (log.isErrorEnabled()) { + log.error("Could not close session", e); + } + } + } + } + + if (!ok) { + + // no conf available + conf = null; + } + return conf; + } + + public RedmineServiceConfiguration newAnonymousConfiguration() throws IOException { - RestClientConfiguration conf = new FakeRedmineServiceConfiguration(); + RedmineServiceConfiguration conf = new FakeRedmineServiceConfiguration(); copyConfiguration(getAnonymousConfiguration(), conf); return conf; } - public RestClientConfiguration newLogguedConfiguration() + public RedmineServiceConfiguration newLogguedConfiguration() throws IOException { - RestClientConfiguration conf = new FakeRedmineServiceConfiguration(); + RedmineServiceConfiguration conf = new FakeRedmineServiceConfiguration(); copyConfiguration(getLogguedConfiguration(), conf); return conf; } - public RedmineAnonymousService newRedmineAnonymousService(RestClientConfiguration configuration) + public RedmineAnonymousService newRedmineAnonymousService(RedmineServiceConfiguration configuration) throws IOException, RedmineServiceException { - DefaultRedmineAnonymousService service = new DefaultRedmineAnonymousService(); + RedmineAnonymousService service = new DefaultRedmineAnonymousService(); service.init(configuration); return service; } - public RedmineService newRedmineService(RestClientConfiguration configuration) + public RedmineService newRedmineService(RedmineServiceConfiguration configuration) throws IOException, RedmineServiceException { - DefaultRedmineService service = new DefaultRedmineService(); + RedmineService service = new DefaultRedmineService(); service.init(configuration); return service; } @@ -235,32 +291,6 @@ return ts.get(pos); } - public Project getJRedmineProject() { - if (JRedmineProject == null) { - JRedmineProject = new Project(); - JRedmineProject.setName("jredmine"); - JRedmineProject.setIdentifier("jredmine"); - JRedmineProject.setIsPublic(true); - JRedmineProject.setHomepage("http://maven-site.nuiton.org/jredmine"); - JRedmineProject.setDescription( - "Permet de communiquer en java avec un serveur " + "redmine qui a installé le plugin rails jredmine"); - JRedmineProject.setId(36); - JRedmineProject.setStatus(1); - } - return JRedmineProject; - } - - - public static final String VERSION_TO_CREATE_NAME = "do_not_use_me"; - - public Version getVersion() { - Version version = new Version(); - version.setName(VERSION_TO_CREATE_NAME); - version.setDescription("Une version créée par les tests de jredmine," + - " ne pas utiliser,et modifiée"); - return version; - } - private void loadModel() throws Exception { model = ArrayListMultimap.create(); @@ -684,29 +714,58 @@ model.put(TimeEntry.class, tempE); } + public Version versionToAdd() { + Version version = new Version(); + version.setName(versionName()); + version.setId(Integer.valueOf(versionId())); + version.setDescription("Version to add"); + return version; + } - public Attachment getAttachment() { - Attachment result = new Attachment(); - File fileToUpload = null; - try { - fileToUpload = File.createTempFile("toupload", ".txt"); - FileUtils.write(fileToUpload, FILE_TO_UPLOAD_CONTENT); - result.setToUpload(fileToUpload); - result.setDescription("attachment description..."); - return result; - } catch (IOException e) { - throw new RuntimeException("Could not create temp file", e); - } + public Version versionToUpdate() { + Version version = new Version(); + version.setName(versionName()); + version.setId(Integer.valueOf(versionId())); + version.setDescription("Version to update"); + return version; + } + public String oldVersionName() { + return "1.2"; } + public News newsToAdd() { + News news = new News(); + news.setTitle("Title"); + news.setDescription("Description"); + news.setSummary("Summary"); + return news; + } + + public TimeEntry timeEntryToAdd() { + TimeEntry timeEntry = new TimeEntry(); + timeEntry.setComments("Comments"); + Date date = new Date(); + DateUtils.setYears(date, 2012); + DateUtils.setMonths(date, 7); + DateUtils.setDays(date, 15); + timeEntry.setSpentOn(date); + return timeEntry; + } + + public Attachment attachmentToAdd() { + Attachment attachmentToAdd = new Attachment(); + attachmentToAdd.setDescription("Description"); + return attachmentToAdd; + } + /** * Configuration of a redmine service for test purposes. * * @author tchemit <chemit@codelutin.com> * @since 1.4 */ - public static class FakeRedmineServiceConfiguration implements RestClientConfiguration { + public static class FakeRedmineServiceConfiguration implements RedmineServiceConfiguration { URL restUrl; @@ -782,8 +841,9 @@ @Override public String toString() { - ToStringBuilder b = new ToStringBuilder(this, - ToStringStyle.MULTI_LINE_STYLE + ToStringBuilder b = new ToStringBuilder( + this, + ToStringStyle.MULTI_LINE_STYLE ); b.append("redmineUrl", restUrl); if (anonymous) { Added: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,74 @@ +package org.nuiton.jredmine; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assume; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.io.IOException; + +/** + * A class rule that provider the {@link RedmineFixtures} and check that the + * valid loggued configuration is found. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineLogguedFixtureClassRule implements TestRule { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(RedmineLogguedFixtureClassRule.class); + + RedmineFixtures fixtures = new RedmineFixtures(); + + RedmineServiceConfiguration conf; + + @Override + public Statement apply(Statement base, Description description) { + + Class<?> testClass = description.getTestClass(); + + try { + conf = fixtures.obtainRedmineConfiguration(); + + if (conf == null) { + + // could not find any configuration + if (log.isWarnEnabled()) { + log.warn("could not connect to server " + + fixtures.newAnonymousConfiguration() + ", will skip test " + + testClass.getName()); + } + Assume.assumeTrue(false); + } else { + + // configuration must NOT be anonymous + + if (conf.isAnonymous()) { + + if (log.isWarnEnabled()) { + log.warn("A authenticated configuration was required, will skip test " + + testClass.getName()); + } + Assume.assumeTrue(false); + } + } + + } catch (IOException e) { + throw new IllegalStateException("Could not check jredmine configuration in test " + testClass.getName(), e); + + } + return base; + } + + public RedmineFixtures getFixtures() { + return fixtures; + } + + public RedmineServiceConfiguration getConf() { + return conf; + } +} Added: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServer.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServer.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServer.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,86 @@ +package org.nuiton.jredmine; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +import java.io.IOException; + +/** + * A redmine server resource used by tests. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public abstract class RedmineServer<S extends RedmineAnonymousService> extends TestWatcher { + + /** + * Fixtures. + * + * @since 1.4 + */ + protected final RedmineFixtures fixtures; + + /** + * Service configuration to use. + * + * @since 1.4 + */ + protected RedmineServiceConfiguration configuration; + + /** + * Redmine service to use. + * + * @since 1.4 + */ + protected S service; + + public RedmineServer(RedmineFixtures fixtures) { + this.fixtures = fixtures; + } + + protected abstract S createService(RedmineServiceConfiguration configuration) throws IOException, RedmineServiceException; + + protected abstract RedmineServiceConfiguration createConfiguration() throws IOException; + + public RedmineFixtures getFixtures() { + return fixtures; + } + + public RedmineServiceConfiguration getConfiguration() { + return configuration; + } + + public S getService() { + return service; + } + + @Override + protected void starting(Description description) { + + try { + configuration = createConfiguration(); + } catch (IOException e) { + + throw new IllegalStateException("Could not create configuration", e); + } + + try { + service = createService(configuration); + } catch (Exception e) { + throw new IllegalStateException("Could not create service", e); + } + } + + @Override + protected void finished(Description description) { + + if (service != null) { + try { + service.destroy(); + } catch (RedmineServiceException e) { + throw new IllegalStateException("Could not close service ", e); + } + } + } + +} \ No newline at end of file Property changes on: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,205 @@ +package org.nuiton.jredmine; + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; + +import java.io.IOException; + +/** + * Tests the {@link RedmineService} service with anonymous configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineServiceAsAnonymousTest { + + @ClassRule + public static final RedmineAnonymousFixtureClassRule classRule = + new RedmineAnonymousFixtureClassRule(); + + + protected RedmineFixtures getFixtures() { + return server.getFixtures(); + } + + @Rule + public final RedmineServer<RedmineService> server = new RedmineServer<RedmineService>(classRule.getFixtures()) { + + @Override + protected RedmineService createService( + RedmineServiceConfiguration configuration) throws IOException, RedmineServiceException { + + return fixtures.newRedmineService(configuration); + } + + @Override + protected RedmineServiceConfiguration createConfiguration() throws IOException { + RedmineServiceConfiguration conf = fixtures.newAnonymousConfiguration(); + return conf; + } + }; + + protected RedmineService getService() { + return server.getService(); + } + + @Test + public void getProjects() throws Exception { + Project[] projects = getService().getProjects(); + Assert.assertNotNull(projects); + Assert.assertTrue(projects.length > 0); + } + + @Test + public void getProject() throws Exception { + Project project = getService().getProject(getFixtures().projectName()); + Assert.assertNotNull(project); + } + + @Test + public void getNews() throws Exception { + News[] news = getService().getNews(getFixtures().projectName()); + Assert.assertNotNull(news); + Assert.assertTrue(news.length > 0); + } + + @Test + public void getProjectIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getVersions() throws Exception { + Version[] versions = getService().getVersions(getFixtures().projectName()); + Assert.assertNotNull(versions); + Assert.assertTrue(versions.length > 0); + } + + @Test + public void getVersion() throws Exception { + Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(version); + } + + @Test + public void getIssueCategories() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); + Assert.assertNotNull(issueCategories); + Assert.assertTrue(issueCategories.length > 0); + } + + @Test + public void getProjectMembers() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + User[] users = getService().getProjectMembers(getFixtures().projectName()); + Assert.assertNotNull(users); + Assert.assertTrue(users.length > 0); + } + + @Test + public void getOpenedIssues() throws Exception { + Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getClosedIssues() throws Exception { + Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getIssueTimeEntries() throws Exception { + TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); + Assert.assertNotNull(timeEntries); + Assert.assertTrue(timeEntries.length > 0); + } + + @Test + public void getIssuePriorities() throws Exception { + IssuePriority[] issuePriorities = getService().getIssuePriorities(); + Assert.assertNotNull(issuePriorities); + Assert.assertTrue(issuePriorities.length > 0); + } + + @Test + public void getIssueStatuses() throws Exception { + IssueStatus[] issueStatuses = getService().getIssueStatuses(); + Assert.assertNotNull(issueStatuses); + Assert.assertTrue(issueStatuses.length > 0); + } + + @Test + public void getTrackers() throws Exception { + Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); + Assert.assertNotNull(trackers); + Assert.assertTrue(trackers.length > 0); + } + + @Test + public void getVersionIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getAttachments() throws Exception { + Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(attachments); + Assert.assertTrue(attachments.length > 0); + } + + @Test(expected = RedmineServiceLoginException.class) + public void getUserProjects() throws Exception { + getService().getUserProjects(); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addVersion() throws Exception { + getService().addVersion(getFixtures().projectName(), new Version()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addAttachment() throws Exception { + getService().addAttachment(getFixtures().projectName(), getFixtures().versionName(), new Attachment()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addNews() throws Exception { + getService().addNews(getFixtures().projectName(), new News()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void updateVersion() throws Exception { + getService().updateVersion(getFixtures().projectName(), new Version()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void nextVersion() throws Exception { + getService().nextVersion(getFixtures().projectName(), getFixtures().versionName(), new Version()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addIssueTime() throws Exception { + getService().addIssueTimeEntry(getFixtures().projectName(), getFixtures().issueId(), new TimeEntry()); + } +} Added: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,212 @@ +package org.nuiton.jredmine; + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; + +import java.io.IOException; + +/** + * Tests the {@link RedmineService} service with loggued configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineServiceTest { + + @ClassRule + public static final RedmineLogguedFixtureClassRule classRule = + new RedmineLogguedFixtureClassRule(); + + @Rule + public final RedmineServer<RedmineService> server = new RedmineServer<RedmineService>(classRule.getFixtures()) { + + @Override + protected RedmineService createService( + RedmineServiceConfiguration configuration) throws IOException, RedmineServiceException { + return fixtures.newRedmineService(configuration); + } + + @Override + protected RedmineServiceConfiguration createConfiguration() throws IOException { + RedmineServiceConfiguration conf = fixtures.newLogguedConfiguration(); + return conf; + } + }; + + protected RedmineFixtures getFixtures() { + return server.getFixtures(); + } + + protected RedmineService getService() { + return server.getService(); + } + + @Test + public void getProjects() throws Exception { + Project[] projects = getService().getProjects(); + Assert.assertNotNull(projects); + Assert.assertTrue(projects.length > 0); + } + + @Test + public void getProject() throws Exception { + Project project = getService().getProject(getFixtures().projectName()); + Assert.assertNotNull(project); + } + + @Test + public void getNews() throws Exception { + News[] news = getService().getNews(getFixtures().projectName()); + Assert.assertNotNull(news); + Assert.assertTrue(news.length > 0); + } + + @Test + public void getProjectIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getVersions() throws Exception { + Version[] versions = getService().getVersions(getFixtures().projectName()); + Assert.assertNotNull(versions); + Assert.assertTrue(versions.length > 0); + } + + @Test + public void getVersion() throws Exception { + Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(version); + } + + @Test + public void getIssueCategories() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); + Assert.assertNotNull(issueCategories); + Assert.assertTrue(issueCategories.length > 0); + } + + @Test + public void getProjectMembers() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + User[] users = getService().getProjectMembers(getFixtures().projectName()); + Assert.assertNotNull(users); + Assert.assertTrue(users.length > 0); + } + + @Test + public void getOpenedIssues() throws Exception { + Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getClosedIssues() throws Exception { + Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getIssueTimeEntries() throws Exception { + TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); + Assert.assertNotNull(timeEntries); + Assert.assertTrue(timeEntries.length > 0); + } + + @Test + public void getIssuePriorities() throws Exception { + IssuePriority[] issuePriorities = getService().getIssuePriorities(); + Assert.assertNotNull(issuePriorities); + Assert.assertTrue(issuePriorities.length > 0); + } + + @Test + public void getIssueStatuses() throws Exception { + IssueStatus[] issueStatuses = getService().getIssueStatuses(); + Assert.assertNotNull(issueStatuses); + Assert.assertTrue(issueStatuses.length > 0); + } + + @Test + public void getTrackers() throws Exception { + Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); + Assert.assertNotNull(trackers); + Assert.assertTrue(trackers.length > 0); + } + + @Test + public void getVersionIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getAttachments() throws Exception { + Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(attachments); + Assert.assertTrue(attachments.length > 0); + } + + @Ignore + @Test + public void addVersion() throws Exception { + getService().addVersion(getFixtures().projectName(), getFixtures().versionToAdd()); + } + + @Ignore + @Test + public void addAttachment() throws Exception { + Version version = getFixtures().versionToUpdate(); + Attachment attachment = getFixtures().attachmentToAdd(); + Attachment updatedAttachment = getService().addAttachment( + getFixtures().projectName(), + version.getName(), + attachment + ); + Assert.assertNotNull(updatedAttachment); + } + + @Ignore + @Test + public void addNews() throws Exception { + getService().addNews(getFixtures().projectName(), getFixtures().newsToAdd()); + } + + @Ignore + @Test + public void updateVersion() throws Exception { + getService().updateVersion(getFixtures().projectName(), getFixtures().versionToUpdate()); + } + + @Ignore + @Test + public void nextVersion() throws Exception { + getService().nextVersion(getFixtures().projectName(), getFixtures().versionName(), getFixtures().versionToUpdate()); + } + + @Ignore + @Test + public void addIssueTime() throws Exception { + getService().addIssueTimeEntry(getFixtures().projectName(), getFixtures().issueId(), getFixtures().timeEntryToAdd()); + } +} Deleted: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java 2012-07-15 19:08:28 UTC (rev 307) @@ -1,90 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -/** - * Contract of methods to tests for both redmine rest client and redmine service. - * <p/> - * Created: 1 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.3 - * @deprecated will be removed in version 2.0 - */ -@Deprecated -public interface RedmineTestContract { - - String PROJECT_NAME = "jredmine"; - - String VERSION_NAME = "1.3"; - - String ISSUE_ID = "1925"; - - void getProjects() throws Exception; - - void getIssuePriorities() throws Exception; - - void getIssueStatuses() throws Exception; - - void getProject() throws Exception; - - void getIssueCategories() throws Exception; - - void getTrackers() throws Exception; - - void getNews() throws Exception; - - void getUserProjects() throws Exception; - - void getProjectMembers() throws Exception; - - void getProjectIssues() throws Exception; - - void getVersions() throws Exception; - - void getVersion() throws Exception; - - void getVersionIssues() throws Exception; - - void getOpenedIssues() throws Exception; - - void getClosedIssues() throws Exception; - - void getIssueTimeEntries() throws Exception; - - void getAttachments() throws Exception; - - void addVersion() throws Exception; - - void addAttachment() throws Exception; - - void addNews() throws Exception; - - void updateVersion() throws Exception; - - void nextVersion() throws Exception; - - void addIssueTime() throws Exception; -} Modified: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/model/io/xpp3/RedmineXpp3HelperTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/model/io/xpp3/RedmineXpp3HelperTest.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/model/io/xpp3/RedmineXpp3HelperTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -320,23 +320,23 @@ } } - public static <T> SingleDataSupplier<T> newSingleData(Class<T> type) { + static <T> SingleDataSupplier<T> newSingleData(Class<T> type) { return new SingleDataSupplier<T>(type); } - public static <T> EmptyListDataSupplier<T> newEmptyListData(Class<T> type) { + static <T> EmptyListDataSupplier<T> newEmptyListData(Class<T> type) { return new EmptyListDataSupplier<T>(type); } - public static <T> SingletonListDataSupplier<T> newSingletonListData(Class<T> type) { + static <T> SingletonListDataSupplier<T> newSingletonListData(Class<T> type) { return new SingletonListDataSupplier<T>(type); } - public static <T> MultiListDataSupplier<T> newMultiListData(Class<T> type) { + static <T> MultiListDataSupplier<T> newMultiListData(Class<T> type) { return new MultiListDataSupplier<T>(type); } - public <T> void assertMyListEquals(Class<T> type, List<T> expecteds, T[] actuals) + <T> void assertMyListEquals(Class<T> type, List<T> expecteds, T... actuals) throws Exception { junit.framework.Assert.assertNotNull(actuals); Added: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java (rev 0) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -0,0 +1,215 @@ +package org.nuiton.jredmine.rest; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.io.rest.RequestFactory; +import org.nuiton.io.rest.RestRequest; +import org.nuiton.jredmine.RedmineFixtures; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.ModelHelper; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Version; + +import java.util.Arrays; + +/** + * Tests the {@link RedmineRequestFactory}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineRequestFactoryTest { + + protected static final RedmineFixtures fixtures = new RedmineFixtures(); + + protected RequestFactory factory; + + protected String projectName; + + protected String versionName; + + protected String issueId; + + @Before + public void setUp() throws Exception { + factory = new RedmineRequestFactory(); + + factory.addDefaultRequests(); + + projectName = fixtures.projectName(); + versionName = fixtures.versionName(); + issueId = fixtures.issueId(); + } + + @Test + public void login() { + assertRequestParameters( + assertRequestUrl("/jredmine/login", ModelHelper.LOGIN_REQUEST_NAME, "redmineuser", "redminepassword"), + "username", "redmineuser", "password", "redminepassword"); + } + + @Test + public void logout() { + assertRequestParameters(assertRequestUrl("/jredmine/logout", ModelHelper.LOGOUT_REQUEST_NAME)); + } + + @Test + public void ping() { + assertRequestParameters(assertRequestUrl("/jredmine/ping", ModelHelper.PING_REQUEST_NAME)); + } + + @Test + public void getAllProjects() { + assertRequestParameters(assertRequestUrl("/jredmine/get_projects.xml", ModelHelper.GET_ALL_PROJECT_REQUEST_NAME)); + } + + @Test + public void getAllIssueStatuses() { + assertRequestParameters(assertRequestUrl("/jredmine/get_issue_statuses.xml", ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME)); + } + + @Test + public void getAllIssuePriorities() { + assertRequestParameters(assertRequestUrl("/jredmine/get_issue_priorities.xml", ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME)); + } + + @Test + public void getProject() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project.xml/" + projectName, ModelHelper.GET_PROJECT_REQUEST_NAME, projectName)); + } + + @Test + public void getAllIssues() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project_issues.xml/" + projectName, ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, projectName)); + } + + @Test + public void getAllOpenedIssues() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project_opened_issues.xml/" + projectName, ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, projectName)); + } + + @Test + public void getAllClosesIssues() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project_closed_issues.xml/" + projectName, ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, projectName)); + } + + @Test + public void getAllVersions() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project_versions.xml/" + projectName, ModelHelper.GET_ALL_VERSION_REQUEST_NAME, projectName)); + } + + @Test + public void getAllIssueCategories() { + assertRequestParameters(assertRequestUrl("/jredmine/get_issue_categories.xml/" + projectName, ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, projectName)); + } + + @Test + public void getAllTrackers() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project_trackers.xml/" + projectName, ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, projectName)); + } + + @Test + public void getAllUsers() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project_users.xml/" + projectName, ModelHelper.GET_ALL_USER_REQUEST_NAME, projectName)); + } + + @Test + public void getAllNews() { + assertRequestParameters(assertRequestUrl("/jredmine/get_project_news.xml/" + projectName, ModelHelper.GET_ALL_NEWS_REQUEST_NAME, projectName)); + } + + @Test + public void addVersion() { + Version version = fixtures.versionToAdd(); + assertRequestParameters(assertRequestUrl("/jredmine/add_version.xml/" + projectName, ModelHelper.ADD_VERSION_REQUEST_NAME, projectName, version), + "version[name]", "1.3", "version[description]", "Version to add", "version[effective_date]", "", "version[status]", "open"); + } + + @Test + public void updateVersion() { + Version version = fixtures.versionToUpdate(); + assertRequestParameters(assertRequestUrl("/jredmine/update_version.xml/" + projectName, ModelHelper.UPDATE_VERSION_REQUEST_NAME, projectName, version), + "version[name]", "1.3", "version[description]", "Version to update", "version[effective_date]", "", "version[status]", "open"); + } + + @Test + public void nextVersion() { + Version version = fixtures.versionToUpdate(); + String oldVersionName = fixtures.oldVersionName(); + assertRequestParameters(assertRequestUrl("/jredmine/next_version.xml/" + projectName, ModelHelper.NEXT_VERSION_REQUEST_NAME, projectName, version, oldVersionName), + "oldVersionName", oldVersionName, "version[name]", "1.3", "version[description]", "Version to update", "version[effective_date]", "", "version[status]", "open"); + } + + @Test + public void addNews() { + News newsToAdd = fixtures.newsToAdd(); + assertRequestParameters(assertRequestUrl("/jredmine/add_news.xml/" + projectName, ModelHelper.ADD_NEWS_REQUEST_NAME, projectName, newsToAdd), + "news[title]", newsToAdd.getTitle(), + "news[summary]", newsToAdd.getSummary(), + "news[description]", newsToAdd.getDescription()); + } + + @Test + public void getVersion() { + assertRequestParameters(assertRequestUrl("/jredmine/get_version.xml/" + projectName, ModelHelper.GET_VERSION_REQUEST_NAME, projectName, versionName), + "version_name", versionName); + } + + @Test + public void getAllVersionIssues() { + assertRequestParameters(assertRequestUrl("/jredmine/get_version_issues.xml/" + projectName, ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, projectName, versionName), + "version_name", versionName); + } + + @Test + public void getAllAttachments() { + assertRequestParameters(assertRequestUrl("/jredmine/get_version_attachments.xml/" + projectName, ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, projectName, versionName), + "version_name", versionName); + } + + @Test + public void addAttachment() { + Attachment attachment = fixtures.attachmentToAdd(); + + assertRequestParameters(assertRequestUrl("/jredmine/add_version_attachment.xml/" + projectName, ModelHelper.ADD_ATTACHMENT_REQUEST_NAME, projectName, versionName, attachment), + "version_name", versionName, + "attachment[description]", attachment.getDescription()); + } + + @Test + public void getAllIssueTimeEntires() { + assertRequestParameters(assertRequestUrl("/jredmine/get_issue_times.xml/" + projectName, ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId), + "issue_id", issueId); + } + + @Test + public void addIssueTimeEntry() { + TimeEntry timeEntry = fixtures.timeEntryToAdd(); + assertRequestParameters(assertRequestUrl("/jredmine/add_issue_time.xml/" + projectName, ModelHelper.ADD_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId, timeEntry), + "issue_id", issueId, + "time_entry[activity_id]", timeEntry.getActivityId() + "", + "time_entry[spent_on]", "2012-07-15", + "time_entry[hours]", timeEntry.getHours() + "", + "time_entry[comments]", timeEntry.getComments()); + } + + protected RestRequest assertRequestUrl(String expectedUrl, + String requestId, + Object... args) { + + RestRequest request = factory.getRequest(requestId, args); + + Assert.assertNotNull(request); + String actual = request.toPath(""); + Assert.assertEquals(expectedUrl, actual); + return request; + } + + protected void assertRequestParameters(RestRequest request, + String... expectedParams) { + String[] actual = request.getParameters(); + Assert.assertArrayEquals("Expected:" + Arrays.toString(expectedParams) + " but was:" + Arrays.toString(actual), expectedParams, actual); + } +} Modified: branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java =================================================================== --- branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java 2012-07-15 18:29:25 UTC (rev 306) +++ branches/jredmine-1.x/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java 2012-07-15 19:08:28 UTC (rev 307) @@ -28,73 +28,55 @@ import org.apache.commons.logging.LogFactory; import org.codehaus.plexus.util.IOUtil; import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; -import org.nuiton.io.rest.RestClientConfiguration; -import org.nuiton.io.rest.RestException; import org.nuiton.io.rest.RestRequest; +import org.nuiton.jredmine.RedmineAnonymousFixtureClassRule; import org.nuiton.jredmine.RedmineFixtures; -import org.nuiton.jredmine.RedmineTestContract; +import org.nuiton.jredmine.RedmineServiceConfiguration; import org.nuiton.jredmine.model.ModelHelper; -import java.io.IOException; import java.io.InputStream; /** * @author tchemit <chemit@codelutin.com> * @since 1.0.0 - * @deprecated since 1.4, will be rethink in version 2.0 (avoid inheritance on tests). */ -@Deprecated -public class RedmineRestClientTest implements RedmineTestContract { +public class RedmineRestClientTest { /** Logger. */ private static final Log log = LogFactory.getLog(RedmineRestClientTest.class); + @ClassRule + public static final RedmineAnonymousFixtureClassRule checkConfigRule = new RedmineAnonymousFixtureClassRule(); - private static final RedmineFixtures fixtures = new RedmineFixtures(); - - static RestClientConfiguration configuration; - - RedmineRestClient client; - - public RedmineRestClientTest() { + protected RedmineFixtures getFixtures() { + return checkConfigRule.getFixtures(); } - @BeforeClass - public static void setUpClass() throws Exception { + protected RedmineRestClient client; - configuration = fixtures.newAnonymousConfiguration(); + protected String projectName; - RedmineRestClient client = new RedmineRestClient(configuration); - try { + protected String versionName; - client.open(); - } catch (Exception e) { + protected String issueId; - // could not log - if (log.isWarnEnabled()) { - log.warn("could not connect to server " + configuration.getRestUrl() + ", will skip test " + RedmineRestClientTest.class.getName()); - } - } finally { - Assume.assumeTrue(client.isOpen()); - } - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - @Before public void setUp() throws Exception { - client = new RedmineRestClient(configuration); + RedmineFixtures fixtures = checkConfigRule.getFixtures(); + + client = new RedmineRestClient(getConfiguration()); client.open(); + + projectName = fixtures.projectName(); + versionName = fixtures.versionName(); + issueId = fixtures.issueId(); } @After @@ -117,173 +99,157 @@ Assert.assertFalse(client.isOpen()); } - @Override @Test public void getProjects() throws Exception { - doRequest(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME); + askData(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME); } - @Override @Test public void getIssuePriorities() throws Exception { - doRequest(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME); + askData(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME); } - @Override @Test public void getIssueStatuses() throws Exception { - doRequest(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME); + askData(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME); } - @Override @Test public void getProject() throws Exception { - doRequest(ModelHelper.GET_PROJECT_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_PROJECT_REQUEST_NAME, projectName); } - @Override @Test public void getIssueCategories() throws Exception { - doRequest(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, projectName); } - @Override @Test public void getTrackers() throws Exception { - doRequest(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, projectName); } - @Override @Test public void getNews() throws Exception { - doRequest(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, projectName); } - @Override - public void getUserProjects() throws Exception { - - doRequest(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME, PROJECT_NAME); - } - - @Override + @Test public void getProjectMembers() throws Exception { - doRequest(ModelHelper.GET_ALL_USER_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_USER_REQUEST_NAME, projectName); } - @Override @Test public void getProjectIssues() throws Exception { - doRequest(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, projectName); } - @Override @Test public void getVersions() throws Exception { - doRequest(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, projectName); } - @Override @Test public void getVersion() throws Exception { - doRequest(ModelHelper.GET_VERSION_REQUEST_NAME, PROJECT_NAME, VERSION_NAME); + askData(ModelHelper.GET_VERSION_REQUEST_NAME, projectName, versionName); } - @Override @Test public void getVersionIssues() throws Exception { - doRequest(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, PROJECT_NAME, VERSION_NAME); + askData(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, projectName, versionName); } - @Override @Test public void getOpenedIssues() throws Exception { - doRequest(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, projectName); } - @Override @Test public void getClosedIssues() throws Exception { - doRequest(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, PROJECT_NAME); + askData(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, projectName); } - @Override @Test public void getIssueTimeEntries() throws Exception { - doRequest(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, PROJECT_NAME, ISSUE_ID); + askData(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId); } - - @Override @Test public void getAttachments() throws Exception { - doRequest(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, PROJECT_NAME, VERSION_NAME); + askData(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, projectName, versionName); } - @Override + @Test + public void getUserProjects() throws Exception { + + Assume.assumeTrue(!getConfiguration().isAnonymous()); + askData(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME, projectName); + } + + @Test public void addVersion() throws Exception { + Assume.assumeTrue(!getConfiguration().isAnonymous()); //TODO } - @Override @Test public void addAttachment() throws Exception { + Assume.assumeTrue(!getConfiguration().isAnonymous()); //TODO } - @Override @Test public void addNews() throws Exception { + Assume.assumeTrue(!getConfiguration().isAnonymous()); //TODO } - @Override @Test public void updateVersion() throws Exception { + Assume.assumeTrue(!getConfiguration().isAnonymous()); //TODO } - @Override @Test public void nextVersion() throws Exception { + Assume.assumeTrue(!getConfiguration().isAnonymous()); //TODO } - @Override @Test public void addIssueTime() throws Exception { + Assume.assumeTrue(!getConfiguration().isAnonymous()); //TODO } - protected void doRequest(String requestId, Object... params) throws IOException, RestException { + protected void askData(String requestId, Object... params) throws Exception { - RestRequest request; - InputStream askData; - String toString; - - request = client.getRequest(requestId, params); - askData = client.askData(request); - toString = IOUtil.toString(askData); - if (configuration.isVerbose()) { - if (log.isInfoEnabled()) { - log.info(toString); - } + RestRequest request = client.getRequest(requestId, params); + InputStream askData = client.askData(request); + String toString = IOUtil.toString(askData); + if (getConfiguration().isVerbose() && log.isInfoEnabled()) { + log.info(toString); } } + + protected RedmineServiceConfiguration getConfiguration() { + return checkConfigRule.getConf(); + } }