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.atom;
18  
19  import static org.junit.jupiter.api.Assertions.*;
20  
21  import org.apache.juneau.*;
22  import org.junit.jupiter.api.*;
23  
24  class Content_Test extends TestBase {
25  
26  	@Test void a01_basic() {
27  		var x = new Content("text");
28  		assertNotNull(x);
29  		assertEquals("text", x.getType());
30  	}
31  
32  	@Test void a02_withText() {
33  		var x = new Content("html");
34  		x.setText("<p>HTML content</p>");
35  		assertEquals("<p>HTML content</p>", x.getText());
36  	}
37  
38  	@Test void a03_withSrc() {
39  		var x = new Content();
40  		x.setSrc("http://example.com/content");
41  		assertEquals("http://example.com/content", x.getSrc().toString());
42  	}
43  
44  	@Test void a04_fluentSetters() {
45  		var x = new Content();
46  
47  		// Test setType returns same instance for fluent chaining
48  		assertSame(x, x.setType("html"));
49  		assertEquals("html", x.getType());
50  
51  		// Test setText returns same instance
52  		assertSame(x, x.setText("Test text"));
53  		assertEquals("Test text", x.getText());
54  
55  		// Test setSrc returns same instance
56  		assertSame(x, x.setSrc("http://example.com/video.mp4"));
57  		assertEquals("http://example.com/video.mp4", x.getSrc().toString());
58  
59  		// Test setBase returns same instance (from Common)
60  		assertSame(x, x.setBase("http://example.com/"));
61  
62  		// Test setLang returns same instance (from Common)
63  		assertSame(x, x.setLang("en"));
64  	}
65  
66  	@Test void a05_fluentChaining() {
67  		// Test multiple fluent calls can be chained
68  		var x = new Content()
69  			.setType("xhtml")
70  			.setText("<div>XHTML content</div>")
71  			.setBase("http://example.com/")
72  			.setLang("en-US");
73  
74  		assertEquals("xhtml", x.getType());
75  		assertEquals("<div>XHTML content</div>", x.getText());
76  		assertEquals("en-US", x.getLang());
77  	}
78  
79  	@Test void a06_outOfLineContent() {
80  		// Test external content (out-of-line) with src attribute
81  		var x = new Content()
82  			.setType("video/mp4")
83  			.setSrc("http://example.org/movie.mp4");
84  
85  		assertEquals("video/mp4", x.getType());
86  		assertEquals("http://example.org/movie.mp4", x.getSrc().toString());
87  	}
88  }