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.xml.filters;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleContext;
11  import org.mule.tck.junit4.AbstractMuleTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertFalse;
16  import static org.junit.Assert.assertTrue;
17  import static org.mockito.Mockito.mock;
18  
19  
20  public class SchemaValidationTestCase extends AbstractMuleTestCase
21  {
22      MuleContext muleContext = mock(MuleContext.class);
23  
24      /**
25       * tests validation
26       */
27      @Test
28      public void testValidate() throws Exception
29      {
30          SchemaValidationFilter filter = new SchemaValidationFilter();
31          filter.setSchemaLocations("schema1.xsd");
32          filter.initialise();
33          
34          assertTrue(filter.accept(new DefaultMuleMessage(getClass().getResourceAsStream("/validation1.xml"), muleContext)));
35          assertFalse(filter.accept(new DefaultMuleMessage(getClass().getResourceAsStream("/validation2.xml"), muleContext)));
36      }
37  
38  }