11package ch .akuhn .fame .test ;
22
3+ import ch .akuhn .fame .MetaRepository ;
34import ch .akuhn .fame .Tower ;
45import ch .akuhn .fame .internal .JSONPrettyPrinter ;
6+ import ch .akuhn .fame .internal .JSONPrinter ;
57import ch .akuhn .fame .parser .InputSource ;
68import junit .framework .TestCase ;
79
@@ -10,6 +12,9 @@ public class JSONPrinterTest extends TestCase {
1012 private JSONPrettyPrinter printer ;
1113 private Appendable stream ;
1214
15+ /** FIXME
16+ * This is not a test but a method to export a meta-model
17+ */
1318 public void testExportJSON () {
1419 InputSource input = InputSource .fromResource ("ch/unibe/fame/resources/lib.mse" );
1520 Tower t = new Tower ();
@@ -28,46 +33,83 @@ public void setUp() throws Exception {
2833
2934 public void testBeginAttributeSimple () {
3035 printer .beginAttribute ("hello" );
31- assertEquals (stream . toString (), "\" hello\" :" );
36+ assertEquals ("\" hello\" :" , stream . toString () );
3237 }
3338
3439 public void testPrimitive () {
3540 printer .primitive ("value" );
36- assertEquals (stream . toString (), "\" value\" " );
41+ assertEquals ("\" value\" " , stream . toString () );
3742 }
3843
3944 public void testPrimitiveWithSpecialCharacter () {
4045 printer .primitive ("MySuper\" String" );
41- assertEquals (stream . toString (), "\" MySuper\\ \" String\" " );
46+ assertEquals ("\" MySuper\\ \" String\" " , stream . toString () );
4247 }
4348
4449 public void testPrimitiveWithSpecialCharacterAndActualExample () {
4550 printer .primitive ("print(\" Printer \" + name() + \" prints \" + thePacket.contents(),false)" );
46- assertEquals (stream . toString (), "\" print(\\ \" Printer \\ \" + name() + \\ \" prints \\ \" + thePacket.contents(),false)\" " );
51+ assertEquals ( "\" print(\\ \" Printer \\ \" + name() + \\ \" prints \\ \" + thePacket.contents(),false)\" " , stream . toString () );
4752 }
4853
4954 public void testReference () {
5055 printer .reference ("hello" );
51- assertEquals (removeWhiteSpaces ( stream . toString ()), "{\" ref\" :\" hello\" }" );
56+ assertEquals ("{\" ref\" :\" hello\" }" , removeWhiteSpaces ( stream . toString ()) );
5257 }
5358
5459 public void testReferenceIndex () {
5560 printer .reference (2 );
56- assertEquals (removeWhiteSpaces ( stream . toString ()), "{\" ref\" :2}" );
61+ assertEquals ("{\" ref\" :2}" , removeWhiteSpaces ( stream . toString ()) );
5762 }
5863
5964 public void testSerial () {
6065 printer .serial (2 );
61- assertEquals (removeWhiteSpaces ( stream . toString ()), " \" id\" :2," );
66+ assertEquals (", \" id\" :2" , removeWhiteSpaces ( stream . toString ()) );
6267 }
6368
6469 public void testBeginElement () {
6570 printer .beginElement ("Java.Class" );
66- assertEquals (removeWhiteSpaces ( stream . toString ()), "{\" FM3\" :\" Java.Class\" ," );
71+ assertEquals ("{\" FM3\" :\" Java.Class\" " , removeWhiteSpaces ( stream . toString ()) );
6772 }
6873
6974
7075 private static String removeWhiteSpaces (String input ) {
7176 return input .replaceAll ("\\ s+" , "" );
7277 }
78+
79+ public void testEmptyEntityPrettyPrinter () {
80+ String str = "((FM3.Package))" ;
81+ Tower t = new Tower ();
82+ t .getMetamodel ().importMSE (str );
83+ MetaRepository repo = t .getMetamodel ();
84+ repo .accept ( printer );
85+ assertEquals ("[{\" FM3\" :\" FM3.Package\" ,\" id\" :1}]" , removeWhiteSpaces (stream .toString ()));
86+ }
87+
88+ public void testEmptyEntityJSONPrinter () {
89+ String str = "((FM3.Package))" ;
90+ Tower t = new Tower ();
91+ t .getMetamodel ().importMSE (str );
92+ MetaRepository repo = t .getMetamodel ();
93+ repo .accept ( new JSONPrinter (stream ));
94+ assertEquals ("[{\" FM3\" :\" FM3.Package\" ,\" id\" :1}]" , stream .toString ());
95+ }
96+
97+ public void testEntityWithAttributePrettyPrinter () {
98+ String str = "((FM3.Package (name 'Blah')))" ;
99+ Tower t = new Tower ();
100+ t .getMetamodel ().importMSE (str );
101+ MetaRepository repo = t .getMetamodel ();
102+ repo .accept ( printer );
103+ assertEquals ("[{\" FM3\" :\" FM3.Package\" ,\" id\" :1,\" name\" :\" Blah\" }]" , removeWhiteSpaces (stream .toString ()));
104+ }
105+
106+ public void testEntityWithAttributeJSONPrinter () {
107+ String str = "((FM3.Package (name 'Blah')))" ;
108+ Tower t = new Tower ();
109+ t .getMetamodel ().importMSE (str );
110+ MetaRepository repo = t .getMetamodel ();
111+ repo .accept ( new JSONPrinter (stream ));
112+ assertEquals ("[{\" FM3\" :\" FM3.Package\" ,\" id\" :1,\" name\" :\" Blah\" }]" , stream .toString ());
113+ }
114+
73115}
0 commit comments