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.microservice.resources;
18  
19  import static org.junit.jupiter.api.Assertions.*;
20  
21  import org.apache.juneau.*;
22  import org.apache.juneau.microservice.resources.LogsResource.*;
23  import org.junit.jupiter.api.*;
24  
25  /**
26   * Tests for {@link LogsResource.Action} fluent setter overrides.
27   */
28  class LogsResource_Action_Test extends TestBase {
29  
30  	@Test void a01_basic() {
31  		// Test basic constructor
32  		var x = new Action("view", "/logs/test.log");
33  
34  		assertEquals("view", x.getName());
35  		assertTrue(x.getUri().toString().contains("/logs/test.log"));
36  	}
37  
38  	@Test void a02_withArgs() {
39  		// Test constructor with URI args
40  		var x = new Action("view", "/logs/{0}", "test.log");
41  
42  		assertEquals("view", x.getName());
43  		assertTrue(x.getUri().toString().contains("test.log"));
44  	}
45  
46  	@Test void a03_setName() {
47  		// Test setName() returns correct type
48  		var x = new Action("view", "/logs/test.log");
49  
50  		Action result = x.setName("download");
51  
52  		// Verify fluent chaining
53  		assertSame(x, result);
54  		assertInstanceOf(Action.class, result);
55  		assertEquals("download", x.getName());
56  	}
57  
58  	@Test void a04_setUri_String() {
59  		// Test setUri(String) returns correct type
60  		var x = new Action("view", "/logs/test.log");
61  
62  		Action result = x.setUri("/logs/other.log");
63  
64  		// Verify fluent chaining
65  		assertSame(x, result);
66  		assertInstanceOf(Action.class, result);
67  		assertTrue(x.getUri().toString().contains("/logs/other.log"));
68  	}
69  
70  	@Test void a05_setUri_URI() {
71  		// Test setUri(java.net.URI) returns correct type
72  		var x = new Action("view", "/logs/test.log");
73  
74  		try {
75  			Action result = x.setUri(new java.net.URI("http://example.com/logs/test.log"));
76  
77  			// Verify fluent chaining
78  			assertSame(x, result);
79  			assertInstanceOf(Action.class, result);
80  			assertTrue(x.getUri().toString().contains("example.com"));
81  		} catch (Exception e) {
82  			fail("URI creation failed: " + e.getMessage());
83  		}
84  	}
85  
86  	@Test void a06_setUri_withArgs() {
87  		// Test setUri(String, Object...) returns correct type
88  		var x = new Action("view", "/logs/test.log");
89  
90  		Action result = x.setUri("/logs/{0}/{1}", "dir", "file.log");
91  
92  		// Verify fluent chaining
93  		assertSame(x, result);
94  		assertInstanceOf(Action.class, result);
95  		assertTrue(x.getUri().toString().contains("dir"));
96  		assertTrue(x.getUri().toString().contains("file.log"));
97  	}
98  
99  	@Test void a07_fluentChaining() {
100 		// Test fluent chaining works correctly
101 		var x = new Action("view", "/logs/test.log")
102 			.setName("download")
103 			.setUri("/logs/other.log");
104 
105 		assertInstanceOf(Action.class, x);
106 		assertEquals("download", x.getName());
107 		assertTrue(x.getUri().toString().contains("/logs/other.log"));
108 
109 		// Continue chaining
110 		x.setName("delete").setUri("/logs/{0}", "final.log");
111 
112 		assertEquals("delete", x.getName());
113 		assertTrue(x.getUri().toString().contains("final.log"));
114 	}
115 }