1515 */ 
1616package  uk .co .real_logic .sbe .json ;
1717
18- import  baseline .Car ;
19- import  baseline . MessageHeader ;
18+ import  baseline .* ;
19+ import  org . junit . BeforeClass ;
2020import  org .junit .Test ;
2121import  uk .co .real_logic .agrona .concurrent .UnsafeBuffer ;
22- import  uk .co .real_logic .sbe .examples .ExampleUsingGeneratedStub ;
2322import  uk .co .real_logic .sbe .ir .Ir ;
2423import  uk .co .real_logic .sbe .ir .IrDecoder ;
2524import  uk .co .real_logic .sbe .ir .IrEncoder ;
3130import  java .io .FileInputStream ;
3231import  java .io .IOException ;
3332import  java .io .InputStream ;
33+ import  java .io .UnsupportedEncodingException ;
3434import  java .nio .ByteBuffer ;
3535
3636import  static  junit .framework .TestCase .assertEquals ;
@@ -42,6 +42,28 @@ public class JsonPrinterTest
4242 private  static  final  int  ACTING_VERSION  = 0 ;
4343 private  static  final  int  MSG_BUFFER_CAPACITY  = 4  * 1024 ;
4444 private  static  final  int  SCHEMA_BUFFER_CAPACITY  = 16  * 1024 ;
45+  private  static  final  String  ENCODING_FILENAME  = "sbe.encoding.filename" ;
46+ 
47+  private  static  byte [] vehicleCode ;
48+  private  static  byte [] manufacturerCode ;
49+  private  static  byte [] make ;
50+  private  static  byte [] model ;
51+ 
52+  @ BeforeClass 
53+  public  static  void  setupExampleData ()
54+  {
55+  try 
56+  {
57+  vehicleCode  = "abcdef" .getBytes (Car .vehicleCodeCharacterEncoding ());
58+  manufacturerCode  = "123" .getBytes (Engine .manufacturerCodeCharacterEncoding ());
59+  make  = "Honda" .getBytes (Car .makeCharacterEncoding ());
60+  model  = "Civic VTi" .getBytes (Car .modelCharacterEncoding ());
61+  }
62+  catch  (final  UnsupportedEncodingException  ex )
63+  {
64+  throw  new  RuntimeException (ex );
65+  }
66+  }
4567
4668 @ Test 
4769 public  void  exampleMessagePrintedAsJson () throws  Exception 
@@ -147,7 +169,54 @@ private static void encodeTestMessage(final ByteBuffer buffer)
147169
148170 bufferOffset  += MESSAGE_HEADER .size ();
149171
150-  bufferOffset  += ExampleUsingGeneratedStub .encode (CAR , directBuffer , bufferOffset );
172+  final  int  srcOffset  = 0 ;
173+ 
174+  CAR .wrapForEncode (directBuffer , bufferOffset )
175+  .serialNumber (1234 )
176+  .modelYear (2013 )
177+  .available (BooleanType .TRUE )
178+  .code (Model .A )
179+  .putVehicleCode (vehicleCode , srcOffset );
180+ 
181+  for  (int  i  = 0 , size  = Car .someNumbersLength (); i  < size ; i ++)
182+  {
183+  CAR .someNumbers (i , i );
184+  }
185+ 
186+  CAR .extras ()
187+  .clear ()
188+  .cruiseControl (true )
189+  .sportsPack (true )
190+  .sunRoof (false );
191+ 
192+  CAR .engine ()
193+  .capacity (2000 )
194+  .numCylinders ((short )4 )
195+  .putManufacturerCode (manufacturerCode , srcOffset );
196+ 
197+  CAR .fuelFiguresCount (3 )
198+  .next ().speed (30 ).mpg (35.9f )
199+  .next ().speed (55 ).mpg (49.0f )
200+  .next ().speed (75 ).mpg (40.0f );
201+ 
202+  final  Car .PerformanceFigures  perfFigures  = CAR .performanceFiguresCount (2 );
203+  perfFigures .next ()
204+  .octaneRating ((short )95 )
205+  .accelerationCount (3 )
206+  .next ().mph (30 ).seconds (4.0f )
207+  .next ().mph (60 ).seconds (7.5f )
208+  .next ().mph (100 ).seconds (12.2f );
209+  perfFigures .next ()
210+  .octaneRating ((short )99 )
211+  .accelerationCount (3 )
212+  .next ().mph (30 ).seconds (3.8f )
213+  .next ().mph (60 ).seconds (7.1f )
214+  .next ().mph (100 ).seconds (11.8f );
215+ 
216+  CAR .make (new  String (make ));
217+  CAR .putModel (model , srcOffset , model .length );
218+ 
219+  bufferOffset  += CAR .size ();
151220
152221 buffer .position (bufferOffset );
153222 }
0 commit comments