|
| 1 | +// BasicDBObjectTest.java |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright (C) 2008 10gen Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package com.mongodb; |
| 20 | + |
| 21 | +import java.util.*; |
| 22 | +import java.util.regex.*; |
| 23 | +import java.io.IOException; |
| 24 | + |
| 25 | +import org.testng.annotations.Test; |
| 26 | + |
| 27 | +import com.mongodb.util.*; |
| 28 | + |
| 29 | +public class BasicDBObjectTest extends TestCase { |
| 30 | + |
| 31 | + @Test(groups = {"basic"}) |
| 32 | + public void testBasic(){ |
| 33 | + BasicDBObject a = new BasicDBObject( "x" , 1 ); |
| 34 | + BasicDBObject b = new BasicDBObject( "x" , 1 ); |
| 35 | + assert( a.equals( b ) ); |
| 36 | + |
| 37 | + DBObject x = JSON.parse( "{ 'x' : 1 }" ); |
| 38 | + assert( a.equals( x ) ); |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + @Test(groups = {"basic"}) |
| 43 | + public void testBasic2(){ |
| 44 | + BasicDBObject a = new BasicDBObject( "x" , 1 ); |
| 45 | + DBObject b = BasicDBObjectBuilder.start().append( "x" , 1 ).get(); |
| 46 | + assert( a.equals( b ) ); |
| 47 | + assert( a.equals( JSON.parse( "{ 'x' : 1 }" ) ) ); |
| 48 | + assert( ! a.equals( JSON.parse( "{ 'x' : 2 }" ) ) ); |
| 49 | + } |
| 50 | + |
| 51 | + @Test(groups = {"basic"}) |
| 52 | + public void testDown1(){ |
| 53 | + BasicDBObjectBuilder b = BasicDBObjectBuilder.start(); |
| 54 | + b.append( "x" , 1 ); |
| 55 | + b.push("y"); |
| 56 | + b.append( "a" , 2 ); |
| 57 | + b.pop(); |
| 58 | + b.push( "z" ); |
| 59 | + b.append( "b" , 3 ); |
| 60 | + |
| 61 | + |
| 62 | + DBObject x = b.get(); |
| 63 | + DBObject y = JSON.parse( "{ 'x' : 1 , 'y' : { 'a' : 2 } , 'z' : { 'b' : 3 } }" ); |
| 64 | + |
| 65 | + assert( x.equals( y ) ); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + public static void main( String args[] ) |
| 70 | + throws Exception { |
| 71 | + (new BasicDBObjectTest()).runConsole(); |
| 72 | + |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments