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.httppart;
18  
19  import static org.junit.jupiter.api.Assertions.*;
20  
21  import org.apache.juneau.*;
22  import org.junit.jupiter.api.*;
23  
24  class RequestHttpPart_FluentSetters_Test extends TestBase {
25  
26  	@Test
27  	public void a01_RequestFormParam_def() throws Exception {
28  		// Test that def() returns correct type for fluent chaining
29  		var x = new RequestFormParam(null, "test", null);
30  		assertSame(x, x.def("default"));
31  		assertEquals("default", x.asString().orElse(null));
32  
33  		// Test fluent chaining with other methods
34  		var y = new RequestFormParam(null, "test", null)
35  			.def("default-value")
36  			.schema(null);
37  		assertInstanceOf(RequestFormParam.class, y);
38  		assertEquals("default-value", y.asString().orElse(null));
39  	}
40  
41  	@Test
42  	public void a02_RequestHeader_def() throws Exception {
43  		// Test that def() returns correct type for fluent chaining
44  		var x = new RequestHeader(null, "X-Missing", null);
45  		assertSame(x, x.def("default"));
46  		assertEquals("default", x.asString().orElse(null));
47  
48  		// Test fluent chaining with other methods
49  		var y = new RequestHeader(null, "X-Missing2", null)
50  			.def("default-header")
51  			.schema(null);
52  		assertInstanceOf(RequestHeader.class, y);
53  		assertEquals("default-header", y.asString().orElse(null));
54  	}
55  
56  	@Test
57  	public void a03_RequestPathParam_def() throws Exception {
58  		// Test that def() returns correct type for fluent chaining
59  		var x = new RequestPathParam(null, "param", null);
60  		assertSame(x, x.def("default"));
61  		assertEquals("default", x.asString().orElse(null));
62  
63  		// Test fluent chaining with other methods
64  		var y = new RequestPathParam(null, "param2", null)
65  			.def("default-path")
66  			.schema(null);
67  		assertInstanceOf(RequestPathParam.class, y);
68  		assertEquals("default-path", y.asString().orElse(null));
69  	}
70  
71  	@Test
72  	public void a04_RequestQueryParam_def() throws Exception {
73  		// Test that def() returns correct type for fluent chaining
74  		var x = new RequestQueryParam(null, "missing", null);
75  		assertSame(x, x.def("default"));
76  		assertEquals("default", x.asString().orElse(null));
77  
78  		// Test fluent chaining with other methods
79  		var y = new RequestQueryParam(null, "missing2", null)
80  			.def("default-query")
81  			.schema(null);
82  		assertInstanceOf(RequestQueryParam.class, y);
83  		assertEquals("default-query", y.asString().orElse(null));
84  	}
85  
86  	@Test
87  	public void a05_def_withExistingValue() throws Exception {
88  		// Test that def() does not override existing values
89  		var x = new RequestHeader(null, "X-Test", "existing");
90  		x.def("default");
91  		assertEquals("existing", x.asString().orElse(null));
92  	}
93  }