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.a.rttests;
18  
19  import static org.junit.jupiter.api.Assertions.*;
20  
21  import org.apache.juneau.annotation.*;
22  import org.junit.jupiter.params.*;
23  import org.junit.jupiter.params.provider.*;
24  
25  /**
26   * Tests designed to serialize and parse objects to make sure we end up
27   * with the same objects for all serializers and parsers.
28   */
29  class ReadOnlyBeans_RoundTripTest extends RoundTripTest_Base {
30  
31  	//====================================================================================================
32  	// test
33  	//====================================================================================================
34  
35  	@ParameterizedTest
36  	@MethodSource("testers")
37  	void a01_basic(RoundTrip_Tester t) throws Exception {
38  		var x1 = new B(1, "a");
39  		var x2 = new B(2, "b");
40  		var x3 = new A(x1, x2);
41  
42  		x3 = t.roundTrip(x3, A.class);
43  		assertEquals(1, x3.getF1().getF1());
44  		assertEquals("a", x3.getF1().getF2());
45  		assertEquals(2, x3.getF2().getF1());
46  		assertEquals("b", x3.getF2().getF2());
47  	}
48  
49  	public static class A {
50  		private B f1;
51  		private final B f2;
52  
53  		@Beanc(properties="f2")
54  		public A(B f2) {
55  			this.f2 = f2;
56  		}
57  
58  		public A(B f1, B f2) {
59  			this.f1 = f1;
60  			this.f2 = f2;
61  		}
62  
63  		public B getF1() { return f1; }
64  		public void setF1(B v) { f1 = v; }
65  
66  		public B getF2() { return f2; }
67  	}
68  
69  	public static class B {
70  		private int f1;
71  		private final String f2;
72  
73  		@Beanc(properties="f2")
74  		public B(String sField) {
75  			this.f2 = sField;
76  		}
77  
78  		public B(int iField, String sField) {
79  			this.f1 = iField;
80  			this.f2 = sField;
81  		}
82  
83  		public int getF1() { return f1;}
84  		public void setF1(int v) { f1 = v; }
85  
86  		public String getF2() { return f2; }
87  	}
88  }