Permalink
Browse files

fixed runit example

fixed documentation problems
  • Loading branch information...
1 parent b2f9b73 commit 0790f3106d7e24adc1608850c6231f8e072d1e7b @tc committed Oct 12, 2010
View
@@ -1,13 +1,13 @@
Package: RMongo
Type: Package
Title: MongoDB Client for R
-Version: 0.0.8
-Date: 2010-10-05
+Version: 0.0.9
+Date: 2010-10-12
Author: Tommy Chheng
Maintainer: Tommy Chheng <tommy.chheng@gmail.com>
Description: MongoDB Database interface for R. The interface is provided via Java calls to the mongo-java-driver.
License: GPL-3
LazyLoad: yes
-Depends: R(>= 2.8.0), rJava, rjson, plyr
+Depends: R(>= 2.11.0), rJava, rjson, plyr, methods
SystemRequirements: Java (>= 1.6), MongoDB (>= 1.6)
URL: http://github.com/quid/RMongo
View
@@ -1,6 +1,10 @@
+library('rJava')
library('plyr')
library('rjson')
+#.jinit()
+#.jaddClassPath("inst/java/r-mongo-scala-1.0-SNAPSHOT.jar"")
+
setClass("RMongo", representation(javaMongo = "jobjRef"))
mongoDbConnect <- function(dbName, host="localhost", port=27017){
View
@@ -1,49 +0,0 @@
-library('RUnit')
-library('rJava')
-
-test.dbInsertDocument <- function(){
- mongo <- mongoDbConnect("test")
- output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
- dbDisconnect(mongo)
-
- checkEquals("ok", output)
-}
-
-test.dbGetQuery <- function(){
- mongo <- mongoDbConnect("test")
- output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
- output <- dbGetQuery(mongo, "test_data", '{"foo": "bar"}', format='json')
- dbDisconnect(mongo)
-
- checkEquals("bar", output[[1]]$foo)
-}
-
-test.dbGetQueryDataFrameFormat <- function(){
- mongo <- mongoDbConnect('test')
- output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
- output <- dbGetQuery(mongo, 'test_data', '{"foo":"bar"}', format='data.frame')
- dbDisconnect(mongo)
-
- checkEquals("bar", as.character(output[1,]$foo))
-}
-
-test.dbGetQueryWithEmptyCollection <- function(){
- mongo <- mongoDbConnect('test')
- output <- dbGetQuery(mongo, 'test_data', '{"EMPTY": "EMPTY"}', format='json')
- dbDisconnect(mongo)
- checkEquals(list(), output)
-}
-
-test.dbGetQuerySorting <- function(){
- #insert the records using r-mongo-scala project
- mongo <- mongoDbConnect("test")
- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
- dbInsertDocument(mongo, "test_data", '{"foo": "newbar"}')
-
- output <- dbGetQuery(mongo, "test_data", '{ "$query": {}, "$orderby": { "foo": -1 } }}', format='json')
- dbDisconnect(mongo)
-
- checkEquals("newbar", output[[1]]$foo)
-}
-
-
@@ -1,5 +1,8 @@
-\name{dbDisconnect}
+\name{dbDisconnect-methods}
+\docType{methods}
\alias{dbDisconnect}
+\alias{dbDisconnect-methods}
+\alias{dbDisconnect,RMongo-method}
\title{Disconnect from the MongoDB database}
@@ -1,5 +1,8 @@
-\name{dbGetQuery}
+\name{dbGetQuery-methods}
+\docType{methods}
\alias{dbGetQuery}
+\alias{dbGetQuery-methods}
+\alias{dbGetQuery,RMongo,character,character,character-method}
\title{Performing a MongoDB query}
@@ -1,5 +1,8 @@
-\name{dbInsertDocument}
+\name{dbInsertDocument-methods}
+\docType{methods}
\alias{dbInsertDocument}
+\alias{dbInsertDocument-methods}
+\alias{dbInsertDocument,RMongo,character,character-method}
\title{Insert a document into a MongoDB collection}
@@ -18,7 +21,7 @@ Insert a json character object into the mongodb collection.
}
\seealso{
- \code{\link{dbGetQuery}}
+ \code{\link{dbGetQuery-methods}}
}
\examples{
mongo <- mongoDbConnect("test")
View
@@ -17,9 +17,6 @@ mongoDbConnect(dbName, host="localhost", port=27017)
\item{port}{ Port number. Default to mongodb's default port 27017. {optional}}
}
-\seealso{
- \code{\link{dbDisconnect}}
-}
\examples{
mongo <- mongoDbConnect("test")
}
@@ -69,9 +69,6 @@ class MongoTest{
val rMongo = new RMongo("test")
val results = rMongo.dbGetQuery("empty_collection", """ {} """)
-// val jsonParsed = scala.util.parsing.json.JSON.parseFull(results)
-// val records = jsonParsed.getOrElse(List()).asInstanceOf[List[Any]]
-
Assert.assertEquals("[]", results)
}
@Test
View
@@ -1,7 +1,57 @@
library("RUnit")
library("RMongo")
+library('rJava')
+library('rjson')
+library('plyr')
-testsuite.rmongo <- defineTestSuite("rmongo", dirs=file.path("."))
+test.dbInsertDocument <- function(){
+ mongo <- mongoDbConnect("test")
+ output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
+ dbDisconnect(mongo)
-testResult <- runTestSuite(testsuite.rmongo)
-printTextProtocol(testResult)
+ checkEquals("ok", output)
+}
+
+test.dbGetQuery <- function(){
+ mongo <- mongoDbConnect("test")
+ output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
+ output <- dbGetQuery(mongo, "test_data", '{"foo": "bar"}', format='json')
+ dbDisconnect(mongo)
+
+ checkEquals("bar", output[[1]]$foo)
+}
+
+test.dbGetQueryDataFrameFormat <- function(){
+ mongo <- mongoDbConnect('test')
+ output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
+ output <- dbGetQuery(mongo, 'test_data', '{"foo":"bar"}', format='data.frame')
+ dbDisconnect(mongo)
+
+ checkEquals("bar", as.character(output[1,]$foo))
+}
+
+test.dbGetQueryWithEmptyCollection <- function(){
+ mongo <- mongoDbConnect('test')
+ output <- dbGetQuery(mongo, 'test_data', '{"EMPTY": "EMPTY"}', format='json')
+ dbDisconnect(mongo)
+ checkEquals(list(), output)
+}
+
+test.dbGetQuerySorting <- function(){
+ #insert the records using r-mongo-scala project
+ mongo <- mongoDbConnect("test")
+ dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
+ dbInsertDocument(mongo, "test_data", '{"foo": "newbar"}')
+
+ output <- dbGetQuery(mongo, "test_data", '{ "$query": {}, "$orderby": { "foo": -1 } }}', format='json')
+ dbDisconnect(mongo)
+
+ checkEquals("newbar", output[[1]]$foo)
+}
+
+
+test.dbInsertDocument()
+test.dbGetQuery()
+test.dbGetQueryDataFrameFormat()
+test.dbGetQueryWithEmptyCollection()
+test.dbGetQuerySorting()
View
@@ -1,4 +1,3 @@
-
R version 2.11.1 (2010-05-31)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
@@ -7,8 +6,6 @@ R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
- Natural language support but running in an English locale
-
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
@@ -18,49 +15,69 @@ Type 'demo()' for some demos, 'help()' for on-line help, or
Type 'q()' to quit R.
> library("RUnit")
-> testsuite.rmongo <- defineTestSuite("rmongo", dirs=file.path("."))
+> library("RMongo")
+Loading required package: rJava
+Loading required package: rjson
+Loading required package: plyr
+> library('rJava')
+> library('rjson')
+> library('plyr')
>
-> testResult <- runTestSuite(testsuite.rmongo)
-
-
-Executing test function test.dbGetQuery ... done successfully.
-
-
-
-Executing test function test.dbGetQueryDataFrameFormat ... done successfully.
-
-
-
-Executing test function test.dbGetQuerySorting ... done successfully.
-
-
-
-Executing test function test.dbInsertDocument ... done successfully.
-
-> printTextProtocol(testResult)
-RUNIT TEST PROTOCOL -- Tue Oct 5 14:03:06 2010
-***********************************************
-Number of test functions: 4
-Number of errors: 0
-Number of failures: 0
-
-
-1 Test Suite :
-rmongo - 4 test functions, 0 errors, 0 failures
-
-
-
-Details
-***************************
-Test Suite: rmongo
-Test function regexp: ^test.+
-Test file regexp: ^runit.+\.[rR]$
-Involved directory:
-.
----------------------------
-Test file: ./runit.rmongo.R
-test.dbGetQuery: (1 checks) ... OK (0.14 seconds)
-test.dbGetQueryDataFrameFormat: (1 checks) ... OK (0.02 seconds)
-test.dbGetQuerySorting: (1 checks) ... OK (0.02 seconds)
-test.dbInsertDocument: (1 checks) ... OK (0.01 seconds)
+> test.dbInsertDocument <- function(){
++ mongo <- mongoDbConnect("test")
++ output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
++ dbDisconnect(mongo)
++
++ checkEquals("ok", output)
++ }
+>
+> test.dbGetQuery <- function(){
++ mongo <- mongoDbConnect("test")
++ output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
++ output <- dbGetQuery(mongo, "test_data", '{"foo": "bar"}', format='json')
++ dbDisconnect(mongo)
++
++ checkEquals("bar", output[[1]]$foo)
++ }
>
+> test.dbGetQueryDataFrameFormat <- function(){
++ mongo <- mongoDbConnect('test')
++ output <- dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
++ output <- dbGetQuery(mongo, 'test_data', '{"foo":"bar"}', format='data.frame')
++ dbDisconnect(mongo)
++
++ checkEquals("bar", as.character(output[1,]$foo))
++ }
+>
+> test.dbGetQueryWithEmptyCollection <- function(){
++ mongo <- mongoDbConnect('test')
++ output <- dbGetQuery(mongo, 'test_data', '{"EMPTY": "EMPTY"}', format='json')
++ dbDisconnect(mongo)
++ checkEquals(list(), output)
++ }
+>
+> test.dbGetQuerySorting <- function(){
++ #insert the records using r-mongo-scala project
++ mongo <- mongoDbConnect("test")
++ dbInsertDocument(mongo, "test_data", '{"foo": "bar"}')
++ dbInsertDocument(mongo, "test_data", '{"foo": "newbar"}')
++
++ output <- dbGetQuery(mongo, "test_data", '{ "$query": {}, "$orderby": { "foo": -1 } }}', format='json')
++ dbDisconnect(mongo)
++
++ checkEquals("newbar", output[[1]]$foo)
++ }
+>
+>
+> test.dbInsertDocument()
+[1] TRUE
+> test.dbGetQuery()
+[1] TRUE
+> test.dbGetQueryDataFrameFormat()
+[1] TRUE
+> test.dbGetQueryWithEmptyCollection()
+[1] TRUE
+> test.dbGetQuerySorting()
+[1] TRUE
+>
+

0 comments on commit 0790f31

Please sign in to comment.