You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by th...@apache.org on 2008/03/14 11:01:50 UTC

svn commit: r637034 - in /labs/droids/trunk: ./ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/droids/ src/test/java/org/apache/droids/handle/ src/test/java/test-files/ targets/

Author: thorsten
Date: Fri Mar 14 03:01:44 2008
New Revision: 637034

URL: http://svn.apache.org/viewvc?rev=637034&view=rev
Log:
Adding junit testing 

Added:
    labs/droids/trunk/src/test/java/org/
    labs/droids/trunk/src/test/java/org/apache/
    labs/droids/trunk/src/test/java/org/apache/droids/
    labs/droids/trunk/src/test/java/org/apache/droids/handle/
    labs/droids/trunk/src/test/java/org/apache/droids/handle/SolrHandleTest.java   (with props)
    labs/droids/trunk/src/test/java/test-files/
    labs/droids/trunk/src/test/java/test-files/log.txt   (with props)
    labs/droids/trunk/targets/
    labs/droids/trunk/targets/common-testing.xml   (with props)
    labs/droids/trunk/testing.properties   (with props)
Modified:
    labs/droids/trunk/build.xml
    labs/droids/trunk/default.properties

Modified: labs/droids/trunk/build.xml
URL: http://svn.apache.org/viewvc/labs/droids/trunk/build.xml?rev=637034&r1=637033&r2=637034&view=diff
==============================================================================
--- labs/droids/trunk/build.xml (original)
+++ labs/droids/trunk/build.xml Fri Mar 14 03:01:44 2008
@@ -25,6 +25,9 @@
   <!-- Ivy dependency manager -->
   <import file="${ivy.repository.dir}/ivy-build.xml"/>
   
+  <!-- Junit testing -->
+  <import file="targets/common-testing.xml"/>
+  
   <!-- the normal classpath -->
   <path id="droids.classpath">
     <pathelement location="${build.classes}"/>

Modified: labs/droids/trunk/default.properties
URL: http://svn.apache.org/viewvc/labs/droids/trunk/default.properties?rev=637034&r1=637033&r2=637034&view=diff
==============================================================================
--- labs/droids/trunk/default.properties (original)
+++ labs/droids/trunk/default.properties Fri Mar 14 03:01:44 2008
@@ -74,6 +74,7 @@
 test.build.data =  ${test.build.dir}/data
 test.build.classes = ${test.build.dir}/classes
 test.build.javadoc = ${test.build.dir}/docs/api
+testing.filter=testing.properties
 
 javacc.home=/usr/java/javacc
 

Added: labs/droids/trunk/src/test/java/org/apache/droids/handle/SolrHandleTest.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/test/java/org/apache/droids/handle/SolrHandleTest.java?rev=637034&view=auto
==============================================================================
--- labs/droids/trunk/src/test/java/org/apache/droids/handle/SolrHandleTest.java (added)
+++ labs/droids/trunk/src/test/java/org/apache/droids/handle/SolrHandleTest.java Fri Mar 14 03:01:44 2008
@@ -0,0 +1,67 @@
+package org.apache.droids.handle;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.droids.api.Parse;
+import org.apache.droids.handle.Solr;
+import org.apache.droids.helper.StAX;
+import org.apache.http.HttpException;
+import org.apache.http.PostFile;
+
+import junit.framework.TestCase;
+
+public class SolrHandleTest extends TestCase {
+  private XMLStreamWriter writer;
+  
+  private String updateUrl = "http://localhost:8983/solr/update";
+
+  public void test() throws XMLStreamException, IOException, HttpException,
+      InterruptedException, URISyntaxException {
+    URL url = new URL("http://svn.apache.org");
+    Solr solr = new Solr();
+    solr.setUpdateUrl(updateUrl);
+    ByteArrayOutputStream out = createUpdateDocument(url, null);
+    BufferedInputStream stream = new BufferedInputStream(
+        new ByteArrayInputStream(out.toByteArray()));
+    PostFile post = new PostFile(updateUrl, stream);
+    out = solr.createCommitDocument();
+    stream = new BufferedInputStream(
+        new ByteArrayInputStream(out.toByteArray()));
+    post = new PostFile(updateUrl, stream);
+
+  }
+
+  private ByteArrayOutputStream createUpdateDocument(URL url, Parse parse)
+      throws XMLStreamException {
+    StAX stax = new StAX();
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    writer = stax.getStreamWriter(new DataOutputStream(out));
+    writer.writeStartDocument("UTF-8", "1.0");
+    writer.writeStartElement("add");
+    writer.writeStartElement("doc");
+    writer.writeStartElement("field");
+    writer.writeAttribute("name", "id");
+    writer.writeCharacters(url.getPath());
+    writer.writeEndElement();
+    writer.writeStartElement("field");
+    writer.writeAttribute("name", "content");
+    writer.writeCharacters("Apache Droids - kick-ass robots by Apache");
+    writer.writeEndElement();
+    writer.writeEndElement();
+    writer.writeEndElement();
+    writer.writeEndDocument();
+    writer.flush();
+    writer.close();
+    return out;
+  }
+
+}
\ No newline at end of file

