You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by mb...@apache.org on 2007/02/14 15:35:47 UTC

svn commit: r507542 [10/10] - in /incubator/uima/sandbox/trunk/CasEditor: ./ icons/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/uima/ src/main/java/org/apache/uima/caseditor/ src/main/java/org/apa...

Added: incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/DefectiveNlpModelTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/DefectiveNlpModelTest.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/DefectiveNlpModelTest.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/DefectiveNlpModelTest.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.test;
+
+import java.io.ByteArrayInputStream;
+
+
+import org.apache.uima.caseditor.core.TaeCorePlugin;
+import org.apache.uima.caseditor.core.model.AnnotatorElement;
+import org.apache.uima.caseditor.core.model.ConsumerElement;
+import org.apache.uima.caseditor.core.model.DocumentElement;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * 
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.1.2.2 $, $Date: 2007/01/04 14:58:09 $
+ */
+public class DefectiveNlpModelTest {
+  private TestProject mProject;
+
+  /**
+   * Initializes the current instance.
+   */
+  public DefectiveNlpModelTest() {
+    mProject = new TestProject();
+  }
+
+  /**
+   * @throws CoreException
+   */
+  @Before
+  public void clearWorkspace() throws CoreException {
+    WorkspaceUtil.clearWorkspace();
+  }
+
+  @Test
+  public void testInvalidDotCorpus() throws CoreException {
+    mProject.createProject();
+    mProject.createProjectContent();
+
+    // create invalid dot corpus
+    mProject.getDotCorpus().create(new ByteArrayInputStream(new byte[0]), true, null);
+
+    // check for default dotCorpus file
+    assertTrue(TaeCorePlugin.getNlpModel().findMember(mProject.getDotCorpus()) != null);
+
+    // check that no content elements exist
+    for (IResource resource : mProject.getResources()) {
+      assertTrue(TaeCorePlugin.getNlpModel().findMember(resource) == null);
+    }
+  }
+
+  @Test
+  public void testFolderDotCorpus() throws CoreException {
+    mProject.createProject();
+    mProject.createProjectContent();
+
+    // create invalid dot corpus
+    IFolder dotCorpusFolder = mProject.getProject().getFolder(".corpus");
+    dotCorpusFolder.create(true, true, null);
+
+    // check for default dotCorpus file
+    assertTrue(TaeCorePlugin.getNlpModel().findMember(mProject.getDotCorpus()) != null);
+
+    // check that no content elements exist
+    for (IResource resource : mProject.getResources()) {
+      assertTrue(TaeCorePlugin.getNlpModel().findMember(resource) == null);
+    }
+  }
+
+  @Test
+  public void testInvalidDocument() throws CoreException {
+    mProject.createProject();
+    mProject.createProjectContent();
+    mProject.createDotCorpus();
+
+    mProject.getDocument().setContents(new ByteArrayInputStream(new byte[0]), true, true, null);
+
+    assertTrue(((DocumentElement) TaeCorePlugin.getNlpModel().findMember(mProject.getDocument()))
+            .getCAS() == null);
+  }
+
+  @Test
+  public void testInvalidAnnotator() throws CoreException {
+    mProject.createProject();
+    mProject.createProjectContent();
+    mProject.createDotCorpus();
+
+    mProject.getAnnotatorFile()
+            .setContents(new ByteArrayInputStream(new byte[0]), true, true, null);
+
+    assertTrue(((AnnotatorElement) TaeCorePlugin.getNlpModel().findMember(
+            mProject.getAnnotatorFile())).getAnnotatorConfiguration() == null);
+  }
+
+  @Test
+  public void testInvalidConsumer() throws CoreException {
+    mProject.createProject();
+    mProject.createProjectContent();
+    mProject.createDotCorpus();
+
+    mProject.getConsumerFile().setContents(new ByteArrayInputStream(new byte[0]), true, true, null);
+
+    assertTrue(((ConsumerElement) TaeCorePlugin.getNlpModel()
+            .findMember(mProject.getConsumerFile())).getConsumerConfiguration() == null);
+  }
+
+  @Test
+  public void testInvalidTypesystem() throws CoreException {
+    mProject.createProject();
+    mProject.createProjectContent();
+    mProject.createDotCorpus();
+
+    mProject.getTypesystem().setContents(new ByteArrayInputStream(new byte[0]), true, true, null);
+
+    assertTrue(TaeCorePlugin.getNlpModel().findMember(mProject.getTypesystem()) == null);
+  }
+
+  @Test
+  public void testFileForCorpusFolder() throws CoreException {
+    mProject.createProject();
+    mProject.createDotCorpus();
+
+    IFile corpusFile = mProject.getProject().getFile("corpus");
+    corpusFile.create(new ByteArrayInputStream(new byte[0]), true, null);
+
+    // check that model and project creation did not failed
+    assertTrue(TaeCorePlugin.getNlpModel().findMember(mProject.getProject()) != null);
+  }
+
+  @Test
+  public void testFileForSourceFolder() throws CoreException {
+    mProject.createProject();
+    mProject.createDotCorpus();
+
+    IFile corpusFile = mProject.getProject().getFile("UimaSourceFolder");
+    corpusFile.create(new ByteArrayInputStream(new byte[0]), true, null);
+
+    // check that model and project creation did not failed
+    assertTrue(TaeCorePlugin.getNlpModel().findMember(mProject.getProject()) != null);
+  }
+}
\ No newline at end of file

