use of com.helger.commons.datetime.XMLOffsetDateTime in project phoss-smp by phax.
the class SMPServiceInformationTest method testBasic.
@Test
public void testBasic() {
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("0088:dummy");
final ISMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
final XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep/>");
assertEquals("tp", aEP.getTransportProfile());
assertEquals("http://localhost/as2", aEP.getEndpointReference());
assertFalse(aEP.isRequireBusinessLevelSignature());
assertEquals("minauth", aEP.getMinimumAuthenticationLevel());
assertEquals(aStartDT, aEP.getServiceActivationDateTime());
assertEquals(aEndDT, aEP.getServiceExpirationDateTime());
assertEquals("cert", aEP.getCertificate());
assertEquals("sd", aEP.getServiceDescription());
assertEquals("tc", aEP.getTechnicalContactUrl());
assertEquals("ti", aEP.getTechnicalInformationUrl());
assertEquals("[{\"Any\":\"<extep />\"}]", aEP.getExtensionsAsString());
final IProcessIdentifier aProcessID = new SimpleProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
final SMPProcess aProcess = new SMPProcess(aProcessID, CollectionHelper.newList(aEP), "<extproc/>");
assertEquals(aProcessID, aProcess.getProcessIdentifier());
assertEquals(1, aProcess.getAllEndpoints().size());
assertEquals("[{\"Any\":\"<extproc />\"}]", aProcess.getExtensionsAsString());
final IDocumentTypeIdentifier aDocTypeID = new SimpleDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
final SMPServiceInformation aSI = new SMPServiceInformation(aSG, aDocTypeID, CollectionHelper.newList(aProcess), "<extsi/>");
assertSame(aSG, aSI.getServiceGroup());
assertEquals(aDocTypeID, aSI.getDocumentTypeIdentifier());
assertEquals(1, aSI.getAllProcesses().size());
assertEquals("[{\"Any\":\"<extsi />\"}]", aSI.getExtensionsAsString());
}
use of com.helger.commons.datetime.XMLOffsetDateTime in project phoss-smp by phax.
the class SMPServiceInformationManagerXMLTest method testServiceRegistration.
@Test
public void testServiceRegistration() throws SMPServerException {
// Ensure the user is present
final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
assertNotNull(aTestUser);
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInformationMgr = SMPMetaManager.getServiceInformationMgr();
assertEquals(0, aServiceInformationMgr.getSMPServiceInformationCount());
// Delete existing service group
final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
assertNotNull(aSG);
try {
final XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
final IProcessIdentifier aProcessID = aIdentifierFactory.createProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
{
// Create a new service information
final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
final SMPProcess aProcess = new SMPProcess(aProcessID, new CommonsArrayList<>(aEP), "<extproc />");
assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(new SMPServiceInformation(aSG, aDocTypeID, new CommonsArrayList<>(aProcess), "<extsi />")).isSuccess());
assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
}
{
// Replace endpoint URL with equal transport profile -> replace
final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
assertNotNull(aSI);
final ISMPProcess aProcess = aSI.getProcessOfID(aProcessID);
assertNotNull(aProcess);
aProcess.setEndpoint(new SMPEndpoint("tp", "http://localhost/as2-ver2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />"));
assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
assertEquals("http://localhost/as2-ver2", CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getAllEndpoints().get(0).getEndpointReference());
}
{
// Add endpoint with different transport profile -> added to existing
// process
final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
assertNotNull(aSI);
final ISMPProcess aProcess = aSI.getProcessOfID(aProcessID);
assertNotNull(aProcess);
aProcess.addEndpoint(new SMPEndpoint("tp2", "http://localhost/as2-tp2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />"));
assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
}
{
// Add endpoint with different process - add to existing
// serviceGroup+docType part
final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
assertNotNull(aSI);
final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
aSI.addProcess(new SMPProcess(PeppolIdentifierFactory.INSTANCE.createProcessIdentifierWithDefaultScheme("testproc2"), new CommonsArrayList<>(aEP), "<extproc />"));
assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(1).getEndpointCount());
}
} finally {
aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
}
}
Aggregations