package com.p6r.kmip;
import org.junit.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class JniBoolAttributesKmip {
private static final String _hostName = "kmiptest01.p6r.com";
@BeforeClass
public static void oneTimeSetUp() {
System.out.println("@BeforeClass - oneTimeSetUp");
}
@AfterClass
public static void oneTimeTearDown() {
System.out.println("@AfterClass - oneTimeTearDown");
}
@Before
public void setUp() {
System.out.println("@Before - setUp");
}
@After
public void tearDown() {
System.out.println("@After - tearDown");
}
@Test
public void JNICall_boolAttributesKMIP() {
System.out.println("@Test - JNICall-boolAttributesKMIP");
String uid1 = null;
String[] attribute = null;
P6KMIPClient kc = new P6KMIPClient();
try {
kc.initializeLibrary(P6KMIPClient.FLAGS_NONE);
kc.open(_hostName, null);
uid1 = kc.createSymmetricKey(KMIPConstants.ALG_AES, 128, (KMIPConstants.USAGE_MASK_ENCRYPT | KMIPConstants.USAGE_MASK_DECRYPT));
System.out.println("UID of new AES key: " + uid1);
attribute = kc.getAttribute(uid1, "Sensitive");
System.out.println("Default value of Sensitive: " + attribute[0]);
assertEquals(Boolean.valueOf(attribute[0]), false);
attribute = kc.getAttribute(uid1, "Extractable");
System.out.println("Default value of Extractable: " + attribute[0]);
assertEquals(Boolean.valueOf(attribute[0]), true);
attribute = kc.getAttribute(uid1, "Always Sensitive");
System.out.println("Default value of Always Sensitive: " + attribute[0]);
assertEquals(Boolean.valueOf(attribute[0]), false);
attribute = kc.getAttribute(uid1, "Never Extractable");
System.out.println("Default value of Never Extractable: " + attribute[0]);
assertEquals(Boolean.valueOf(attribute[0]), false);
kc.modifyBooleanAttribute(uid1, "Sensitive", true, 0);
attribute = kc.getAttribute(uid1, "Sensitive");
assertEquals(Boolean.valueOf(attribute[0]), true);
kc.modifyBooleanAttribute(uid1, "Extractable", false, 0);
attribute = kc.getAttribute(uid1, "Extractable");
assertEquals(Boolean.valueOf(attribute[0]), false);
kc.addBooleanAttribute(uid1, "x-test1-bool", true);
kc.addBooleanAttribute(uid1, "x-test2-bool", false);
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.modifyBooleanAttribute(uid1, "x-test1-bool", false, 0);
attribute = kc.getAttribute(uid1, "x-test1-bool");
assertEquals(Boolean.valueOf(attribute[0]), false);
kc.deleteAttribute(uid1, "x-test2-bool", 0);
attribute = kc.getAttribute(uid1, "x-test2-bool");
assertEquals(attribute.length,0);
System.out.println("\nShow ALL attributes associated with the key after we delete one attribute");
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) {
System.out.println(e.toString());
assertEquals(0, 1);
}
}
}