1   /*
2    * Copyright 2006 the original author or authors.
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  
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, Properties headers) {
35          Assert.notNull(inputStream, "inputStream must not be null");
36          Assert.notNull(headers, "headers must not be null");
37          this.inputStream = inputStream;
38          this.headers = headers;
39      }
40  
41      public MockTransportInputStream(InputStream inputStream) {
42          Assert.notNull(inputStream, "inputStream must not be null");
43          this.inputStream = inputStream;
44          headers = new Properties();
45      }
46  
47      protected InputStream createInputStream() throws IOException {
48          return inputStream;
49      }
50  
51      public Iterator getHeaderNames() throws IOException {
52          return headers.keySet().iterator();
53      }
54  
55      public Iterator getHeaders(String name) throws IOException {
56          String[] values = StringUtils.delimitedListToStringArray(headers.getProperty(name), ", ");
57          return Arrays.asList(values).iterator();
58      }
59  }