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  
18  package org.orekit.propagation.conversion;
19  
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.DisplayName;
23  import org.junit.jupiter.api.Test;
24  import org.mockito.Mockito;
25  import org.orekit.attitudes.AttitudeProvider;
26  import org.orekit.frames.Frame;
27  import org.orekit.frames.FramesFactory;
28  import org.orekit.orbits.CartesianOrbit;
29  import org.orekit.orbits.Orbit;
30  import org.orekit.propagation.SpacecraftState;
31  import org.orekit.propagation.SpacecraftStateInterpolator;
32  import org.orekit.propagation.analytical.Ephemeris;
33  import org.orekit.time.AbsoluteDate;
34  import org.orekit.time.TimeInterpolator;
35  import org.orekit.utils.Constants;
36  import org.orekit.utils.PVCoordinates;
37  
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  import static org.orekit.propagation.conversion.AbstractPropagatorBuilderTest.assertPropagatorBuilderIsACopy;
42  
43  /**
44   * Unit tests for {@link EphemerisPropagatorBuilder}.
45   *
46   * @author Vincent Cucchietti
47   */
48  public class EphemerisPropagatorBuilderTest {
49      @Test
50      @DisplayName("Test buildPropagator method")
51      void should_create_expected_propagator() {
52  
53          // Given
54          final Orbit orbit = new CartesianOrbit(new PVCoordinates(
55                  new Vector3D(Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS + 400000, 0, 0),
56                  new Vector3D(0, 7668.6, 0)), FramesFactory.getGCRF(), new AbsoluteDate(),
57                                                 Constants.EIGEN5C_EARTH_MU);
58          final List<SpacecraftState> states = new ArrayList<>();
59          states.add(new SpacecraftState(orbit));
60          states.add(new SpacecraftState(orbit.shiftedBy(1)));
61  
62          final Frame                             frame             = FramesFactory.getGCRF();
63          final TimeInterpolator<SpacecraftState> stateInterpolator = new SpacecraftStateInterpolator(frame);
64  
65          final EphemerisPropagatorBuilder builder =
66                  new EphemerisPropagatorBuilder(states, stateInterpolator);
67  
68          // When
69          final Ephemeris builtPropagator = (Ephemeris) builder.buildPropagator(builder.getSelectedNormalizedParameters());
70  
71          // Then
72          final Ephemeris expectedPropagator = new Ephemeris(states, stateInterpolator);
73  
74          Assertions.assertEquals(expectedPropagator.getFrame(), builtPropagator.getFrame());
75          Assertions.assertEquals(expectedPropagator.getMinDate(), builtPropagator.getMinDate());
76          Assertions.assertEquals(expectedPropagator.getMaxDate(), builtPropagator.getMaxDate());
77  
78          Assertions.assertArrayEquals(expectedPropagator.getManagedAdditionalStates(),
79                                       builtPropagator.getManagedAdditionalStates());
80          // Initial state has also been verified to be equal between both ephemeris (except for the Attitude which is expected
81          // to have different memory address)
82      }
83  
84      @Test
85      @DisplayName("Test copy method")
86      void testCopyMethod() {
87  
88          // Given
89          final Orbit orbit = new CartesianOrbit(new PVCoordinates(
90                  new Vector3D(Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS + 400000, 0, 0),
91                  new Vector3D(0, 7668.6, 0)), FramesFactory.getGCRF(),
92                                                 new AbsoluteDate(), Constants.EIGEN5C_EARTH_MU);
93          final List<SpacecraftState> states = new ArrayList<>();
94          states.add(new SpacecraftState(orbit));
95          states.add(new SpacecraftState(orbit));
96  
97          final Frame                             frame             = FramesFactory.getGCRF();
98          final TimeInterpolator<SpacecraftState> stateInterpolator = new SpacecraftStateInterpolator(frame);
99          final AttitudeProvider                  attitudeProvider  = Mockito.mock(AttitudeProvider.class);
100 
101         final EphemerisPropagatorBuilder builder =
102                 new EphemerisPropagatorBuilder(states, stateInterpolator, attitudeProvider);
103 
104         // When
105         final EphemerisPropagatorBuilder copyBuilder = builder.copy();
106 
107         // Then
108         assertPropagatorBuilderIsACopy(builder, copyBuilder);
109     }
110 }