View Javadoc
1   // ***************************************************************************************************************************
2   // * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
3   // * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
4   // * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
5   // * with the License.  You may obtain a copy of the License at                                                              *
6   // *                                                                                                                         *
7   // *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
8   // *                                                                                                                         *
9   // * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
10  // * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
11  // * specific language governing permissions and limitations under the License.                                              *
12  // ***************************************************************************************************************************
13  package org.apache.juneau.microservice.resources;
14  
15  import static org.junit.jupiter.api.Assertions.*;
16  
17  import java.net.*;
18  
19  import org.apache.juneau.*;
20  import org.apache.juneau.microservice.resources.DirectoryResource.*;
21  import org.junit.jupiter.api.*;
22  
23  /**
24   * Tests for DirectoryResource.Action fluent setter overrides.
25   */
26  class DirectoryResource_Action_Test extends TestBase {
27  
28  	@Test void a01_fluentChaining_setName() {
29  		var action = new Action("view", "/view", "file.txt");
30  
31  		// Test that setName() returns Action (not LinkString)
32  		Action result = action.setName("download");
33  
34  		assertSame(action, result);
35  		assertInstanceOf(Action.class, result);
36  		assertEquals("download", result.getName());
37  	}
38  
39  	@Test void a02_fluentChaining_setUri_URI() throws Exception {
40  		var action = new Action("view", "/view", "file.txt");
41  
42  		// Test that setUri(URI) returns Action (not LinkString)
43  		var newUri = new URI("http://example.com/file");
44  		Action result = action.setUri(newUri);
45  
46  		assertSame(action, result);
47  		assertInstanceOf(Action.class, result);
48  		assertEquals(newUri, result.getUri());
49  	}
50  
51  	@Test void a03_fluentChaining_setUri_String() {
52  		var action = new Action("view", "/view", "file.txt");
53  
54  		// Test that setUri(String) returns Action (not LinkString)
55  		Action result = action.setUri("/download");
56  
57  		assertSame(action, result);
58  		assertInstanceOf(Action.class, result);
59  		assertEquals("/download", result.getUri().toString());
60  	}
61  
62  	@Test void a04_fluentChaining_setUri_StringWithArgs() {
63  		var action = new Action("view", "/view", "file.txt");
64  
65  		// Test that setUri(String, Object...) returns Action (not LinkString)
66  		Action result = action.setUri("/files/{0}/download", "myfile.txt");
67  
68  		assertSame(action, result);
69  		assertInstanceOf(Action.class, result);
70  		assertTrue(result.getUri().toString().contains("myfile.txt"));
71  	}
72  
73  	@Test void a05_fluentChaining_complex() {
74  		// Test chaining multiple fluent calls
75  		var result = new Action("view", "/view", "file.txt")
76  			.setName("download")
77  			.setUri("/download/{0}", "newfile.txt");
78  
79  		assertInstanceOf(Action.class, result);
80  		assertEquals("download", result.getName());
81  		assertTrue(result.getUri().toString().contains("newfile.txt"));
82  	}
83  
84  	@Test void a06_constructor() {
85  		// Test basic constructor functionality
86  		var action = new Action("view", "/files/{0}/view", "test.txt");
87  
88  		assertEquals("view", action.getName());
89  		assertTrue(action.getUri().toString().contains("test.txt"));
90  	}
91  }