01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.jetspeed.layout;
18:
19: import org.apache.jetspeed.components.portletregistry.PortletRegistry;
20: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
21: import org.apache.pluto.om.common.Parameter;
22: import org.apache.pluto.om.common.ParameterSet;
23: import org.jmock.Mock;
24: import org.jmock.core.Constraint;
25: import org.jmock.core.InvocationMatcher;
26: import org.jmock.core.constraint.IsEqual;
27: import org.jmock.core.matcher.InvokeAtLeastOnceMatcher;
28: import org.jmock.core.stub.ReturnStub;
29:
30: /**
31: * @version $Id: MockPortletRegistryFactory.java 598481 2007-11-27 00:47:29Z ate $
32: *
33: */
34: public class MockPortletRegistryFactory {
35: public static PortletRegistry createMockPortletRegistry() {
36: Mock portletRegistryMock;
37: PortletRegistry portletRegistry;
38: Mock portletDefMock;
39: PortletDefinitionComposite portletDef;
40: Mock portletDefInitParamsMock;
41: ParameterSet portletDefInitParams;
42:
43: Mock portletSizesParamMock;
44: Parameter portletSizesParam;
45:
46: portletRegistryMock = new Mock(PortletRegistry.class);
47: portletRegistry = (PortletRegistry) portletRegistryMock.proxy();
48:
49: portletDefMock = new Mock(PortletDefinitionComposite.class);
50: portletDef = (PortletDefinitionComposite) portletDefMock
51: .proxy();
52:
53: portletDefInitParamsMock = new Mock(ParameterSet.class);
54: portletDefInitParams = (ParameterSet) portletDefInitParamsMock
55: .proxy();
56:
57: portletSizesParamMock = new Mock(Parameter.class);
58: portletSizesParam = (Parameter) portletSizesParamMock.proxy();
59:
60: expectAndReturn(new InvokeAtLeastOnceMatcher(),
61: portletSizesParamMock, "getValue", "33%,66%");
62: expectAndReturn(new InvokeAtLeastOnceMatcher(),
63: portletDefInitParamsMock, "get",
64: new Constraint[] { new IsEqual("sizes") },
65: portletSizesParam);
66: expectAndReturn(new InvokeAtLeastOnceMatcher(), portletDefMock,
67: "getInitParameterSet", portletDefInitParams);
68: expectAndReturn(new InvokeAtLeastOnceMatcher(),
69: portletRegistryMock,
70: "getPortletDefinitionByUniqueName",
71: new Constraint[] { new IsEqual("layout") }, portletDef);
72: return portletRegistry;
73: }
74:
75: protected static void expectAndReturn(InvocationMatcher matcher,
76: Mock mock, String methodName, Constraint[] constraints,
77: Object returnValue) {
78: mock.expects(matcher).method(methodName).with(constraints)
79: .will(new ReturnStub(returnValue));
80: }
81:
82: protected static void expectAndReturn(InvocationMatcher matcher,
83: Mock mock, String methodName, Object returnValue) {
84: mock.expects(matcher).method(methodName).withNoArguments()
85: .will(new ReturnStub(returnValue));
86: }
87: }
|