Skip to content

Commit

Permalink
Added tests for module search (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Sep 4, 2012
1 parent 9731add commit 9758971
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 21 deletions.
Expand Up @@ -19,17 +19,21 @@
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collection;
import java.util.Map.Entry;

import org.junit.Assert;

import com.redhat.ceylon.cmr.api.Logger;
import com.redhat.ceylon.cmr.api.ModuleQuery;
import com.redhat.ceylon.cmr.api.ModuleResult;
import com.redhat.ceylon.cmr.api.ModuleSearchResult;
import com.redhat.ceylon.cmr.api.ModuleVersionDetails;
import com.redhat.ceylon.cmr.api.ModuleVersionQuery;
import com.redhat.ceylon.cmr.api.ModuleVersionResult;
import com.redhat.ceylon.cmr.api.RepositoryManager;
import com.redhat.ceylon.cmr.api.ModuleQuery.Type;
import com.redhat.ceylon.cmr.api.ModuleSearchResult.ModuleDetails;
import com.redhat.ceylon.cmr.impl.JULLogger;
import com.redhat.ceylon.cmr.impl.RootRepositoryManager;

Expand Down Expand Up @@ -72,7 +76,8 @@ protected void testComplete(String query, String[] expected, RepositoryManager m
}
}

protected void testListVersions(String query, String versionQuery, ModuleVersionDetails[] expected, RepositoryManager manager){
protected void testListVersions(String query, String versionQuery, ModuleVersionDetails[] expected) throws Exception{
RepositoryManager manager = getRepositoryManager();
ModuleVersionQuery lookup = new ModuleVersionQuery(query, versionQuery, ModuleQuery.Type.JVM);
ModuleVersionResult result = manager.completeVersions(lookup);
int i=0;
Expand All @@ -87,4 +92,25 @@ protected void testListVersions(String query, String versionQuery, ModuleVersion
Assert.assertArrayEquals(expectedVersion.getBy(), version.getBy());
}
}

protected void testSearchResults(String q, Type type, ModuleDetails[] expected) throws Exception{
testSearchResults(q, type, expected, 0, 20);
}

protected void testSearchResults(String q, Type type, ModuleDetails[] expected, int start, int count) throws Exception{
RepositoryManager manager = getRepositoryManager();

ModuleQuery query = new ModuleQuery(q, type);
query.setStart(start);
query.setCount(count);
ModuleSearchResult results = manager.searchModules(query);

int i=0;
Collection<ModuleDetails> resultsList = results.getResults();
Assert.assertEquals(expected.length, resultsList.size());
for(ModuleDetails result : resultsList){
ModuleDetails expectedResult = expected[i++];
Assert.assertEquals(expectedResult.getName(), result.getName());
}
}
}
Expand Up @@ -17,6 +17,13 @@

package com.redhat.ceylon.test.smoke.test;

import java.net.URISyntaxException;

import org.junit.Ignore;
import org.junit.Test;

