use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteServiceInformationSMPClient.
@Test
public void testCreateAndDeleteServiceInformationSMPClient() throws SMPClientException {
// Lower case
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
// Upper case
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
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/as2"));
aEndpoint.setRequireBusinessLevelSignature(false);
aEndpoint.setCertificate("blacert");
aEndpoint.setServiceDescription("Unit test service");
aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
aSEL.addEndpoint(aEndpoint);
aProcess.setServiceEndpointList(aSEL);
aPL.addProcess(aProcess);
aSI.setProcessList(aPL);
}
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aSIMgr = SMPMetaManager.getServiceInformationMgr();
final SMPClient aSMPClient = new MockSMPClient();
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
try {
// PUT ServiceGroup
aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
// Read both
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
assertNotNull(aServiceGroup);
final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
assertEquals(aServiceGroup, aServiceGroup_UC);
try {
// PUT 1 ServiceInformation
aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// PUT 2 ServiceInformation
aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 ServiceInformation
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 ServiceInformation
try {
aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aSMPClient.getServiceGroup(aPI_LC));
} finally {
// DELETE ServiceGroup
try {
aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
} catch (final SMPClientNotFoundException ex) {
// Expected
}
assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.
the class ServiceMetadataInterfaceTest method testCreateAndDeleteRedirectJerseyClient.
@Test
public void testCreateAndDeleteRedirectJerseyClient() {
// Lower case
final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
final String sPI_LC = aPI_LC.getURIEncoded();
// Upper case
final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
final String sPI_UC = aPI_UC.getURIEncoded();
final IDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
final String sDT = aDT.getURIEncoded();
final ServiceGroupType aSG = new ServiceGroupType();
aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
final ServiceMetadataType aSM = new ServiceMetadataType();
aSM.setRedirect(_createRedirect());
final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPRedirectManager aSRMgr = SMPMetaManager.getRedirectMgr();
final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
Response aResponseMsg;
_testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
_testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
try {
// PUT ServiceGroup
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG)));
_testResponseJerseyClient(aResponseMsg, 200);
assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
assertNotNull(aTarget.path(sPI_UC).request().get(ServiceGroupType.class));
final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
assertNotNull(aServiceGroup);
final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
assertEquals(aServiceGroup, aServiceGroup_UC);
try {
// PUT 1 ServiceInformation
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).put(Entity.xml(m_aObjFactory.createServiceMetadata(aSM)));
_testResponseJerseyClient(aResponseMsg, 200);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// PUT 2 ServiceInformation
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).put(Entity.xml(m_aObjFactory.createServiceMetadata(aSM)));
_testResponseJerseyClient(aResponseMsg, 200);
assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
// DELETE 1 Redirect
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200);
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
} finally {
// DELETE 2 Redirect
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).path("services").path(sDT).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
}
assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
} finally {
// DELETE ServiceGroup
aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
_testResponseJerseyClient(aResponseMsg, 200, 404);
_testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
_testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
}
}
use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.
the class SMPParticipantMigrationMicroTypeConverter method convertToNative.
@Nonnull
@ContainsSoftMigration
public SMPParticipantMigration convertToNative(@Nonnull final IMicroElement aElement) {
final String sID = aElement.getAttributeValue(ATTR_ID);
final String sDirection = aElement.getAttributeValue(ATTR_DIRECTION);
final EParticipantMigrationDirection eDirection = EParticipantMigrationDirection.getFromIDOrNull(sDirection);
if (eDirection == null)
throw new IllegalStateException("Failed to resolve Participant Migration Direction with ID '" + sDirection + "'");
String sState = aElement.getAttributeValue(ATTR_STATE);
if (sState == null) {
// Migration
sState = EParticipantMigrationState.IN_PROGRESS.getID();
}
final EParticipantMigrationState eState = EParticipantMigrationState.getFromIDOrNull(sState);
if (eState == null)
throw new IllegalStateException("Failed to resolve Participant Migration State with ID '" + sState + "'");
final SimpleParticipantIdentifier aParticipantID = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_PARTICIPANT_IDENTIFIER), SimpleParticipantIdentifier.class);
final LocalDateTime aInitiationDT = aElement.getAttributeValueWithConversion(ATTR_INITIATION_DATETIME, LocalDateTime.class);
final String sMigrationKey = aElement.getAttributeValue(ATTR_MIGRATION_KEY);
return new SMPParticipantMigration(sID, eDirection, eState, aParticipantID, aInitiationDT, sMigrationKey);
}
use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.
the class SMPServiceGroup method getAsJAXBObjectPeppol.
@Nonnull
public com.helger.xsds.peppol.smp1.ServiceGroupType getAsJAXBObjectPeppol() {
final com.helger.xsds.peppol.smp1.ServiceGroupType ret = new com.helger.xsds.peppol.smp1.ServiceGroupType();
// Explicit constructor call is needed here!
ret.setParticipantIdentifier(new SimpleParticipantIdentifier(m_aParticipantIdentifier));
if (false) {
// This is set by the REST server
ret.setServiceMetadataReferenceCollection(null);
}
ret.setExtension(getAsPeppolExtension());
return ret;
}
use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.
the class SMPServiceGroupMicroTypeConverter method convertToNative.
@Nonnull
public static SMPServiceGroup convertToNative(@Nonnull final IMicroElement aElement, @Nonnull final Function<String, IUser> aOwningUserProvider) {
final String sOwnerID = aElement.getAttributeValue(ATTR_OWNER_ID);
final IUser aOwner = aOwningUserProvider.apply(sOwnerID);
if (aOwner == null)
throw new IllegalStateException("Failed to resolve user ID '" + sOwnerID + "'");
final SimpleParticipantIdentifier aParticipantIdentifier = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_PARTICIPANT_ID), SimpleParticipantIdentifier.class);
if (aParticipantIdentifier == null)
throw new IllegalStateException("Failed to parse participant identifier " + MicroHelper.getChildTextContent(aElement, ELEMENT_PARTICIPANT_ID));
final String sExtension = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_EXTENSION);
// Use the new ID in case the ID was changed!
return new SMPServiceGroup(aOwner.getID(), aParticipantIdentifier, sExtension);
}
Aggregations