Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JniLocateKmip.java
package com.p6r.kmip;
import org.junit.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class JniLocateKmip {
private static final String _hostName = "kmiptest01.p6r.com";
@BeforeClass
public static void oneTimeSetUp() {
// NOOP
System.out.println("@BeforeClass - oneTimeSetUp");
}
@AfterClass
public static void oneTimeTearDown() {
// NOOP
System.out.println("@AfterClass - oneTimeTearDown");
}
@Before
public void setUp() {
// NOOP
System.out.println("@Before - setUp");
}
@After
public void tearDown() {
// NOOP
System.out.println("@After - tearDown");
}
@Test
public void JNICall_locateKMIP() {
System.out.println("@Test - JNICall-locateKMIP");
String uid1 = null;
String uid2 = null;
String uid3 = null;
String[] uidList = null;
P6KMIPClient kc = new P6KMIPClient();
try {
kc.initializeLibrary(P6KMIPClient.FLAGS_NONE);
kc.open(_hostName, null);
// -> create 3 keys each with the same custom attribute
uid1 = kc.createSymmetricKey(KMIPConstants.ALG_AES, 128, (KMIPConstants.USAGE_MASK_ENCRYPT | KMIPConstants.USAGE_MASK_DECRYPT));
System.out.println("UID of new AES key 1: " + uid1);
kc.addTextAttribute(uid1, "x-ID", "Java-JNI-basic-test2");
uid2 = kc.createSymmetricKey(KMIPConstants.ALG_AES, 128, (KMIPConstants.USAGE_MASK_ENCRYPT | KMIPConstants.USAGE_MASK_DECRYPT));
System.out.println("UID of new AES key 2: " + uid2);
kc.addTextAttribute(uid2, "x-ID", "Java-JNI-basic-test2");
uid3 = kc.createSymmetricKey(KMIPConstants.ALG_AES, 128, (KMIPConstants.USAGE_MASK_ENCRYPT | KMIPConstants.USAGE_MASK_DECRYPT));
System.out.println("UID of new AES key 3: " + uid3);
kc.addTextAttribute(uid3, "x-ID", "Java-JNI-basic-test2");
// -> search for the keys by the one custom attribute and get all 3 UIDs back
uidList = null;
uidList = kc.locateByTextAttribute("x-ID", "Java-JNI-basic-test2");
assertEquals(uidList.length, 3);
for (int i = 0; i < uidList.length; i++) {
System.out.println("locateByTextAttribute found: " + uidList[i]);
}
// -> what happens if we find nothing?
uidList = null;
uidList = kc.locateByTextAttribute("Name", "Miller-Mary-Joe");
assertEquals(uidList.length, 0);
// -> clean up
kc.destroy(uid1);
kc.destroy(uid2);
kc.destroy(uid3);
kc.close();
kc.freeLibrary();
} catch (Exception e) {
// -> we shoud not get here
System.out.println(e.toString());
assertEquals(0, 1);
}
}
}