PeppolIdentifierFactory implements IIdentifierFactory { @Override public boolean isParticipantIdentifierValueValid (@Nullable final String sValue) { if (sValue == null) return false; final int nLength = sValue.length (); if (nLength == 0 || nLength > PeppolIdentifierHelper.MAX_PARTICIPANT_VALUE_LENGTH) return false; if (false) if (sValue.indexOf (':') < 0) return false; return PeppolIdentifierHelper.areCharsetChecksDisabled () || StandardCharsets.US_ASCII.newEncoder ().canEncode (sValue); } PeppolIdentifierFactory(); @Override boolean isDocumentTypeIdentifierSchemeMandatory(); @Nonnull @Override String getDefaultDocumentTypeIdentifierScheme(); @Override boolean isDocumentTypeIdentifierSchemeValid(@Nullable final String sScheme); @Override boolean isDocumentTypeIdentifierValueValid(@Nullable final String sValue); @Nullable @Override PeppolDocumentTypeIdentifier createDocumentTypeIdentifierWithDefaultScheme(@Nullable final String sValue); @Nullable PeppolDocumentTypeIdentifier createDocumentTypeIdentifier(@Nullable final String sScheme, @Nullable final String sValue); @Override boolean isParticipantIdentifierSchemeMandatory(); @Nonnull @Override String getDefaultParticipantIdentifierScheme(); @Override boolean isParticipantIdentifierCaseInsensitive(@Nullable final String sScheme); @Override boolean isParticipantIdentifierSchemeValid(@Nullable final String sScheme); @Override boolean isParticipantIdentifierValueValid(@Nullable final String sValue); @Nullable @Override PeppolParticipantIdentifier createParticipantIdentifierWithDefaultScheme(@Nullable final String sValue); @Nullable PeppolParticipantIdentifier createParticipantIdentifier(@Nullable final String sScheme, @Nullable final String sValue); @Nonnull @Override String getDefaultProcessIdentifierScheme(); @Override boolean isProcessIdentifierSchemeValid(@Nullable final String sScheme); @Override boolean isProcessIdentifierValueValid(@Nullable final String sValue); @Nullable @Override PeppolProcessIdentifier createProcessIdentifierWithDefaultScheme(@Nullable final String sValue); @Nullable PeppolProcessIdentifier createProcessIdentifier(@Nullable final String sScheme, @Nullable final String sValue); @Override String toString(); static final PeppolIdentifierFactory INSTANCE; }
@Test public void testIsValidParticipantIdentifierValue () { assertFalse (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid (null)); assertFalse (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("9908:976098897")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("9908:976098897 ")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("990:976098897")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("990976098897")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("9909:976098896")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("9908:976098896")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("9956:DE:EPROC:BMIEVG:BeschA")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid ("9906:02419170044_01")); assertTrue (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid (VALUE_MAX_LENGTH)); assertFalse (PeppolIdentifierFactory.INSTANCE.isParticipantIdentifierValueValid (VALUE_MAX_LENGTH_PLUS_1)); }