View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.bean.html5;
18  
19  import static org.apache.juneau.bean.html5.HtmlBuilder.*;
20  import static org.apache.juneau.junit.bct.BctAssertions.*;
21  import static org.junit.jupiter.api.Assertions.*;
22  
23  import org.apache.juneau.*;
24  import org.junit.jupiter.api.*;
25  
26  class HtmlElement_Test extends TestBase {
27  
28  	@Test void a01_getAttr_withNull() {
29  		A x = a();
30  		assertNull(x.getAttr(String.class, "nonexistent"));
31  	}
32  
33  	@Test void a02_getAttr_withValue() {
34  		A x = a().href("test");
35  		assertString("test", x.getAttr(String.class, "href"));
36  	}
37  
38  	@Test void a03_deminimize() {
39  		Button x1 = button().disabled(true);
40  		assertString("<button disabled='disabled'></button>", x1);
41  		
42  		Button x2 = button().disabled(false);
43  		assertString("<button></button>", x2);
44  		
45  		Button x3 = button().disabled("custom");
46  		assertString("<button disabled='custom'></button>", x3);
47  	}
48  
49  	@Test void a04_attr_withNull() {
50  		A x = a().href("test");
51  		assertString("<a href='test'></a>", x);
52  		x.attr("href", null);
53  		assertString("<a></a>", x);
54  	}
55  
56  	@Test void a05_attr_urlConversion() {
57  		A x = a();
58  		x.attr("url", "http://example.com");
59  		assertString("http://example.com", x.getAttr(String.class, "url"));
60  		
61  		A x2 = a();
62  		x2.attr("href", "http://example.com");
63  		assertString("http://example.com", x2.getAttr(String.class, "href"));
64  		
65  		Form x3 = form();
66  		x3.attr("action", "http://example.com");
67  		assertString("http://example.com", x3.getAttr(String.class, "action"));
68  	}
69  }