1   package org.orekit.files.ccsds.section;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import org.junit.jupiter.api.Assertions;
7   import org.junit.jupiter.api.BeforeEach;
8   import org.junit.jupiter.api.Test;
9   import org.orekit.Utils;
10  import org.orekit.data.DataSource;
11  import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
12  import org.orekit.files.ccsds.ndm.ParserBuilder;
13  import org.orekit.files.ccsds.ndm.odm.opm.Opm;
14  
15  public class CommentsContainerTest {
16      
17      @BeforeEach
18      public void setUp() {
19          Utils.setDataRoot("regular-data");
20      }
21  
22      @Test
23      void testSetComments() {
24  
25          final String expectedOldComment  = "GEOCENTRIC, CARTESIAN, EARTH FIXED";
26          final String expectedNewComment1 = "NEW COMMENT 1";
27          final String expectedNewComment2 = "LAST NEW COMMENT!";
28  
29          // Parse OPM and check comments in metadata
30          final String opmName = "/ccsds/odm/opm/OPMExample1.txt";
31          final DataSource source1  = new DataSource(opmName, () -> getClass().getResourceAsStream(opmName));
32          final Opm        original = new ParserBuilder().
33                                      withParsedUnitsBehavior(ParsedUnitsBehavior.STRICT_COMPLIANCE).
34                                      buildOpmParser().
35                                      parseMessage(source1);
36  
37          Assertions.assertEquals(1, original.getMetadata().getComments().size());
38          Assertions.assertEquals(expectedOldComment, original.getMetadata().getComments().get(0));
39  
40          // Set new comments and check
41          List<String> newComments = new ArrayList<>();
42          newComments.add(expectedNewComment1);
43          newComments.add(expectedNewComment2);
44          original.getMetadata().setComments(newComments);
45  
46          Assertions.assertEquals(2, original.getMetadata().getComments().size());
47          Assertions.assertEquals(expectedNewComment1, original.getMetadata().getComments().get(0));
48          Assertions.assertEquals(expectedNewComment2, original.getMetadata().getComments().get(1));
49      }
50  }