Search in sources :

Example 1 with Repeat

use of edu.umass.cs.utils.Repeat in project GNS by MobilityFirst.

the class ContextServiceTest method test_620_contextServiceTest.

/**
   * Test to check context service triggers.
   */
// these two attributes right now are supported by CS
@Test
@Repeat(times = REPEAT)
public void test_620_contextServiceTest() {
    // run it only when CS is enabled
    // to check if context service is enabled.
    boolean enableContextService = Config.getGlobalBoolean(GNSConfig.GNSC.ENABLE_CNS);
    String csIPPort = Config.getGlobalString(GNSConfig.GNSC.CNS_NODE_ADDRESS);
    if (enableContextService) {
        try {
            JSONObject attrValJSON = new JSONObject();
            attrValJSON.put("geoLocationCurrentLat", 42.466);
            attrValJSON.put("geoLocationCurrentLong", -72.58);
            clientCommands.update(masterGuid, attrValJSON);
            // just wait for 2 sec before sending search
            Thread.sleep(1000);
            String[] parsed = csIPPort.split(":");
            String csIP = parsed[0];
            int csPort = Integer.parseInt(parsed[1]);
            ContextServiceClient csClient = new ContextServiceClient(csIP, csPort, false, PrivacySchemes.NO_PRIVACY);
            // context service query format
            String query = "geoLocationCurrentLat >= 40 " + "AND geoLocationCurrentLat <= 50 AND " + "geoLocationCurrentLong >= -80 AND " + "geoLocationCurrentLong <= -70";
            JSONArray resultArray = new JSONArray();
            // third argument is arbitrary expiry time, not used now
            int resultSize = csClient.sendSearchQuery(query, resultArray, 300000);
            Assert.assertThat(resultSize, Matchers.greaterThanOrEqualTo(1));
        } catch (Exception e) {
            Utils.failWithStackTrace("Exception during contextServiceTest: ", e);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ContextServiceClient(edu.umass.cs.contextservice.client.ContextServiceClient) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Test(org.junit.Test) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Repeat(edu.umass.cs.utils.Repeat)

Example 2 with Repeat

use of edu.umass.cs.utils.Repeat 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 3 with Repeat

use of edu.umass.cs.utils.Repeat 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 4 with Repeat

use of edu.umass.cs.utils.Repeat in project GNS by MobilityFirst.

the class ServerIntegrationTest method test_620_contextServiceTest.

/**
   * Test to check context service triggers.
   */
// these two attributes right now are supported by CS
@Test
@Repeat(times = REPEAT)
public void test_620_contextServiceTest() {
    // run it only when CS is enabled
    // to check if context service is enabled.
    boolean enableContextService = Config.getGlobalBoolean(GNSConfig.GNSC.ENABLE_CNS);
    String csIPPort = Config.getGlobalString(GNSConfig.GNSC.CNS_NODE_ADDRESS);
    if (enableContextService) {
        try {
            JSONObject attrValJSON = new JSONObject();
            attrValJSON.put("geoLocationCurrentLat", 42.466);
            attrValJSON.put("geoLocationCurrentLong", -72.58);
            clientCommands.update(masterGuid, attrValJSON);
            // just wait for 2 sec before sending search
            Thread.sleep(1000);
            String[] parsed = csIPPort.split(":");
            String csIP = parsed[0];
            int csPort = Integer.parseInt(parsed[1]);
            ContextServiceClient csClient = new ContextServiceClient(csIP, csPort, false, PrivacySchemes.NO_PRIVACY);
            // context service query format
            String query = "geoLocationCurrentLat >= 40 " + "AND geoLocationCurrentLat <= 50 AND " + "geoLocationCurrentLong >= -80 AND " + "geoLocationCurrentLong <= -70";
            JSONArray resultArray = new JSONArray();
            // third argument is arbitrary expiry time, not used now
            int resultSize = csClient.sendSearchQuery(query, resultArray, 300000);
            Assert.assertThat(resultSize, Matchers.greaterThanOrEqualTo(1));
        } catch (Exception e) {
            failWithStackTrace("Exception during contextServiceTest: ", e);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) RandomString(edu.umass.cs.gnscommon.utils.RandomString) ContextServiceClient(edu.umass.cs.contextservice.client.ContextServiceClient) 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) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test) Repeat(edu.umass.cs.utils.Repeat)

Example 5 with Repeat

use of edu.umass.cs.utils.Repeat in project GNS by MobilityFirst.

the class ServerIntegrationTest method test_117_ACLTest_Single_Field.

/**
   * Runs the set of ACL tests for checking single field access as an independent unit.
   *
   * @throws Exception
   * @throws JSONException
   */
@Test
@Repeat(times = REPEAT * 10)
public void test_117_ACLTest_Single_Field() throws JSONException, Exception {
    final String TEST_FIELD_NAME = "testField";
    String testFieldName = TEST_FIELD_NAME + RandomString.randomString(6);
    test_101_ACLCreateField(masterGuid, testFieldName);
    test_120_CreateAcl(testFieldName);
    test_121_CheckAcl(testFieldName);
    test_122_DeleteAcl(testFieldName);
    test_123_CheckAclGone(testFieldName);
}
Also used : RandomString(edu.umass.cs.gnscommon.utils.RandomString) DefaultGNSTest(edu.umass.cs.gnsserver.utils.DefaultGNSTest) Test(org.junit.Test) Repeat(edu.umass.cs.utils.Repeat)

Aggregations

DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)13 Repeat (edu.umass.cs.utils.Repeat)13 Test (org.junit.Test)13 RandomString (edu.umass.cs.gnscommon.utils.RandomString)11 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)7 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)5 JSONObject (org.json.JSONObject)5 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)4 IOException (java.io.IOException)4 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)3 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)3 FileNotFoundException (java.io.FileNotFoundException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 ContextServiceClient (edu.umass.cs.contextservice.client.ContextServiceClient)2 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1