Search in sources :

Example 81 with IParticipantIdentifier

use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.

the class ServiceMetadataInterfaceFillDBTest method testCreateAndDeleteServiceInformationSMPClient.

@Test
public void testCreateAndDeleteServiceInformationSMPClient() throws SMPClientException {
    final SMPClient aSMPClient = new MockSMPClient();
    final StopWatch aSW = StopWatch.createdStarted();
    int nEndpoints = 0;
    try (final WebScoped aWS = new WebScoped(new MockHttpServletRequest())) {
        final int nCount = 2_000;
        for (int i = 0; i < nCount; ++i) {
            final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme(PID_PREFIX_9999_PHOSS + StringHelper.getLeadingZero(i, 4));
            final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
            final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
            for (final ESMPTransportProfile eTP : new ESMPTransportProfile[] { ESMPTransportProfile.TRANSPORT_PROFILE_AS2, ESMPTransportProfile.TRANSPORT_PROFILE_PEPPOL_AS4_V2 }) {
                final ServiceInformationType aSI = new ServiceInformationType();
                aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
                aSI.setDocumentIdentifier(aDT);
                {
                    final ProcessListType aPL = new ProcessListType();
                    final ProcessType aProcess = new ProcessType();
                    aProcess.setProcessIdentifier(aProcID);
                    final ServiceEndpointList aSEL = new ServiceEndpointList();
                    final EndpointType aEndpoint = new EndpointType();
                    aEndpoint.setEndpointReference(W3CEndpointReferenceHelper.createEndpointReference("http://test.smpserver/" + eTP.getID()));
                    aEndpoint.setRequireBusinessLevelSignature(false);
                    aEndpoint.setCertificate("blacert");
                    aEndpoint.setServiceDescription("Unit test service");
                    aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
                    aEndpoint.setTransportProfile(eTP.getID());
                    aSEL.addEndpoint(aEndpoint);
                    aProcess.setServiceEndpointList(aSEL);
                    aPL.addProcess(aProcess);
                    aSI.setProcessList(aPL);
                }
                aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
                ++nEndpoints;
            }
        }
    }
    aSW.stop();
    LOGGER.info("Created " + nEndpoints + " ServiceInformation in " + aSW.getDuration() + " (= " + (aSW.getMillis() / nEndpoints) + " ms/entry)");
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) PeppolProcessIdentifier(com.helger.peppolid.peppol.process.PeppolProcessIdentifier) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) StopWatch(com.helger.commons.timing.StopWatch) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) SMPClient(com.helger.smpclient.peppol.SMPClient) PeppolDocumentTypeIdentifier(com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 82 with IParticipantIdentifier

use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.

the class BusinessCardInterfaceTest method testGetCreateV1GetDeleteGet.

@Test
public void testGetCreateV1GetDeleteGet() {
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    assertNotNull(aSGMgr);
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    assertNotNull(aBCMgr);
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:tester");
    final String sPI = aPI.getURIEncoded();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
    Response aResponseMsg;
    try {
        // Create SG
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get SG - must work
        assertNotNull(aTarget.path(sPI).request().get(ServiceGroupType.class));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI));
        // Get BC - not existing
        aResponseMsg = aTarget.path("businesscard").path(sPI).request().get();
        _testResponseJerseyClient(aResponseMsg, 404);
        // Create BC with some entities
        final PD1BusinessCardType aBC = new PD1BusinessCardType();
        aBC.setParticipantIdentifier(PD1APIHelper.createIdentifier(aPI.getScheme(), aPI.getValue()));
        PD1BusinessEntityType aBE = new PD1BusinessEntityType();
        aBE.setName("BusinessEntity1");
        aBE.setCountryCode("AT");
        aBE.setGeographicalInformation("Vienna");
        aBC.addBusinessEntity(aBE);
        aBE = new PD1BusinessEntityType();
        aBE.setName("BusinessEntity2");
        aBE.setCountryCode("DE");
        aBE.setGeographicalInformation("Berlin");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC1ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        PD3BusinessCardType aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(2, aReadBC.getBusinessEntityCount());
        ISMPBusinessCard aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
        // Update BC - add entity
        aBE = new PD1BusinessEntityType();
        aBE.setName("BusinessEntity3");
        aBE.setCountryCode("SE");
        aBE.setGeographicalInformation("Stockholm");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC1ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(3, aReadBC.getBusinessEntityCount());
        aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
    } finally {
        // Delete Business Card
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path("businesscard").path(sPI).request().get(), 404);
        assertNull(aBCMgr.getSMPBusinessCardOfID(aPI));
        // Delete service Group
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path(sPI).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI));
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) PD1BusinessEntityType(com.helger.pd.businesscard.v1.PD1BusinessEntityType) PD1BusinessCardType(com.helger.pd.businesscard.v1.PD1BusinessCardType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) Response(javax.ws.rs.core.Response) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 83 with IParticipantIdentifier

use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.

the class BusinessCardInterfaceTest method testGetCreateV3GetDeleteGet.

