View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.tests.remoting.jaxws;
18  
19  //Checkstyle: EmptyBlock off
20  //Checkstyle: MagicNumber off
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   * This class is a test for JAX-WS using the generated classes directly.
39   *
40   * @svnLink $Revision: 4181 $;$Date: 2010-10-28 09:12:24 +0200 (Do, 28. Okt 2010) $;$Author: sstelca $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/tests/remoting_jaxws/functional-tests/src/test/java/ch/elca/el4j/tests/remoting/jaxws/CalculatorJaxwsGeneratedTest.java $
41   *
42   * @author Philippe Jacot (PJA)
43   * @author Stefan Wismer (SWI)
44   */
45  public class CalculatorJaxwsGeneratedTest extends AbstractJaxwsTest {
46  	/**
47  	 * Is the delta to doubles can have to be equal.
48  	 */
49  	private static final double DOUBLE_TOLERANCE = 0.000000001;
50  	
51  	/** {@inheritDoc} */
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  	 * This test tests the area calculation method.
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  	 * This test tests the exception handling.
77  	 */
78  	@Test
79  	public void testExceptionBehaviour() {
80  		// Checkstyle: EmptyBlock off
81  		try {
82  			getCalc().throwMeAnException();
83  			fail("No exception was thrown.");
84  		} catch (CalculatorException_Exception e) {
85  			// This is expected
86  		}
87  	}
88  	
89  	/**
90  	 * This test tests the counting of uppercase letters.
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 	 * This test is used to test if a value object will be serialized and
103 	 * deserialized correctly.
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 		// test int[]
121 		o.setMyByteArray(MY_BYTE_ARRAY);
122 		o.getMyIntArray().add(9);
123 		o.getMyIntArray().add(2);
124 		
125 		// test int[][]
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 	 * Get the calculator to use.
201 	 * @return Calculator to use
202 	 */
203 	public Calculator getCalc() {
204 		return (Calculator) getApplicationContext().getBean("calculatorGenerated");
205 	}
206 }