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.soap;
18  
19  import static org.apache.juneau.commons.utils.CollectionUtils.*;
20  import static org.junit.jupiter.api.Assertions.*;
21  
22  import java.util.function.*;
23  
24  import org.apache.juneau.*;
25  import org.apache.juneau.commons.reflect.*;
26  import org.apache.juneau.soap.annotation.*;
27  import org.apache.juneau.svl.*;
28  import org.junit.jupiter.api.*;
29  
30  /**
31   * Tests the @SoapXmlConfig annotation.
32   */
33  class SoapXmlConfigAnnotationTest extends TestBase {
34  
35  	private static void check(String expected, Object o) {
36  		assertEquals(expected, TO_STRING.apply(o));
37  	}
38  
39  	private static final Function<Object,String> TO_STRING = Object::toString;
40  
41  	static VarResolverSession sr = VarResolver.create().vars(XVar.class).build().createSession();
42  
43  	//-----------------------------------------------------------------------------------------------------------------
44  	// Basic tests
45  	//-----------------------------------------------------------------------------------------------------------------
46  
47  	@SoapXmlConfig(
48  		soapAction="$X{foo}"
49  	)
50  	static class A {}
51  	static ClassInfo a = ClassInfo.of(A.class);
52  
53  	@Test void basic() {
54  		var al = AnnotationWorkList.of(sr, rstream(a.getAnnotations()));
55  		var x = SoapXmlSerializer.create().apply(al).build().getSession();
56  		check("foo", x.getSoapAction());
57  	}
58  
59  	//-----------------------------------------------------------------------------------------------------------------
60  	// Annotation with no values.
61  	//-----------------------------------------------------------------------------------------------------------------
62  
63  	@SoapXmlConfig()
64  	static class B {}
65  	static ClassInfo b = ClassInfo.of(B.class);
66  
67  	@Test void noValues() {
68  		var al = AnnotationWorkList.of(sr, rstream(b.getAnnotations()));
69  		var x = SoapXmlSerializer.create().apply(al).build().getSession();
70  		check("http://www.w3.org/2003/05/soap-envelope", x.getSoapAction());
71  	}
72  
73  	//-----------------------------------------------------------------------------------------------------------------
74  	// No annotation.
75  	//-----------------------------------------------------------------------------------------------------------------
76  
77  	static class C {}
78  	static ClassInfo c = ClassInfo.of(C.class);
79  
80  	@Test void noAnnotation() {
81  		var al = AnnotationWorkList.of(sr, rstream(c.getAnnotations()));
82  		var x = SoapXmlSerializer.create().apply(al).build().getSession();
83  		check("http://www.w3.org/2003/05/soap-envelope", x.getSoapAction());
84  	}
85  }