summaryrefslogtreecommitdiffstats
path: root/bindings/java/tests/BindingTests.java
blob: ebd1a6391d32d8c1463d346feab1a5a9d92ce13d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * $Id: BindingTests.java 3238 2007-05-30 17:24:50Z dlaniel $
 *
 * Java unit tests for Lasso library
 *
 * Copyright (C) 2004-2007 Entr'ouvert
 * http://lasso.entrouvert.org
 *
 * Authors: See AUTHORS file in top-level directory.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import com.entrouvert.lasso.*;
import java.util.*;


public class BindingTests extends TestCase {
    public static void main(String args[]) { 
	junit.textui.TestRunner.run(suite());
        System.gc();
    }

    public static Test suite() { 
	return new TestSuite(BindingTests.class); 
    }

    public void test01() {
	// Create and delete nodes.

	LibAuthnRequest authnRequest = new LibAuthnRequest();
        assertNotNull(authnRequest);
	authnRequest = null;
    }

    public void test02() {
	// Get & set simple attributes of nodes.

	LibAuthnRequest authnRequest = new LibAuthnRequest();

	// Test a string attribute.
	assertNull(authnRequest.getConsent());
	authnRequest.setConsent(LassoConstants.LIB_CONSENT_OBTAINED);
	assertEquals(authnRequest.getConsent(), LassoConstants.LIB_CONSENT_OBTAINED);
	authnRequest.setConsent(null);
	assertNull(authnRequest.getConsent());

	// Test a renamed string attribute.
	assertNull(authnRequest.getRelayState());
	authnRequest.setRelayState("Hello World!");
	assertEquals(authnRequest.getRelayState(), "Hello World!");
	authnRequest.setRelayState(null);
	assertNull(authnRequest.getRelayState());

	// Test an integer attribute.
	assertEquals(authnRequest.getMajorVersion(), 0);
	authnRequest.setMajorVersion(314);
	assertEquals(authnRequest.getMajorVersion(), 314);

	authnRequest = null;
    }

    public void test03() {
	// Get & set attributes of nodes of type string list.

	LibAuthnRequest authnRequest = new LibAuthnRequest();

	assertTrue(authnRequest.getRespondWith().isEmpty());

	List respondWith = new ArrayList();
	assertEquals(respondWith.size(), 0);
	respondWith.add("first string");
	assertEquals(respondWith.size(), 1);
	assertEquals(respondWith.get(0), "first string");
	assertEquals(respondWith.get(0), "first string");
	respondWith.add("second string");
	assertEquals(respondWith.size(), 2);
	assertEquals(respondWith.get(0), "first string");
	assertEquals(respondWith.get(1), "second string");
	respondWith.add("third string");
	assertEquals(respondWith.size(), 3);
	assertEquals(respondWith.get(0), "first string");
	assertEquals(respondWith.get(1), "second string");
	assertEquals(respondWith.get(2), "third string");
	authnRequest.setRespondWith(respondWith);
	assertEquals(authnRequest.getRespondWith().get(0), "first string");
	assertEquals(authnRequest.getRespondWith().get(1), "second string");
	assertEquals(authnRequest.getRespondWith().get(2), "third string");
	assertEquals(respondWith.get(0), "first string");
	assertEquals(respondWith.get(1), "second string");
	assertEquals(respondWith.get(2), "third string");
	respondWith = null;
	assertEquals(authnRequest.getRespondWith().get(0), "first string");
	assertEquals(authnRequest.getRespondWith().get(1), "second string");
	assertEquals(authnRequest.getRespondWith().get(2), "third string");
	respondWith = authnRequest.getRespondWith();
	assertEquals(respondWith.get(0), "first string");
	assertEquals(respondWith.get(1), "second string");
	assertEquals(respondWith.get(2), "third string");
	respondWith = null;
	assertEquals(authnRequest.getRespondWith().get(0), "first string");
	assertEquals(authnRequest.getRespondWith().get(1), "second string");
	assertEquals(authnRequest.getRespondWith().get(2), "third string");
        authnRequest.removeFromRespondWith("second string");
	assertEquals(authnRequest.getRespondWith().get(0), "first string");
	assertEquals(authnRequest.getRespondWith().get(1), "third string");
        authnRequest.addToRespondWith("second string");
	assertEquals(authnRequest.getRespondWith().get(0), "first string");
	assertEquals(authnRequest.getRespondWith().get(1), "third string");
	assertEquals(authnRequest.getRespondWith().get(2), "second string");
	authnRequest.setRespondWith(null);
	assertTrue(authnRequest.getRespondWith().isEmpty());

	authnRequest = null;
    }

