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-RegisterTemplateKMIP");
55 P6KMIPServerLib sl =
new P6KMIPServerLib();
59 "<RequestMessage><RequestHeader><ProtocolVersion><ProtocolVersionMajor type=\"Integer\" value=\"1\"/><ProtocolVersionMinor type=\"Integer\" value=\"2\"/></ProtocolVersion><BatchCount type=\"Integer\" value=\"1\"/></RequestHeader><BatchItem><Operation type=\"Enumeration\" value=\"Register\"/><RequestPayload><ObjectType type=\"Enumeration\" value=\"Template\"/><TemplateAttribute><Attribute><AttributeName type=\"TextString\" value=\"Name\"/><AttributeValue><NameValue type=\"TextString\" value=\"TC-312-12-template8\"/><NameType type=\"Enumeration\" value=\"UninterpretedTextString\"/></AttributeValue></Attribute></TemplateAttribute><Template><Attribute><AttributeName type=\"TextString\" value=\"Object Group\"/><AttributeValue type=\"TextString\" value=\"Group1\"/></Attribute><Attribute><AttributeName type=\"TextString\" value=\"Application Specific Information\"/><AttributeValue><ApplicationNamespace type=\"TextString\" value=\"ssl\"/><ApplicationData type=\"TextString\" value=\"www.example.com\"/></AttributeValue></Attribute><Attribute><AttributeName type=\"TextString\" value=\"Contact Information\"/><AttributeValue type=\"TextString\" value=\"Joe\"/></Attribute><Attribute><AttributeName type=\"TextString\" value=\"x-Purpose\"/><AttributeValue type=\"TextString\" value=\"demonstration\"/></Attribute><Attribute><AttributeName type=\"TextString\" value=\"x-ID\"/><AttributeValue type=\"TextString\" value=\"TC-312-12-from-template\"/></Attribute></Template></RequestPayload></BatchItem></RequestMessage>";
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_MSGXML);
72 RequestHeader rh = sl.getRequestHeader();
73 assertEquals(
"1.2", rh.getProtocolVersion());
76 for (
int i = 0; i < rh.getBatchCount(); i++) {
78 BatchItem bi = sl.getBatchItem(i + 1);
79 if (bi instanceof RegisterTemplateBatchItem) {
80 RegisterTemplateBatchItem tb = (RegisterTemplateBatchItem) bi;
83 byte[] batchId = tb.getUniqueBatchId();
84 assertEquals(null, batchId);
86 String[] names = tb.getTemplateNames();
87 assertEquals(null, names);
89 String[] registerAttributes = tb.getTemplateAttributes();
90 assertEquals(1, registerAttributes.length);
91 assertEquals(
"Name: TC-312-12-template8 - text_string", registerAttributes[0]);
93 String[] objAttributes = tb.getAttributeList();
94 assertEquals(5, objAttributes.length);
95 assertEquals(
"Object Group: Group1", objAttributes[0]);
96 assertEquals(
"Application Specific Information: ssl - www.example.com", objAttributes[1]);
97 assertEquals(
"Contact Information: Joe", objAttributes[2]);
98 assertEquals(
"x-Purpose: demonstration", objAttributes[3]);
99 assertEquals(
"x-ID: TC-312-12-from-template", objAttributes[4]);
104 }
catch (Exception e) {
106 System.out.println(e.toString());
static void oneTimeSetUp()
void JNICall_RegisterTemplateKMIP()
Test: Verify parser can handle an XML formated Register Template operation.
A JUNIT test demonstrating how to parse an incoming KMIP request from a client.
static void oneTimeTearDown()