View Javadoc

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