Search in sources :

Example 21 with GuidEntry

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

the class ServerIntegrationTest method test_001_CreateAndUpdate.

/**
   * @throws Exception
   */
@Test
@Repeat(times = REPEAT * 10)
public void test_001_CreateAndUpdate() throws Exception {
    // CHECKED FOR VALIDITY
    String alias = "testGUID" + RandomString.randomString(12);
    String createdGUID = client.execute(GNSCommand.guidCreate(masterGuid, alias)).getResultString();
    GuidEntry createdGUIDEntry = GuidUtils.getGUIDKeys(alias);
    String key = "key1", value = "value1";
    client.execute(GNSCommand.update(createdGUID, new JSONObject().put(key, value), createdGUIDEntry));
    Assert.assertEquals(value, client.execute(GNSCommand.fieldRead(createdGUIDEntry, key)).getResultMap().get(key));
}
Also used : JSONObject(org.json.JSONObject) RandomString(edu.umass.cs.gnscommon.utils.RandomString) 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) Repeat(edu.umass.cs.utils.Repeat)

Example 22 with GuidEntry

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

the class AclDefaultsTest method test_149_ACLALLFields.

/**
   *
   */
@Test
public void test_149_ACLALLFields() {
    String superUserName = "superuser" + RandomString.randomString(12);
    try {
        try {
            clientCommands.lookupGuid(superUserName);
            Utils.failWithStackTrace(superUserName + " entity should not exist");
        } catch (ClientException e) {
        }
        GuidEntry superuserEntry = clientCommands.guidCreate(masterGuid, superUserName);
        // let superuser read any of barney's fields
        clientCommands.aclAdd(AclAccessType.READ_WHITELIST, barneyEntry, GNSProtocol.ENTIRE_RECORD.toString(), superuserEntry.getGuid());
        Assert.assertEquals("413-555-1234", clientCommands.fieldRead(barneyEntry.getGuid(), "cell", superuserEntry));
        Assert.assertEquals("100 Main Street", clientCommands.fieldRead(barneyEntry.getGuid(), "address", superuserEntry));
        try {
            clientCommands.guidRemove(masterGuid, superuserEntry.getGuid());
        } catch (IOException | ClientException e) {
            Utils.failWithStackTrace("Exception while deleting superuserEntry in ACLALLFields: ", e);
        }
    } catch (IOException | ClientException e) {
        Utils.failWithStackTrace("Exception when we were not expecting it in ACLALLFields: ", e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) 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 23 with GuidEntry

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

the class DatabaseTest method test_16_Substitute.

/**
   *
   */
@Test
public void test_16_Substitute() {
    String testSubstituteGuid = "testSubstituteGUID" + RandomString.randomString(12);
    String field = "people";
    GuidEntry testEntry = null;
    try {
        testEntry = clientCommands.guidCreate(masterGuid, testSubstituteGuid);
    //System.out.println("created test guid: " + testEntry);
    } catch (IOException | ClientException e) {
        Utils.failWithStackTrace("Exception during init: " + e);
    }
    if (testEntry != null) {
        try {
            clientCommands.fieldAppendOrCreateList(testEntry.getGuid(), field, new JSONArray(Arrays.asList("Frank", "Joe", "Sally", "Rita")), testEntry);
        } catch (IOException | ClientException e) {
            Utils.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 (IOException | ClientException | JSONException e) {
            Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
        }
        try {
            clientCommands.fieldSubstitute(testEntry.getGuid(), field, "Christy", "Sally", testEntry);
        } catch (IOException | ClientException e) {
            Utils.failWithStackTrace("Exception during substitute: " + e);
        }
        try {
            HashSet<String> expected = new HashSet<>(Arrays.asList("Frank", "Joe", "Christy", "Rita"));
            HashSet<String> actual = JSONUtils.JSONArrayToHashSet(clientCommands.fieldReadArray(testEntry.getGuid(), field, testEntry));
            Assert.assertEquals(expected, actual);
        } catch (IOException | ClientException | JSONException e) {
            Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
        }
        try {
            clientCommands.guidRemove(masterGuid, testEntry.getGuid());
        } catch (ClientException | IOException e) {
            Utils.failWithStackTrace("Exception while deleting guid: " + e);
        }
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) HashSet(java.util.HashSet) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 24 with GuidEntry

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

the class DatabaseTest method test_17_SubstituteList.

/**
   *
   */
@Test
public void test_17_SubstituteList() {
    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.println("created test guid: " + testEntry);
    } catch (IOException | ClientException e) {
        Utils.failWithStackTrace("Exception during init: " + e);
    }
    if (testEntry != null) {
        try {
            clientCommands.fieldAppendOrCreateList(testEntry.getGuid(), field, new JSONArray(Arrays.asList("Frank", "Joe", "Sally", "Rita")), testEntry);
        } catch (IOException | ClientException e) {
            Utils.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 (IOException | ClientException | JSONException e) {
            Utils.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) {
            Utils.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 (IOException | ClientException | JSONException e) {
            Utils.failWithStackTrace("Exception when we were not expecting it: " + e);
        }
        try {
            clientCommands.guidRemove(masterGuid, testEntry.getGuid());
        } catch (ClientException | IOException e) {
            Utils.failWithStackTrace("Exception while deleting guid: " + e);
        }
    }
}
Also used : JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) HashSet(java.util.HashSet) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 25 with GuidEntry

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

the class AclTest method test_130_ACLALLFields.

/**
   *
   */
@Test
public void test_130_ACLALLFields() {
    //testACL();
    String superUserName = "superuser" + RandomString.randomString(12);
    try {
        try {
            clientCommands.lookupGuid(superUserName);
            Utils.failWithStackTrace(superUserName + " entity should not exist");
        } catch (ClientException e) {
        }
        GuidEntry superuserEntry = clientCommands.guidCreate(masterGuid, superUserName);
        // let superuser read any of barney's fields
        clientCommands.aclAdd(AclAccessType.READ_WHITELIST, barneyEntry, GNSProtocol.ENTIRE_RECORD.toString(), superuserEntry.getGuid());
        Assert.assertEquals("413-555-1234", clientCommands.fieldReadArrayFirstElement(barneyEntry.getGuid(), "cell", superuserEntry));
        Assert.assertEquals("100 Main Street", clientCommands.fieldReadArrayFirstElement(barneyEntry.getGuid(), "address", superuserEntry));
        try {
            clientCommands.guidRemove(masterGuid, superuserEntry.getGuid());
        } catch (ClientException | IOException e) {
            Utils.failWithStackTrace("Exception while removing superuserEntry in  ACLALLFields: " + e);
        }
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception when we were not expecting it in ACLALLFields: " + e);
    }
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) 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)

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