1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.tests.remoting.jaxws;
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Set;
27
28 import org.junit.Test;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32 import static org.junit.Assert.fail;
33
34 import ch.elca.el4j.tests.remoting.jaxws.service.Calculator;
35 import ch.elca.el4j.tests.remoting.jaxws.service.CalculatorException;
36 import ch.elca.el4j.tests.remoting.jaxws.service.CalculatorValueObject;
37 import ch.elca.el4j.tests.remoting.jaxws.service.SomeIntValue;
38
39
40
41
42
43
44
45
46
47
48
49 public class CalculatorJaxwsTest extends AbstractJaxwsTest {
50
51
52
53 private static final double DOUBLE_TOLERANCE = 0.000000001;
54
55
56 @Override
57 protected String[] getIncludeConfigLocations() {
58 return new String[] {"classpath*:mandatory/*.xml",
59 "classpath*:scenarios/db/raw/*.xml",
60 "classpath*:scenarios/dataaccess/*.xml",
61 "classpath*:scenarios/dataaccess/hibernate/*.xml",
62 "classpath*:scenarios/dataaccess/hibernate/refdb/*.xml",
63 "scenarios/client/remotingtests-jaxws-client-config.xml"};
64 }
65
66
67
68
69 @Test
70 public void testAreaCalculation() {
71 final double VALUE_A = 2.3;
72 final double VALUE_B = 5.7;
73 final double FAULT_DELTA = 0.00000001;
74 double result = getCalc().getArea(VALUE_A, VALUE_B);
75 assertEquals("The area is not correctly calculated.", result,
76 VALUE_A * VALUE_B, FAULT_DELTA);
77 }
78
79
80
81
82 @Test
83 public void testExceptionBehaviour() {
84
85 try {
86 getCalc().throwMeAnException();
87 fail("No exception was thrown.");
88 } catch (CalculatorException e) {
89
90 }
91 }
92
93
94
95
96 @Test
97 public void testNumberOfUppercaseCharacters() {
98 String message = "Hans Müller likes to pay with Euro.";
99 int numberOfUppercaseLetters = 3;
100 int result = getCalc().countNumberOfUppercaseLetters(message);
101 assertEquals("The number of uppercase letter was not "
102 + "counted correctly.", result, numberOfUppercaseLetters);
103 }
104
105
106
107
108
109 @Test
110 public void testEchoOfValueObject() {
111 final int MY_INT = 449312154;
112 final long MY_LONG = 3121846575454654L;
113 final double MY_DOUBLE = 6994.641368469;
114 final String MY_STRING
115 = "I can not find any ä, ö, ü, é, è or à character on my keyboard.";
116 final byte[] MY_BYTE_ARRAY = MY_STRING.getBytes();
117
118 CalculatorValueObject o = new CalculatorValueObject();
119 o.setMyInt(MY_INT);
120 o.setMyLong(MY_LONG);
121 o.setMyDouble(MY_DOUBLE);
122 o.setMyString(MY_STRING);
123 o.setMyByteArray(MY_BYTE_ARRAY);
124
125
126 o.setMyIntArray(new int[] {9, 2});
127
128
129 o.setMyIntMatrix(new int[][]{new int[] {5, 8}, new int[] {1, -4}});
130
131 SomeIntValue v = new SomeIntValue(MY_INT);
132 o.setSomeValue(v);
133
134 List<SomeIntValue> intValues = new ArrayList<SomeIntValue>();
135 intValues.add(v);
136 o.setMyNestedObjectList(intValues);
137
138 List<Integer> list = new ArrayList<Integer>();
139 list.add(4);
140 list.add(7);
141 o.setMyIntegerList(list);
142
143 Set<Integer> set = new HashSet<Integer>();
144 set.add(2);
145 set.add(5);
146 o.setMyIntegerSet(set);
147
148 CalculatorValueObject echo = getCalc().echoValueObject(o);
149
150 assertEquals("Int values are not equal.",
151 o.getMyInt(), echo.getMyInt());
152 assertEquals("Long values are not equal.",
153 o.getMyLong(), echo.getMyLong());
154 assertEquals("Double values are not equal.",
155 o.getMyDouble(), echo.getMyDouble(), DOUBLE_TOLERANCE);
156 assertEquals("Strings are not equal.",
157 o.getMyString(), echo.getMyString());
158 assertTrue("Byte arrays are not equal.",
159 Arrays.equals(o.getMyByteArray(), echo.getMyByteArray()));
160 assertEquals("SomeIntValue are not equal.",
161 o.getSomeValue().getSomeValue(),
162 echo.getSomeValue().getSomeValue());
163
164 assertEquals("MyNestedObjectList is not equal.",
165 o.getMyNestedObjectList().get(0).getSomeValue(),
166 echo.getMyNestedObjectList().get(0).getSomeValue());
167
168 if (echo.getMyIntegerList().size() == list.size()) {
169 assertTrue("List items are not equal.",
170 echo.getMyIntegerList().get(0).equals(Integer.valueOf(4))
171 && echo.getMyIntegerList().get(1).equals(Integer.valueOf(7)));
172 } else {
173 fail("List size is not equal.");
174 }
175
176 if (echo.getMyIntegerSet().size() == set.size()) {
177 assertTrue("Set items are not equal.",
178 echo.getMyIntegerSet().contains(Integer.valueOf(2))
179 && echo.getMyIntegerSet().contains(Integer.valueOf(5)));
180 } else {
181 fail("Set size is not equal.");
182 }
183
184 assertTrue("int[] is not equal.",
185 echo.getMyIntArray()[0] == 9
186 && echo.getMyIntArray()[1] == 2);
187
188 assertTrue("int[][] is not equal.",
189 echo.getMyIntMatrix()[0][0] == 5
190 && echo.getMyIntMatrix()[0][1] == 8
191 && echo.getMyIntMatrix()[1][0] == 1
192 && echo.getMyIntMatrix()[1][1] == -4);
193 }
194
195
196
197
198
199 public Calculator getCalc() {
200 return (Calculator) getApplicationContext().getBean("calculator");
201 }
202 }