Search in sources :

Example 6 with BasicGuidEntry

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

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

Example 8 with BasicGuidEntry

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

the class ServerIntegrationTest method test_551_QueryRemovePreviousTestFields.

/**
   * Remove any old fields from previous tests for group tests.
   *
   * @param groupTestFieldName
   */
public void test_551_QueryRemovePreviousTestFields(String groupTestFieldName) {
    // find all the guids that have our field and remove it from them
    try {
        String query = "~" + groupTestFieldName + " : {$exists: true}";
        JSONArray result = clientCommands.selectQuery(query);
        for (int i = 0; i < result.length(); i++) {
            BasicGuidEntry guidInfo = new BasicGuidEntry(clientCommands.lookupGuidRecord(result.getString(i)));
            GuidEntry guidEntry = GuidUtils.lookupGuidEntryFromDatabase(clientCommands, guidInfo.getEntityName());
            System.out.println("Removing from " + guidEntry.getEntityName());
            clientCommands.fieldRemove(guidEntry, groupTestFieldName);
        }
    } catch (Exception e) {
        failWithStackTrace("Trying to remove previous test's fields: ", e);
    }
}
Also used : BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) 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)

Example 9 with BasicGuidEntry

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

the class ContextAwareGroupGuidExample method main.

/**
   *
   * @param args
   * @throws IOException
   * @throws InvalidKeySpecException
   * @throws NoSuchAlgorithmException
   * @throws ClientException
   * @throws InvalidKeyException
   * @throws SignatureException
   * @throws Exception
   */
public static void main(String[] args) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, ClientException, InvalidKeyException, SignatureException, Exception {
    // BOILER PLATE FOR RUNNING AN EXAMPLE
    // Start the client
    client = new GNSClientCommands(null);
    try {
        // Create the account guid using your email address and password = "password"
        masterGuid = lookupOrCreateAccountGuid(client, ACCOUNT_ALIAS, "password");
    } catch (Exception e) {
        System.out.println("Exception during accountGuid creation: " + e);
        System.exit(1);
    }
    System.out.println("Client connected to GNS.");
    // Create 5 guids each of which have the field using our fieldname with a value of 25
    for (int cnt = 0; cnt < 5; cnt++) {
        GuidEntry guidEntry = client.guidCreate(masterGuid, "valueField-" + cnt);
        client.fieldUpdate(guidEntry, fieldName, 25);
    }
    //FIXME: THIS CODE IS OBSOLETE. THE INTERFACE HAS CHANGED.
    // Create a guid for the first group
    groupOneGuidEntry = client.guidCreate(masterGuid, "contextAware > 20 Group");
    // Set up the group context with a query
    String query = "~" + fieldName + " : {$gt: 20}";
    // Note that the zero for the interval means that we will never get stale results (not a 
    // good idea to do in production code! The default is 60 (seconds))
    JSONArray result = client.selectSetupGroupQuery(masterGuid, groupOneGuidEntry.getGuid(), query, 0);
    // Show the values from the guids that we got back
    System.out.println("Members of " + groupOneGuidEntry.getEntityName() + ":");
    showFieldValuesInGuids(result, fieldName);
    //FIXME: THIS CODE IS OBSOLETE. THE INTERFACE HAS CHANGED.
    // Create a second group guid
    groupTwoGuidEntry = client.guidCreate(masterGuid, "contextAware = 0 Group");
    // Set up a second group with a different query
    query = "~" + fieldName + " : 0";
    // Note that the zero for the interval means that we will never get stale results (not a 
    // good idea to do in production code!  The default is 60 (seconds))
    JSONArray resultTwo = client.selectSetupGroupQuery(masterGuid, groupTwoGuidEntry.getGuid(), query, 0);
    // Show the values from the guids that we got back
    System.out.println("Members of " + groupTwoGuidEntry.getEntityName() + ": (should be empty)");
    showFieldValuesInGuids(resultTwo, fieldName);
    // Now we lookup the values of the first group again
    JSONArray resultThree = client.selectLookupGroupQuery(groupOneGuidEntry.getGuid());
    System.out.println("Members of " + groupOneGuidEntry.getEntityName() + ": (should still be 5 of them)");
    showFieldValuesInGuids(resultThree, fieldName);
    // THIS IS WHERE IT GETS INTERESTING
    // And change the values of all but one of them
    System.out.println("Changing 4 of the 5 guids to have a their " + fieldName + " field's value be 0");
    for (int i = 0; i < result.length() - 1; i++) {
        BasicGuidEntry guidInfo = new BasicGuidEntry(client.lookupGuidRecord(result.getString(i)));
        GuidEntry entry = GuidUtils.lookupGuidEntryFromDatabase(client, guidInfo.getEntityName());
        System.out.println("Changing value of " + fieldName + " field in " + entry.getEntityName() + " to 0");
        client.fieldUpdate(entry, fieldName, 0);
    }
    // Now we lookup the values of the first group again - showing that there is only one guid in the group
    JSONArray resultFour = client.selectLookupGroupQuery(groupOneGuidEntry.getGuid());
    System.out.println("Members of " + groupOneGuidEntry.getEntityName() + ": (should only be one of them)");
    showFieldValuesInGuids(resultFour, fieldName);
    // Now we lookup the values of the second group again - this one now has 4 guids
    JSONArray resultFive = client.selectLookupGroupQuery(groupTwoGuidEntry.getGuid());
    System.out.println("Members of " + groupTwoGuidEntry.getEntityName() + ": (should be 4 of them)");
    showFieldValuesInGuids(resultFive, fieldName);
    // So we can run this again without duplicate name/guid errors.
    cleanupAllGuids();
    System.exit(0);
}
Also used : GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) JSONArray(org.json.JSONArray) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) BasicGuidEntry(edu.umass.cs.gnsclient.client.util.BasicGuidEntry) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry)

Example 10 with BasicGuidEntry

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

the class ServerIntegrationTest method checkSelectTheReturnValues.

private static void checkSelectTheReturnValues(JSONArray result, String groupTestFieldName) 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

BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)13 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)13 JSONArray (org.json.JSONArray)10 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)9 IOException (java.io.IOException)9 RandomString (edu.umass.cs.gnscommon.utils.RandomString)8 JSONException (org.json.JSONException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)4 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)4 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)4 FileNotFoundException (java.io.FileNotFoundException)4 Test (org.junit.Test)4 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)1 InvalidKeyException (java.security.InvalidKeyException)1 SignatureException (java.security.SignatureException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1