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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
}
Aggregations