Search in sources :

Example 16 with GuidEntry

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

the class ServerIntegrationTest method test_190_Substitute.

/**
   * Tests different DB substitute methods.
   */
@Test
public void test_190_Substitute() {
    //CHECKED FOR VALIDITY
    String testSubstituteGuid = "testSubstituteGUID" + RandomString.randomString(12);
    String field = "people";
    GuidEntry testEntry = null;
    try {
        // Utils.clearTestGuids(client);
        // System.out.println("cleared old GUIDs");
        testEntry = clientCommands.guidCreate(masterGuid, testSubstituteGuid);
    } catch (Exception e) {
        failWithStackTrace("Exception during init: ", e);
    }
    try {
        clientCommands.fieldAppendOrCreateList(testEntry.getGuid(), field, new JSONArray(Arrays.asList("Frank", "Joe", "Sally", "Rita")), testEntry);
    } catch (IOException | ClientException e) {
        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 (Exception e) {
        failWithStackTrace("Exception when we were not expecting it: ", e);
    }
    try {
        clientCommands.fieldSubstitute(testEntry.getGuid(), field, "Christy", "Sally", testEntry);
    } catch (Exception e) {
        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 (Exception e) {
        failWithStackTrace("Exception when we were not expecting it: ", e);
    }
}
Also used : JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) 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) HashSet(java.util.HashSet) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test)

Example 17 with GuidEntry

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

the class CreateGuidTest method test_01_CreateEntity.

/**
   *
   */
@Test
public void test_01_CreateEntity() {
    String alias = "testGUID" + RandomString.randomString(12);
    GuidEntry guidEntry = null;
    try {
        guidEntry = clientCommands.guidCreate(masterGuid, alias);
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while creating guid: " + e);
    }
    Assert.assertNotNull(guidEntry);
    Assert.assertEquals(alias, guidEntry.getEntityName());
    try {
        clientCommands.guidRemove(masterGuid, guidEntry.getGuid());
    } catch (ClientException | IOException e) {
        Utils.failWithStackTrace("Exception while creating guid: " + 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) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test)

Example 18 with GuidEntry

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

the class CreateUpdateRemoveRepeatTest method test_001_CreateAndUpdate.

/**
   * @throws Exception
   */
@Test
@Repeat(times = REPEAT)
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);
    Assert.assertEquals(alias, createdGUIDEntry.entityName);
    Assert.assertEquals(createdGUID, GuidUtils.getGUIDKeys(alias).guid);
    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));
    client.execute(GNSCommand.guidRemove(masterGuid, createdGUID));
}
Also used : JSONObject(org.json.JSONObject) RandomString(edu.umass.cs.gnscommon.utils.RandomString) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Repeat(edu.umass.cs.utils.Repeat)

Example 19 with GuidEntry

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

the class AdminTestSuite method test_001_CreateEntity.

/**
   *
   * @throws Exception
   */
@Test
public void test_001_CreateEntity() throws Exception {
    String alias = "testGUID" + RandomString.randomString(12);
    GuidEntry guidEntry = clientCommands.guidCreate(masterGuid, alias);
    Assert.assertNotNull(guidEntry);
    Assert.assertEquals(alias, guidEntry.getEntityName());
    clientCommands.guidRemove(masterGuid, guidEntry.getGuid());
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) GuidEntry(edu.umass.cs.gnsclient.client.util.GuidEntry) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest)

Example 20 with GuidEntry

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

the class ServerIntegrationTest method test_245_UnsignedReadTests.

/**
   * Runs a set of UnsignedRead tests.
   *
   * @throws Exception
   */
@Test
public void test_245_UnsignedReadTests() throws Exception {
    GuidEntry unsignedReadAccountGuid = test_249_UnsignedReadDefaultWriteCreateAccountGuid();
    p("test_249_UnsignedReadDefaultWriteCreateAccountGuid");
    test_250_UnsignedReadDefaultAccountGuidWrite(unsignedReadAccountGuid);
    p("test_250_UnsignedReadDefaultAccountGuidWrite");
    test_251_UnsignedReadDefaultAccountGuidRead(unsignedReadAccountGuid);
    p("test_251_UnsignedReadDefaultAccountGuidRead");
    String unsignedReadFieldName = "allreadaccess";
    String unreadAbleReadFieldName = "cannotreadreadaccess";
    GuidEntry unsignedReadTestGuid = test_252_UnsignedReadCreateGuids(unsignedReadAccountGuid);
    test_253_UnsignedReadCheckACL(unsignedReadAccountGuid, unsignedReadTestGuid);
    p("test_253_UnsignedReadCheckACL");
    test_254_UnsignedReadDefaultWrite(unsignedReadTestGuid, unsignedReadFieldName);
    p("test_254_UnsignedReadDefaultWrite");
    test_255_UnsignedReadDefaultRead(unsignedReadTestGuid, unsignedReadFieldName);
    test_256_UnsignedReadFailRemoveDefaultReadAccess(unsignedReadTestGuid);
    test_257_UnsignedReadCheckACLForRecord(unsignedReadAccountGuid, unsignedReadTestGuid);
    test_258_UnsignedReadFailWriteField(unsignedReadTestGuid, unreadAbleReadFieldName);
    test_259_UnsignedReadFailRead(unsignedReadTestGuid, unreadAbleReadFieldName);
    test_260_UnsignedReadAddFieldAccess(unsignedReadTestGuid, unsignedReadFieldName);
    test_261_UnsignedReadWithFieldAccess(unsignedReadTestGuid, unsignedReadFieldName);
    test_262_UnsignedReadFailAgain(unsignedReadTestGuid, unreadAbleReadFieldName);
    test_263_UnsignedReadFailMissingField(unsignedReadTestGuid);
}
Also used : 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)

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