1   /*
2    * $Id: CheckRequiredAttributesTestCase.java 10256 2008-01-08 15:20:25Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.config.spring.parsers.processors;
12  
13  import org.mule.config.spring.parsers.PreProcessor;
14  
15  import javax.xml.parsers.ParserConfigurationException;
16  
17  public class CheckRequiredAttributesTestCase extends AbstractPreProcessorTestCase
18  {
19  
20      public void testTwoSets() throws ParserConfigurationException
21      {
22          String[][] a1b2 = new String[][]{new String[]{"a1"}, new String[]{"b1", "b2"}};
23          String text12 = "must have all attributes for one of the sets: a1; b1, b2";
24          assertBad(a1b2, "", text12);
25          assertBad(a1b2, "x", text12);
26          assertBad(a1b2, "b2", text12);
27          assertBad(a1b2, "x b1", text12);
28          assertOk(a1b2, "a1");
29          assertOk(a1b2, "a1 x");
30          assertOk(a1b2, "b1 b2");
31          assertOk(a1b2, "a1 b1");
32          assertOk(a1b2, "a1 b2");
33          assertOk(a1b2, "a1 b1 b2");
34          assertOk(a1b2, "a1 b2 x");
35          String[][] a1b0 = new String[][]{new String[]{"a1"}, new String[]{}};
36          String text10 = "must have all attributes for one of the sets: a1";
37          assertBad(a1b0, "", text10);
38          assertBad(a1b0, "x", text10);
39          assertBad(a1b0, "b2", text10);
40          assertBad(a1b0, "x b1", text10);
41          assertOk(a1b0, "a1");
42          assertOk(a1b0, "a1 x");
43          assertBad(a1b0, "b1 b2", text10);
44          assertOk(a1b0, "a1 b1");
45          assertOk(a1b0, "a1 b2");
46          assertOk(a1b0, "a1 b1 b2");
47          assertOk(a1b0, "a1 b2 x");
48      }
49  
50      public void testSingleSet() throws ParserConfigurationException
51      {
52          String[][] a1 = new String[][]{new String[]{"a1"}};
53          String text1 = "must have all attributes for one of the sets: a1";
54          assertBad(a1, "", text1);
55          assertBad(a1, "x", text1);
56          assertBad(a1, "b2", text1);
57          assertBad(a1, "x b1", text1);
58          assertOk(a1, "a1");
59          assertOk(a1, "a1 x");
60          assertBad(a1, "b1 b2", text1);
61          assertOk(a1, "a1 b1");
62          assertOk(a1, "a1 b2");
63          assertOk(a1, "a1 b1 b2");
64          assertOk(a1, "a1 b2 x");
65          String[][] b2 = new String[][]{new String[]{"b1", "b2"}};
66          String text2 = "must have all attributes for one of the sets: b1, b2";
67          assertBad(b2, "", text2);
68          assertBad(b2, "x", text2);
69          assertBad(b2, "b2", text2);
70          assertBad(b2, "x b1", text2);
71          assertBad(b2, "a1", text2);
72          assertBad(b2, "a1 x", text2);
73          assertOk(b2, "b1 b2");
74          assertBad(b2, "a1 b1", text2);
75          assertBad(b2, "a1 b2", text2);
76          assertOk(b2, "a1 b1 b2");
77          assertBad(b2, "a1 b2 x", text2);
78      }
79  
80      protected PreProcessor createCheck(String[][] constraint)
81      {
82          return new CheckRequiredAttributes(constraint);
83      }
84  
85  }