Search in sources :

Example 31 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class ReadTest method test_02_CreateField.

/**
   *
   */
@Test
public void test_02_CreateField() {
    try {
        westyEntry = clientCommands.guidCreate(masterGuid, "westy" + RandomString.randomString(12));
        samEntry = clientCommands.guidCreate(masterGuid, "sam" + RandomString.randomString(12));
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
    }
    try {
        // remove default read acces for this test
        clientCommands.aclRemove(AclAccessType.READ_WHITELIST, westyEntry, GNSProtocol.ENTIRE_RECORD.toString(), GNSProtocol.ALL_GUIDS.toString());
        clientCommands.fieldCreateOneElementList(westyEntry.getGuid(), "environment", "work", westyEntry);
        clientCommands.fieldCreateOneElementList(westyEntry.getGuid(), "ssn", "000-00-0000", westyEntry);
        clientCommands.fieldCreateOneElementList(westyEntry.getGuid(), "password", "666flapJack", westyEntry);
        clientCommands.fieldCreateOneElementList(westyEntry.getGuid(), "address", "100 Hinkledinkle Drive", westyEntry);
        // read my own field
        Assert.assertEquals("work", clientCommands.fieldReadArrayFirstElement(westyEntry.getGuid(), "environment", westyEntry));
        // read another field
        Assert.assertEquals("000-00-0000", clientCommands.fieldReadArrayFirstElement(westyEntry.getGuid(), "ssn", westyEntry));
        // read another field
        Assert.assertEquals("666flapJack", clientCommands.fieldReadArrayFirstElement(westyEntry.getGuid(), "password", westyEntry));
        try {
            String result = clientCommands.fieldReadArrayFirstElement(westyEntry.getGuid(), "environment", samEntry);
            Utils.failWithStackTrace("Result of read of westy's environment by sam is " + result + " which is wrong because it should have been rejected.");
        } catch (ClientException e) {
        } catch (IOException e) {
            Utils.failWithStackTrace("Exception during read of westy's environment by sam: " + e);
        }
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
    }
}
Also used : ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 32 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class SelectGeoTest method test_30_GeoSpatialSelectSelectWithin.

/**
   *
   */
@Test
public void test_30_GeoSpatialSelectSelectWithin() {
    try {
        JSONArray rect = new JSONArray();
        JSONArray upperLeft = new JSONArray();
        upperLeft.put(1.0);
        upperLeft.put(1.0);
        JSONArray lowerRight = new JSONArray();
        lowerRight.put(-1.0);
        lowerRight.put(-1.0);
        rect.put(upperLeft);
        rect.put(lowerRight);
        JSONArray result = clientCommands.selectWithin(GNSProtocol.LOCATION_FIELD_NAME.toString(), rect);
        // best we can do should be at least 5, but possibly more objects in results
        Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
    } catch (JSONException | ClientException | IOException e) {
        Utils.failWithStackTrace("Exception executing selectWithin: " + e);
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 33 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class SecureCommandTest method test_06_SecureRetrieveACL.

/**
   *
   */
@Test
public void test_06_SecureRetrieveACL() {
    try {
        JSONArray expected = new JSONArray(new ArrayList<>(Arrays.asList(GNSProtocol.EVERYONE.toString())));
        JSONArray actual = client.execute(GNSCommand.aclGetSecure(AclAccessType.READ_WHITELIST, accountGuid, GNSProtocol.ENTIRE_RECORD.toString())).getResultJSONArray();
        JSONAssert.assertEquals(expected, actual, false);
    } catch (ClientException | IOException | JSONException e) {
        Utils.failWithStackTrace("Exception while retrieving account record acl: ", e);
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 34 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class SelectSingleTest method test_03_BasicSelect.

/**
   *
   */
@Test
public void test_03_BasicSelect() {
    try {
        JSONArray result = clientCommands.select(masterGuid, "cats", "fred");
        // best we can do since there will be one, but possibly more objects in results
        Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(1));
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
    }
}
Also used : JSONArray(org.json.JSONArray) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 35 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class SingleRemoveGuidTest method test_01_RemoveGuidUsingAccount.

/**
   *
   */
@Test
public void test_01_RemoveGuidUsingAccount() {
    String testGuidName = "testGUID" + RandomString.randomString(12);
    GuidEntry testGuid = null;
    try {
        testGuid = clientCommands.guidCreate(masterGuid, testGuidName);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while creating testGuid: " + e);
    }
    if (testGuid != null) {
        try {
            clientCommands.guidRemove(masterGuid, testGuid.getGuid());
        } catch (ClientException | IOException e) {
            Utils.failWithStackTrace("Exception while removing testGuid: " + e);
        }
        try {
            clientCommands.lookupGuidRecord(testGuid.getGuid());
            Utils.failWithStackTrace("Lookup testGuid should have throw an exception.");
        } catch (ClientException e) {
        } catch (IOException e) {
            Utils.failWithStackTrace("Exception while doing Lookup testGuid: " + e);
        }
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test)

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