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.rest.beans;
18  
19  import static org.apache.juneau.junit.bct.BctAssertions.*;
20  import static org.junit.jupiter.api.Assertions.*;
21  
22  import org.apache.juneau.*;
23  import org.junit.jupiter.api.*;
24  
25  class ChildResourceDescriptions_Test extends TestBase {
26  
27  	@Test void a01_basic() {
28  		var x = new ChildResourceDescriptions();
29  		assertNotNull(x);
30  		assertEmpty(x);
31  	}
32  
33  	@Test void a02_appendWithDescription() {
34  		var x = new ChildResourceDescriptions();
35  		x.append("child1", "Description 1");
36  		assertSize(1, x);
37  		assertEquals("child1", x.get(0).getName());
38  		assertEquals("Description 1", x.get(0).getDescription());
39  	}
40  
41  	@Test void a03_appendWithUri() {
42  		var x = new ChildResourceDescriptions();
43  		x.append("child1", "/api/child1", "Child 1 API");
44  		assertSize(1, x);
45  		assertEquals("child1", x.get(0).getName());
46  		assertEquals("/api/child1", x.get(0).getUri());
47  		assertEquals("Child 1 API", x.get(0).getDescription());
48  	}
49  
50  	@Test void a04_fluentSetters() {
51  		var x = new ChildResourceDescriptions();
52  
53  		// Test append(String, String) returns same instance for fluent chaining
54  		assertSame(x, x.append("resource1", "Resource 1"));
55  		assertSize(1, x);
56  
57  		// Test append(String, String, String) returns same instance
58  		assertSame(x, x.append("resource2", "/api/resource2", "Resource 2 API"));
59  		assertSize(2, x);
60  	}
61  
62  	@Test void a05_fluentChaining() {
63  		// Test multiple fluent calls can be chained
64  		var x = new ChildResourceDescriptions()
65  			.append("users", "User management")
66  			.append("products", "/api/products", "Product catalog")
67  			.append("orders", "Order processing");
68  
69  		assertSize(3, x);
70  		assertEquals("users", x.get(0).getName());
71  		assertEquals("User management", x.get(0).getDescription());
72  		assertEquals("products", x.get(1).getName());
73  		assertEquals("/api/products", x.get(1).getUri());
74  		assertEquals("Product catalog", x.get(1).getDescription());
75  		assertEquals("orders", x.get(2).getName());
76  		assertEquals("Order processing", x.get(2).getDescription());
77  	}
78  
79  	@Test void a06_multipleResources() {
80  		// Test building a list of child resources
81  		var x = new ChildResourceDescriptions()
82  			.append("child1", "First child resource")
83  			.append("child2", "/child2", "Second child resource")
84  			.append("child3", "Third child resource");
85  
86  		assertSize(3, x);
87  		assertNotNull(x.get(0));
88  		assertNotNull(x.get(1));
89  		assertNotNull(x.get(2));
90  	}
91  }