Sorry, did the reformat thing again. I only changed the static
paths to use System.getProperty("file.separator") instead of a
hard coded /. Sorry about that.
--Thilo
[email protected] wrote:
> Author: twgoetz
> Date: Mon Jul 27 12:38:26 2009
> New Revision: 798115
>
> URL: http://svn.apache.org/viewvc?rev=798115&view=rev
> Log:
> UIMA-1403: two test cases broken on windows.
>
> https://issues.apache.org/jira/browse/UIMA-1403
>
> Modified:
>
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/consumer/LuceneCASIndexerTest.java
>
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/indexer/IndexWriterProviderImplTest.java
>
> Modified:
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/consumer/LuceneCASIndexerTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/consumer/LuceneCASIndexerTest.java?rev=798115&r1=798114&r2=798115&view=diff
> ==============================================================================
> ---
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/consumer/LuceneCASIndexerTest.java
> (original)
> +++
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/consumer/LuceneCASIndexerTest.java
> Mon Jul 27 12:38:26 2009
> @@ -48,77 +48,85 @@
>
> public class LuceneCASIndexerTest {
>
> + private static final String pathSep = System.getProperty("file.separator");
> +
> private static final String TEST_FILTER_ANNOTATION =
> "testFilterAnnotation";
> +
> private static final String TEST_FILTER_FIELD = "testFilterField";
> +
> private static final String FIELD_NAME = "annotation1";
> - private static final String DESCRIPTOR_FILE =
> "src/main/resources/LuceneCASIndexer.xml";
> - private static final String INDEX_DIRECTORY =
> "src/test/resources/test-index";
>
> - private LuceneCASIndexer consumer;
> + private static final String DESCRIPTOR_FILE =
> "src/main/resources/LuceneCASIndexer.xml";
> +
> + private static final String INDEX_DIRECTORY = "src" + pathSep
> + + "test" + pathSep + "resources" + pathSep + "test-index";
> +
> + private LuceneCASIndexer consumer;
> +
> + @Before
> + public void setUp() throws InvalidXMLException, IOException,
> ResourceInitializationException {
> +
> + CasConsumerDescription consumerDescription = (CasConsumerDescription)
> UIMAFramework
> + .getXMLParser().parseCasConsumerDescription(new
> XMLInputSource(DESCRIPTOR_FILE));
> + consumer = (LuceneCASIndexer)
> UIMAFramework.produceCasConsumer(consumerDescription);
> + }
> +
> + @After
> + public void tearDown() throws Exception {
> + FSDirectory directory = (FSDirectory)
> consumer.getIndexWriter().getDirectory();
> + File directoryFile = directory.getFile();
> + consumer.destroy();
> +
> + directory = FSDirectory.getDirectory(directoryFile);
> +
> + for (String file : directory.list())
> + directory.deleteFile(file);
> +
> + directory.getFile().delete();
> + }
>
> - @Before
> - public void setUp() throws InvalidXMLException, IOException,
> ResourceInitializationException{
> -
> - CasConsumerDescription consumerDescription =
> (CasConsumerDescription)
> UIMAFramework.getXMLParser().parseCasConsumerDescription(new
> XMLInputSource(DESCRIPTOR_FILE));
> - consumer = (LuceneCASIndexer)
> UIMAFramework.produceCasConsumer(consumerDescription);
> - }
> -
> - @After
> - public void tearDown() throws Exception{
> - FSDirectory directory = (FSDirectory)
> consumer.getIndexWriter().getDirectory();
> - File directoryFile = directory.getFile();
> - consumer.destroy();
> -
> - directory = FSDirectory.getDirectory(directoryFile);
> -
> - for( String file: directory.list() )
> - directory.deleteFile(file);
> -
> - directory.getFile().delete();
> - }
> -
> - @Test
> - public void testIndexOutDir(){
> - FSDirectory directory = (FSDirectory)
> consumer.getIndexWriter().getDirectory();
> -
> - String path = directory.getFile().getPath();
> - assertTrue(path.contains(INDEX_DIRECTORY));
> - }
> -
> - @Test
> - public void testMappingFile(){
> - Collection<FieldDescription> fieldDescriptions =
> consumer.getFieldDescriptions();
> - assertEquals(1, fieldDescriptions.size());
> - FieldDescription fieldDescription =
> fieldDescriptions.iterator().next();
> - assertEquals(FIELD_NAME, fieldDescription.getName());
> - assertEquals(2,
> fieldDescription.getAnnotationDescriptions().size());
> - }
> -
> - @Test
> - public void testPreloadResources() throws IOException{
> - Collection<FieldDescription> fieldDescriptions =
> consumer.getFieldDescriptions();
> - TokenFilterFactory testFactoryField =
> createMock(TokenFilterFactory.class);
> + @Test
> + public void testIndexOutDir() {
> + FSDirectory directory = (FSDirectory)
> consumer.getIndexWriter().getDirectory();
> +
> + String path = directory.getFile().getPath();
> + assertTrue(path.contains(INDEX_DIRECTORY));
> + }
> +
> + @Test
> + public void testMappingFile() {
> + Collection<FieldDescription> fieldDescriptions =
> consumer.getFieldDescriptions();
> + assertEquals(1, fieldDescriptions.size());
> + FieldDescription fieldDescription = fieldDescriptions.iterator().next();
> + assertEquals(FIELD_NAME, fieldDescription.getName());
> + assertEquals(2, fieldDescription.getAnnotationDescriptions().size());
> + }
> +
> + @Test
> + public void testPreloadResources() throws IOException {
> + Collection<FieldDescription> fieldDescriptions =
> consumer.getFieldDescriptions();
> + TokenFilterFactory testFactoryField =
> createMock(TokenFilterFactory.class);
> TokenFilterFactory testFactoryAnnotation =
> createMock(TokenFilterFactory.class);
> -
> - Capture<Properties> propertiesCaptureField = new
> Capture<Properties>();
> - Capture<Properties> propertiesCaptureAnnotation = new
> Capture<Properties>();
> -
> - testFactoryField.preloadResources(capture(propertiesCaptureField));
> -
> testFactoryAnnotation.preloadResources(capture(propertiesCaptureAnnotation));
> -
> - replay(testFactoryField);
> - replay(testFactoryAnnotation);
> -
> - consumer.preloadResources(fieldDescriptions,
> Maps.immutableBiMap(TEST_FILTER_ANNOTATION, testFactoryAnnotation,
> -
> TEST_FILTER_FIELD, testFactoryField));
> - verify(testFactoryField);
> - verify(testFactoryAnnotation);
> -
> - Properties fieldFilterProperties = propertiesCaptureField.getValue();
> - assertEquals("value1", fieldFilterProperties.getProperty("key1"));
> -
> +
> + Capture<Properties> propertiesCaptureField = new Capture<Properties>();
> + Capture<Properties> propertiesCaptureAnnotation = new
> Capture<Properties>();
> +
> + testFactoryField.preloadResources(capture(propertiesCaptureField));
> +
> testFactoryAnnotation.preloadResources(capture(propertiesCaptureAnnotation));
> +
> + replay(testFactoryField);
> + replay(testFactoryAnnotation);
> +
> + consumer.preloadResources(fieldDescriptions,
> Maps.immutableBiMap(TEST_FILTER_ANNOTATION,
> + testFactoryAnnotation, TEST_FILTER_FIELD, testFactoryField));
> + verify(testFactoryField);
> + verify(testFactoryAnnotation);
> +
> + Properties fieldFilterProperties = propertiesCaptureField.getValue();
> + assertEquals("value1", fieldFilterProperties.getProperty("key1"));
> +
> Properties annotationFilterProperties =
> propertiesCaptureAnnotation.getValue();
> assertEquals("value2", annotationFilterProperties.getProperty("key2"));
> - }
> -
> + }
> +
> }
>
> Modified:
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/indexer/IndexWriterProviderImplTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/indexer/IndexWriterProviderImplTest.java?rev=798115&r1=798114&r2=798115&view=diff
> ==============================================================================
> ---
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/indexer/IndexWriterProviderImplTest.java
> (original)
> +++
> incubator/uima/sandbox/trunk/Lucas/src/test/java/org/apache/uima/lucas/indexer/IndexWriterProviderImplTest.java
> Mon Jul 27 12:38:26 2009
> @@ -44,59 +44,68 @@
>
> public class IndexWriterProviderImplTest {
>
> - private static final String TEST_INDEX = "src/test/resources/test-index";
> - private static final String RESOURCES_TEST_INDEX_PROPERTIES =
> "src/test/resources/IndexWriter.properties";
> + private static final String fileSep = System.getProperty("file.separator");
> +
> + private static final String TEST_INDEX = "src" + fileSep + "test" +
> fileSep + "resources"
> + + fileSep + "test-index";
> +
> + private static final String RESOURCES_TEST_INDEX_PROPERTIES = "src" +
> fileSep + "test" + fileSep
> + + "resources" + fileSep + "IndexWriter.properties";
> +
> private IndexWriterProviderImpl indexWriterProviderImpl;
> +
> private DataResource dataResource;
> +
> private InputStream propertiesInputStream;
> -
> +
> @Before
> - public void setUp() throws IOException{
> + public void setUp() throws IOException {
> indexWriterProviderImpl = new IndexWriterProviderImpl();
> dataResource = createMock(DataResource.class);
> FileInputStream fileInputStream = new
> FileInputStream(RESOURCES_TEST_INDEX_PROPERTIES);
> propertiesInputStream = new BufferedInputStream(fileInputStream);
> }
> -
> +
> @After
> - public void tearDown() throws Exception{
> -
> + public void tearDown() throws Exception {
> +
> FSDirectory directory = (FSDirectory)
> indexWriterProviderImpl.getIndexWriter().getDirectory();
> File directoryFile = directory.getFile();
> -
> +
> directory = FSDirectory.getDirectory(directoryFile);
> IndexWriter.unlock(directory);
> -
> - for( String file: directory.list() )
> +
> + for (String file : directory.list())
> directory.deleteFile(file);
>
> directory.getFile().delete();
> }
> -
> +
> @Test
> - public void testLoadData() throws IOException,
> ResourceInitializationException{
> -
> + public void testLoadData() throws IOException,
> ResourceInitializationException {
> +
> expect(dataResource.getInputStream()).andReturn(propertiesInputStream);
> replay(dataResource);
> -
> +
> indexWriterProviderImpl.load(dataResource);
> IndexWriter indexWriter = indexWriterProviderImpl.getIndexWriter();
> FSDirectory fsDirectory = (FSDirectory) indexWriter.getDirectory();
> -
> +
> String hostname = getHostName();
> String pid = getPID();
> -
> - assertTrue(fsDirectory.getFile().getAbsolutePath().endsWith(TEST_INDEX
> +"-"+hostname+"-"+pid));
> +
> + assertTrue(fsDirectory.getFile().getAbsolutePath().endsWith(
> + TEST_INDEX + "-" + hostname + "-" + pid));
> assertEquals(513, indexWriter.getRAMBufferSizeMB(), 0.5);
> assertEquals(9999, indexWriter.getMaxFieldLength(), 0.5);
> }
> -
> - protected String getPID(){
> +
> + protected String getPID() {
> String id = ManagementFactory.getRuntimeMXBean().getName();
> - return id.substring(0, id.indexOf("@") );
> + return id.substring(0, id.indexOf("@"));
> }
> -
> - public String getHostName(){
> +
> + public String getHostName() {
> InetAddress address;
> String hostName;
> try {
> @@ -104,7 +113,7 @@
> hostName = address.getHostName();
> } catch (UnknownHostException e) {
> throw new IllegalStateException(e);
> - }
> + }
> return hostName;
> }
> }
>