jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r724767 - in /jackrabbit/sandbox/jackrabbit-jdbc2jcr: ./ src/main/java/org/apache/jackrabbit/jdbc/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/jackrabbit/ src/test/java/org/apache/jackrabbi...
Date Tue, 09 Dec 2008 16:09:23 GMT
Author: jukka
Date: Tue Dec  9 08:09:22 2008
New Revision: 724767

URL: http://svn.apache.org/viewvc?rev=724767&view=rev
Log:
jdbc2jcr: Rudimentary TestNG test for the TpsReport class.

Added:
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
  (with props)
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/TpsReportTest.java
  (with props)
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/testng.xml   (with props)
Modified:
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/pom.xml
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/TpsReport.java

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/pom.xml?rev=724767&r1=724766&r2=724767&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/pom.xml (original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/pom.xml Tue Dec  9 08:09:22 2008
@@ -46,11 +46,24 @@
       <version>1.1.104</version>
     </dependency>
     <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <classifier>jdk15</classifier>
+      <version>5.8</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.jackrabbit</groupId>
       <artifactId>jackrabbit-core</artifactId>
       <version>1.5.0</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.5.3</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -58,8 +71,8 @@
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
-          <source>1.4</source>
-          <target>1.4</target>
+          <source>1.5</source>
+          <target>1.5</target>
         </configuration>
       </plugin>
     </plugins>

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/TpsReport.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/TpsReport.java?rev=724767&r1=724766&r2=724767&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/TpsReport.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/TpsReport.java
Tue Dec  9 08:09:22 2008
@@ -16,11 +16,20 @@
  */
 package org.apache.jackrabbit.jdbc;
 
-import org.apache.jackrabbit.core.TransientRepository;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Statement;
 
-import java.sql.*;
-import javax.jcr.*;
-import javax.jcr.query.*;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
 
 /**
  * This example application shows how to query a JCR repository using the JDBC
@@ -47,28 +56,10 @@
      * which in turn returns the result of the JCR query.
      */
     void run() throws Exception {
-        initJcrRepository();
         initDatabase();
         runQuery();
     }
-    
-    /**
-     * Initialize the JCR repository. This will create a repository with one
-     * node 'test' that has a property 'text'.
-     */
-    void initJcrRepository() throws Exception {
-        Repository rep = new TransientRepository();
-        Session session = rep.login(new SimpleCredentials("admin", "admin".toCharArray()));
-        Node root = session.getRootNode();
-        if (root.hasNode("test")) {
-            root.getNode("test").remove();
-        }
-        Node n = root.addNode("test");
-        n.setProperty("text", "Hello");
-        session.save();
-        session.logout();
-    }
-    
+
     /**
      * Initialize the database. This will create a database called 'jcr' that
      * contains a Java function 'TPS_REPORT'. This only needs to be done once,
@@ -133,7 +124,7 @@
             // first, the method is called to get the column list of the result
             // (to parse and prepare the query and resolve column names),
             // but here the method is called to get the actual data
-            Repository rep = new TransientRepository();
+            Repository rep = Fixture.getRepository();
             Session session = rep.login(new SimpleCredentials(jcrUser, jcrPassword
                     .toCharArray()));
             generateReportData(session, conn);

Added: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java?rev=724767&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
(added)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
Tue Dec  9 08:09:22 2008
@@ -0,0 +1,102 @@
+/*
+ * 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.jackrabbit.jdbc;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+
+public class Fixture {
+
+    private static File directory;
+
+    private static RepositoryImpl repository;
+
+    private static Connection h2Connection;
+
+    private static Connection derbyConnection;
+
+    public static Repository getRepository() {
+        return repository;
+    }
+
+    public static Connection getH2Connection() {
+        return h2Connection;
+    }
+
+    public static Connection getDerbyConnection() {
+        return derbyConnection;
+    }
+
+    @BeforeSuite
+    public void setUpRepository() throws Exception {
+        directory = File.createTempFile("jackrabbit", "jdbc");
+        directory.delete();
+        directory.mkdir();
+
+        repository = RepositoryImpl.create(RepositoryConfig.create(
+                RepositoryImpl.class.getResourceAsStream("repository.xml"),
+                new File(directory, "repository").getPath()));
+
+        Session session = repository.login(
+                new SimpleCredentials("admin", "admin".toCharArray()));
+        try {
+            Node root = session.getRootNode();
+            Node test = root.addNode("test");
+            test.setProperty("text", "Hello");
+            session.save();
+        } finally {
+            session.logout();
+        }
+
+        Class.forName("org.h2.Driver");
+        h2Connection = DriverManager.getConnection(
+                "jdbc:h2:" + new File(directory, "h2").getPath(), "sa", "sa");
+
+        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+        derbyConnection = DriverManager.getConnection(
+                "jdbc:derby:" + new File(directory, "derby").getPath()
+                + ";create=true");
+        
+    }
+
+    @AfterSuite
+    public void tearDownRepository() throws Exception {
+        derbyConnection.close();
+        DriverManager.getConnection(
+                "jdbc:derby:" + new File(directory, "derby").getPath()
+                + ";shutdown=true");
+
+        h2Connection.close();
+
+        repository.shutdown();
+
+        FileUtils.deleteDirectory(directory);
+    }
+
+}

Propchange: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/Fixture.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/TpsReportTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/TpsReportTest.java?rev=724767&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/TpsReportTest.java
(added)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/TpsReportTest.java
Tue Dec  9 08:09:22 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.jackrabbit.jdbc;
+
+import org.testng.annotations.Test;
+
+public class TpsReportTest {
+
+    @Test
+    public void testTpsReport() throws Exception {
+        TpsReport.main(new String[0]);
+    }
+
+}

Propchange: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/test/java/org/apache/jackrabbit/jdbc/TpsReportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/jackrabbit-jdbc2jcr/testng.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/testng.xml?rev=724767&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/testng.xml (added)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/testng.xml Tue Dec  9 08:09:22 2008
@@ -0,0 +1,8 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="jackrabbit-jdbc2jcr-tests">
+  <test name="JDBC to JCR tests">
+    <packages>
+      <package name="org.apache.jackrabbit.jdbc"/>
+    </packages>
+  </test>
+</suite>

Propchange: jackrabbit/sandbox/jackrabbit-jdbc2jcr/testng.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message