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 java.util.List;
20  
21  import org.hipparchus.ode.events.Action;
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.orekit.frames.Frame;
25  import org.orekit.frames.FramesFactory;
26  import org.orekit.orbits.KeplerianOrbit;
27  import org.orekit.orbits.Orbit;
28  import org.orekit.orbits.PositionAngle;
29  import org.orekit.propagation.SpacecraftState;
30  import org.orekit.propagation.events.DateDetector;
31  import org.orekit.propagation.events.handlers.RecordAndContinue.Event;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.utils.Constants;
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<DateDetector> handler =
49                  new RecordAndContinue<DateDetector>();
50          AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
51          DateDetector detector = new DateDetector(date);
52          Frame eci = FramesFactory.getGCRF();
53          Orbit orbit = new KeplerianOrbit(6378137 + 500e3, 0, 0, 0, 0, 0,
54                  PositionAngle.TRUE, eci, date, Constants.EIGEN5C_EARTH_MU);
55          SpacecraftState s1 = new SpacecraftState(orbit);
56          SpacecraftState s2 = s1.shiftedBy(-10);
57          SpacecraftState s3 = s2.shiftedBy(1);
58          SpacecraftState s4 = s3.shiftedBy(1);
59  
60          // actions
61          Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s1, detector, true));
62          Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s2, detector, true));
63          Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s3, detector, false));
64  
65          // verify
66          List<Event<DateDetector>> events = handler.getEvents();
67          Assert.assertEquals(3, events.size());
68          Assert.assertEquals(s1, events.get(0).getState());
69          Assert.assertEquals(s2, events.get(1).getState());
70          Assert.assertEquals(s3, events.get(2).getState());
71          Assert.assertEquals(true, events.get(0).isIncreasing());
72          Assert.assertEquals(true, events.get(1).isIncreasing());
73          Assert.assertEquals(false, events.get(2).isIncreasing());
74          for (Event<DateDetector> event : events) {
75              Assert.assertEquals(detector, event.getDetector());
76          }
77  
78          // action: clear
79          handler.clear();
80  
81          // verify is empty
82          Assert.assertEquals(0, handler.getEvents().size());
83  
84          // action add more
85          Assert.assertEquals(Action.CONTINUE, handler.eventOccurred(s4, detector, false));
86  
87          // verify new events
88          events = handler.getEvents();
89          Assert.assertEquals(1, events.size());
90          Assert.assertEquals(s4, events.get(0).getState());
91          Assert.assertEquals(false, events.get(0).isIncreasing());
92          Assert.assertEquals(detector, events.get(0).getDetector());
93      }
94  
95  }