View Javadoc

1   /*
2    * $Id: IsJsonFilterTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.AbstractMuleTestCase;
15  
16  public class IsJsonFilterTestCase extends AbstractMuleTestCase 
17  {
18  
19      private IsJsonFilter filter;
20  
21      protected void doSetUp() throws Exception 
22      {
23          filter = new IsJsonFilter();
24          filter.setValidateParsing(true);
25      }
26      
27      public void testFilterFalse() throws Exception
28      {
29          assertFalse(filter.accept(new DefaultMuleMessage("This is definitely not JSON.", muleContext)));
30      }
31  
32      public void testFilterFalse2() throws Exception
33      {
34          assertFalse(filter.accept(new DefaultMuleMessage("{name=\"This may be JSON\",bool:}", muleContext)));
35      }
36      
37      public void testFilterFalse3() throws Exception
38      {
39          assertFalse(filter.accept(new DefaultMuleMessage("[name=\"This may be JSON\",bool:]", muleContext)));
40      }
41      
42      public void testFilterTrue() throws Exception
43      {
44          assertTrue(filter.accept(new DefaultMuleMessage("{\n" +
45                  "        \"in_reply_to_user_id\":null,\n" +
46                  "        \"text\":\"test from Mule: 6ffca02b-9d52-475e-8b17-946acdb01492\"}", muleContext)));
47      }
48      
49      public void testFilterNull() throws Exception
50      {
51          assertFalse(filter.accept(new DefaultMuleMessage(null, muleContext)));
52      }
53  
54      public void testFilterWithObject() throws Exception
55      {
56          assertFalse(filter.accept(new DefaultMuleMessage(new Object(), muleContext)));
57      }
58  
59  }