View Javadoc
1   /*
2    * Copyright 2009 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  package org.openehealth.ipf.commons.ihe.ws.utils;
17  
18  import org.junit.Assert;
19  
20  import javax.activation.DataSource;
21  import java.io.InputStream;
22  import java.io.IOException;
23  import java.io.OutputStream;
24  
25  /**
26   * Data source used in tests to provide a large content stream.
27   * @author Jens Riemschneider
28   */
29  public class LargeDataSource implements DataSource {
30      /** Content stream size for tests with large content. Must be larger than 64K to ensure
31       * CXF does use MTOM. */
32      public static final int STREAM_SIZE = 70000;
33  
34      @Override
35      public InputStream getInputStream() throws IOException {
36          return new InputStream() {
37              private int idx;
38  
39              @Override
40              public int read() throws IOException {
41                  if (idx >= STREAM_SIZE) {
42                      return -1;
43                  }
44                  ++idx;
45                  return 65;
46              }
47  
48              @Override
49              public void close() throws IOException {
50                  Assert.assertEquals(STREAM_SIZE, idx);
51                  super.close();
52              }
53          };
54      }
55  
56      @Override
57      public OutputStream getOutputStream() throws IOException {
58          throw new UnsupportedOperationException();
59      }
60  
61      @Override
62      public String getContentType() {
63          return "test/plain";
64      }
65  
66      @Override
67      public String getName() {
68          return "dummy";
69      }
70  }