content: /*
   * Copyright (C) 2012-2023 52°North Spatial Information Research GmbH
   *
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 as published
   * by the Free Software Foundation.
   *
   * If the program is linked with libraries which are licensed under one of
   * the following licenses, the combination of the program with the linked
   * library is not considered a "derivative work" of the program:
   *
   *     - Apache License, version 2.0
   *     - Apache Software License, version 1.0
   *     - GNU Lesser General Public License, version 3
   *     - Mozilla Public License, versions 1.0, 1.1 and 2.0
   *     - Common Development and Distribution License (CDDL), version 1.0
   *
   * Therefore the distribution of the program linked with libraries licensed
   * under the aforementioned licenses, is permitted by the copyright holders
   * if the distribution is compliant with both the GNU General Public
   * License version 2 and the aforementioned licenses.
   *
   * This program is distributed in the hope that it will be useful, but
   * WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
   * Public License for more details.
   */
  package org.n52.sos.decode.kvp;
  
  import java.util.Collections;
  import java.util.List;
  
  import org.hamcrest.MatcherAssert;
  import org.hamcrest.Matchers;
  import org.junit.Test;
  import org.n52.shetland.ogc.filter.FilterConstants.TimeOperator;
  import org.n52.shetland.ogc.filter.FilterConstants.TimeOperator2;
  import org.n52.shetland.ogc.filter.TemporalFilter;
  import org.n52.shetland.ogc.ows.service.OwsServiceRequest;
  import org.n52.shetland.ogc.sos.Sos1Constants;
  import org.n52.shetland.ogc.sos.Sos2Constants;
  import org.n52.svalbard.decode.exception.DecodingException;
  
  import com.google.common.collect.Lists;
  
  public abstract class AbstractKvpDecoderTest extends AbstractSosKvpDecoder<OwsServiceRequest> {
  
      private static final String START_TIME = "2012-11-19T14:00:00+01:00";
  
      private static final String END_TIME = "2012-11-19T14:15:00+01:00";
  
      private static final String START_END_TIME = "2012-11-19T14:15:00+01:00/" + END_TIME;
  
      private static final String OM_PHENOMENON_TIME = "om:phenomenonTime";
  
      public AbstractKvpDecoderTest() {
          super(() -> null, Collections.emptySet());
      }
  
      /*
       * two parameter
       */
  
      @Test
      public void should_decode_eventTime_TM_Equals_2_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, START_TIME)), TimeOperator.TM_Equals);
      }
  
      @Test
      public void should_decode_eventTime_TM_During_2_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, START_END_TIME)), TimeOperator.TM_During);
      }
  
      /*
       * three parameter
       */
      @Test
      public void should_decode_eventTime_TM_After_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_After.name(), START_TIME)),
                  TimeOperator.TM_After);
      }
  
      @Test
      public void should_decode_eventTime_TM_Before_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_Before.name(), START_TIME)),
                  TimeOperator.TM_Before);
      }
  
      @Test
      public void should_decode_eventTime_TM_Begins_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_Begins.name(), START_TIME)),
                  TimeOperator.TM_Begins);
      }
  
      @Test
      public void should_decode_eventTime_TM_BegunBy_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_BegunBy.name(), START_TIME)),
                  TimeOperator.TM_BegunBy);
      }
  
      @Test
      public void should_decode_eventTime_TM_Contains_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_Contains.name(), START_TIME)),
                  TimeOperator.TM_Contains);
      }
  
      @Test
      public void should_decode_eventTime_TM_During_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_During.name(), START_END_TIME)),
                  TimeOperator.TM_During);
      }
  
      @Test
      public void should_decode_eventTime_TM_EndedBy_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_EndedBy.name(), START_TIME)),
                  TimeOperator.TM_EndedBy);
      }
  
      @Test
      public void should_decode_eventTime_TM_Ends_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_Ends.name(), START_TIME)),
                  TimeOperator.TM_Ends);
      }
  
      @Test
      public void should_decode_eventTime_TM_Equals_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_Equals.name(), START_TIME)),
                  TimeOperator.TM_Equals);
      }
  
      @Test
      public void should_decode_eventTime_TM_Meets_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_Meets.name(), START_TIME)),
                  TimeOperator.TM_Meets);
      }
  
      @Test
      public void should_decode_eventTime_TM_MetBy_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_MetBy.name(), START_TIME)),
                  TimeOperator.TM_MetBy);
      }
  
      @Test
      public void should_decode_eventTime_TM_OverlappedBy_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_OverlappedBy.name(), START_TIME)),
                  TimeOperator.TM_OverlappedBy);
      }
  
      @Test
      public void should_decode_eventTime_TM_Overlaps_3_Param() throws DecodingException {
          check(parseEventTime(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator.TM_Overlaps.name(), START_TIME)),
                  TimeOperator.TM_Overlaps);
      }
  
      /*
       * SOS 2.0 tests
       */
  
      /*
       * three parameter
       */
  
      @Test
      public void should_decode_temporalFilter_After_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.After.name(), START_TIME)),
                  TimeOperator.TM_After);
      }
  
      @Test
      public void should_decode_temporalFilter_Before_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.Before.name(), START_TIME)),
                  TimeOperator.TM_Before);
      }
  
      @Test
      public void should_decode_temporalFilter_Begins_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.Begins.name(), START_TIME)),
                  TimeOperator.TM_Begins);
      }
  
      @Test
      public void should_decode_temporalFilter_BegunBy_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.BegunBy.name(), START_TIME)),
                  TimeOperator.TM_BegunBy);
      }
  
      @Test
      public void should_decode_temporalFilter_TContains_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.TContains.name(), START_TIME)),
                  TimeOperator.TM_Contains);
      }
  
      @Test
      public void should_decode_temporalFilter_During_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.During.name(), START_END_TIME)),
                  TimeOperator.TM_During);
      }
  
      @Test
      public void should_decode_temporalFilter_EndedBy_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.EndedBy.name(), START_TIME)),
                  TimeOperator.TM_EndedBy);
      }
  
      @Test
      public void should_decode_temporalFilter_Ends_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.Ends.name(), START_TIME)),
                  TimeOperator.TM_Ends);
      }
  
      @Test
      public void should_decode_temporalFilter_TEquals_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.TEquals.name(), START_TIME)),
                  TimeOperator.TM_Equals);
      }
  
      @Test
      public void should_decode_temporalFilter_Meets_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.Meets.name(), START_TIME)),
                  TimeOperator.TM_Meets);
      }
  
      @Test
      public void should_decode_temporalFilter_MetBy_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.MetBy.name(), START_TIME)),
                  TimeOperator.TM_MetBy);
      }
  
      @Test
      public void should_decode_temporalFilter_OverlappedBy_3_Param() throws DecodingException {
          check(parseTemporalFilter(
                  Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.OverlappedBy.name(), START_TIME)),
                  TimeOperator.TM_OverlappedBy);
      }
  
      @Test
      public void should_decode_temporalFilter_TOverlaps_3_Param() throws DecodingException {
          check(parseTemporalFilter(Lists.newArrayList(OM_PHENOMENON_TIME, TimeOperator2.TOverlaps.name(), START_TIME)),
                  TimeOperator.TM_Overlaps);
      }
  
      private List<TemporalFilter> parseEventTime(List<String> parameterValues) throws DecodingException {
          return Collections.singletonList(
                  decodeTemporalFilter(Sos1Constants.GetObservationParams.eventTime.name(), parameterValues));
      }
  
      private List<TemporalFilter> parseTemporalFilter(List<String> parameterValues) throws DecodingException {
          return Collections.singletonList(
                  decodeTemporalFilter(Sos2Constants.GetObservationParams.temporalFilter.name(), parameterValues));
      }
  
      private void check(List<TemporalFilter> parseEventTime, TimeOperator operator) {
          for (TemporalFilter temporalFilter : parseEventTime) {
              MatcherAssert.assertThat(temporalFilter.getOperator().name(), Matchers.is(operator.name()));
          }
      }
  
  }
  