Search in sources :

Example 6 with XMLOffsetDateTime

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());
}
Also used : SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 7 with XMLOffsetDateTime

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);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) IUser(com.helger.photon.security.user.IUser) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Aggregations

XMLOffsetDateTime (com.helger.commons.datetime.XMLOffsetDateTime)7 Nonnull (javax.annotation.Nonnull)4 Test (org.junit.Test)4 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)3 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)3 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)3 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)2 SMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint)2 ContainsSoftMigration (com.helger.commons.annotation.ContainsSoftMigration)1 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)1 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 PeppolSBDHDocument (com.helger.peppol.sbdh.PeppolSBDHDocument)1 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)1 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)1 SimpleProcessIdentifier (com.helger.peppolid.simple.process.SimpleProcessIdentifier)1 SMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup)1 ISMPEndpoint (com.helger.phoss.smp.domain.serviceinfo.ISMPEndpoint)1 ISMPProcess (com.helger.phoss.smp.domain.serviceinfo.ISMPProcess)1