diff --git a/xmlbeans/src/main/java/org/n52/svalbard/decode/AbstractCapabilitiesBaseTypeDecoder.java b/xmlbeans/src/main/java/org/n52/svalbard/decode/AbstractCapabilitiesBaseTypeDecoder.java index d0e871e31..1ff2773a0 100644 --- a/xmlbeans/src/main/java/org/n52/svalbard/decode/AbstractCapabilitiesBaseTypeDecoder.java +++ b/xmlbeans/src/main/java/org/n52/svalbard/decode/AbstractCapabilitiesBaseTypeDecoder.java @@ -325,6 +325,9 @@ private OwsOperationsMetadata parseOperationMetadata(OperationsMetadata operatio } private OwsServiceIdentification parseServiceIdentification(ServiceIdentification serviceIdentification) { + if (serviceIdentification == null) { + return null; + } OwsCode serviceType = parseCode(serviceIdentification.getServiceType()); Set serviceTypeVersion = Optional.ofNullable(serviceIdentification.getServiceTypeVersionArray()) .map(Arrays::stream).orElseGet(Stream::empty).collect(toSet()); diff --git a/xmlbeans/src/test/java/org/n52/svalbard/decode/AbstractCapabilitiesBaseTypeDecoderTest.java b/xmlbeans/src/test/java/org/n52/svalbard/decode/AbstractCapabilitiesBaseTypeDecoderTest.java new file mode 100644 index 000000000..ad8562fcc --- /dev/null +++ b/xmlbeans/src/test/java/org/n52/svalbard/decode/AbstractCapabilitiesBaseTypeDecoderTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016-2017 52°North Initiative for Geospatial Open Source + * Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.n52.svalbard.decode; + +import java.util.Set; + +import org.hamcrest.core.Is; +import org.junit.Assert; +import org.junit.Test; +import org.n52.shetland.ogc.ows.OwsCapabilities; +import org.n52.svalbard.decode.exception.DecodingException; + +import net.opengis.ows.x11.CapabilitiesBaseType; + +public class AbstractCapabilitiesBaseTypeDecoderTest { + + @Test + public void shouldNotThrowNullPointerExceptionWhenServiceIdentificationIsMissing() throws DecodingException { + AbstractCapabilitiesBaseTypeDecoder decoder = new TestSeam(); + CapabilitiesBaseType cbt = CapabilitiesBaseType.Factory.newInstance(); + cbt.setVersion("2.0.0"); + cbt.setUpdateSequence("nothing-to-see-here"); + Assert.assertThat(decoder.parseCapabilitiesBaseType("SOS", cbt).getServiceIdentification().isPresent(), Is.is(false)); + } + + private class TestSeam extends AbstractCapabilitiesBaseTypeDecoder { + + @Override + public OwsCapabilities decode(CapabilitiesBaseType objectToDecode) throws DecodingException { + return null; + } + + @Override + public Set getKeys() { + return null; + } + + } + +}