Skip to content

Commit

Permalink
Added unit tests for TfsIssueProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Piessens committed Jun 4, 2015
1 parent aa707e9 commit bf1349f
Show file tree
Hide file tree
Showing 23 changed files with 2,695 additions and 635 deletions.
8 changes: 5 additions & 3 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/dictionaries/dan_piessens.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_mockito_mockito_all_1_10_19.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,441 changes: 1,030 additions & 411 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/build.iml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
Expand Down
17 changes: 16 additions & 1 deletion tfs-workitem-plugin-server/pom.xml
Expand Up @@ -38,11 +38,26 @@
<scope>compile</scope>
</dependency>

<dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jetbrains.teamcity</groupId>
<artifactId>tests-support</artifactId>
<version>${teamcity-version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Expand Up @@ -7,8 +7,9 @@
import jetbrains.buildServer.issueTracker.IssueMention;
import jetbrains.buildServer.util.cache.EhCacheUtil;
import jetbrains.buildServer.vcs.*;
import org.apache.commons.httpclient.*;
import net.sf.ehcache.Cache;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.jetbrains.annotations.NotNull;
import org.jfree.util.Log;

Expand All @@ -17,8 +18,6 @@
import java.util.Collection;
import java.util.Map;

import net.sf.ehcache.Cache;

public class TfsIssueProvider extends AbstractIssueProvider {

private static final String USE_CREDS_PROPERTY = "useVcsCredentials";
Expand Down Expand Up @@ -67,17 +66,19 @@ public Collection<IssueMention> getRelatedIssues(@NotNull final VcsModification
}

// Filter by getting the VCS Root and figuring out if that is a TFS root
final SVcsModification vcsModification = this.vcsManager.findModificationById(modification.getId(), false);
final long revisionId = modification.getId();
final SVcsModification vcsModification = this.vcsManager.findModificationById(revisionId, false);
if (vcsModification == null) {
Log.warn(String.format("Could not find VCS Modification %d in build system", modification.getId()));
Log.warn(String.format("Could not find VCS Modification %d in build system", revisionId));
return result;
}

final VcsRootInstance vcsRoot = vcsModification.getVcsRoot();
final String vcsName = vcsRoot.getVcsName();

LOG.debug("Issue Tracker VCS Root Type: " + vcsRoot.getVcsName());
LOG.debug("Issue Tracker VCS Root Type: " + vcsName);

if (!vcsRoot.getVcsName().equalsIgnoreCase("tfs")) {
if (!vcsName.equalsIgnoreCase("tfs")) {
return result;
}

Expand All @@ -90,10 +91,6 @@ public Collection<IssueMention> getRelatedIssues(@NotNull final VcsModification
return result;
}


LOG.debug(String.format("VCS Properties: %s", vcsRoot.getProperties()));

//TODO: Get host and optionally credentials from VCS root as a priority
LOG.debug(String.format("Getting issues for revision: %d from host: %s", revision, this.myHost));

try {
Expand Down Expand Up @@ -134,7 +131,6 @@ public Collection<SerializableIssueMention> fetch() throws Exception {
* @param vcsRoot The VCS root for the revision
* @return The appropriate credentials.
*/
@NotNull
private org.apache.commons.httpclient.Credentials checkForVcsCredentials(final VcsRoot vcsRoot) {

// If flag is checked use TFS credentials instead
Expand All @@ -143,7 +139,10 @@ private org.apache.commons.httpclient.Credentials checkForVcsCredentials(final V
if (properties.containsKey(USE_CREDS_PROPERTY) && Boolean.parseBoolean(properties.get(USE_CREDS_PROPERTY))) {
String username = vcsRoot.getProperty("tfs-username");
String password = vcsRoot.getProperty("secure:tfs-password");
return new UsernamePasswordCredentials(username, password);

if (username != null && password != null) {
return new UsernamePasswordCredentials(username, password);
}
}

return myCredentials;
Expand All @@ -162,7 +161,7 @@ private Collection<SerializableIssueMention> getFromCacheOrFetch(@NotNull Object
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

try {
net.sf.ehcache.Element element = myCache.get(key);
net.sf.ehcache.Element element = myCache != null ? myCache.get(key) : null;
if (element != null) {
Serializable value = element.getValue();
if (value == null) {
Expand All @@ -176,11 +175,15 @@ private Collection<SerializableIssueMention> getFromCacheOrFetch(@NotNull Object
try {
LOG.debug(String.format("Adding revision %s to revision cache", key));
Collection<SerializableIssueMention> result = function.fetch();
myCache.put(new net.sf.ehcache.Element(key, result));
if (myCache != null) {
myCache.put(new net.sf.ehcache.Element(key, result));
}
return result;
}
catch (Exception e) {
myCache.put(new net.sf.ehcache.Element(key, null));
if (myCache != null) {
myCache.put(new net.sf.ehcache.Element(key, null));
}
throw e;
}
}
Expand All @@ -193,7 +196,7 @@ private Collection<SerializableIssueMention> getFromCacheOrFetch(@NotNull Object
* An interface represents an action of actual issue fetching.
* This action takes place when a suitable issue isn't found in cache, or expired.
*/
private static interface FetchFunction {
private interface FetchFunction {
/**
* Fetches the issue. Throws an exception in case of a problem.
* @return a non-null issue in case of success
Expand Down

This file was deleted.

0 comments on commit bf1349f

Please sign in to comment.