1 package org.orekit.files.ccsds.definitions;
2
3 import org.hamcrest.MatcherAssert;
4 import org.hamcrest.Matchers;
5 import org.hipparchus.geometry.euclidean.threed.Rotation;
6 import org.junit.jupiter.api.Assertions;
7 import org.junit.jupiter.api.Test;
8 import org.orekit.OrekitMatchers;
9 import org.orekit.Utils;
10 import org.orekit.bodies.CelestialBody;
11 import org.orekit.bodies.CelestialBodyFactory;
12 import org.orekit.data.DataContext;
13 import org.orekit.errors.OrekitException;
14 import org.orekit.frames.Frame;
15 import org.orekit.frames.Frames;
16 import org.orekit.frames.Transform;
17 import org.orekit.time.AbsoluteDate;
18 import org.orekit.utils.PVCoordinates;
19
20
21
22
23
24
25 public class OrekitCcsdsFrameMapperTest {
26
27
28 private final DataContext context = Utils.newDataContext("regular-data");
29
30
31 @Test
32 public void testBuildCcsdsFrameEarthIcrfIsGcrf() {
33
34 CcsdsFrameMapper mapper = new OrekitCcsdsFrameMapper();
35 final Frames frames = context.getFrames();
36 final Frame icrf = frames.getICRF();
37 final Frame gcrf = frames.getGCRF();
38 final CelestialBody earth = context.getCelestialBodies().getEarth();
39
40
41 final Frame actual = mapper.buildCcsdsFrame(
42 new BodyFacade("EARTH", earth),
43 new FrameFacade(icrf, CelestialBodyFrame.ICRF, null, null, "ICRF"),
44 null);
45
46
47 MatcherAssert.assertThat(actual, Matchers.sameInstance(gcrf));
48 }
49
50
51 @Test
52 public void testBuildCcsdsFrameIcrfNotSsbOrEarth() {
53
54 CcsdsFrameMapper mapper = new OrekitCcsdsFrameMapper();
55 final Frames frames = context.getFrames();
56 final Frame icrf = frames.getICRF();
57 final CelestialBody emb = context.getCelestialBodies()
58 .getEarthMoonBarycenter();
59 final AbsoluteDate date = context.getTimeScales().getJ2000Epoch();
60
61
62 final Frame actual = mapper.buildCcsdsFrame(
63 new BodyFacade(CelestialBodyFactory.EARTH_MOON, emb),
64 new FrameFacade(icrf, CelestialBodyFrame.ICRF, null, null, "ICRF"),
65 null);
66
67
68 Transform actualTransform = actual.getTransformTo(icrf, date);
69 MatcherAssert.assertThat(actualTransform.getRotation(),
70 OrekitMatchers.distanceIs(Rotation.IDENTITY, Matchers.closeTo(0, 0.0)));
71 PVCoordinates actualPv = emb.getPVCoordinates(date, actual);
72 MatcherAssert.assertThat(actualPv,
73 OrekitMatchers.pvCloseTo(PVCoordinates.ZERO, 0.0));
74 }
75
76
77
78
79
80
81 @Test
82 public void testBuildOrientationOnly() {
83
84 CcsdsFrameMapper mapper = new OrekitCcsdsFrameMapper();
85 Frame frame = context.getFrames().getVeis1950();
86 FrameFacade orientation =
87 new FrameFacade(frame, null, null, null, null);
88
89
90 final Frame actual = mapper.buildCcsdsFrame(orientation, null);
91
92
93
94 MatcherAssert.assertThat(actual, Matchers.sameInstance(frame));
95
96
97 try {
98 mapper.buildCcsdsFrame(null, null);
99 Assertions.fail("Expected exception");
100 } catch (OrekitException e) {
101
102 }
103
104 final String name = "Bill";
105 orientation = new FrameFacade(null, null, null, null, name);
106 try {
107 mapper.buildCcsdsFrame(orientation, null);
108 Assertions.fail("Expected exception");
109 } catch (OrekitException e) {
110
111 MatcherAssert.assertThat(e.getMessage(),
112 Matchers.containsString(name));
113 }
114 }
115
116
117 @Test
118 public void testBuildNullCenter() {
119
120 CcsdsFrameMapper mapper = new OrekitCcsdsFrameMapper();
121
122
123 try {
124 mapper.buildCcsdsFrame(null, null, null);
125 Assertions.fail("Expected exception");
126 } catch (OrekitException e) {
127
128 }
129 }
130
131
132 @Test
133 public void testInstancesAreEqual() {
134
135 CcsdsFrameMapper m1 = new OrekitCcsdsFrameMapper();
136 CcsdsFrameMapper m2 = new OrekitCcsdsFrameMapper();
137
138
139 MatcherAssert.assertThat(m1.hashCode(), Matchers.is(m2.hashCode()));
140 MatcherAssert.assertThat(m1, Matchers.is(m2));
141 MatcherAssert.assertThat(m2, Matchers.is(m1));
142 }
143
144
145 @Test
146 public void testSubclassesNotEqual() {
147
148 CcsdsFrameMapper m1 = new OrekitCcsdsFrameMapper();
149 CcsdsFrameMapper m2 = new OrekitCcsdsFrameMapper(){};
150
151
152 MatcherAssert.assertThat(m1.hashCode(), Matchers.not(m2.hashCode()));
153 MatcherAssert.assertThat(m1, Matchers.not(m2));
154 MatcherAssert.assertThat(m2, Matchers.not(m1));
155 }
156
157 }