use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class GuidImport method parse.
@Override
public void parse(String commandText) throws Exception {
try {
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 1) {
wrongArguments();
return;
}
String filename = st.nextToken();
File f = new File(filename);
GuidEntry guidEntry;
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f))) {
guidEntry = new GuidEntry(ois);
ois.close();
}
KeyPairUtils.saveKeyPair(module.getGnsInstance(), guidEntry.getEntityName(), guidEntry.getGuid(), new KeyPair(guidEntry.getPublicKey(), guidEntry.getPrivateKey()));
console.printString("Keys for " + guidEntry.getEntityName() + " read from " + filename + " and saved in local preferences.");
console.printNewline();
} catch (IOException | EncryptionException e) {
console.printString("Failed to load keys ( " + e + ")\n");
}
}
use of edu.umass.cs.gnsclient.client.util.GuidEntry in project GNS by MobilityFirst.
the class AccountVerify method parse.
@Override
public void parse(String commandText) throws Exception {
try {
GNSClientCommands client = module.getGnsClient();
StringTokenizer st = new StringTokenizer(commandText.trim());
if (st.countTokens() != 2) {
wrongArguments();
return;
}
String alias = st.nextToken();
GuidEntry guid = KeyPairUtils.getGuidEntry(module.getGnsInstance(), alias);
if (guid == null) {
printString("Unable to retrieve GUID for alias " + alias + "\n");
return;
}
String code = st.nextToken();
try {
if (client.accountGuidVerify(guid, code).startsWith(GNSProtocol.OK_RESPONSE.toString())) {
printString("Account verified.\n");
module.setAccountVerified(true);
return;
}
// this happens if it was already verified, but we didn't notice
} catch (VerificationException e) {
module.setAccountVerified(true);
printString("Account already verified" + "\n");
return;
} catch (Exception e) {
printString("Account not verified: " + e + "\n");
}
} catch (Exception e) {
console.printString("Failed to access GNS ( " + e + ")\n");
}
module.setAccountVerified(false);
}
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);
}
}
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);
}
}
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));
}
Aggregations