Search in sources :

Example 11 with ClientException

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

the class ServerIntegrationTest method test_030_RemoveCreatedSansAccountInfo.

/**
   * Removes a guid not using an account guid.
   *
   * @throws IOException
   * @throws ClientException
   * @throws NoSuchAlgorithmException
   */
@Test
public void test_030_RemoveCreatedSansAccountInfo() throws NoSuchAlgorithmException, ClientException, IOException {
    //CHECKED FOR VALIDITY
    String testGuidName = "testGUID" + RandomString.randomString(12);
    String testGUID = client.execute(GNSCommand.guidCreate(masterGuid, testGuidName)).getResultString();
    client.execute(GNSCommand.guidRemove(GuidUtils.getGUIDKeys(testGuidName)));
    try {
        //      clientCommands.lookupGuidRecord(testGuid.getGuid());
        client.execute(GNSCommand.lookupGUID(testGUID));
        failWithStackTrace("Lookup testGuid should have throw an exception.");
    } catch (ClientException e) {
    // expected
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test)

Example 12 with ClientException

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

the class ServerIntegrationTest method test_262_UnsignedReadFailAgain.

/**
   * Insures that we still can't read the non-world-readable field without a guid.
   *
   * @param unsignedReadTestGuid
   * @param unreadAbleReadFieldName
   */
public void test_262_UnsignedReadFailAgain(GuidEntry unsignedReadTestGuid, String unreadAbleReadFieldName) {
    try {
        try {
            String result = clientCommands.fieldRead(unsignedReadTestGuid.getGuid(), unreadAbleReadFieldName, null);
            failWithStackTrace("Result of read of test guid's " + unreadAbleReadFieldName + " in " + unsignedReadTestGuid.entityName + " as world readable was " + result + " which is wrong because it should have been rejected in UnsignedRead.");
        } catch (ClientException e) {
        }
    } catch (Exception e) {
        failWithStackTrace("Exception while testing for denied unsigned access in UnsignedRead: ", e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 13 with ClientException

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

the class ServerIntegrationTest method test_139_ACLNotReadOtherGuidFieldTest.

/**
   *
   * @param westyEntry
   * @param samEntry
   */
public void test_139_ACLNotReadOtherGuidFieldTest(GuidEntry westyEntry, GuidEntry samEntry) {
    //CHECKED FOR VALIDITY
    try {
        try {
            String result = clientCommands.fieldRead(westyEntry.getGuid(), "environment", samEntry);
            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 (Exception e) {
        failWithStackTrace("Exception while reading fields in ACLNotReadOtherGuidFieldTest: ", e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 14 with ClientException

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

the class ServerIntegrationTest method test_200_SubstituteList.

/**
   * Tests different DB substitute list methods.
   */
@Test
@Repeat(times = REPEAT)
public void test_200_SubstituteList() {
    //CHECKED FOR VALIDITY
    String testSubstituteListGuid = "testSubstituteListGUID" + RandomString.randomString(12);
    String field = "people";
    GuidEntry testEntry = null;
    try {
        // Utils.clearTestGuids(client);
        // System.out.println("cleared old GUIDs");
        testEntry = clientCommands.guidCreate(masterGuid, testSubstituteListGuid);
        System.out.print(testEntry + " ");
    } catch (Exception e) {
        failWithStackTrace("Exception during init: ", e);
    }
    try {
        clientCommands.fieldAppendOrCreateList(testEntry.getGuid(), field, new JSONArray(Arrays.asList("Frank", "Joe", "Sally", "Rita")), testEntry);
    } catch (IOException | ClientException e) {
        failWithStackTrace("Exception during create: ", e);
    }
    try {
        HashSet<String> expected = new HashSet<>(Arrays.asList("Frank", "Joe", "Sally", "Rita"));
        HashSet<String> actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(testEntry.getGuid(), field, testEntry));
        Assert.assertEquals(expected, actual);
    } catch (Exception e) {
        failWithStackTrace("Exception when we were not expecting it: ", e);
    }
    try {
        clientCommands.fieldSubstitute(testEntry.getGuid(), field, new JSONArray(Arrays.asList("BillyBob", "Hank")), new JSONArray(Arrays.asList("Frank", "Joe")), testEntry);
    } catch (IOException | ClientException e) {
        failWithStackTrace("Exception during substitute: ", e);
    }
    try {
        HashSet<String> expected = new HashSet<>(Arrays.asList("BillyBob", "Hank", "Sally", "Rita"));
        HashSet<String> actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(testEntry.getGuid(), field, testEntry));
        Assert.assertEquals(expected, actual);
    } catch (Exception e) {
        failWithStackTrace("Exception when we were not expecting it: ", e);
    }
}
Also used : JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) EncryptionException(edu.umass.cs.gnscommon.exceptions.client.EncryptionException) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException) JSONException(org.json.JSONException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) HashSet(java.util.HashSet) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test) Repeat(edu.umass.cs.utils.Repeat)

Example 15 with ClientException

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

the class ServerIntegrationTest method test_330_QuerySelectWithReader.

/**
   * Tests that selectQuery works with a reader.
   */
@Test
public void test_330_QuerySelectWithReader() {
    String fieldName = "testQuery";
    try {
        for (int cnt = 0; cnt < 5; cnt++) {
            GuidEntry testEntry = clientCommands.guidCreate(masterGuid, "queryTest-" + RandomString.randomString(12));
            // Remove default all fields / all guids ACL;
            clientCommands.aclRemove(AclAccessType.READ_WHITELIST, testEntry, GNSProtocol.ENTIRE_RECORD.toString(), GNSProtocol.ALL_GUIDS.toString());
            // save them so we can delete them later
            CREATED_GUIDS.add(testEntry);
            JSONArray array = new JSONArray(Arrays.asList(25));
            clientCommands.fieldReplaceOrCreateList(testEntry.getGuid(), fieldName, array, testEntry);
        }
    } catch (ClientException | IOException e) {
        failWithStackTrace("Exception while trying to create the guids: ", e);
    }
    try {
        //See comment under the method header for test_320_GeoSpatialSelect
        waitSettle(SELECT_WAIT);
        String query = "~" + fieldName + " : ($gt: 0)";
        JSONArray result = clientCommands.selectQuery(masterGuid, query);
        //      for (int i = 0; i < result.length(); i++) {
        //        System.out.print("guid: " + result.get(i).toString() + "  ");
        //      }
        // best we can do should be at least 5, but possibly more objects in
        // results
        Assert.assertThat(result.length(), Matchers.greaterThanOrEqualTo(5));
    } catch (ClientException | IOException e) {
        failWithStackTrace("Exception executing selectQuery: ", e);
    }
    try {
        for (GuidEntry guid : CREATED_GUIDS) {
            clientCommands.guidRemove(masterGuid, guid.getGuid());
        }
        CREATED_GUIDS.clear();
    } catch (ClientException | IOException e) {
        failWithStackTrace("Exception during cleanup: " + e);
    }
}
Also used : JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) 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