@Test
public void testGetCreateV3GetDeleteGet() {
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    assertNotNull(aSGMgr);
    final ISMPBusinessCardManager aBCMgr = SMPMetaManager.getBusinessCardMgr();
    assertNotNull(aBCMgr);
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:tester");
    final String sPI = aPI.getURIEncoded();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
    Response aResponseMsg;
    try {
        // Create SG
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get SG - must work
        assertNotNull(aTarget.path(sPI).request().get(ServiceGroupType.class));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI));
        // Get BC - not existing
        aResponseMsg = aTarget.path("businesscard").path(sPI).request().get();
        _testResponseJerseyClient(aResponseMsg, 404);
        // Create BC with some entities
        final PD3BusinessCardType aBC = new PD3BusinessCardType();
        aBC.setParticipantIdentifier(PD3APIHelper.createIdentifier(aPI.getScheme(), aPI.getValue()));
        PD3BusinessEntityType aBE = new PD3BusinessEntityType();
        aBE.addName(PD3APIHelper.createName("BusinessEntity1", null));
        aBE.setCountryCode("AT");
        aBE.setGeographicalInformation("Vienna");
        aBC.addBusinessEntity(aBE);
        aBE = new PD3BusinessEntityType();
        aBE.addName(PD3APIHelper.createName("BusinessEntity2", null));
        aBE.setCountryCode("DE");
        aBE.setGeographicalInformation("Berlin");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC3ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        PD3BusinessCardType aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(2, aReadBC.getBusinessEntityCount());
        ISMPBusinessCard aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
        // Update BC - add entity
        aBE = new PD3BusinessEntityType();
        aBE.addName(PD3APIHelper.createName("BusinessEntity3", null));
        aBE.setCountryCode("SE");
        aBE.setGeographicalInformation("Stockholm");
        aBC.addBusinessEntity(aBE);
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).put(Entity.xml(m_aBC3ObjFactory.createBusinessCard(aBC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Get BC - must work (always V3)
        aReadBC = aTarget.path("businesscard").path(sPI).request().get(PD3BusinessCardType.class);
        assertNotNull(aReadBC);
        assertEquals(3, aReadBC.getBusinessEntityCount());
        aGetBC = aBCMgr.getSMPBusinessCardOfID(aPI);
        assertNotNull(aGetBC);
    } finally {
        // Delete Business Card
        aResponseMsg = _addCredentials(aTarget.path("businesscard").path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path("businesscard").path(sPI).request().get(), 404);
        assertNull(aBCMgr.getSMPBusinessCardOfID(aPI));
        // Delete service Group
        aResponseMsg = _addCredentials(aTarget.path(sPI).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // must be deleted
        _testResponseJerseyClient(aTarget.path(sPI).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI));
    }
}
Also used : Response(javax.ws.rs.core.Response) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) PD3BusinessCardType(com.helger.pd.businesscard.v3.PD3BusinessCardType) PD3BusinessEntityType(com.helger.pd.businesscard.v3.PD3BusinessEntityType) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 84 with IParticipantIdentifier

use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.

the class MainReadFromFilePeppol method main.

public static void main(final String[] args) throws Throwable {
    final SMPServerRESTTestRule aRule = new SMPServerRESTTestRule(ClassPathResource.getAsFile("test-smp-server-xml-peppol.properties").getAbsolutePath());
    aRule.before();
    try {
        final String sServerBasePath = aRule.getFullURL();
        final StopWatch aSWOverall = StopWatch.createdStarted();
        // These values must match the values in the test file
        final IParticipantIdentifier aParticipantID = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
        final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1");
        // Delete existing ServiceGroup (if exists)
        {
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("delete-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
            _testResponseJerseyClient(aResponseMsg, 200, 404);
        }
        {
            // Create a new ServiceGroup
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("create-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-service-group.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        {
            // Add endpoint
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).path("services").path(aDocTypeID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-service-metadata.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        {
            // Add Business Card
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path("businesscard").path(aParticipantID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-business-card-v3.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        aSWOverall.stop();
        LOGGER.info("Overall process took " + aSWOverall.getMillis() + " ms or " + aSWOverall.getDuration());
    } finally {
        aRule.after();
    }
}
Also used : Response(javax.ws.rs.core.Response) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) File(java.io.File) SMPServerRESTTestRule(com.helger.phoss.smp.mock.SMPServerRESTTestRule) StopWatch(com.helger.commons.timing.StopWatch) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 85 with IParticipantIdentifier

use of com.helger.peppolid.IParticipantIdentifier in project phoss-smp by phax.

the class RegistrationHookWriteToSMLTest method testCreateAndDelete.

@Test
@Ignore("Potentially modifies the DNS!")
public void testCreateAndDelete() throws RegistrationHookException {
    final RegistrationHookWriteToSML aHook = new RegistrationHookWriteToSML();
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("0088:12345test");
    aHook.createServiceGroup(aPI);
    aHook.deleteServiceGroup(aPI);
// Throws ExceptionInInitializerError:
// Happens when no keystore is present!
}
Also used : IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)218 Test (org.junit.Test)70 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)58 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)57 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)51 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)47 File (java.io.File)46 Nonnull (javax.annotation.Nonnull)43 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)42 Element (org.w3c.dom.Element)41 SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)40 AS4RawResponseConsumerWriteToFile (com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile)38 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)35 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)35 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)30 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)24 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)24 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)24 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)19 ICommonsList (com.helger.commons.collection.impl.ICommonsList)18