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.conversion;
18  
19  import org.hipparchus.linear.ArrayRealVector;
20  import org.junit.jupiter.api.BeforeAll;
21  import org.junit.jupiter.api.Test;
22  import org.mockito.Mockito;
23  import org.orekit.Utils;
24  import org.orekit.frames.Frame;
25  import org.orekit.frames.FramesFactory;
26  import org.orekit.orbits.KeplerianOrbit;
27  import org.orekit.orbits.PositionAngleType;
28  import org.orekit.propagation.Propagator;
29  import org.orekit.propagation.analytical.KeplerianPropagator;
30  import org.orekit.time.AbsoluteDate;
31  import org.orekit.utils.Constants;
32  import org.orekit.utils.ParameterDriver;
33  import org.orekit.utils.ParameterDriversList;
34  
35  /**
36   * Unit tests for {@link FiniteDifferencePropagatorConverter}.
37   *
38   * @author Evan Ward
39   */
40  public class FiniteDifferencePropagatorConverterTest {
41  
42      /** Set Orekit data . */
43      @BeforeAll
44      public static void setUp() {
45          Utils.setDataRoot("regular-data");
46      }
47  
48      /**
49       * Test case for bug #362. Check that scaling is only applied once.
50       */
51      @Test
52      public void testGetObjectiveFunctionParametersOnlyScaledOnce() {
53          // setup
54          // create some arbitrary sample data to run with
55          Frame eci = FramesFactory.getGCRF();
56          double gm = Constants.EIGEN5C_EARTH_MU;
57          AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
58          Propagator source = new KeplerianPropagator(new KeplerianOrbit(
59                  6878137, 0, 0, 0, 0, 0, PositionAngleType.TRUE, eci, date, gm));
60          // Create a mock builder that allows us to check the values passed to it
61          PropagatorBuilder builder = Mockito.mock(PropagatorBuilder.class);
62          ParameterDriversList list = new ParameterDriversList();
63          list.add(new ParameterDriver("p1", 0, 1e-3, Double.NEGATIVE_INFINITY,
64                  Double.POSITIVE_INFINITY));
65          Mockito.when(builder.getOrbitalParametersDrivers()).thenReturn(list);
66          Mockito.when(builder.getPropagationParametersDrivers())
67                  .thenReturn(new ParameterDriversList());
68          Mockito.when(builder.getFrame()).thenReturn(eci);
69          Mockito.when(builder.getSelectedNormalizedParameters()).thenReturn(new double[1]);
70          Mockito.when(builder.buildPropagator(Mockito.any(double[].class)))
71                  .thenReturn(source);
72          // subject under test
73          FiniteDifferencePropagatorConverter converter =
74                  new FiniteDifferencePropagatorConverter(builder, 1, 100);
75          // set some internal variables in FDPC that are not settable using another
76          // interface
77          converter.convert(source, 1, 2);
78          // Forget all the side effect of the call to convert()
79          Mockito.clearInvocations(builder);
80  
81          // action
82          converter.getModel().value(new ArrayRealVector(1));
83  
84          // verify
85          Mockito.verify(builder).buildPropagator(new double[]{0});
86          Mockito.verify(builder).buildPropagator(new double[]{1});
87      }
88  
89  }