    public void test04() {
        // Get & set attributes of nodes of type node list.

        SamlpResponse response = new SamlpResponse();

        assertTrue(response.getAssertion().isEmpty());

        List assertions = new ArrayList();
        assertEquals(assertions.size(), 0);
        SamlAssertion assertion1 = new SamlAssertion();
        assertion1.setAssertionId("assertion 1");
        assertions.add(assertion1);
        assertEquals(assertions.size(), 1);
        assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1");
        SamlAssertion assertion2 = new SamlAssertion();
        assertion2.setAssertionId("assertion 2");
        assertions.add(assertion2);
        assertEquals(assertions.size(), 2);
        assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) assertions.get(1)).getAssertionId(), "assertion 2");
        SamlAssertion assertion3 = new SamlAssertion();
        assertion3.setAssertionId("assertion 3");
        assertions.add(assertion3);
        assertEquals(assertions.size(), 3);
        assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) assertions.get(1)).getAssertionId(), "assertion 2");
        assertEquals(((SamlAssertion) assertions.get(2)).getAssertionId(), "assertion 3");
        response.setAssertion(assertions);
        assertEquals(((SamlAssertion) response.getAssertion().get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) response.getAssertion().get(1)).getAssertionId(), "assertion 2");
        assertEquals(((SamlAssertion) response.getAssertion().get(2)).getAssertionId(), "assertion 3");
        assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) assertions.get(1)).getAssertionId(), "assertion 2");
        assertEquals(((SamlAssertion) assertions.get(2)).getAssertionId(), "assertion 3");
        assertions = null;;
        assertEquals(((SamlAssertion) response.getAssertion().get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) response.getAssertion().get(1)).getAssertionId(), "assertion 2");
        assertEquals(((SamlAssertion) response.getAssertion().get(2)).getAssertionId(), "assertion 3");
        assertions = response.getAssertion();
        assertEquals(((SamlAssertion) assertions.get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) assertions.get(1)).getAssertionId(), "assertion 2");
        assertEquals(((SamlAssertion) assertions.get(2)).getAssertionId(), "assertion 3");
        assertions = null;
        assertEquals(((SamlAssertion) response.getAssertion().get(0)).getAssertionId(), "assertion 1");
        assertEquals(((SamlAssertion) response.getAssertion().get(1)).getAssertionId(), "assertion 2");
        assertEquals(((SamlAssertion) response.getAssertion().get(2)).getAssertionId(), "assertion 3");
        response.setAssertion(null);
        assertTrue(response.getAssertion().isEmpty());

	response = null;
    }

    public void test05() {
	// Get & set attributes of nodes of type XML list.

	LibAuthnRequest authnRequest = new LibAuthnRequest();

	assertTrue(authnRequest.getExtension().isEmpty());

        String actionString1 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" + "  <action>do 1</action>\n" + "</lib:Extension>";
        String actionString2 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" + "  <action>do 2</action>\n" + "</lib:Extension>";
        String actionString3 = "<lib:Extension xmlns:lib=\"urn:liberty:iff:2003-08\">\n" + "  <action>do 3</action>\n" + "</lib:Extension>";
	List extension = new ArrayList();
	assertEquals(extension.size(), 0);
	extension.add(actionString1);
	assertEquals(extension.size(), 1);
	assertEquals(extension.get(0), actionString1);
	assertEquals(extension.get(0), actionString1);
	extension.add(actionString2);
	assertEquals(extension.size(), 2);
	assertEquals(extension.get(0), actionString1);
	assertEquals(extension.get(1), actionString2);
	extension.add(actionString3);
	assertEquals(extension.size(), 3);
	assertEquals(extension.get(0), actionString1);
	assertEquals(extension.get(1), actionString2);
	assertEquals(extension.get(2), actionString3);
	authnRequest.setExtension(extension);
	assertEquals(authnRequest.getExtension().get(0), actionString1);
	assertEquals(authnRequest.getExtension().get(1), actionString2);
	assertEquals(authnRequest.getExtension().get(2), actionString3);
	assertEquals(extension.get(0), actionString1);
	assertEquals(extension.get(1), actionString2);
	assertEquals(extension.get(2), actionString3);
	extension = null;
	assertEquals(authnRequest.getExtension().get(0), actionString1);
	assertEquals(authnRequest.getExtension().get(1), actionString2);
	assertEquals(authnRequest.getExtension().get(2), actionString3);
	extension = authnRequest.getExtension();
	assertEquals(extension.get(0), actionString1);
	assertEquals(extension.get(1), actionString2);
	assertEquals(extension.get(2), actionString3);
	extension = null;
	assertEquals(authnRequest.getExtension().get(0), actionString1);
	assertEquals(authnRequest.getExtension().get(1), actionString2);
	assertEquals(authnRequest.getExtension().get(2), actionString3);
	authnRequest.setExtension(null);
	assertTrue(authnRequest.getExtension().isEmpty());

	authnRequest = null;
    }

    public void test06() {
        // Get & set attributes of nodes of type node.

        Login login = new Login(new Server(null, null, null, null));

        assertNull(login.getRequest());
        login.setRequest((SamlpRequestAbstract) new LibAuthnRequest());
        ((LibAuthnRequest) login.getRequest()).setConsent(LassoConstants.LIB_CONSENT_OBTAINED);
        assertEquals(((LibAuthnRequest) login.getRequest()).getConsent(), LassoConstants.LIB_CONSENT_OBTAINED);
        login.setRequest(null);
        assertNull(login.getRequest());

        login = null;
    }
}