1 package com.p6r.kmipserverlib;
5 import java.nio.charset.Charset;
6 import static org.junit.Assert.assertEquals;
22 System.out.println(
"@BeforeClass - oneTimeSetUp");
28 System.out.println(
"@AfterClass - oneTimeTearDown");
34 System.out.println(
"@Before - setUp");
40 System.out.println(
"@After - tearDown");
50 System.out.println(
"@Test - JNICall-HashKMIP");
52 byte[] expectedData = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
56 P6KMIPServerLib sl =
new P6KMIPServerLib();
59 String testMessage =
"{\"tag\":\"RequestMessage\", \"value\":[{\"tag\":\"RequestHeader\", \"value\":[{\"tag\":\"ProtocolVersion\", \"value\":[{\"tag\":\"ProtocolVersionMajor\", \"type\":\"Integer\", \"value\":1}, {\"tag\":\"ProtocolVersionMinor\", \"type\":\"Integer\", \"value\":3}]}, {\"tag\":\"BatchCount\", \"type\":\"Integer\", \"value\":1}]}, {\"tag\":\"BatchItem\", \"value\":[{\"tag\":\"Operation\", \"type\":\"Enumeration\", \"value\":\"Hash\"}, {\"tag\":\"RequestPayload\", \"value\":[{\"tag\":\"CryptographicParameters\", \"value\":[{\"tag\":\"HashingAlgorithm\", \"type\":\"Enumeration\", \"value\":\"SHA_256\"}]}, {\"tag\":\"Data\", \"type\":\"ByteString\", \"value\":\"01020304050607080910111213141516\"}]}]}]}";
62 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
64 String libVersion = sl.getLibraryVersion();
65 System.out.println(libVersion);
69 sl.setMessageBuffer(testMessage.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGJSON);
72 RequestHeader rh = sl.getRequestHeader();
73 assertEquals(
"1.3", rh.getProtocolVersion());
76 for (
int i = 0; i < rh.getBatchCount(); i++) {
78 BatchItem bi = sl.getBatchItem(i + 1);
79 if (bi instanceof HashBatchItem) {
80 HashBatchItem ck = (HashBatchItem) bi;
82 CryptograhicParameters params = ck.getParams();
83 int alg = params.getHashAlgorithm();
84 assertEquals(alg, KMIPConstants.HASH_SHA256);
86 byte[] dataToEncrypt = ck.getData();
87 assertEquals(16, dataToEncrypt.length);
88 for(
int j=0; j < dataToEncrypt.length; j++) {
89 assertEquals( expectedData[j], dataToEncrypt[j]);
95 }
catch (Exception e) {
97 System.out.println(e.toString());
static void oneTimeSetUp()
static void oneTimeTearDown()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
void JNICall_HashKMIP()
Test: Verify parser can handle an JSON formated Encrypt operation.