Search in sources :

Example 86 with ClientException

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);
    }
}
Also used : JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 87 with ClientException

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);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 88 with ClientException

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);
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 89 with ClientException

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);
    }
}
Also used : JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 90 with ClientException

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);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Aggregations

ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)239 IOException (java.io.IOException)215 Test (org.junit.Test)134 JSONException (org.json.JSONException)126 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)125 RandomString (edu.umass.cs.gnscommon.utils.RandomString)113 JSONArray (org.json.JSONArray)74 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)71 JSONObject (org.json.JSONObject)59 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)40 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)37 StringTokenizer (java.util.StringTokenizer)30 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)23 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)20 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)19 FileNotFoundException (java.io.FileNotFoundException)18 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)15 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)13 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)13 InvalidKeyException (java.security.InvalidKeyException)12