View Javadoc

1   /*
2    * $Id: IsJsonFilterTestCase.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.filters;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.tck.junit4.AbstractMuleContextTestCase;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertFalse;
19  import static org.junit.Assert.assertTrue;
20  
21  public class IsJsonFilterTestCase extends AbstractMuleContextTestCase
22  {
23  
24      private IsJsonFilter filter;
25  
26      protected void doSetUp() throws Exception 
27      {
28          filter = new IsJsonFilter();
29          filter.setValidateParsing(true);
30      }
31      
32      @Test
33      public void testFilterFalse() throws Exception
34      {
35          assertFalse(filter.accept(new DefaultMuleMessage("This is definitely not JSON.", muleContext)));
36      }
37  
38      @Test
39      public void testFilterFalse2() throws Exception
40      {
41          assertFalse(filter.accept(new DefaultMuleMessage("{name=\"This may be JSON\",bool:}", muleContext)));
42      }
43      
44      @Test
45      public void testFilterFalse3() throws Exception
46      {
47          assertFalse(filter.accept(new DefaultMuleMessage("[name=\"This may be JSON\",bool:]", muleContext)));
48      }
49      
50      @Test
51      public void testFilterTrue() throws Exception
52      {
53          assertTrue(filter.accept(new DefaultMuleMessage("{\n" +
54                  "        \"in_reply_to_user_id\":null,\n" +
55                  "        \"text\":\"test from Mule: 6ffca02b-9d52-475e-8b17-946acdb01492\"}", muleContext)));
56      }
57      
58      @Test
59      public void testFilterNull() throws Exception
60      {
61          assertFalse(filter.accept(new DefaultMuleMessage(null, muleContext)));
62      }
63  
64      @Test
65      public void testFilterWithObject() throws Exception
66      {
67          assertFalse(filter.accept(new DefaultMuleMessage(new Object(), muleContext)));
68      }
69  
70  }