use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class DatabaseTest method test_74_MultiFieldLookup.
/**
*
*/
@Test
public void test_74_MultiFieldLookup() {
try {
String actual = clientCommands.fieldRead(updateEntry, new ArrayList<>(Arrays.asList("name", "occupation")));
JSONAssert.assertEquals("{\"name\":\"frank\",\"occupation\":\"rocket scientist\"}", actual, true);
} catch (ClientException | IOException | JSONException e) {
Utils.failWithStackTrace("Exception while reading \"name\" and \"occupation\": " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class DatabaseTest method test_71_JSONUpdate.
/**
*
*/
@Test
public void test_71_JSONUpdate() {
try {
updateEntry = clientCommands.guidCreate(masterGuid, "westy" + RandomString.randomString(12));
//System.out.println("Created: " + updateEntry);
} catch (IOException | ClientException e) {
Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
}
try {
JSONObject json = new JSONObject();
json.put("name", "frank");
json.put("occupation", "busboy");
json.put("location", "work");
json.put("friends", new ArrayList<>(Arrays.asList("Joe", "Sam", "Billy")));
JSONObject subJson = new JSONObject();
subJson.put("einy", "floop");
subJson.put("meiny", "bloop");
json.put("gibberish", subJson);
clientCommands.update(updateEntry, json);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("Exception while updating JSON: " + e);
}
try {
JSONObject expected = new JSONObject();
expected.put("name", "frank");
expected.put("occupation", "busboy");
expected.put("location", "work");
expected.put("friends", new ArrayList<>(Arrays.asList("Joe", "Sam", "Billy")));
JSONObject subJson = new JSONObject();
subJson.put("einy", "floop");
subJson.put("meiny", "bloop");
expected.put("gibberish", subJson);
JSONObject actual = clientCommands.read(updateEntry);
JSONAssert.assertEquals(expected, actual, true);
//System.out.println(actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("Exception while reading JSON: " + e);
}
try {
JSONObject json = new JSONObject();
json.put("occupation", "rocket scientist");
clientCommands.update(updateEntry, json);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("Exception while changing \"occupation\" to \"rocket scientist\": " + e);
}
try {
JSONObject expected = new JSONObject();
expected.put("name", "frank");
expected.put("occupation", "rocket scientist");
expected.put("location", "work");
expected.put("friends", new ArrayList<>(Arrays.asList("Joe", "Sam", "Billy")));
JSONObject subJson = new JSONObject();
subJson.put("einy", "floop");
subJson.put("meiny", "bloop");
expected.put("gibberish", subJson);
JSONObject actual = clientCommands.read(updateEntry);
JSONAssert.assertEquals(expected, actual, true);
//System.out.println(actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("Exception while reading change of \"occupation\" to \"rocket scientist\": " + e);
}
try {
JSONObject json = new JSONObject();
json.put("ip address", "127.0.0.1");
clientCommands.update(updateEntry, json);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("Exception while adding field \"ip address\" with value \"127.0.0.1\": " + e);
}
try {
JSONObject expected = new JSONObject();
expected.put("name", "frank");
expected.put("occupation", "rocket scientist");
expected.put("location", "work");
expected.put("ip address", "127.0.0.1");
expected.put("friends", new ArrayList<>(Arrays.asList("Joe", "Sam", "Billy")));
JSONObject subJson = new JSONObject();
subJson.put("einy", "floop");
subJson.put("meiny", "bloop");
expected.put("gibberish", subJson);
JSONObject actual = clientCommands.read(updateEntry);
JSONAssert.assertEquals(expected, actual, true);
//System.out.println(actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("Exception while reading JSON: " + e);
}
try {
clientCommands.fieldRemove(updateEntry.getGuid(), "gibberish", updateEntry);
} catch (IOException | ClientException e) {
Utils.failWithStackTrace("Exception during remove field \"gibberish\": " + e);
}
try {
JSONObject expected = new JSONObject();
expected.put("name", "frank");
expected.put("occupation", "rocket scientist");
expected.put("location", "work");
expected.put("ip address", "127.0.0.1");
expected.put("friends", new ArrayList<>(Arrays.asList("Joe", "Sam", "Billy")));
JSONObject actual = clientCommands.read(updateEntry);
JSONAssert.assertEquals(expected, actual, true);
//System.out.println(actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("Exception while reading JSON: " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class DatabaseTest method test_15_DBUpserts.
/**
*
*/
@Test
public void test_15_DBUpserts() {
HashSet<String> expected;
HashSet<String> actual;
try {
clientCommands.fieldAppendOrCreate(westyEntry.getGuid(), "dogs", "bear", westyEntry);
expected = new HashSet<>(Arrays.asList("bear"));
actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(westyEntry.getGuid(), "dogs", westyEntry));
Assert.assertEquals(expected, actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("1) Looking for bear: " + e);
}
try {
clientCommands.fieldAppendOrCreateList(westyEntry.getGuid(), "dogs", new JSONArray(Arrays.asList("wags", "tucker")), westyEntry);
expected = new HashSet<>(Arrays.asList("bear", "wags", "tucker"));
actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(westyEntry.getGuid(), "dogs", westyEntry));
Assert.assertEquals(expected, actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("2) Looking for bear, wags, tucker: " + e);
}
try {
clientCommands.fieldReplaceOrCreate(westyEntry.getGuid(), "goats", "sue", westyEntry);
expected = new HashSet<>(Arrays.asList("sue"));
actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(westyEntry.getGuid(), "goats", westyEntry));
Assert.assertEquals(expected, actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("3) Looking for sue: " + e);
}
try {
clientCommands.fieldReplaceOrCreate(westyEntry.getGuid(), "goats", "william", westyEntry);
expected = new HashSet<>(Arrays.asList("william"));
actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(westyEntry.getGuid(), "goats", westyEntry));
Assert.assertEquals(expected, actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("4) Looking for william: " + e);
}
try {
clientCommands.fieldReplaceOrCreateList(westyEntry.getGuid(), "goats", new JSONArray(Arrays.asList("dink", "tink")), westyEntry);
expected = new HashSet<>(Arrays.asList("dink", "tink"));
actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(westyEntry.getGuid(), "goats", westyEntry));
Assert.assertEquals(expected, actual);
} catch (IOException | ClientException | JSONException e) {
Utils.failWithStackTrace("5) Looking for dink, tink: " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class DottedReadTest method test_60_ReadShallow.
/**
*
*/
@Test
public void test_60_ReadShallow() {
try {
String actual = clientCommands.fieldRead(westyEntry.getGuid(), "flapjack", westyEntry);
String expected = "{ \"sammy\" : \"green\" , \"sally\" : { \"left\" : \"eight\" , \"right\" : \"seven\"}}";
//System.out.println("expected:" + expected);
//System.out.println("actual:" + actual);
JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
} catch (ClientException | IOException | JSONException e) {
Utils.failWithStackTrace("Exception while reading \"flapjack\": " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.
the class AclDefaultsTest method test_142_ACLCreateAnotherGuid.
/**
*
*/
@Test
public void test_142_ACLCreateAnotherGuid() {
try {
String barneyName = "barney" + RandomString.randomString(12);
try {
clientCommands.lookupGuid(barneyName);
Utils.failWithStackTrace(barneyName + " entity should not exist");
} catch (ClientException e) {
// normal result
} catch (IOException e) {
Utils.failWithStackTrace("Exception looking up Barney: ", e);
}
barneyEntry = clientCommands.guidCreate(masterGuid, barneyName);
} catch (ClientException | IOException e) {
Utils.failWithStackTrace("Exception when we were not expecting it in ACLPartTwo: ", e);
}
}
Aggregations