summaryrefslogtreecommitdiffstats
path: root/java/tests/BindingTests.java
blob: ddde3ba336e91c2808a43d0f394632ad396aae29 (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
/*
 * $Id$
 *
 * Java unit tests for Lasso library
 *
 * Copyright (C) 2004, 2005 Entr'ouvert
 * http://lasso.entrouvert.org
 *
 * Authors: See AUTHORS file.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

// To run it:
// $ export LD_LIBRARY_PATH=../
// $ javac -classpath /usr/share/java/junit.jar:../lasso.jar:. BindingTests.java
// $ java -classpath /usr/share/java/junit.jar:../lasso.jar:. BindingTests
// or for gcj:
// $ export LD_LIBRARY_PATH=../
// $ gcj -C -classpath /usr/share/java/junit.jar:../lasso.jar:. BindingTests.java
// $ gij -classpath /usr/share/java/junit.jar:../lasso.jar:. BindingTests


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

import com.entrouvert.lasso.*;


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

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

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

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

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

	LibAuthnRequest authnRequest = new LibAuthnRequest();

	// Test a string attribute.
	assertNull(authnRequest.getConsent());
	authnRequest.setConsent(lasso.libConsentObtained);
	assertEquals(authnRequest.getConsent(), lasso.libConsentObtained);
	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();

	assertNull(authnRequest.getRespondWith());

	StringList respondWith = new StringList();
	assertEquals(respondWith.length(), 0);
	respondWith.append("first string");
	assertEquals(respondWith.length(), 1);
	assertEquals(respondWith.getItem(0), "first string");
	assertEquals(respondWith.getItem(0), "first string");
	respondWith.append("second string");
	assertEquals(respondWith.length(), 2);
	assertEquals(respondWith.getItem(0), "first string");
	assertEquals(respondWith.getItem(1), "second string");
	respondWith.append("third string");
	assertEquals(respondWith.length(), 3);
	assertEquals(respondWith.getItem(0), "first string");
	assertEquals(respondWith.getItem(1), "second string");
	assertEquals(respondWith.getItem(2), "third string");
	authnRequest.setRespondWith(respondWith);
	assertEquals(authnRequest.getRespondWith().getItem(0), "first string");
	assertEquals(authnRequest.getRespondWith().getItem(1), "second string");
	assertEquals(authnRequest.getRespondWith().getItem(2), "third string");
	assertEquals(respondWith.getItem(0), "first string");
	assertEquals(respondWith.getItem(1), "second string");
	assertEquals(respondWith.getItem(2), "third string");
	respondWith = null;
	assertEquals(authnRequest.getRespondWith().getItem(0), "first string");
	assertEquals(authnRequest.getRespondWith().getItem(1), "second string");
	assertEquals(authnRequest.getRespondWith().getItem(2), "third string");
	respondWith = authnRequest.getRespondWith();
	assertEquals(respondWith.getItem(0), "first string");
	assertEquals(respondWith.getItem(1), "second string");
	assertEquals(respondWith.getItem(2), "third string");
	respondWith = null;
	assertEquals(authnRequest.getRespondWith().getItem(0), "first string");
	assertEquals(authnRequest.getRespondWith().getItem(1), "second string");
	assertEquals(authnRequest.getRespondWith().getItem(2), "third string");
	authnRequest.setRespondWith(null);
	assertNull(authnRequest.getRespondWith());

	authnRequest = null;
    }
}