Search in sources :

Example 16 with FailedDBOperationException

use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.

the class NoSQLTest method test_03_LookupEntireRecord.

/**
   *
   */
@Test
public void test_03_LookupEntireRecord() {
    JSONObject json = new JSONObject();
    try {
        json.put(field, "some value");
    } catch (JSONException e) {
        fail("Problem creating json: " + e);
    }
    ValuesMap valuesMap = new ValuesMap(json);
    JSONObject expected = new JSONObject();
    try {
        expected.put(NameRecord.NAME.getName(), guid);
        expected.put(NameRecord.VALUES_MAP.getName(), valuesMap);
    } catch (JSONException e) {
        fail("Problem creating json expected value: " + e);
    }
    try {
        JSONAssert.assertEquals(expected, instance.lookupEntireRecord(collection, guid), JSONCompareMode.STRICT);
    } catch (RecordNotFoundException | FailedDBOperationException | JSONException e) {
        fail("Problem during LookupEntireRecord: " + e);
    }
}
Also used : RecordNotFoundException(edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException) JSONObject(org.json.JSONObject) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Example 17 with FailedDBOperationException

use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.

the class NoSQLTest method test_31_LookupEntireRecordGuid2YetAgain.

/**
   *
   */
@Test
public void test_31_LookupEntireRecordGuid2YetAgain() {
    JSONObject json = new JSONObject();
    ValuesMap valuesMap = new ValuesMap(json);
    JSONObject expected = new JSONObject();
    try {
        expected.put(NameRecord.NAME.getName(), guid2);
        expected.put(NameRecord.VALUES_MAP.getName(), valuesMap);
    } catch (JSONException e) {
        fail("Problem creating json expected value: " + e);
    }
    try {
        JSONAssert.assertEquals(expected, instance.lookupEntireRecord(collection, guid2), JSONCompareMode.STRICT);
    } catch (RecordNotFoundException | FailedDBOperationException | JSONException e) {
        fail("Problem during LookupEntireRecord: " + e);
    }
}
Also used : RecordNotFoundException(edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException) JSONObject(org.json.JSONObject) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Example 18 with FailedDBOperationException

use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.

the class NoSQLTest method test_01_Insert.

/**
   *
   */
@Test
public void test_01_Insert() {
    JSONObject json = new JSONObject();
    try {
        json.put(field, "some value");
    } catch (JSONException e) {
        fail("Problem creating json " + e);
    }
    ValuesMap valuesMap = new ValuesMap(json);
    NameRecord nameRecord = new NameRecord(recordMap, guid, valuesMap);
    try {
        instance.insert(collection, guid, nameRecord.toJSONObject());
    } catch (FailedDBOperationException | JSONException | RecordExistsException e) {
        fail("Problem during insert " + e);
    }
}
Also used : RecordExistsException(edu.umass.cs.gnscommon.exceptions.server.RecordExistsException) NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) JSONObject(org.json.JSONObject) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Example 19 with FailedDBOperationException

use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.

the class NoSQLTest method test_04_LookupSomeFields.

/**
   *
   */
@Test
public void test_04_LookupSomeFields() {
    Map<ColumnField, Object> expected = new HashMap<>();
    expected.put(NameRecord.NAME, guid);
    JSONObject json = new JSONObject();
    try {
        json.put(field, "some value");
    } catch (JSONException e) {
        fail("Problem creating json: " + e);
    }
    expected.put(NameRecord.VALUES_MAP, new ValuesMap(json));
    try {
        Map<ColumnField, Object> actual = instance.lookupSomeFields(collection, guid, NameRecord.NAME, NameRecord.VALUES_MAP, new ArrayList<>(Arrays.asList(new ColumnField(field, ColumnFieldType.USER_JSON))));
        assertEquals(expected.get(NameRecord.NAME), actual.get(NameRecord.NAME));
        JSONAssert.assertEquals(((JSONObject) expected.get(NameRecord.VALUES_MAP)), ((JSONObject) actual.get(NameRecord.VALUES_MAP)), JSONCompareMode.STRICT);
    } catch (RecordNotFoundException | FailedDBOperationException | JSONException e) {
        fail("Problem during LookupSomeFields: " + e);
    }
}
Also used : RecordNotFoundException(edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Example 20 with FailedDBOperationException

use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.

the class NoSQLTest method test_22_LookupEntireRecordGuid2.

/**
   *
   */
@Test
public void test_22_LookupEntireRecordGuid2() {
    JSONObject json = new JSONObject();
    try {
        JSONObject innerJson = new JSONObject();
        innerJson.put("key", "value");
        json.put("map", innerJson);
    } catch (JSONException e) {
        fail("Problem creating json " + e);
    }
    ValuesMap valuesMap = new ValuesMap(json);
    JSONObject expected = new JSONObject();
    try {
        expected.put(NameRecord.NAME.getName(), guid2);
        expected.put(NameRecord.VALUES_MAP.getName(), valuesMap);
    } catch (JSONException e) {
        fail("Problem creating json expected value: " + e);
    }
    try {
        JSONAssert.assertEquals(expected, instance.lookupEntireRecord(collection, guid2), JSONCompareMode.STRICT);
    } catch (RecordNotFoundException | FailedDBOperationException | JSONException e) {
        fail("Problem during LookupEntireRecord: " + e);
    }
}
Also used : RecordNotFoundException(edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException) JSONObject(org.json.JSONObject) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Aggregations

FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)49 JSONException (org.json.JSONException)36 JSONObject (org.json.JSONObject)36 ValuesMap (edu.umass.cs.gnsserver.utils.ValuesMap)22 RecordNotFoundException (edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException)18 BasicDBObject (com.mongodb.BasicDBObject)13 MongoException (com.mongodb.MongoException)13 DBCollection (com.mongodb.DBCollection)12 DBObject (com.mongodb.DBObject)12 IOException (java.io.IOException)11 JSONArray (org.json.JSONArray)9 Test (org.junit.Test)9 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)7 RecordExistsException (edu.umass.cs.gnscommon.exceptions.server.RecordExistsException)7 NameRecord (edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord)7 DBCursor (com.mongodb.DBCursor)6 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)6 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)6 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.server.FieldNotFoundException)5 RandomString (edu.umass.cs.gnscommon.utils.RandomString)4