Added: incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Document.xcas
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Document.xcas?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Document.xcas (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Document.xcas Wed Feb 14 06:35:40 2007
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CAS>
+    <uima.cas.Sofa _indexed="0" _id="1" sofaNum="1"
+        sofaID="_InitialView" mimeType="text" sofaString="On March 15, there was an accident near Munich. The driver got badly&#xd;&#xa;injured. Driving alone not far from her home, the middle-aged woman&#xd;&#xa;crashed at high speed into a tree. A resident, who lives near the&#xd;&#xa;street where the accident took place, called instantly the police. He &#xd;&#xa;reported what had happened and gave his name and address to the officer.&#xd;&#xa;He's called Peter Schubert and he lives at Max-Löw-Straße 13 in&#xd;&#xa;84630 Gauting. The police arrived ten minutes later and brought&#xd;&#xa;the woman into hospital. Although she had multiple trauma, she's &#xd;&#xa;out of mortal danger.&#xd;&#xa;"/>
+    <uima.tcas.DocumentAnnotation _indexed="1" _id="12" _ref_sofa="1"
+        begin="0" end="572" language="x-unspecified"/>
+    <net.sf.tae.Token _indexed="1" _id="17" _ref_sofa="1" begin="0"
+        end="2" pos="IN"/>
+    <net.sf.tae.Token _indexed="1" _id="22" _ref_sofa="1" begin="9"
+        end="11" pos="CD"/>
+    <net.sf.tae.Token _indexed="1" _id="27" _ref_sofa="1" begin="11"
+        end="12" pos=","/>
+    <net.sf.tae.Token _indexed="1" _id="32" _ref_sofa="1" begin="13"
+        end="18" pos="EX"/>
+    <net.sf.tae.Token _indexed="1" _id="37" _ref_sofa="1" begin="19"
+        end="22" pos="VBD"/>
+    <net.sf.tae.Token _indexed="1" _id="42" _ref_sofa="1" begin="23"
+        end="25" pos="DT"/>
+    <net.sf.tae.Token _indexed="1" _id="47" _ref_sofa="1" begin="26"
+        end="34" pos="NN"/>
+    <net.sf.tae.Token _indexed="1" _id="52" _ref_sofa="1" begin="35"
+        end="39" pos="IN"/>
+    <net.sf.tae.Token _indexed="1" _id="57" _ref_sofa="1" begin="40"
+        end="46" pos="NNP"/>
+    <net.sf.tae.Token _indexed="1" _id="62" _ref_sofa="1" begin="46"
+        end="47" pos="."/>
+    <net.sf.tae.Token _indexed="1" _id="67" _ref_sofa="1" begin="48"
+        end="51" pos="DT"/>
+    <net.sf.tae.Token _indexed="1" _id="72" _ref_sofa="1" begin="52"
+        end="58" pos="NN"/>
+    <net.sf.tae.Token _indexed="1" _id="77" _ref_sofa="1" begin="59"
+        end="62" pos="VBD"/>
+    <net.sf.tae.Token _indexed="1" _id="82" _ref_sofa="1" begin="63"
+        end="68" pos="RB"/>
+    <net.sf.tae.Token _indexed="1" _id="87" _ref_sofa="1" begin="70"
+        end="77" pos="VBN"/>
+    <net.sf.tae.Token _indexed="1" _id="92" _ref_sofa="1" begin="77"
+        end="78" pos="."/>
+    <net.sf.tae.Token _indexed="1" _id="97" _ref_sofa="1" begin="79"
+        end="86" pos="VBG"/>
+    <net.sf.tae.Token _indexed="1" _id="102" _ref_sofa="1" begin="93"
+        end="96" pos="RB"/>
+    <net.sf.tae.Token _indexed="1" _id="107" _ref_sofa="1" begin="97"
+        end="100" pos="RB"/>
+    <net.sf.tae.Token _indexed="1" _id="112" _ref_sofa="1" begin="101"
+        end="105" pos="IN"/>
+    <net.sf.tae.Token _indexed="1" _id="117" _ref_sofa="1" begin="106"
+        end="109" pos="PRP$"/>
+    <net.sf.tae.Token _indexed="1" _id="122" _ref_sofa="1" begin="110"
+        end="114" pos="NN"/>
+    <net.sf.tae.Token _indexed="1" _id="127" _ref_sofa="1" begin="114"
+        end="115" pos=","/>
+    <net.sf.tae.Token _indexed="1" _id="132" _ref_sofa="1" begin="116"
+        end="119" pos="DT"/>
+    <net.sf.tae.Token _indexed="1" _id="137" _ref_sofa="1" begin="120"
+        end="131" pos="JJ"/>
+    <net.sf.tae.Token _indexed="1" _id="142" _ref_sofa="1" begin="132"
+        end="137" pos="NN"/>
+    <net.sf.tae.Token _indexed="1" _id="147" _ref_sofa="1" begin="147"
+        end="149" pos="IN"/>
+    <net.sf.tae.Token _indexed="1" _id="152" _ref_sofa="1" begin="139"
+        end="146" pos="VBD"/>
+    <net.sf.tae.Sentence _indexed="1" _id="157" _ref_sofa="1" begin="0" end="47"/>
+    <net.sf.tae.Sentence _indexed="1" _id="161" _ref_sofa="1" begin="48" end="78"/>
+    <net.sf.tae.Sentence _indexed="1" _id="165" _ref_sofa="1" begin="79" end="173"/>
+    <net.sf.tae.City _indexed="1" _id="169" _ref_sofa="1" begin="40" end="46"/>
+    <net.sf.tae.Address _indexed="1" _id="173" _ref_person="305"
+        _ref_street="301" _ref_city="297" _ref_zip="293"/>
+    <net.sf.tae.Parse _indexed="1" _id="178" _ref_sofa="1" begin="3"
+        end="11" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="183" _ref_sofa="1" begin="0"
+        end="11" type="PP"/>
+    <net.sf.tae.Parse _indexed="1" _id="188" _ref_sofa="1" begin="13"
+        end="18" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="193" _ref_sofa="1" begin="23"
+        end="34" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="198" _ref_sofa="1" begin="40"
+        end="46" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="203" _ref_sofa="1" begin="35"
+        end="46" type="PP"/>
+    <net.sf.tae.Parse _indexed="1" _id="208" _ref_sofa="1" begin="23"
+        end="46" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="213" _ref_sofa="1" begin="19"
+        end="46" type="VP"/>
+    <net.sf.tae.Parse _indexed="1" _id="218" _ref_sofa="1" begin="0"
+        end="47" type="S"/>
+    <net.sf.tae.Parse _indexed="1" _id="223" _ref_sofa="1" begin="48"
+        end="58" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="228" _ref_sofa="1" begin="63"
+        end="68" type="ADVP"/>
+    <net.sf.tae.Parse _indexed="1" _id="233" _ref_sofa="1" begin="70"
+        end="77" type="VP"/>
+    <net.sf.tae.Parse _indexed="1" _id="238" _ref_sofa="1" begin="59"
+        end="77" type="VP"/>
+    <net.sf.tae.Parse _indexed="1" _id="243" _ref_sofa="1" begin="48"
+        end="78" type="S"/>
+    <net.sf.tae.Parse _indexed="1" _id="248" _ref_sofa="1" begin="106"
+        end="114" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="253" _ref_sofa="1" begin="101"
+        end="114" type="PP"/>
+    <net.sf.tae.Parse _indexed="1" _id="258" _ref_sofa="1" begin="93"
+        end="114" type="ADVP"/>
+    <net.sf.tae.Parse _indexed="1" _id="263" _ref_sofa="1" begin="79"
+        end="114" type="VP"/>
+    <net.sf.tae.Parse _indexed="1" _id="268" _ref_sofa="1" begin="79"
+        end="114" type="S"/>
+    <net.sf.tae.Parse _indexed="1" _id="273" _ref_sofa="1" begin="116"
+        end="137" type="NP"/>
+    <net.sf.tae.Parse _indexed="1" _id="278" _ref_sofa="1" begin="147"
+        end="172" type="PP"/>
+    <net.sf.tae.Parse _indexed="1" _id="283" _ref_sofa="1" begin="139"
+        end="172" type="VP"/>
+    <net.sf.tae.Parse _indexed="1" _id="288" _ref_sofa="1" begin="79"
+        end="173" type="S"/>
+    <net.sf.tae.Zip _id="293" _ref_sofa="1" begin="417" end="422"/>
+    <net.sf.tae.City _id="297" _ref_sofa="1" begin="423" end="430"/>
+    <net.sf.tae.Street _id="301" _ref_sofa="1" begin="395" end="412"/>
+    <net.sf.tae.Person _id="305" _ref_sofa="1" begin="364" end="378"/>
+</CAS>
\ No newline at end of file

Added: incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/NlpModelTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/NlpModelTest.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/NlpModelTest.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/NlpModelTest.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+
+import org.apache.uima.caseditor.core.TaeCorePlugin;
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.apache.uima.caseditor.core.model.delta.INlpElementDelta;
+import org.apache.uima.caseditor.core.model.delta.INlpModelChangeListener;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * 
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.4.2.2 $, $Date: 2007/01/04 14:58:09 $
+ */
+public class NlpModelTest {
+  private TestProject mProject;
+
+  /**
+   * Initializes the current instance.
+   */
+  public NlpModelTest() {
+    mProject = new TestProject();
+  }
+
+  /**
+   * @throws CoreException
+   */
+  @Before
+  public void clearWorkspace() throws CoreException {
+    WorkspaceUtil.clearWorkspace();
+  }
+
+  /**
+   * Creates the nlp project from an existing project structure.
+   * 
+   * @throws CoreException
+   */
+  @Test
+  public void testCreationFromExistingProject() throws CoreException {
+    mProject.createProject();
+    mProject.createProjectContent();
+    mProject.createDotCorpus();
+
+    // creates implicit the nlp model
+    mProject.validateNlpProject();
+  }
+
+  /**
+   * Adds the dotcorpus to an empty existing nlp project.
+   * 
+   * @throws CoreException
+   */
+  @Test
+  public void testAddDotCorpus() throws CoreException {
+    TaeCorePlugin.destroyNlpModelForTesting();
+
+    mProject.createProject();
+    mProject.createProjectContent();
+
+    // create the nlp model now
+    TaeCorePlugin.getNlpModel();
+
+    mProject.createDotCorpus();
+
+    mProject.validateNlpProject();
+  }
+
+  /**
+   * This creates an nlp project. Then it creates the dot corpus and the NlpModel.
+   * 
+   * After that all resources are added to the project.
+   * 
+   * @throws CoreException
+   */
+  @Test
+  public void testAddNlpElements() throws CoreException {
+    TaeCorePlugin.destroyNlpModelForTesting();
+
+    mProject.createProject();
+    mProject.createDotCorpus();
+
+    TaeCorePlugin.getNlpModel();
+
+    mProject.createProjectContent();
+
+    mProject.validateNlpProject();
+  }
+
+  /**
+   * 1. create project with nlp nature 2. then create the dot corpus file 3. add all folders and
+   * files
+   * 
+   * Note: the listener must be removed after the test
+   * 
+   * @throws CoreException
+   */
+  @Test
+  public void testAddChangeEventListener() throws CoreException {
+    TaeCorePlugin.destroyNlpModelForTesting();
+
+    final Set<IResource> addedElements = new HashSet<IResource>();
+
+    INlpModelChangeListener listener = new INlpModelChangeListener() {
+      public void refresh(INlpElement element) {
+      }
+
+      public void resourceChanged(INlpElementDelta delta) {
+        if (delta.getKind().equals(Kind.ADDED) && delta.getNlpElement() != null) {
+          addedElements.add(delta.getResource());
+        }
+
+        for (INlpElementDelta child : delta.getAffectedChildren()) {
+          resourceChanged(child);
+        }
+      }
+    };
+
+    TaeCorePlugin.getNlpModel().addNlpModelChangeListener(listener);
+
+    try {
+      mProject.createProject();
+      mProject.createDotCorpus();
+      mProject.createProjectContent();
+
+      // check for add events
+      for (IResource resource : mProject.getResources()) {
+        assertTrue(resource.getName() + " add event is missing!", addedElements.contains(resource));
+      }
+    } finally {
+      TaeCorePlugin.getNlpModel().removeNlpModelChangeListener(listener);
+    }
+  }
+
+  /**
+   * Tests if a project can be removed.
+   * 
+   * @throws CoreException
+   */
+  @Test
+  public void testRemoveProject() throws CoreException {
+    TaeCorePlugin.destroyNlpModelForTesting();
+
+    mProject.createProject();
+    mProject.createDotCorpus();
+    mProject.createProjectContent();
+
+    TaeCorePlugin.getNlpModel();
+
+    mProject.removeProjectContent();
+
+    mProject.removeProject();
+
+    // check if nlp elements are all gone
+    for (IResource resource : mProject.getResources()) {
+      assertTrue(resource.getName() + " must not exist!", TaeCorePlugin.getNlpModel().findMember(
+              resource) == null);
+    }
+
+    // TODO: check if all resources are there
+  }
+
+  /**
+   * Note: the listener must be removed after the test.
+   * 
+   * @throws CoreException
+   */
+  @Test
+  public void testRemoveChangeListener() throws CoreException {
+    mProject.createProject();
+    mProject.createDotCorpus();
+    mProject.createProjectContent();
+
+    final Set<IResource> removedElements = new HashSet<IResource>();
+
+    INlpModelChangeListener listener = new INlpModelChangeListener() {
+      public void refresh(INlpElement element) {
+      }
+
+      public void resourceChanged(INlpElementDelta delta) {
+        if (delta.getKind().equals(Kind.REMOVED) && delta.getNlpElement() != null) {
+          removedElements.add(delta.getResource());
+        }
+
+        for (INlpElementDelta child : delta.getAffectedChildren()) {
+          resourceChanged(child);
+        }
+      }
+
+    };
+
+    TaeCorePlugin.getNlpModel().addNlpModelChangeListener(listener);
+
+    try {
+      mProject.removeProjectContent();
+
+      mProject.removeProject();
+
+      // check for removed events
+      for (IResource resource : mProject.getResources()) {
+        assertTrue(resource.getName() + " remove event is missing!", removedElements
+                .contains(resource));
+      }
+    } finally {
+      TaeCorePlugin.getNlpModel().removeNlpModelChangeListener(listener);
+    }
+  }
+}
\ No newline at end of file

Added: incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/TestProject.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/TestProject.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/TestProject.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/TestProject.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+
+import org.apache.uima.caseditor.core.TaeCorePlugin;
+import org.apache.uima.caseditor.core.model.NlpProject;
+import org.apache.uima.caseditor.core.model.dotcorpus.DotCorpus;
+import org.apache.uima.caseditor.core.model.dotcorpus.DotCorpusSerializer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * 
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.1.2.2 $, $Date: 2007/01/04 14:58:09 $
+ */
+public class TestProject {
+  private IProject mProject;
+
+  private IFile mDotCorpus;
+
+  private IFolder mCorpusFolder;
+
+  private IFolder mSourceFolder;
+
+  private IFolder mConfiguration;
+
+  private IFile mTypesystem;
+
+  private IFile mDocument;
+
+  private IFile mAnnotatorFile;
+
+  private IFile mConsumerFile;
+
+  private IResource mContentResources[];
+
+  public TestProject() {
+    mProject = ResourcesPlugin.getWorkspace().getRoot().getProject("JUnitTestProject");
+
+    mDotCorpus = mProject.getFile(".corpus");
+
+    mCorpusFolder = mProject.getFolder("corpus");
+
+    mSourceFolder = mProject.getFolder("UimaSourceFolder");
+    mConfiguration = mProject.getFolder("UimaSourceFolder/Config");
+
+    mTypesystem = mProject.getFile("Typesystem.xml");
+    mDocument = mCorpusFolder.getFile("Document.xcas");
+    mAnnotatorFile = mConfiguration.getFile("Annotator.ann");
+    mConsumerFile = mConfiguration.getFile("Consumer.con");
+
+    mContentResources = new IResource[] { mCorpusFolder, mSourceFolder, mConfiguration, mDocument,
+        mAnnotatorFile, mConsumerFile };
+  }
+
+  IFile getDotCorpus() {
+    return mDotCorpus;
+  }
+
+  IResource[] getResources() {
+    return mContentResources;
+  }
+
+  IFile getAnnotatorFile() {
+    return mAnnotatorFile;
+  }
+
+  IFolder getConfiguration() {
+    return mConfiguration;
+  }
+
+  IFile getConsumerFile() {
+    return mConsumerFile;
+  }
+
+  IFolder getCorpusFolder() {
+    return mCorpusFolder;
+  }
+
+  IFile getDocument() {
+    return mDocument;
+  }
+
+  IFolder getSourceFolder() {
+    return mSourceFolder;
+  }
+
+  IFile getTypesystem() {
+    return mTypesystem;
+  }
+
+  IProject getProject() {
+    return mProject;
+  }
+
+  /**
+   * Creates an emtpy project with nlp nature.
+   * 
+   * @throws CoreException
+   */
+  void createProject() throws CoreException {
+    mProject.create(null);
+
+    mProject.open(null);
+
+    NlpProject.addNLPNature(mProject);
+  }
+
+  /**
+   * Creates the Nlp Project content.
+   * 
+   * @throws CoreException
+   */
+  void createProjectContent() throws CoreException {
+    // create corpus folder
+    mCorpusFolder.create(true, true, null);
+
+    // create source folder
+    mSourceFolder.create(true, true, null);
+
+    // create config folder
+    mConfiguration.create(true, true, null);
+
+    // create a typesystem file here ...
+    mTypesystem.create(getClass().getResourceAsStream("/net/sf/tae/core/test/Typesystem.xml"),
+            true, null);
+
+    // create annotator.ann
+    mAnnotatorFile.create(getClass().getResourceAsStream("/net/sf/tae/core/test/Annotator.ann"),
+            true, null);
+
+    // careate consumer.con
+    mConsumerFile.create(getClass().getResourceAsStream("/net/sf/tae/core/test/Consumer.con"),
+            true, null);
+
+    // create a document
+    mDocument.create(getClass().getResourceAsStream("/net/sf/tae/core/test/Document.xcas"), true,
+            null);
+  }
+
+  /**
+   * 
+   * @throws CoreException
+   */
+  void createDotCorpus() throws CoreException {
+    DotCorpus dotCorpus = new DotCorpus();
+
+    dotCorpus.addCorpusFolder(mCorpusFolder.getName());
+    dotCorpus.setUimaConfigFolderName(mSourceFolder.getName());
+    dotCorpus.setTypeSystemFilename(mTypesystem.getName());
+
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    DotCorpusSerializer.serialize(dotCorpus, out);
+
+    InputStream in = new ByteArrayInputStream(out.toByteArray());
+
+    mDotCorpus.create(in, true, null);
+  }
+
+  void removeProject() throws CoreException {
+    mProject.delete(true, null);
+  }
+
+  void removeProjectContent() throws CoreException {
+    mDocument.delete(true, null);
+    mCorpusFolder.delete(true, null);
+    mAnnotatorFile.delete(true, null);
+    mConsumerFile.delete(true, null);
+    mConfiguration.delete(true, null);
+    mSourceFolder.delete(true, null);
+  }
+
+  void validateNlpProject() {
+    // TODO: add nlp project validation
+    for (IResource resource : mContentResources) {
+      assertTrue(resource.getName() + " does not exist!", (TaeCorePlugin.getNlpModel().findMember(
+              resource) != null));
+    }
+  }
+}
\ No newline at end of file

Added: incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Typesystem.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Typesystem.xml?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Typesystem.xml (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/Typesystem.xml Wed Feb 14 06:35:40 2007
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<typeSystemDescription xmlns="http://uima.watson.ibm.com/resourceSpecifier">
+	<name>TutorialTypeSystemTutorialTypeSystem</name>
+	<description>Sample project typesystem</description>
+	<version>1.0</version>
+	<vendor>IBM</vendor>
+	<types>
+		<typeDescription>
+			<name>net.sf.tae.Test</name>
+			<description>a test</description>
+			<supertypeName>uima.tcas.Annotation</supertypeName>
+		</typeDescription>
+</types>
+</typeSystemDescription>
\ No newline at end of file

Added: incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/WorkspaceUtil.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/WorkspaceUtil.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/WorkspaceUtil.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/test/WorkspaceUtil.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.test;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * 
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.3.2.2 $, $Date: 2007/01/04 14:58:09 $
+ */
+class WorkspaceUtil {
+  /**
+   * Deletes all projects inside the workspace.
+   * 
+   * Will be run after every test.
+   * 
+   * @throws CoreException
+   *           is thrown if deletion goes wrong
+   */
+  static void clearWorkspace() throws CoreException {
+    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+
+    IProject projects[] = root.getProjects();
+
+    for (IProject project : projects) {
+      project.delete(true, null);
+    }
+  }
+
+  static boolean containsIFolder(IResource resources[], String name) {
+    for (IResource resource : resources) {
+      if (name.equals(resource.getName())) {
+        return true;
+      }
+    }
+
+    return false;
+  }
+}
\ No newline at end of file

Added: incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/util/SpanTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/util/SpanTest.java?view=auto&rev=507542
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/util/SpanTest.java (added)
+++ incubator/uima/sandbox/trunk/CasEditor/src/test/java/org/apache/uima/caseditor/core/util/SpanTest.java Wed Feb 14 06:35:40 2007
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.core.util;
+
+import org.apache.uima.caseditor.core.util.Span;
+
+/**
+ * Unit test for the <code>Span</code> class.
+ * 
+ * @author <a href="mailto:kottmann@gmail.com">Joern Kottmann</a>
+ * @version $Revision: 1.6.2.2 $, $Date: 2007/01/04 14:56:26 $
+ */
+public class SpanTest {
+  /**
+   * Test the Span.equals() method.
+   */
+  @Test
+  public void testEquals() {
+    Span a = new Span(100, 1000);
+    Span b = new Span(100, 1000);
+
+    assertEquals(a.equals(b), true);
+  }
+
+  /**
+   * Test the Span.equals() method.
+   */
+  @Test
+  public void testEqualsWithAnotherObject() {
+    Span a = new Span(0, 0);
+
+    assertFalse(Boolean.TRUE.equals(a));
+  }
+
+  /**
+   * Test the Span.equals() method.
+   */
+  @Test
+  public void testEqualsWithNull() {
+    Span a = new Span(0, 0);
+
+    assertEquals(a.equals(null), false);
+  }
+
+  /**
+   * Test the Span.compareTo(Object) method.
+   */
+  @Test
+  public void testCompareToWithBiggerSpan() {
+    Span a = new Span(100, 1000);
+    Span b = new Span(5000, 900);
+
+    assertEquals(true, a.compareTo(b) > 0);
+  }
+
+  /**
+   * Test the Span.compareTo(Object) method.
+   */
+  @Test
+  public void testCompareToWithBiggerIntersectSpan() {
+    Span a = new Span(100, 1000);
+    Span b = new Span(900, 900);
+
+    assertEquals(true, a.compareTo(b) > 0);
+  }
+
+  /**
+   * Test the Span.compareTo(Object) method.
+   */
+  @Test
+  public void testCompareToWithLowerSpan() {
+    Span a = new Span(5000, 900);
+    Span b = new Span(100, 1000);
+
+    assertEquals(true, a.compareTo(b) < 0);
+  }
+
+  /**
+   * Test the Span.compareTo(Object) method.
+   */
+  @Test
+  public void testCompareToWithLowerIntersectSpan() {
+    Span a = new Span(5000, 900);
+    Span b = new Span(4900, 1000);
+
+    assertEquals(true, a.compareTo(b) < 0);
+  }
+
+  /**
+   * Test the Span.compareTo(Object) method.
+   */
+  @Test
+  public void testCompareToEquals() {
+    Span a = new Span(4900, 1000);
+    Span b = new Span(4900, 1000);
+
+    assertEquals(true, a.compareTo(b) == 0);
+  }
+
+  /**
+   * Test the Span.IsContaining(Span) method.
+   */
+  @Test
+  public void testIsContaining() {
+    Span a = new Span(5000, 900);
+    Span b = new Span(5200, 600);
+
+    assertEquals(true, a.isContaining(b));
+  }
+
+  /**
+   * Test the Span.IsContaining(Span) method.
+   */
+  @Test
+  public void testIsContainingWithEqual() {
+    Span a = new Span(5000, 900);
+
+    assertEquals(true, a.isContaining(a));
+  }
+
+  /**
+   * Test the Span.IsContaining(Span) method.
+   */
+  @Test
+  public void testIsContainingWithLowerIntersect() {
+    Span a = new Span(5000, 900);
+    Span b = new Span(4500, 1000);
+
+    assertEquals(false, a.isContaining(b));
+  }
+
+  /**
+   * Test the Span.IsContaining(Span) method.
+   */
+  @Test
+  public void testIsContainingWithHigherIntersect() {
+    Span a = new Span(5000, 900);
+    Span b = new Span(5000, 1000);
+
+    assertEquals(false, a.isContaining(b));
+  }
+}
\ No newline at end of file