1 package com.p6r.kmipserverlib;
5 import java.nio.charset.Charset;
7 import static org.junit.Assert.assertEquals;
23 System.out.println(
"@BeforeClass - oneTimeSetUp");
29 System.out.println(
"@AfterClass - oneTimeTearDown");
35 System.out.println(
"@Before - setUp");
41 System.out.println(
"@After - tearDown");
51 System.out.println(
"@Test - JNICall-ModifyAttributeKMIP");
55 P6KMIPServerLib sl =
new P6KMIPServerLib();
58 String testMessage20_1 =
"<RequestMessage>\n" +
60 " <ProtocolVersion>\n" +
61 " <ProtocolVersionMajor type=\"Integer\" value=\"2\"/>\n" +
62 " <ProtocolVersionMinor type=\"Integer\" value=\"0\"/>\n" +
63 " </ProtocolVersion>\n" +
64 " <ClientCorrelationValue type=\"TextString\" value=\"AKLC-M-3-20 step=4\"/>\n" +
65 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
66 "</RequestHeader>\n" +
68 " <Operation type=\"Enumeration\" value=\"ModifyAttribute\"/>\n" +
69 " <RequestPayload>\n" +
70 " <UniqueIdentifier type=\"TextString\" value=\"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f\"/>\n" +
71 " <CurrentAttribute>\n" +
73 " <NameValue type=\"TextString\" value=\"Fake-Modify-test-23\"/>\n" +
74 " <NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/>\n" +
76 " </CurrentAttribute>\n" +
78 " <ActivationDate type=\"DateTime\" value=\"2018-03-18T15:16:30Z\"/>\n" +
79 " </NewAttribute>\n" +
80 " </RequestPayload>\n" +
84 String testMessage20_2 =
"<RequestMessage>\n" +
86 " <ProtocolVersion>\n" +
87 " <ProtocolVersionMajor type=\"Integer\" value=\"2\"/>\n" +
88 " <ProtocolVersionMinor type=\"Integer\" value=\"0\"/>\n" +
89 " </ProtocolVersion>\n" +
90 " <ClientCorrelationValue type=\"TextString\" value=\"AKLC-M-3-20 step=4\"/>\n" +
91 " <BatchCount type=\"Integer\" value=\"1\"/>\n" +
92 "</RequestHeader>\n" +
94 " <Operation type=\"Enumeration\" value=\"AddAttribute\"/>\n" +
95 " <RequestPayload>\n" +
96 " <UniqueIdentifier type=\"TextString\" value=\"f82a80f0-fe20-4cbb-a1b6-00e3a81a7e90\"/>\n" +
97 " <CurrentAttribute>\n" +
99 " <NameValue type=\"TextString\" value=\"JackTheGermanShepherd\"/>\n" +
100 " <NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/>\n" +
102 " </CurrentAttribute>\n" +
103 " </RequestPayload>\n" +
107 String testMessage14 =
"<RequestMessage>\n" +
108 "<RequestHeader>\n" +
109 "<ProtocolVersion>\n" +
110 "<ProtocolVersionMajor type=\"Integer\" value=\"1\"/>\n" +
111 "<ProtocolVersionMinor type=\"Integer\" value=\"4\"/>\n" +
112 "</ProtocolVersion>\n" +
113 "<BatchCount type=\"Integer\" value=\"1\"/>\n" +
114 "</RequestHeader>\n" +
116 " <Operation type=\"Enumeration\" value=\"ModifyAttribute\"/>\n" +
117 " <RequestPayload>\n" +
118 " <UniqueIdentifier type=\"TextString\" value=\"91bdcfb4-130b-439d-af45-de781286e9e4\"/>\n" +
120 " <AttributeName type=\"TextString\" value=\"Activation Date\"/>\n" +
121 " <AttributeValue type=\"DateTime\" value=\"2018-03-19T14:28:10Z\"/>\n" +
123 " </RequestPayload>\n" +
128 sl.initializeLibrary(P6KMIPServerLib.FLAGS_NONE);
130 String libVersion = sl.getLibraryVersion();
131 System.out.println(libVersion);
135 sl.setMessageBuffer(testMessage20_1.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
138 RequestHeader rh = sl.getRequestHeader();
139 assertEquals(
"2.0", rh.getProtocolVersion());
142 for (
int i = 0; i < rh.getBatchCount(); i++) {
144 BatchItem bi = sl.getBatchItem(i + 1);
145 if (bi instanceof ModifyAttribute2BatchItem) {
146 ModifyAttribute2BatchItem rb = (ModifyAttribute2BatchItem) bi;
148 String uniqueId = rb.getUniqueId();
149 assertEquals(
"e82a80f0-fe20-4cbb-a1b6-00e3a81a7e9f", uniqueId);
151 String currentAttribute = rb.getCurrentAttribute();
152 assertEquals(
"Name: Fake-Modify-test-23 - text_string", currentAttribute);
154 String newAttribute = rb.getNewAttribute();
155 assertEquals(
"Activation Date: 2018-3-18T15:16:30Z", newAttribute);
160 sl.setMessageBuffer(testMessage20_2.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
161 rh = sl.getRequestHeader();
162 assertEquals(
"2.0", rh.getProtocolVersion());
165 for (
int i = 0; i < rh.getBatchCount(); i++) {
167 BatchItem bi = sl.getBatchItem(i + 1);
168 if (bi instanceof AddAttributeBatchItem) {
169 AddAttributeBatchItem rb = (AddAttributeBatchItem) bi;
171 String uniqueId = rb.getUniqueId();
172 assertEquals(
"f82a80f0-fe20-4cbb-a1b6-00e3a81a7e90", uniqueId);
174 String currentAttribute = rb.getAttribute();
175 assertEquals(
"Name: JackTheGermanShepherd - text_string", currentAttribute);
180 sl.setMessageBuffer(testMessage14.getBytes(Charset.forName(
"UTF-8")), KMIPConstants.FORMAT_MSGXML);
181 rh = sl.getRequestHeader();
182 assertEquals(
"1.4", rh.getProtocolVersion());
184 for (
int i = 0; i < rh.getBatchCount(); i++) {
186 BatchItem bi = sl.getBatchItem(i + 1);
187 if (bi instanceof ModifyAttributeBatchItem) {
188 ModifyAttributeBatchItem rb = (ModifyAttributeBatchItem) bi;
190 String uniqueId = rb.getUniqueId();
191 assertEquals(
"91bdcfb4-130b-439d-af45-de781286e9e4", uniqueId);
193 String attribute = rb.getAttribute();
194 assertEquals(
"Activation Date: 2018-3-19T14:28:10Z", attribute);
200 }
catch (Exception e) {
202 System.out.println(e.toString());
static void oneTimeTearDown()
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeSetUp()
void JniModifyAttributeKmip()
Test: Modify Attribute operation for KMIP 1.x and 2.0.