Propchange: labs/droids/trunk/src/test/java/org/apache/droids/handle/SolrHandleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: labs/droids/trunk/src/test/java/test-files/log.txt
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/test/java/test-files/log.txt?rev=637034&view=auto
==============================================================================
    (empty)

Propchange: labs/droids/trunk/src/test/java/test-files/log.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: labs/droids/trunk/targets/common-testing.xml
URL: http://svn.apache.org/viewvc/labs/droids/trunk/targets/common-testing.xml?rev=637034&view=auto
==============================================================================
--- labs/droids/trunk/targets/common-testing.xml (added)
+++ labs/droids/trunk/targets/common-testing.xml Fri Mar 14 03:01:44 2008
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+  <!-- Macro for compilation -->
+  <macrodef name="common-javac">
+    <attribute name="destdir" />
+    <attribute name="classpathref" />
+    <element name="nested" optional="true" implicit="true" />
+    <sequential>
+      <mkdir dir="@{destdir}" />
+      <javac destdir="@{destdir}"
+             target="${javac.version}"
+             source="${javac.version}"
+             debug="on"
+             encoding="utf8"
+             sourcepath=""
+             classpathref="@{classpathref}">
+         <nested />
+      </javac>
+    </sequential>
+  </macrodef>
+  <property name="junit.output.dir" location="${test.build.dir}"/>
+  <property name="junit.reports" location="${junit.output.dir}/reports"/>
+  <property name="junit.includes" value="**/Test*.java,**/*Test.java"/>
+  <available property="junitPresent"
+             classname="junit.framework.TestCase" />
+  <!-- The testing runtime classpath -->
+  <path id="testing.run.classpath">
+    <path refid="droids.classpath"/>
+  </path>
+  <target name="testing.junit" depends="testing.compileTests"
+    description="--> testing junit cases. To test a single class use the 'testcase' variable.">
+    <mkdir dir="${junit.output.dir}"/>
+    <junit printsummary="on" haltonfailure="no" errorProperty="tests.failed"
+      failureProperty="tests.failed" dir="${test.src.dir.core}/test-files/"
+      fork="yes" maxmemory="100m">
+      <formatter type="brief" usefile="false" if="junit.details"/>
+      <syspropertyset>
+        <propertyref prefix="${project.name}"/>
+      </syspropertyset>
+      <classpath refid="testing.run.classpath"/>
+      <formatter type="xml"/>
+      <batchtest fork="yes" todir="${junit.output.dir}" unless="testcase">
+        <fileset dir="${test.src.dir.core}" includes="${junit.includes}"/>
+      </batchtest>
+      <batchtest fork="yes" todir="${junit.output.dir}" if="testcase">
+        <fileset dir="${test.src.dir.core}" includes="**/${testcase}.java"/>
+      </batchtest>
+    </junit>
+    <property name="tests.failed" value="none"/>
+    <!--<fail if="tests.failed">Tests failed!</fail>-->
+    <echo>Tests failed: ${tests.failed}</echo>
+  </target>
+  <target name="testing.test-reports"
+          description="--> Generates HTML test reports." >
+    <mkdir dir="${junit.reports}"/>
+    <junitreport todir="${junit.output.dir}">
+      <fileset dir="${junit.output.dir}">
+        <include name="TEST-*.xml"/>
+      </fileset>
+      <report format="frames" todir="${junit.reports}"/>
+    </junitreport>
+  </target>
+    <!-- Compile unit tests. -->
+  <target name="testing.compileTests"
+          description="--> Compile unit tests."
+          depends="droids.compile">
+
+    <mkdir dir="${test.build.dir}" />
+    <common-javac 
+       destdir="${build.classes}"
+       classpathref="testing.run.classpath">
+      <src path="${test.src.dir.core}" />
+    </common-javac>
+    <antcall target="testing.classes-resources"/>
+  </target>
+  <!-- Copy resources that belong in the classes dir -->
+  <target name="testing.classes-resources">
+    <filter filtersfile="${testing.filter}"/>
+    <copy todir="${build.classes}/test-files" preservelastmodified="true" filtering="true">
+      <fileset dir="${test.src.dir.core}/test-files"/>
+    </copy>
+  </target>
+</project>

Propchange: labs/droids/trunk/targets/common-testing.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: labs/droids/trunk/testing.properties
URL: http://svn.apache.org/viewvc/labs/droids/trunk/testing.properties?rev=637034&view=auto
==============================================================================
    (empty)

Propchange: labs/droids/trunk/testing.properties
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org