use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.
the class SMPClientTest method testCRUDServiceGroup.
@Test
public void testCRUDServiceGroup() throws SMPClientException {
final String sContent = "Test";
final String sElement = "TestElement";
final String sExtensionXML = "<" + sElement + ">" + sContent + "</" + sElement + ">";
final SMPClient aSMPClient = new SMPClient(SMP_URI);
final ServiceGroupType aServiceGroupCreate = aSMPClient.saveServiceGroup(MockSMPClientConfig.getParticipantID(), SMP_CREDENTIALS);
aServiceGroupCreate.setExtension(SMPExtensionConverter.convert(sExtensionXML));
aSMPClient.saveServiceGroup(aServiceGroupCreate, SMP_CREDENTIALS);
final ParticipantIdentifierType aServiceGroupID = aServiceGroupCreate.getParticipantIdentifier();
final ServiceGroupType aServiceGroupRead = aSMPClient.getServiceGroup(SimpleParticipantIdentifier.wrap(aServiceGroupID));
assertNotNull(aServiceGroupRead);
assertNotNull(aServiceGroupRead.getExtension());
assertNotNull(aServiceGroupRead.getExtension().getAny());
assertEquals(sContent, aServiceGroupRead.getExtension().getAny().getTextContent());
assertEquals(sElement, aServiceGroupRead.getExtension().getAny().getLocalName());
aSMPClient.deleteServiceGroup(MockSMPClientConfig.getParticipantID(), SMP_CREDENTIALS);
}
use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.
the class SMPClientWithDNSFuncTest method testGetByDNS.
@Test
public void testGetByDNS() throws Exception {
// Make sure that the dns exists.
final String sParticipantID = "0088:5798000000001";
final String sDocumentID = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::InvoiceDisputeDisputeInvoice##UBL-2.0";
final IParticipantIdentifier aServiceGroupID = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme(sParticipantID);
final IDocumentTypeIdentifier aDocumentTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme(sDocumentID);
final ServiceGroupType aGroup = SMPClientReadOnly.getServiceGroupByDNS(URL_PROVIDER, SML_INFO, aServiceGroupID);
assertNotNull(aGroup);
final SignedServiceMetadataType aMetadata = SMPClientReadOnly.getServiceRegistrationByDNS(URL_PROVIDER, SML_INFO, aServiceGroupID, aDocumentTypeID);
assertNotNull(aMetadata);
}
use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.
the class MainCheckIfSMPIsWorking method main.
public static void main(final String[] args) throws Exception {
final URI SMP_URI = MockSMPClientConfig.getSMPURI();
final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
// The main SMP client
final SMPClient aClient = new SMPClient(SMP_URI);
// Ensure that the service group does not exist
LOGGER.info("Ensuring that the service group is not existing!");
if (aClient.getServiceGroupOrNull(PARTICIPANT_ID) != null) {
LOGGER.info("Deleting existing service group for init");
aClient.deleteServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
LOGGER.info("Finished deletion of service group");
}
// Create, read and delete the service group
LOGGER.info("Creating the new service group");
aClient.saveServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
LOGGER.info("Retrieving the service group");
final ServiceGroupType aSGT = aClient.getServiceGroup(PARTICIPANT_ID);
if (!SimpleParticipantIdentifier.wrap(aSGT.getParticipantIdentifier()).equals(PARTICIPANT_ID))
throw new IllegalStateException("Participant identifiers are not equal!");
LOGGER.info("Deleting the service group again");
aClient.deleteServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
LOGGER.info("Checking if the service group is really deleted");
if (aClient.getServiceGroupOrNull(PARTICIPANT_ID) != null)
throw new IllegalStateException("Deletion of the service group failed!");
LOGGER.info("Seems like the SMP is working as expected!");
}
use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.
the class BDXRClient method saveServiceGroup.
/**
* Saves a service group. The meta data references should not be set and are
* not used.
*
* @param aParticipantID
* The participant identifier for which the service group is to save.
* @param aCredentials
* The user name and password to use as credentials.
* @return The created {@link ServiceGroupType} object.
* @throws SMPClientException
* in case something goes wrong
* @throws SMPClientUnauthorizedException
* The user name or password was not correct.
* @throws SMPClientNotFoundException
* A HTTP Not Found was received. This can happen if the service was
* not found.
* @throws SMPClientBadRequestException
* The request was not well formed.
*/
@Nonnull
public ServiceGroupType saveServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notNull(aCredentials, "Credentials");
final ServiceGroupType aServiceGroup = new ServiceGroupType();
// Explicit constructor call is needed here!
aServiceGroup.setParticipantIdentifier(new BDXR1ParticipantIdentifier(aParticipantID));
// Mandatory element, but can be empty
aServiceGroup.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
saveServiceGroup(aServiceGroup, aCredentials);
return aServiceGroup;
}
use of com.helger.xsds.bdxr.smp2.ServiceGroupType in project peppol-commons by phax.
the class SMPClient method saveServiceGroup.
/**
* Saves a service group. The meta data references should not be set and are
* not used.
*
* @param aParticipantID
* The participant identifier for which the service group is to save.
* @param aCredentials
* The user name and password to use as credentials.
* @return The created {@link ServiceGroupType} object.
* @throws SMPClientException
* in case something goes wrong
* @throws SMPClientUnauthorizedException
* The user name or password was not correct.
* @throws SMPClientNotFoundException
* A HTTP Not Found was received. This can happen if the service was
* not found.
* @throws SMPClientBadRequestException
* The request was not well formed.
*/
@Nonnull
public ServiceGroupType saveServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notNull(aCredentials, "Credentials");
final ServiceGroupType aServiceGroup = new ServiceGroupType();
// Explicit constructor call is needed here!
aServiceGroup.setParticipantIdentifier(new SimpleParticipantIdentifier(aParticipantID));
// Mandatory element, but can be empty
aServiceGroup.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
saveServiceGroup(aServiceGroup, aCredentials);
return aServiceGroup;
}
Aggregations