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