use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.
the class PeppolDocumentTypeIdentifierTest method testValue.
@Test
public void testValue() throws Exception {
final IIdentifierFactory aIF = PeppolIdentifierFactory.INSTANCE;
final String documentIdAsText = "urn:oasis:names:specification:ubl:schema:xsd:ApplicationResponse-2::ApplicationResponse##urn:www.cenbii.eu:transaction:biicoretrdm057:ver1.0:#urn:www.peppol.eu:bis:peppol1a:ver1.0::2.0";
final IDocumentTypeIdentifier documentTypeIdentifier = aIF.createDocumentTypeIdentifierWithDefaultScheme(documentIdAsText);
assertEquals(documentTypeIdentifier.getValue(), documentIdAsText);
assertTrue(documentTypeIdentifier.hasValue(documentIdAsText));
}
use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.
the class PeppolSBDHDocumentWriterTest method testBadCase.
@Test
public void testBadCase() {
final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
final PeppolSBDHDocument aData = new PeppolSBDHDocument(aIF);
try {
// Not all fields are set
new PeppolSBDHDocumentWriter().createStandardBusinessDocument(aData);
fail();
} catch (final IllegalArgumentException ex) {
// Expected
}
}
use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.
the class PeppolSBDHDocumentTest method testText.
@Test
public void testText() {
final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
final PeppolSBDHDocument dd = new PeppolSBDHDocument(aIF);
dd.setBusinessMessageTextOnly("abc", CMimeType.APPLICATION_OCTET_STREAM);
assertNotNull(dd.getBusinessMessage());
assertEquals("<TextContent xmlns=\"http://peppol.eu/xsd/ticc/envelope/1.0\" mimeType=\"application/octet-stream\">abc</TextContent>", XMLWriter.getNodeAsString(dd.getBusinessMessage()).trim());
final TextContentType aTC = dd.getBusinessMessageAsTextContent();
assertNotNull(aTC);
assertEquals("abc", aTC.getValue());
assertEquals(CMimeType.APPLICATION_OCTET_STREAM.getAsString(), aTC.getMimeType());
assertNull(dd.getBusinessMessageAsBinaryContent());
}
use of com.helger.peppolid.factory.IIdentifierFactory in project peppol-commons by phax.
the class PeppolSBDHDocumentTest method testBasic.
@Test
public void testBasic() {
final IIdentifierFactory aIF = SimpleIdentifierFactory.INSTANCE;
final PeppolSBDHDocument dd = new PeppolSBDHDocument(aIF);
assertNull(dd.getSenderScheme());
assertNull(dd.getSenderValue());
assertNull(dd.getReceiverScheme());
assertNull(dd.getReceiverValue());
assertNull(dd.getDocumentTypeScheme());
assertNull(dd.getDocumentTypeValue());
assertNull(dd.getProcessScheme());
assertNull(dd.getProcessValue());
assertNull(dd.getStandard());
assertNull(dd.getTypeVersion());
assertNull(dd.getType());
assertNull(dd.getInstanceIdentifier());
assertNull(dd.getCreationDateAndTime());
assertFalse(dd.hasBusinessMessage());
assertNull(dd.getBusinessMessage());
assertEquals(0, dd.additionalAttributes().size());
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF));
assertNotNull(dd.getSenderAsIdentifier());
assertNotNull(dd.getReceiverAsIdentifier());
assertNotNull(dd.getDocumentTypeAsIdentifier());
assertNotNull(dd.getProcessAsIdentifier());
assertFalse(dd.areAllFieldsSet());
assertTrue(dd.areAllAdditionalAttributesValid());
// Sender
dd.setSenderWithDefaultScheme("abc");
assertEquals(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, dd.getSenderScheme());
assertEquals("abc", dd.getSenderValue());
CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSender("scheme", "abc"));
CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF));
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc"));
// Receiver
dd.setReceiverWithDefaultScheme("def");
assertEquals(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, dd.getReceiverScheme());
assertEquals("def", dd.getReceiverValue());
CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc"));
CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiver("scheme", "def"));
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def"));
// Document type 1
dd.setDocumentTypeWithBusdoxDocidQns("doctype");
assertEquals(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, dd.getDocumentTypeScheme());
assertEquals("doctype", dd.getDocumentTypeValue());
CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithBusdoxDocidQns("other"));
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithBusdoxDocidQns("doctype"));
// Document type 2
dd.setDocumentTypeWithPeppolDoctypeWildcard("doctype");
assertEquals(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_PEPPOL_DOCTYPE_WILDCARD, dd.getDocumentTypeScheme());
assertEquals("doctype", dd.getDocumentTypeValue());
CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("other"));
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("doctype"));
// Process type
dd.setProcessWithDefaultScheme("proctype");
assertEquals(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, dd.getProcessScheme());
assertEquals("proctype", dd.getProcessValue());
CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("doctype").setProcessWithDefaultScheme("other"));
CommonsTestHelper.testDefaultImplementationWithEqualContentObject(dd, new PeppolSBDHDocument(aIF).setSenderWithDefaultScheme("abc").setReceiverWithDefaultScheme("def").setDocumentTypeWithPeppolDoctypeWildcard("doctype").setProcessWithDefaultScheme("proctype"));
}
use of com.helger.peppolid.factory.IIdentifierFactory in project phoss-smp by phax.
the class SMPServerAPI method getCompleteServiceGroup.
@Nonnull
public CompleteServiceGroupType getCompleteServiceGroup(final String sPathServiceGroupID) throws SMPServerException {
final String sLog = LOG_PREFIX + "GET /complete/" + sPathServiceGroupID;
final String sAction = "getCompleteServiceGroup";
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog);
STATS_COUNTER_INVOCATION.increment(sAction);
try {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
if (aPathServiceGroupID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
}
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
if (aServiceGroup == null) {
// No such service group
throw new SMPNotFoundException("Unknown Service Group ID '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
}
// Then add the service metadata references
final ServiceMetadataReferenceCollectionType aRefCollection = new ServiceMetadataReferenceCollectionType();
for (final IDocumentTypeIdentifier aDocTypeID : aServiceInfoMgr.getAllSMPDocumentTypesOfServiceGroup(aServiceGroup)) {
// Ignore all service information without endpoints
final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDocTypeID);
if (aServiceInfo != null && aServiceInfo.getTotalEndpointCount() > 0) {
final ServiceMetadataReferenceType aMetadataReference = new ServiceMetadataReferenceType();
aMetadataReference.setHref(m_aAPIDataProvider.getServiceMetadataReferenceHref(aPathServiceGroupID, aDocTypeID));
aRefCollection.addServiceMetadataReference(aMetadataReference);
}
}
final ServiceGroupType aSG = aServiceGroup.getAsJAXBObjectPeppol();
aSG.setServiceMetadataReferenceCollection(aRefCollection);
// a CompleteSG may be empty
final CompleteServiceGroupType aCompleteServiceGroup = new CompleteServiceGroupType();
aCompleteServiceGroup.setServiceGroup(aSG);
for (final ISMPServiceInformation aServiceInfo : aServiceInfoMgr.getAllSMPServiceInformationOfServiceGroup(aServiceGroup)) {
final ServiceMetadataType aSM = aServiceInfo.getAsJAXBObjectPeppol();
if (aSM != null)
aCompleteServiceGroup.addServiceMetadata(aSM);
}
if (LOGGER.isInfoEnabled())
LOGGER.info(sLog + " SUCCESS");
STATS_COUNTER_SUCCESS.increment(sAction);
return aCompleteServiceGroup;
} catch (final SMPServerException ex) {
if (LOGGER.isWarnEnabled())
LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
STATS_COUNTER_ERROR.increment(sAction);
throw ex;
}
}
Aggregations