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