Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
JniMultiInstanceKmip.java
package com.p6r.kmip;
import org.junit.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class JniMultiInstanceKmip {
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_multiInstanceKMIP() {
System.out.println("@Test - JNICall-multiInstanceKMIP");
String uid1 = null;
String[] attribute = null;
P6KMIPClient kc = new P6KMIPClient();
try {
kc.initializeLibrary(P6KMIPClient.FLAGS_NONE);
kc.open(_hostName, null);
// -> create a symmetric key and use it to test out attributes
uid1 = kc.createSymmetricKey(KMIPConstants.ALG_AES, 128, (KMIPConstants.USAGE_MASK_ENCRYPT | KMIPConstants.USAGE_MASK_DECRYPT));
System.out.println("UID of new AES key: " + uid1);
// -> if server supports multi-value attributes then the second call with be at index 1
kc.addTextAttribute(uid1, "Name", "Mary-A1111");
kc.addTextAttribute(uid1, "Name", "Mary-B1211");
kc.addTextAttribute(uid1, "Name", "Mary-C1311");
attribute = kc.getAttribute(uid1, "Name");
assertEquals(3, attribute.length);
//System.out.println( attribute[1] );
assertEquals("Mary-B1211 (index:1)", attribute[1]);
// -> modify the 2nd instance
kc.modifyTextAttribute(uid1, "Name", "frank-change", 1);
attribute = kc.getAttribute(uid1, "Name");
System.out.println("\nModified Name attribute at index 0: " + attribute[0]);
System.out.println("\nModified Name attribute at index 1: " + attribute[1]);
System.out.println("\nModified Name attribute at index 2: " + attribute[2]);
assertEquals(3, attribute.length);
assertEquals("frank-change (index:1)", attribute[1]);
// -> delete the 2nd instance
kc.deleteAttribute(uid1, "Name", 1);
attribute = kc.getAttribute(uid1, "Name");
assertEquals(2, attribute.length);
System.out.println("\nShow ALL attributes associated with the key");
attribute = kc.getAllAttributes(uid1);
assertNotEquals(attribute, null);
for( int i=0; i < attribute.length; i++ ) {
System.out.println( "attribute " + i + "> " + attribute[i]);
}
kc.destroy(uid1);
kc.close();
kc.freeLibrary();
} catch (Exception e) {
// -> we shoud not get here
System.out.println(e.toString());
assertEquals(0, 1);
}
}
}