|
| 1 | +/** |
| 2 | + * See the NOTICE.txt file distributed with this work for |
| 3 | + * information regarding copyright ownership. |
| 4 | + * |
| 5 | + * The authors license this file to you under the |
| 6 | + * Apache License, Version 2.0 (the "License"); you may not use |
| 7 | + * this file except in compliance with the License. You may |
| 8 | + * 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, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package com.mongodb; |
| 20 | + |
| 21 | +import org.testng.annotations.Test; |
| 22 | +import org.testng.annotations.BeforeClass; |
| 23 | + |
| 24 | +/** |
| 25 | + * |
| 26 | + */ |
| 27 | +public class ErrorTest { |
| 28 | + |
| 29 | + Mongo _db; |
| 30 | + |
| 31 | + @BeforeClass |
| 32 | + public void setUp() throws Exception{ |
| 33 | + _db = new Mongo("com_mongodb_ErrorTest"); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testLastError() { |
| 38 | + |
| 39 | + assert(_db.getLastError().get("err") == null); |
| 40 | + |
| 41 | + _db.forceError(); |
| 42 | + |
| 43 | + assert(_db.getLastError().get("err") != null); |
| 44 | + |
| 45 | + _db.resetError(); |
| 46 | + assert(_db.getLastError().get("err") == null); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testPrevError() { |
| 51 | + |
| 52 | + _db.resetError(); |
| 53 | + |
| 54 | + assert(_db.getLastError().get("err") == null); |
| 55 | + assert(_db.getPreviousError().get("err") == null); |
| 56 | + |
| 57 | + _db.forceError(); |
| 58 | + |
| 59 | + assert(_db.getLastError().get("err") != null); |
| 60 | + assert(_db.getPreviousError().get("err") != null); |
| 61 | + |
| 62 | + _db.getCollection("misc").insert(new BasicDBObject("foo", 1)); |
| 63 | + |
| 64 | + assert(_db.getLastError().get("err") == null); |
| 65 | + assert(_db.getPreviousError().get("err") != null); |
| 66 | + |
| 67 | + _db.resetError(); |
| 68 | + |
| 69 | + assert(_db.getLastError().get("err") == null); |
| 70 | + assert(_db.getPreviousError().get("err") == null); |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments