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.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 SchemaValidationException_Test extends TestBase {
25  
26  	@Test void a01_basic() {
27  		var x = new SchemaValidationException("Test message");
28  		assertNotNull(x);
29  		assertTrue(x.getMessage().contains("Test message"));
30  	}
31  
32  	@Test void a02_withArgs() {
33  		var x = new SchemaValidationException("Test {0} {1}", "foo", "bar");
34  		assertTrue(x.getMessage().contains("Test foo bar"));
35  	}
36  
37  	@Test void a03_setMessage_fluentChaining() {
38  		var x = new SchemaValidationException("Original");
39  
40  		// Test that setMessage returns SchemaValidationException for fluent chaining
41  		SchemaValidationException result = x.setMessage("New message");
42  		assertSame(x, result);
43  		assertInstanceOf(SchemaValidationException.class, result);
44  		assertTrue(result.getMessage().contains("New message"));
45  	}
46  
47  	@Test void a04_getRootCause_single() {
48  		var x = new SchemaValidationException("Root cause");
49  
50  		// Test that getRootCause returns SchemaValidationException (not ParseException)
51  		SchemaValidationException root = x.getRootCause();
52  		assertSame(x, root);
53  		assertInstanceOf(SchemaValidationException.class, root);
54  	}
55  
56  	@Test void a05_getRootCause_nested() {
57  		var cause = new SchemaValidationException("Cause");
58  		var middle = new SchemaValidationException("Middle");
59  		middle.initCause(cause);
60  		var top = new SchemaValidationException("Top");
61  		top.initCause(middle);
62  
63  		// Test that getRootCause returns the deepest SchemaValidationException
64  		SchemaValidationException root = top.getRootCause();
65  		assertSame(cause, root);
66  		assertInstanceOf(SchemaValidationException.class, root);
67  		assertTrue(root.getMessage().contains("Cause"));
68  	}
69  
70  	@Test void a06_fluentChaining() {
71  		// Test multiple fluent calls can be chained
72  		var x = new SchemaValidationException("Initial")
73  			.setMessage("Updated message");
74  
75  		assertTrue(x.getMessage().contains("Updated message"));
76  	}
77  }