1   /* Copyright 2002-2022 CS GROUP
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.frames;
18  
19  
20  import java.io.ByteArrayInputStream;
21  import java.io.ByteArrayOutputStream;
22  import java.io.IOException;
23  import java.io.ObjectInputStream;
24  import java.io.ObjectOutputStream;
25  
26  import org.junit.Assert;
27  import org.junit.Test;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.utils.Constants;
30  
31  
32  public class FixedTransformProviderTest {
33  
34      @Test
35      public void testEME2000() {
36          Frame gcrf    = FramesFactory.getGCRF();
37          Frame eme2000 = FramesFactory.getEME2000();
38          TransformProvider fixed = new FixedTransformProvider(gcrf.getTransformTo(eme2000,
39                                                                                   AbsoluteDate.J2000_EPOCH));
40          for (double dt = 0; dt < Constants.JULIAN_YEAR; dt += Constants.JULIAN_DAY) {
41              final AbsoluteDate t = AbsoluteDate.J2000_EPOCH.shiftedBy(dt);
42              final Transform expectedIdentity =
43                              new Transform(t, fixed.getTransform(t), eme2000.getTransformTo(gcrf, t));
44              Assert.assertEquals(0, expectedIdentity.getTranslation().getNorm(), 1.0e-15);
45              Assert.assertEquals(0, expectedIdentity.getRotation().getAngle(), 1.0e-15);
46          }
47      }
48  
49      @Test
50      public void testSerialization() throws IOException, ClassNotFoundException {
51          Frame gcrf    = FramesFactory.getGCRF();
52          Frame eme2000 = FramesFactory.getEME2000();
53          TransformProvider fixed = new FixedTransformProvider(gcrf.getTransformTo(eme2000,
54                                                                                   AbsoluteDate.J2000_EPOCH));
55  
56          ByteArrayOutputStream bos = new ByteArrayOutputStream();
57          ObjectOutputStream    oos = new ObjectOutputStream(bos);
58          oos.writeObject(fixed);
59  
60          Assert.assertTrue(bos.size() >  990);
61          Assert.assertTrue(bos.size() < 1010);
62  
63          ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
64          ObjectInputStream     ois = new ObjectInputStream(bis);
65          FixedTransformProvider deserialized  = (FixedTransformProvider) ois.readObject();
66          for (double dt = 0; dt < Constants.JULIAN_DAY; dt += 3600) {
67              AbsoluteDate date = AbsoluteDate.J2000_EPOCH.shiftedBy(dt);
68              Transform expectedIdentity = new Transform(date,
69                                                         fixed.getTransform(date).getInverse(),
70                                                         deserialized.getTransform(date));
71              Assert.assertEquals(0.0, expectedIdentity.getTranslation().getNorm(), 1.0e-15);
72              Assert.assertEquals(0.0, expectedIdentity.getRotation().getAngle(),   1.0e-15);
73          }
74  
75      }
76  
77  }