Search in sources :

Example 96 with ClientException

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

the class HttpClientTest method test_999_Cleanup.

/**
   *
   */
@Test
public void test_999_Cleanup() {
    try {
        httpClient.guidRemove(masterGuid, httpOneEntry.getGuid());
        httpClient.guidRemove(masterGuid, httpTwoEntry.getGuid());
        httpClient.guidRemove(masterGuid, mygroupEntry.getGuid());
        for (GuidEntry guid : createdGuids) {
            httpClient.guidRemove(masterGuid, guid.getGuid());
        }
        createdGuids.clear();
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while removing guids: " + e);
    }
}
Also used : ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 97 with ClientException

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

the class HttpClientTest method test_935_ReadMid.

/**
   *
   */
@Test
public void test_935_ReadMid() {
    try {
        String actual = httpClient.fieldRead(httpOneEntry.getGuid(), "flapjack.sally", httpOneEntry);
        String expected = "{ \"left\" : \"eight\" , \"right\" : \"seven\"}";
        //System.out.println("expected:" + expected);
        //System.out.println("actual:" + actual);
        JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
    } catch (IOException | ClientException | JSONException e) {
        Utils.failWithStackTrace("Exception while reading \"flapjack.sally\": ", e);
    }
}
Also used : 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 98 with ClientException

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

the class HttpClientTest method test_933_ReadAll.

/**
   *
   */
@Test
public void test_933_ReadAll() {
    try {
        JSONObject expected = new JSONObject();
        JSONObject subJson = new JSONObject();
        subJson.put("sammy", "green");
        JSONObject subsubJson = new JSONObject();
        subsubJson.put("right", "seven");
        subsubJson.put("left", "eight");
        subJson.put("sally", subsubJson);
        expected.put("flapjack", subJson);
        expected.put("environment", "work");
        expected.put("ssn", "000-00-0000");
        expected.put("password", "666flapJack");
        expected.put("address", "100 Hinkledinkle Drive");
        JSONObject actual = httpClient.read(httpOneEntry);
        JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE);
    //System.out.println(actual);
    } catch (JSONException | IOException | ClientException 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 99 with ClientException

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

the class SelectAutoGroupTest method test_552_QuerySetupGuids.

/**
   *
   */
@Test
public void test_552_QuerySetupGuids() {
    try {
        for (int cnt = 0; cnt < 5; cnt++) {
            GuidEntry testEntry = clientCommands.guidCreate(masterGuid, "queryTest-" + RandomString.randomString(12));
            createdGuids.add(testEntry);
            JSONArray array = new JSONArray(Arrays.asList(Integer.parseInt(TEST_HIGH_VALUE)));
            clientCommands.fieldReplaceOrCreateList(testEntry, groupTestFieldName, array);
        }
        for (int cnt = 0; cnt < 5; cnt++) {
            GuidEntry testEntry = clientCommands.guidCreate(masterGuid, "queryTest-" + RandomString.randomString(12));
            createdGuids.add(testEntry);
            JSONArray array = new JSONArray(Arrays.asList(Integer.parseInt(TEST_LOW_VALUE)));
            clientCommands.fieldReplaceOrCreateList(testEntry, groupTestFieldName, array);
        }
    } catch (ClientException | IOException | NumberFormatException e) {
        Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
    }
    try {
        // the HRN is a hash of the query
        String groupOneGuidName = Base64.encodeToString(SHA1HashFunction.getInstance().hash(queryOne), false);
        groupOneGuid = clientCommands.guidCreate(masterGuid, groupOneGuidName);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
    }
    try {
        // the HRN is a hash of the query
        String groupTwoGuidName = Base64.encodeToString(SHA1HashFunction.getInstance().hash(queryTwo), false);
        groupTwoGuid = clientCommands.guidCreate(masterGuid, groupTwoGuidName);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while trying to create the guids: " + e);
    }
}
Also used : JSONArray(org.json.JSONArray) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 100 with ClientException

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

the class SelectAutoGroupTest method test_561_QueryLookupSecondGroup.

/**
   *
   */
@Test
public // Check to see if the second group has members now... it should.
void test_561_QueryLookupSecondGroup() {
    try {
        JSONArray result = clientCommands.selectLookupGroupQuery(groupTwoGuid.getGuid());
        // should be 4 now
        Assert.assertThat(result.length(), Matchers.equalTo(4));
        // look up the individual values
        for (int i = 0; i < result.length(); i++) {
            BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
            GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
            String value = clientCommands.fieldReadArrayFirstElement(entry, groupTestFieldName);
            Assert.assertEquals("0", value);
        }
    } catch (ClientException | IOException | JSONException e) {
        Utils.failWithStackTrace("Exception executing selectLookupGroupQuery: " + e);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) 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) 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