Search in sources :

Example 11 with RecordNotFoundException

use of edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException 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 12 with RecordNotFoundException

use of edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException 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 13 with RecordNotFoundException

use of edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException 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)

Example 14 with RecordNotFoundException

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

the class NoSQLTest method test_24_LookupEntireRecordGuid2Again.

/**
   *
   */
@Test
public void test_24_LookupEntireRecordGuid2Again() {
    JSONObject json = new JSONObject();
    try {
        JSONObject innerJson = new JSONObject();
        innerJson.put("key", "value");
        json.put("map", innerJson);
        json.put("new", "newValue");
    } 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)

Example 15 with RecordNotFoundException

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

the class GNSApp method checkpoint.

/**
   *
   * @param name
   * @return the record
   */
@Override
public String checkpoint(String name) {
    try {
        NameRecord nameRecord = NameRecord.getNameRecord(nameRecordDB, name);
        GNSConfig.getLogger().log(Level.FINE, "{0} getting state for {1} : {2} ", new Object[] { this, name, nameRecord.getValuesMap().getSummary() });
        return nameRecord.getValuesMap().toString();
    } catch (RecordNotFoundException e) {
    // the above RecordNotFoundException is a normal result
    } catch (FieldNotFoundException e) {
        GNSConfig.getLogger().log(Level.SEVERE, "Field not found exception: {0}", e.getMessage());
        e.printStackTrace();
    } catch (FailedDBOperationException e) {
        GNSConfig.getLogger().log(Level.SEVERE, "State not read from DB: {0}", e.getMessage());
        e.printStackTrace();
    }
    return null;
}
Also used : RecordNotFoundException(edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException) NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.server.FieldNotFoundException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)

Aggregations

RecordNotFoundException (edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException)16 JSONObject (org.json.JSONObject)15 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)14 JSONException (org.json.JSONException)12 ValuesMap (edu.umass.cs.gnsserver.utils.ValuesMap)10 Test (org.junit.Test)6 NameRecord (edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord)5 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.server.FieldNotFoundException)4 HashMap (java.util.HashMap)3 BasicDBObject (com.mongodb.BasicDBObject)2 DBCollection (com.mongodb.DBCollection)2 DBObject (com.mongodb.DBObject)2 MongoException (com.mongodb.MongoException)2 RecordExistsException (edu.umass.cs.gnscommon.exceptions.server.RecordExistsException)2 DBCursor (com.mongodb.DBCursor)1 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)1 GNSRecordMap (edu.umass.cs.gnsserver.gnsapp.recordmap.GNSRecordMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1