01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.springframework.ws.transport;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.util.Arrays;
22: import java.util.Iterator;
23: import java.util.Properties;
24:
25: import org.springframework.util.Assert;
26: import org.springframework.util.StringUtils;
27:
28: public class MockTransportInputStream extends TransportInputStream {
29:
30: private Properties headers;
31:
32: private InputStream inputStream;
33:
34: public MockTransportInputStream(InputStream inputStream,
35: Properties headers) {
36: Assert.notNull(inputStream, "inputStream must not be null");
37: Assert.notNull(headers, "headers must not be null");
38: this .inputStream = inputStream;
39: this .headers = headers;
40: }
41:
42: public MockTransportInputStream(InputStream inputStream) {
43: Assert.notNull(inputStream, "inputStream must not be null");
44: this .inputStream = inputStream;
45: headers = new Properties();
46: }
47:
48: protected InputStream createInputStream() throws IOException {
49: return inputStream;
50: }
51:
52: public Iterator getHeaderNames() throws IOException {
53: return headers.keySet().iterator();
54: }
55:
56: public Iterator getHeaders(String name) throws IOException {
57: String[] values = StringUtils.delimitedListToStringArray(
58: headers.getProperty(name), ", ");
59: return Arrays.asList(values).iterator();
60: }
61: }
|