View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License. 
18   */
19  package org.apache.creadur.whisker.fromxml;
20  
21  import org.apache.creadur.whisker.model.Organisation;
22  
23  import junit.framework.TestCase;
24  import org.jdom2.Element;
25  
26  /**
27   * 
28   */
29  public class JDomBuilderOrganisationTest extends TestCase {
30      private JDomBuilder subject;
31      
32      @Override
33      protected void setUp() throws Exception {
34          super.setUp();
35          subject = new JDomBuilder();
36      }
37  
38      @Override
39      protected void tearDown() throws Exception {
40          super.tearDown();
41      }
42  
43      public void testOrganisationSetsIdNameUrl() throws Exception {
44          final Organisation result = subject.organisation(
45                  new Element("organisation")
46                  .setAttribute("name", "a name")
47                  .setAttribute("url", "an url")
48                  .setAttribute("id", "an id"));
49          assertNotNull("Builder should build an organisation", result);
50          
51      }
52      
53      public void testThrowIllegalArgumentWhenResourceIsNotOrganisation() throws Exception {
54          try {
55              subject.organisation(
56                  new Element("bogus")
57                      .setAttribute("name", "name")
58                      .setAttribute("url", "url")
59                      .setAttribute("id", "id"));
60              fail("Expected IllegalArgument throw when elements is not named 'organisation'");  
61          } catch (UnexpectedElementException e) {
62              //expected
63          } catch (Throwable t) {
64              fail("Expected IllegalArgument throw when elements is not named 'organisation' but " + t + " was instead");
65          }
66      }
67  }