01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: /**
19: * @author Vera Y. Petrashkova
20: * @version $Revision$
21: */package org.apache.harmony.auth.tests.javax.security.sasl.serialization;
22:
23: import java.io.Serializable;
24:
25: import javax.security.sasl.RealmChoiceCallback;
26:
27: import org.apache.harmony.testframework.serialization.SerializationTest;
28:
29: /**
30: * Test for RealmChoiceCallback serialization
31: *
32: */
33:
34: public class RealmChoiceCallbackTest extends SerializationTest
35: implements SerializationTest.SerializableAssert {
36:
37: public static String[] msgs = {
38: "New String",
39: "Another string",
40: "Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string. Long string.",
41: "t" };
42:
43: public static final int[] idx = { 2, 3 };
44:
45: @Override
46: protected Object[] getData() {
47: Object[] oo = {
48: new RealmChoiceCallback(msgs[0], msgs, 0, true),
49: new RealmChoiceCallback(msgs[1], msgs, 1, true),
50: new RealmChoiceCallback(msgs[1], msgs, 0, false),
51: new RealmChoiceCallback(msgs[2], msgs, 0, false)
52:
53: };
54: for (Object element : oo) {
55: RealmChoiceCallback rc = (RealmChoiceCallback) element;
56: if (rc.allowMultipleSelections()) {
57: rc.setSelectedIndexes(idx);
58: } else {
59: rc.setSelectedIndex(msgs.length - 1);
60: }
61: }
62: return oo;
63: }
64:
65: public void assertDeserialized(Serializable oref, Serializable otest) {
66: RealmChoiceCallback ref = (RealmChoiceCallback) oref;
67: RealmChoiceCallback test = (RealmChoiceCallback) otest;
68:
69: boolean all = ref.allowMultipleSelections();
70: assertEquals(all, test.allowMultipleSelections());
71: String prompt = ref.getPrompt();
72: assertEquals(prompt, test.getPrompt());
73:
74: String[] ch = ref.getChoices();
75: String[] tCh = test.getChoices();
76: assertEquals(ch.length, tCh.length);
77: for (int i = 0; i < ch.length; i++) {
78: assertEquals(ch[i], tCh[i]);
79: }
80: assertEquals(ref.getDefaultChoice(), test.getDefaultChoice());
81: int[] in = ref.getSelectedIndexes();
82: int[] tIn = test.getSelectedIndexes();
83: // assertNull("in is not null", in);
84: // assertNull("tIn is not null", tIn);
85:
86: if (!all) {
87: assertEquals("Incorrect length in ", in.length, 1);
88: assertEquals("Incorrect length tIn ", tIn.length, 1);
89: assertEquals("Incorrect index", in[0], tIn[0]);
90: } else {
91: assertEquals("Incorrect length", in.length, tIn.length);
92: for (int i = 0; i < in.length; i++) {
93: assertEquals(in[i], tIn[i]);
94: }
95: }
96: }
97: }
|