VIVO-618 Revise SearchService to parse uploaded files correctly and to respond properly to authentication errors.
This commit is contained in:
parent
0944a0d883
commit
d08c3f61ff
10 changed files with 557 additions and 618 deletions
|
@ -2,65 +2,88 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.search.controller;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Accepts requests to update a set of URIs in the search index.
|
||||
* Accepts requests to update a set of URIs in the search index.
|
||||
*/
|
||||
public class UpdateUrisInIndexTest {
|
||||
|
||||
@Test
|
||||
public void lineToUrisTest(){
|
||||
Assert.assertEquals(Arrays.asList("uri1"), UpdateUrisInIndex.lineToUris( "uri1"));
|
||||
Assert.assertEquals(Arrays.asList("uri1", "uri2"), UpdateUrisInIndex.lineToUris( "uri1,uri2"));
|
||||
|
||||
Assert.assertEquals(Arrays.asList("uri1"), UpdateUrisInIndex.lineToUris( "uri1\n"));
|
||||
Assert.assertEquals(Arrays.asList("uri1","uri2"), UpdateUrisInIndex.lineToUris( "uri1\nuri2"));
|
||||
|
||||
Assert.assertEquals(Collections.EMPTY_LIST, UpdateUrisInIndex.lineToUris( "" ));
|
||||
Assert.assertEquals(Collections.EMPTY_LIST, UpdateUrisInIndex.lineToUris( "," ));
|
||||
Assert.assertEquals(Collections.EMPTY_LIST, UpdateUrisInIndex.lineToUris( " , " ));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void UrisFromInputIteratorTest(){
|
||||
doUrisFromInputIterator("",0);
|
||||
doUrisFromInputIterator(" ",0);
|
||||
doUrisFromInputIterator(" , ",0);
|
||||
doUrisFromInputIterator("\n",0);
|
||||
doUrisFromInputIterator("\n\n\n",0);
|
||||
doUrisFromInputIterator("http://bogus.com/n234",1);
|
||||
doUrisFromInputIterator("http://bogus.com/n234\nhttp://bogus.com/n442",2);
|
||||
doUrisFromInputIterator("http://bogus.com/n234, http://bogus.com/n442",2);
|
||||
doUrisFromInputIterator("http://bogus.com/n234,\nhttp://bogus.com/n442\n",2);
|
||||
|
||||
doUrisFromInputIterator("http://bogus.com/n234\n",1);
|
||||
doUrisFromInputIterator("\nhttp://bogus.com/n234",1);
|
||||
doUrisFromInputIterator("\nhttp://bogus.com/n234\n",1);
|
||||
|
||||
}
|
||||
|
||||
public void doUrisFromInputIterator(String input, int expectedUris){
|
||||
Iterator<String> it = new UpdateUrisInIndex.UrisFromInputIterator( new StringReader(input) );
|
||||
int count = 0;
|
||||
while( it.hasNext()){
|
||||
String uri = it.next();
|
||||
if( uri == null)
|
||||
Assert.fail("UrisFromInputIterator should not return null strings \n " +
|
||||
"Null string for uri #" + count + " for input '" + input + "'");
|
||||
if( uri.isEmpty())
|
||||
Assert.fail("UrisFromInputIterator should not return empty strings \n " +
|
||||
"Empty string for uri #" + count + " for input '" + input + "'");
|
||||
count++;
|
||||
}
|
||||
Assert.assertEquals("Incorrect number of URIs from input '" + input + "'", expectedUris, count);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void nullString() {
|
||||
scan(null, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyString() {
|
||||
scan("", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingButDelimiters() {
|
||||
scan(" , ", 0);
|
||||
scan("\n", 0);
|
||||
scan("\n\n\n", 0);
|
||||
scan("\n, \t\r ,\n\n", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneTokenNoDelimiters() {
|
||||
scan("http://bogus.com/n234", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneTokenAssortedDelimiters() {
|
||||
scan("http://bogus.com/n234\n", 1);
|
||||
scan("\nhttp://bogus.com/n234", 1);
|
||||
scan("\nhttp://bogus.com/n234\n", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoTokensAssortedDelimiters() {
|
||||
scan("http://bogus.com/n234\nhttp://bogus.com/n442", 2);
|
||||
scan("http://bogus.com/n234, http://bogus.com/n442", 2);
|
||||
scan("http://bogus.com/n234,\nhttp://bogus.com/n442\n", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonBreakingSpace() {
|
||||
scan("non\u00A0breaking\u00A0space", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void omnibus() {
|
||||
scan(" a , b,c d\t,\re", 5);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public void scan(String input, int expectedUris) {
|
||||
Reader reader = (input == null) ? null : new StringReader(input);
|
||||
Iterator<String> it = new UpdateUrisInIndex().createScanner(reader);
|
||||
int count = 0;
|
||||
while (it.hasNext()) {
|
||||
String uri = it.next();
|
||||
if (uri == null) {
|
||||
Assert.fail("Scanner should not return null strings \n "
|
||||
+ "Null string for uri #" + count + " for input '"
|
||||
+ input + "'");
|
||||
} else if (uri.isEmpty()) {
|
||||
Assert.fail("Scanner should not return empty strings \n "
|
||||
+ "Empty string for uri #" + count + " for input '"
|
||||
+ input + "'");
|
||||
}
|
||||
count++;
|
||||
}
|
||||
Assert.assertEquals("Incorrect number of URIs from input '" + input
|
||||
+ "'", expectedUris, count);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue