Skip to content

Commit

Permalink
Added tests that Pascal found as problematic and failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas authored and Pascal Rapicault committed Dec 3, 2010
1 parent 267a4bf commit 5256fd4
Showing 1 changed file with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
package org.eclipse.m2e.tests.internal.index;

import java.io.File;
import java.util.Collection;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.index.IIndex;
Expand All @@ -27,18 +30,21 @@


/**
* Tests search functionality within the NexusIndexManager with repos that only
* need minimum indexing details.
* Tests search functionality within the NexusIndexManager with repos that only need minimum indexing details.
*
* @author dyocum
*/
public class NexusIndexManagerSearchTest extends AbstractNexusIndexManagerTest {
private static final String SETTINGS_ECLIPSE_REPO = "src/org/eclipse/m2e/tests/internal/index/public_mirror_repo_settings.xml";

private static final String REPO_URL_ECLIPSE = "http://repository.sonatype.org/content/repositories/eclipse";

private IMavenConfiguration mavenConfiguration = MavenPlugin.getDefault().getMavenConfiguration();

private NexusIndexManager indexManager = (NexusIndexManager) MavenPlugin.getDefault().getIndexManager();

private RepositoryRegistry repositoryRegistry = (RepositoryRegistry) MavenPlugin.getDefault().getRepositoryRegistry();

protected void setUp() throws Exception {
super.setUp();
updateRepo(REPO_URL_ECLIPSE, SETTINGS_ECLIPSE_REPO);
Expand All @@ -51,39 +57,39 @@ protected void setupPublicMirror(String publicRepoUrl, String settingsFile) thro
mavenConfiguration.setUserSettingsFile(mirroredRepoFile.getCanonicalPath());
waitForJobsToComplete();
}

private IRepository getRepository(String repoUrl) {
for (IRepository repository : repositoryRegistry.getRepositories(IRepositoryRegistry.SCOPE_SETTINGS)) {
if (repoUrl.equals(repository.getUrl())) {
for(IRepository repository : repositoryRegistry.getRepositories(IRepositoryRegistry.SCOPE_SETTINGS)) {
if(repoUrl.equals(repository.getUrl())) {
return repository;
}
}
throw new IllegalArgumentException("Repository registry does not have repository with url=" + repoUrl);
}

protected void updateRepo(String repoUrl, String settingsFile) throws Exception{
protected void updateRepo(String repoUrl, String settingsFile) throws Exception {
setupPublicMirror(repoUrl, settingsFile);
waitForJobsToComplete();
IRepository repository = getRepository(repoUrl);
NexusIndex index = indexManager.getIndex(repository);
if(index != null){
if(index != null) {
index.updateIndex(true, null);
}
waitForJobsToComplete();
}

public void testPluginSearch() throws Exception {
Map<String, IndexedArtifact> search = indexManager.search("maven-tycho", IIndex.SEARCH_PLUGIN);
assertTrue(search.size() > 0);

Map<String, IndexedArtifact> noResultsSearch = indexManager.search("maven-fake-plugin", IIndex.SEARCH_PLUGIN);
assertTrue(noResultsSearch.size() == 0);
}

public void testGroupSearch() throws Exception {
Map<String, IndexedArtifact> search = indexManager.search("org.junit", IIndex.SEARCH_GROUP);
assertTrue(search.size() > 0);

//TODO: this should probably be returning results, but it seems like there result space is too big,
//so its not returning results now
Map<String, IndexedArtifact> noResultsSearch = indexManager.search("orgXX", IIndex.SEARCH_GROUP);
Expand All @@ -95,37 +101,52 @@ public void testArtifactSearch() throws Exception {
IndexedArtifact ia = search.get("null : null : org.eclipse : org.eclipse.jdt.junit");
assertNotNull(ia);
boolean hasVersion = false;
for(IndexedArtifactFile file : ia.getFiles()){
if(file.version.startsWith("3.3.1")){
for(IndexedArtifactFile file : ia.getFiles()) {
if(file.version.startsWith("3.3.1")) {
hasVersion = true;
break;
}
}
}
assertTrue(hasVersion);

search = indexManager.search("junit", IIndex.SEARCH_ARTIFACT, IIndex.SEARCH_JAVADOCS);
assertTrue(search.size()>0);
assertTrue(search.size() > 0);
search = indexManager.search("junit", IIndex.SEARCH_ARTIFACT, IIndex.SEARCH_SOURCES);
assertTrue(search.size()>0);
assertTrue(search.size() > 0);
search = indexManager.search("junit", IIndex.SEARCH_ARTIFACT, IIndex.SEARCH_TESTS);
assertTrue(search.size()>0);
assertTrue(search.size() > 0);

Map<String, IndexedArtifact> noResultsSearch = indexManager.search("beepbeep-nothing", IIndex.SEARCH_ARTIFACT);
assertTrue(noResultsSearch.size() == 0);
}

/**
* TODO: Stupid test at this point. Not sure what a valid sha1 search should look like.
*
* @throws Exception
*/
public void testSha1Search() throws Exception {
Map<String, IndexedArtifact> search = indexManager.search("what-should-this-be", IIndex.SEARCH_SHA1);
assertTrue(search.size() == 0);
}

public void testBogusSearchType() throws Exception {
Map<String, IndexedArtifact> search = indexManager.search("commons-logging", "BadSearchType");
assertTrue(search.size() == 0);
}

public void testSearchGroups() throws CoreException {
Collection<IndexedArtifact> result = indexManager.getIndex((IProject) null).find("", null, null, null);
assertTrue(String.format("Wrong result set returned! (size=%s)", new Object[] {result.size()}), result.size() == 0);
}

public void testSearchGroups2() throws CoreException {
Collection<IndexedArtifact> result = indexManager.getIndex((IProject) null).find(null, null, null, null);
assertTrue(String.format("Wrong result set returned! (size=%s)", new Object[] {result.size()}), result.size() == 0);
}

public void testSearchGroups3() throws CoreException {
Collection<IndexedArtifact> result = indexManager.getIndex((IProject) null).find("org.ju", null, null, null);
assertTrue(String.format("Wrong result set returned! (size=%s)", new Object[] {result.size()}), result.size() > 0);
}
}

0 comments on commit 5256fd4

Please sign in to comment.