2222import esa .mo .mal .encoder .binary .fixed .FixedBinaryStreamFactory ;
2323import java .io .ByteArrayInputStream ;
2424import java .io .ByteArrayOutputStream ;
25+ import org .ccsds .moims .mo .mal .MALException ;
26+ import org .ccsds .moims .mo .mal .OperationField ;
2527import org .ccsds .moims .mo .mal .encoding .MALElementInputStream ;
2628import org .ccsds .moims .mo .mal .encoding .MALElementOutputStream ;
27- import org .ccsds .moims .mo .mal .structures .Identifier ;
28- import org .ccsds .moims .mo .mal .structures .NullableAttribute ;
29- import org .ccsds .moims .mo .mal .structures .NullableAttributeList ;
30- import org .ccsds .moims .mo .mal .structures .StringList ;
29+ import org .ccsds .moims .mo .mal .structures .Element ;
3130import org .junit .After ;
3231import org .junit .AfterClass ;
33- import static org .junit .Assert .assertEquals ;
34- import static org .junit .Assert .assertNotNull ;
3532import org .junit .Before ;
3633import org .junit .BeforeClass ;
37- import org .junit .Test ;
3834
3935/**
4036 * Tests for Encoding and Decoding with FixedBinary
4137 */
42- public class FixedEncoderDecoderTest {
38+ public class FixedEncoderDecoderTest extends EncoderDecoderTest {
4339
4440 public FixedEncoderDecoderTest () {
4541 }
@@ -60,69 +56,18 @@ public void setUp() {
6056 public void tearDown () {
6157 }
6258
63- /**
64- * Simple test for encoding decoding a list of NullableAttributeList.
65- *
66- * @throws java.lang.Exception
67- */
68- @ Test
69- public void testEncodeDecodeNullableAttributeList () throws Exception {
70- NullableAttributeList list = new NullableAttributeList ();
71- list .add (new NullableAttribute (new Identifier ("String A" )));
72- list .add (new NullableAttribute (new Identifier ("String B" )));
73- list .add (new NullableAttribute (new Identifier ("String C" )));
74-
59+ @ Override
60+ public Element encodeThenDecode (Element element , OperationField field ) throws MALException {
61+ // Encode
7562 FixedBinaryStreamFactory factory = new FixedBinaryStreamFactory ();
7663 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
7764 MALElementOutputStream malWriter = factory .createOutputStream (baos );
65+ malWriter .writeElement (element , field );
7866
79- malWriter .writeElement (list , null );
80-
67+ // Decode
8168 final ByteArrayInputStream bais = new ByteArrayInputStream (baos .toByteArray ());
8269 MALElementInputStream malReader = factory .createInputStream (bais );
83-
84- NullableAttributeList readList = new NullableAttributeList ();
85- readList = (NullableAttributeList ) malReader .readElement (readList , null );
86-
87- // Assertions:
88- assertNotNull (readList );
89- assertEquals (3 , readList .size ());
90- assertEquals ("NullableAttributeList.get(0)" , list .get (0 ), readList .get (0 ));
91- assertEquals ("NullableAttributeList.get(1)" , list .get (1 ), readList .get (1 ));
92- assertEquals ("NullableAttributeList.get(2)" , list .get (2 ), readList .get (2 ));
70+ return malReader .readElement (element .createElement (), field );
9371 }
9472
95- /**
96- * Simple test for encoding decoding a list of StringList. Note that the
97- * String MAL type is mapped to the String Java type, therefore the type
98- * might need to be wrapped in a Union type for correct encoding/decoding.
99- *
100- * @throws java.lang.Exception
101- */
102- @ Test
103- public void testEncodeDecodeStringList () throws Exception {
104- StringList list = new StringList ();
105- list .add ("String A" );
106- list .add ("String B" );
107- list .add ("String C" );
108-
109- FixedBinaryStreamFactory factory = new FixedBinaryStreamFactory ();
110- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
111- MALElementOutputStream malWriter = factory .createOutputStream (baos );
112-
113- malWriter .writeElement (list , null );
114-
115- final ByteArrayInputStream bais = new ByteArrayInputStream (baos .toByteArray ());
116- MALElementInputStream malReader = factory .createInputStream (bais );
117-
118- StringList readList = new StringList ();
119- readList = (StringList ) malReader .readElement (readList , null );
120-
121- // Assertions:
122- assertNotNull (readList );
123- assertEquals (3 , readList .size ());
124- assertEquals ("StringList.get(0)" , list .get (0 ), readList .get (0 ));
125- assertEquals ("StringList.get(1)" , list .get (1 ), readList .get (1 ));
126- assertEquals ("StringList.get(2)" , list .get (2 ), readList .get (2 ));
127- }
12873}
0 commit comments