import com.redhat.ceylon.cmr.api.ModuleQuery.Type;
import com.redhat.ceylon.cmr.api.ModuleSearchResult;
import com.redhat.ceylon.cmr.api.ModuleVersionDetails;
import com.redhat.ceylon.cmr.api.Repository;
import com.redhat.ceylon.cmr.api.RepositoryManager;
Expand All @@ -37,30 +44,35 @@ public class HerdTestCase extends AbstractTest {
public void testDummy() {
}

@Test
@Ignore("Required Herd running locally")
public void testHerdCompleteVersions() throws URISyntaxException{
protected RepositoryManager getRepositoryManager() throws URISyntaxException {
RepositoryManagerBuilder builder = new RepositoryManagerBuilder(getRepositoryRoot(), log);
WebDAVContentStore rcs = new WebDAVContentStore("http://localhost:9000/test", log);
Repository repo = new DefaultRepository(rcs.createRoot());
RepositoryManager manager = builder.appendRepository(repo).buildRepository();

return builder.appendRepository(repo).buildRepository();
}

@Test
//@Ignore("Required Herd running locally")
public void testHerdCompleteVersions() throws Exception{
ModuleVersionDetails[] expected = new ModuleVersionDetails[]{
new ModuleVersionDetails("0.3.0", "A module for collections \"foo\" `hehe` < 3\n\n some code `with` \"stuff\" < 𐒅 &lt; &#32; &#x32; 2\n\nboo", "Apache Software License", "Stéphane Épardaud"),
};
testListVersions("ceylon.collection", null, expected, manager);
testListVersions("ceylon.collection", null, expected);
}

@Test
@Ignore("Required Herd running locally")
public void testHerdCompleteVersionsFiltered() throws URISyntaxException{
RepositoryManagerBuilder builder = new RepositoryManagerBuilder(getRepositoryRoot(), log);
WebDAVContentStore rcs = new WebDAVContentStore("http://localhost:9000/test", log);
Repository repo = new DefaultRepository(rcs.createRoot());
RepositoryManager manager = builder.appendRepository(repo).buildRepository();

//@Ignore("Required Herd running locally")
public void testHerdCompleteVersionsFiltered() throws Exception{
ModuleVersionDetails[] expected = new ModuleVersionDetails[]{
};
testListVersions("ceylon.collection", "1.0", expected, manager);
testListVersions("ceylon.collection", "1.0", expected);
}

@Test
//@Ignore("Required Herd running locally")
public void testHerdSearch() throws Exception{
ModuleSearchResult.ModuleDetails[] expected = new ModuleSearchResult.ModuleDetails[]{
};
testSearchResults("ceylon.collection", Type.JVM, expected);
}
}
Expand Up @@ -28,6 +28,8 @@
import com.redhat.ceylon.cmr.api.ArtifactContext;
import com.redhat.ceylon.cmr.api.ArtifactResult;
import com.redhat.ceylon.cmr.api.ModuleQuery;
import com.redhat.ceylon.cmr.api.ModuleQuery.Type;
import com.redhat.ceylon.cmr.api.ModuleSearchResult.ModuleDetails;
import com.redhat.ceylon.cmr.api.ModuleVersionDetails;
import com.redhat.ceylon.cmr.api.Repository;
import com.redhat.ceylon.cmr.api.RepositoryManager;
Expand Down Expand Up @@ -304,20 +306,84 @@ public void testCompleteStopAtVersion() throws Exception {

@Test
public void testListVersion() throws Exception {
RepositoryManager manager = getRepositoryManager();

ModuleVersionDetails[] expected = new ModuleVersionDetails[]{
new ModuleVersionDetails("1.0.0", "The classic Hello World module", "Public domain", "Stef Epardaud"),
};
testListVersions("com.acme.helloworld", null, expected, manager);
testListVersions("com.acme.helloworld", null, expected);
}

@Test
public void testListVersionFiltered() throws Exception {
RepositoryManager manager = getRepositoryManager();

ModuleVersionDetails[] expected = new ModuleVersionDetails[]{
};
testListVersions("com.acme.helloworld", "9", expected, manager);
testListVersions("com.acme.helloworld", "9", expected);
}

@Test
public void testSearchModules() throws Exception {
ModuleDetails[] expected = new ModuleDetails[]{
new ModuleDetails("com.acme.helloworld"),
new ModuleDetails("hello"),
new ModuleDetails("moduletest"),
new ModuleDetails("org.jboss.acme"),
new ModuleDetails("org.jboss.jboss-vfs"),
new ModuleDetails("test-jar"),
};

testSearchResults("", Type.JVM, expected);
}

@Test
public void testSearchModulesPaged() throws Exception {
ModuleDetails[] expected = new ModuleDetails[]{
new ModuleDetails("moduletest"),
new ModuleDetails("org.jboss.acme"),
};

testSearchResults("", Type.JVM, expected, 2, 2);
}

@Test
public void testSearchModulesFilteredByName() throws Exception {
ModuleDetails[] expected = new ModuleDetails[]{
new ModuleDetails("com.acme.helloworld"),
new ModuleDetails("hello"),
};

testSearchResults("hello", Type.JVM, expected);
}

// com.acme.helloworld: ("1.0.0", "The classic Hello World module", "Public domain", "Stef Epardaud")

@Test
public void testSearchModulesFilteredByDocLicenseAndAuthor() throws Exception {
ModuleDetails[] expected = new ModuleDetails[]{
new ModuleDetails("com.acme.helloworld"),
};

testSearchResults("classic", Type.JVM, expected);
testSearchResults("domain", Type.JVM, expected);
testSearchResults("epardaud", Type.JVM, expected);
}

@Test
public void testSearchModulesFilteredByDocLicenseAndAuthorSrc() throws Exception {
ModuleDetails[] expected = new ModuleDetails[]{
new ModuleDetails("com.acme.helloworld"),
};

testSearchResults("classic", Type.SRC, expected);
testSearchResults("domain", Type.SRC, expected);
testSearchResults("epardaud", Type.SRC, expected);
}

@Test
public void testSearchModulesFilteredByDocLicenseAndAuthorJs() throws Exception {
ModuleDetails[] expected = new ModuleDetails[]{
};

testSearchResults("classic", Type.JS, expected);
testSearchResults("domain", Type.JS, expected);
testSearchResults("epardaud", Type.JS, expected);
}
}

0 comments on commit 9758971

Please sign in to comment.