1 /*
2 * Copyright 2010 James Pether Sörling
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * $Id$
17 * $HeadURL$
18 */
19 package com.hack23.cia.testfoundation;
20
21 import java.io.BufferedReader;
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.InputStreamReader;
25 import java.nio.charset.StandardCharsets;
26
27 import javax.xml.transform.stream.StreamSource;
28
29 import org.springframework.oxm.Unmarshaller;
30
31 /**
32 * The Class AbstractUnmarshallXmlTest.
33 *
34 * @param <T>
35 * the generic type
36 */
37 public abstract class AbstractUnmarshallXmlTest<T> extends AbstractFunctionalIntegrationTest {
38
39 /**
40 * Instantiates a new abstract unmarshall xml test.
41 */
42 public AbstractUnmarshallXmlTest() {
43 super();
44 }
45
46 /**
47 * Unmarshall xml.
48 *
49 * @param unmarshaller
50 * the unmarshaller
51 * @param filename
52 * the filename
53 * @return the t
54 * @throws Exception
55 * the exception
56 */
57 protected final T unmarshallXml(final Unmarshaller unmarshaller,final String filename) throws Exception {
58 final BufferedReader inputStream= new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename)),StandardCharsets.UTF_8));
59
60 return (T) unmarshaller.unmarshal(new StreamSource(inputStream));
61 }
62 }