Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit d46392d7 authored by Pawel GUTOWSKI's avatar Pawel GUTOWSKI
Browse files

EDELIVERY-1856 Added ServiceGroup references validation

parent 910629cf
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ import eu.europa.ec.edelivery.smp.error.exceptions.BadRequestException;
import eu.europa.ec.smp.api.Identifiers;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceMetadataReferenceCollectionType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
......@@ -24,6 +25,7 @@ import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import static eu.europa.ec.edelivery.smp.error.ErrorBusinessCode.WRONG_FIELD;
import static org.springframework.util.CollectionUtils.isEmpty;
/**
......@@ -55,6 +57,11 @@ public class ServiceGroupValidator {
if (!schemaPattern.matcher(scheme).matches()) {
throw new BadRequestException(WRONG_FIELD, "Service Group scheme does not match allowed pattern: " + schemaPattern.pattern());
}
ServiceMetadataReferenceCollectionType references = serviceGroup.getServiceMetadataReferenceCollection();
if (references != null && !isEmpty(references.getServiceMetadataReferences())) {
throw new BadRequestException(WRONG_FIELD, "ServiceMetadataReferenceCollection must be empty");
}
}
}
......@@ -18,8 +18,11 @@ import org.junit.Before;
import org.junit.Test;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceGroup;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceMetadataReferenceCollectionType;
import org.oasis_open.docs.bdxr.ns.smp._2016._05.ServiceMetadataReferenceType;
import static eu.europa.ec.smp.api.Identifiers.asString;
import static java.util.Arrays.asList;
/**
* Created by gutowpa on 02/08/2017.
......@@ -68,4 +71,19 @@ public class ServiceGroupValidatorTest {
validator.validate(asString(id), sg);
}
@Test(expected = BadRequestException.class)
public void testServiceGroupWithReference() throws Throwable {
//given
ServiceMetadataReferenceType ref = new ServiceMetadataReferenceType("http://poland.pl");
ServiceMetadataReferenceCollectionType references = new ServiceMetadataReferenceCollectionType(asList(ref));
ParticipantIdentifierType id = new ParticipantIdentifierType("urn:poland:ncpb", "correct-scheme-ok");
ServiceGroup sg = new ServiceGroup();
sg.setServiceMetadataReferenceCollection(references);
sg.setParticipantIdentifier(id);
//when-then
validator.validate(asString(id), sg);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment