View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.json.transformers;
8   
9   import org.mule.tck.junit4.AbstractMuleContextTestCase;
10  
11  import org.junit.Test;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  
17  public class JsonStringTestCase extends AbstractMuleContextTestCase
18  {
19      public static final String TEST_JSON_MESSAGE = "{\"data\" : {\"value1\" : \"foo\", \"value2\" : \"bar\"}, \"replyTo\" : \"/response\"}";
20  
21      /**
22       * Test that a Json string doesn't get modified in any way
23       */
24      @Test
25      public void testTryConvertJsonStringToJsonString() throws Exception
26      {
27          ObjectToJson transformer = createObject(ObjectToJson.class);
28          Object result = transformer.transform(TEST_JSON_MESSAGE);
29          assertNotNull(result);
30          assertEquals(TEST_JSON_MESSAGE, result);
31      }
32  
33  
34      @Test
35      public void testTryConvertJsonStringToJustString() throws Exception
36      {
37          ObjectToJson transformer = createObject(ObjectToJson.class);
38          //This is still valid json
39          assertEquals("\"Hello\"", transformer.transform("Hello"));
40      }
41  }