Skip to content

Commit 42e18e6

Browse files
committed
fixed OpenEntityManagerInViewTests through the addition of a local copy of our Servlet API mocks; restoredOpenPersistenceManagerInViewTests
1 parent d876777 commit 42e18e6

13 files changed

+2825
-138
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2002-2011 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.mock.web;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import javax.servlet.ServletInputStream;
22+
23+
import org.springframework.util.Assert;
24+
25+
/**
26+
* Delegating implementation of {@link javax.servlet.ServletInputStream}.
27+
*
28+
* <p>Used by {@link org.springframework.mock.web.MockHttpServletRequest}; typically not directly
29+
* used for testing application controllers.
30+
*
31+
* @author Juergen Hoeller
32+
* @since 1.0.2
33+
* @see org.springframework.mock.web.MockHttpServletRequest
34+
*/
35+
public class DelegatingServletInputStream extends ServletInputStream {
36+
37+
private final InputStream sourceStream;
38+
39+
40+
/**
41+
* Create a DelegatingServletInputStream for the given source stream.
42+
* @param sourceStream the source stream (never <code>null</code>)
43+
*/
44+
public DelegatingServletInputStream(InputStream sourceStream) {
45+
Assert.notNull(sourceStream, "Source InputStream must not be null");
46+
this.sourceStream = sourceStream;
47+
}
48+
49+
/**
50+
* Return the underlying source stream (never <code>null</code>).
51+
*/
52+
public final InputStream getSourceStream() {
53+
return this.sourceStream;
54+
}
55+
56+
57+
public int read() throws IOException {
58+
return this.sourceStream.read();
59+
}
60+
61+
public void close() throws IOException {
62+
super.close();
63+
this.sourceStream.close();
64+
}
65+
66+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2002-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+
17+
package org.springframework.mock.web;
18+
19+
import java.io.IOException;
20+
import java.io.OutputStream;
21+
import javax.servlet.ServletOutputStream;
22+
23+
import org.springframework.util.Assert;
24+
25+
/**
26+
* Delegating implementation of {@link javax.servlet.ServletOutputStream}.
27+
*
28+
* <p>Used by {@link org.springframework.mock.web.MockHttpServletResponse}; typically not directly
29+
* used for testing application controllers.
30+
*
31+
* @author Juergen Hoeller
32+
* @since 1.0.2
33+
* @see org.springframework.mock.web.MockHttpServletResponse
34+
*/
35+
public class DelegatingServletOutputStream extends ServletOutputStream {
36+
37+
private final OutputStream targetStream;
38+
39+
40+
/**
41+
* Create a DelegatingServletOutputStream for the given target stream.
42+
* @param targetStream the target stream (never <code>null</code>)
43+
*/
44+
public DelegatingServletOutputStream(OutputStream targetStream) {
45+
Assert.notNull(targetStream, "Target OutputStream must not be null");
46+
this.targetStream = targetStream;
47+
}
48+
49+
/**
50+
* Return the underlying target stream (never <code>null</code>).
51+
*/
52+
public final OutputStream getTargetStream() {
53+
return this.targetStream;
54+
}
55+
56+
57+
public void write(int b) throws IOException {
58+
this.targetStream.write(b);
59+
}
60+
61+
public void flush() throws IOException {
62+
super.flush();
63+
this.targetStream.flush();
64+
}
65+
66+
public void close() throws IOException {
67+
super.close();
68+
this.targetStream.close();
69+
}
70+
71+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2002-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+
17+
package org.springframework.mock.web;
18+
19+
import java.util.ArrayList;
20+
import java.util.Collection;
21+
import java.util.Collections;
22+
import java.util.LinkedList;
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
import org.springframework.util.Assert;
27+
import org.springframework.util.CollectionUtils;
28+
29+
/**
30+
* Internal helper class that serves as value holder for request headers.
31+
*
32+
* @author Juergen Hoeller
33+
* @author Rick Evans
34+
* @since 2.0.1
35+
*/
36+
class HeaderValueHolder {
37+
38+
private final List<Object> values = new LinkedList<Object>();
39+
40+
41+
public void setValue(Object value) {
42+
this.values.clear();
43+
this.values.add(value);
44+
}
45+
46+
public void addValue(Object value) {
47+
this.values.add(value);
48+
}
49+
50+
public void addValues(Collection<?> values) {
51+
this.values.addAll(values);
52+
}
53+
54+
public void addValueArray(Object values) {
55+
CollectionUtils.mergeArrayIntoCollection(values, this.values);
56+
}
57+
58+
public List<Object> getValues() {
59+
return Collections.unmodifiableList(this.values);
60+
}
61+
62+
public List<String> getStringValues() {
63+
List<String> stringList = new ArrayList<String>(this.values.size());
64+
for (Object value : this.values) {
65+
stringList.add(value.toString());
66+
}
67+
return Collections.unmodifiableList(stringList);
68+
}
69+
70+
public Object getValue() {
71+
return (!this.values.isEmpty() ? this.values.get(0) : null);
72+
}
73+
74+
75+
/**
76+
* Find a HeaderValueHolder by name, ignoring casing.
77+
* @param headers the Map of header names to HeaderValueHolders
78+
* @param name the name of the desired header
79+
* @return the corresponding HeaderValueHolder,
80+
* or <code>null</code> if none found
81+
*/
82+
public static HeaderValueHolder getByName(Map<String, HeaderValueHolder> headers, String name) {
83+
Assert.notNull(name, "Header name must not be null");
84+
for (String headerName : headers.keySet()) {
85+
if (headerName.equalsIgnoreCase(name)) {
86+
return headers.get(headerName);
87+
}
88+
}
89+
return null;
90+
}
91+
92+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2002-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+
17+
package org.springframework.mock.web;
18+
19+
import javax.servlet.FilterChain;
20+
import javax.servlet.ServletRequest;
21+
import javax.servlet.ServletResponse;
22+
23+
import org.springframework.util.Assert;
24+
25+
/**
26+
* Mock implementation of the {@link javax.servlet.FilterConfig} interface.
27+
*
28+
* <p>Used for testing the web framework; also useful for testing
29+
* custom {@link javax.servlet.Filter} implementations.
30+
*
31+
* @author Juergen Hoeller
32+
* @since 2.0.3
33+
* @see org.springframework.mock.web.MockFilterConfig
34+
* @see org.springframework.mock.web.PassThroughFilterChain
35+
*/
36+
public class MockFilterChain implements FilterChain {
37+
38+
private ServletRequest request;
39+
40+
private ServletResponse response;
41+
42+
43+
/**
44+
* Records the request and response.
45+
*/
46+
public void doFilter(ServletRequest request, ServletResponse response) {
47+
Assert.notNull(request, "Request must not be null");
48+
Assert.notNull(response, "Response must not be null");
49+
if (this.request != null) {
50+
throw new IllegalStateException("This FilterChain has already been called!");
51+
}
52+
this.request = request;
53+
this.response = response;
54+
}
55+
56+
/**
57+
* Return the request that {@link #doFilter} has been called with.
58+
*/
59+
public ServletRequest getRequest() {
60+
return this.request;
61+
}
62+
63+
/**
64+
* Return the response that {@link #doFilter} has been called with.
65+
*/
66+
public ServletResponse getResponse() {
67+
return this.response;
68+
}
69+
70+
}

0 commit comments

Comments
 (0)