1   /* Contributed in the public domain.
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.propagation.events.handlers;
18  
19  import org.hipparchus.ode.events.Action;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.frames.Frame;
23  import org.orekit.frames.FramesFactory;
24  import org.orekit.orbits.KeplerianOrbit;
25  import org.orekit.orbits.Orbit;
26  import org.orekit.orbits.PositionAngleType;
27  import org.orekit.propagation.SpacecraftState;
28  import org.orekit.propagation.events.DateDetector;
29  import org.orekit.propagation.events.handlers.RecordAndContinue.Event;
30  import org.orekit.time.AbsoluteDate;
31  import org.orekit.utils.Constants;
32  
33  import java.util.List;
34  
35  /**
36   * Unit tests for {@link RecordAndContinue}.
37   *
38   * @author Evan Ward
39   */
40  public class RecordAndContinueTest {
41  
42      /**
43       * check add and clear behavior.
44       */
45      @Test
46      public void testGetEvents() {
47          // setup
48          RecordAndContinue handler = new RecordAndContinue();
49          AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
50          DateDetector detector = new DateDetector(date);
51          Frame eci = FramesFactory.getGCRF();
52          Orbit orbit = new KeplerianOrbit(6378137 + 500e3, 0, 0, 0, 0, 0,
53                  PositionAngleType.TRUE, eci, date, Constants.EIGEN5C_EARTH_MU);
54          SpacecraftState s1 = new SpacecraftState(orbit);
55          SpacecraftState s2 = s1.shiftedBy(-10);
56          SpacecraftState s3 = s2.shiftedBy(1);
57          SpacecraftState s4 = s3.shiftedBy(1);
58  
59          // actions
60          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s1, detector, true));
61          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s2, detector, true));
62          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s3, detector, false));
63  
64          // verify
65          List<Event> events = handler.getEvents();
66          Assertions.assertEquals(3, events.size());
67          Assertions.assertEquals(s1, events.get(0).getState());
68          Assertions.assertEquals(s2, events.get(1).getState());
69          Assertions.assertEquals(s3, events.get(2).getState());
70          Assertions.assertEquals(true, events.get(0).isIncreasing());
71          Assertions.assertEquals(true, events.get(1).isIncreasing());
72          Assertions.assertEquals(false, events.get(2).isIncreasing());
73          for (Event event : events) {
74              Assertions.assertEquals(detector, event.getDetector());
75          }
76  
77          // action: clear
78          handler.clear();
79  
80          // verify is empty
81          Assertions.assertEquals(0, handler.getEvents().size());
82  
83          // action add more
84          Assertions.assertEquals(Action.CONTINUE, handler.eventOccurred(s4, detector, false));
85  
86          // verify new events
87          events = handler.getEvents();
88          Assertions.assertEquals(1, events.size());
89          Assertions.assertEquals(s4, events.get(0).getState());
90          Assertions.assertEquals(false, events.get(0).isIncreasing());
91          Assertions.assertEquals(detector, events.get(0).getDetector());
92      }
93  
94  }