Search in sources :

Example 31 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry 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 32 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry 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 33 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry 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)

Example 34 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.

the class SelectAutoGroupTest method test_562_QueryLookupSelectCleanup.

/**
   *
   */
@Test
public void test_562_QueryLookupSelectCleanup() {
    try {
        clientCommands.guidRemove(masterGuid, groupOneGuid.getGuid());
        clientCommands.guidRemove(masterGuid, groupTwoGuid.getGuid());
        for (GuidEntry guid : createdGuids) {
            clientCommands.guidRemove(masterGuid, guid.getGuid());
        }
        createdGuids.clear();
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception during cleanup: " + e);
    }
}
Also used : 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)

Example 35 with GuidEntry

use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.

the class SelectAutoGroupTest method checkSelectTheReturnValues.

private void checkSelectTheReturnValues(JSONArray result) throws Exception {
    // should be 5
    Assert.assertThat(result.length(), Matchers.equalTo(5));
    // 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(TEST_HIGH_VALUE, value);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) RandomString(edu.umass.cs.gnscommon.utils.RandomString) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry)

Aggregations

GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)134 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)87 IOException (java.io.IOException)85 Test (org.junit.Test)69 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 RandomString (edu.umass.cs.gnscommon.utils.RandomString)54 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)46 JSONException (org.json.JSONException)45 JSONArray (org.json.JSONArray)36 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)28 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)18 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)15 DuplicateNameException (edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException)14 StringTokenizer (java.util.StringTokenizer)13 JSONObject (org.json.JSONObject)12 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)11 FileNotFoundException (java.io.FileNotFoundException)11 HashSet (java.util.HashSet)10 FileInputStream (java.io.FileInputStream)8 Repeat (edu.umass.cs.utils.Repeat)7