01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
18:
19: import java.util.Collections;
20: import java.util.Map;
21:
22: import org.apache.tapestry.internal.test.InternalBaseTestCase;
23: import org.apache.tapestry.services.ApplicationStatePersistenceStrategy;
24: import org.apache.tapestry.services.ApplicationStatePersistenceStrategySource;
25: import org.testng.annotations.Test;
26:
27: public class ApplicationStatePersistenceStrategySourceImplTest extends
28: InternalBaseTestCase {
29: @Test
30: public void strategy_found() {
31: ApplicationStatePersistenceStrategy strategy = mockApplicationStatePersistenceStrategy();
32:
33: Map<String, ApplicationStatePersistenceStrategy> configuration = Collections
34: .singletonMap("session", strategy);
35:
36: replay();
37:
38: ApplicationStatePersistenceStrategySource source = new ApplicationStatePersistenceStrategySourceImpl(
39: configuration);
40:
41: assertSame(strategy, source.get("session"));
42:
43: verify();
44: }
45:
46: @Test
47: public void not_found() {
48: ApplicationStatePersistenceStrategy strategy = mockApplicationStatePersistenceStrategy();
49:
50: Map<String, ApplicationStatePersistenceStrategy> configuration = newMap();
51:
52: configuration.put("session", strategy);
53: configuration.put("application", strategy);
54:
55: replay();
56:
57: ApplicationStatePersistenceStrategySource source = new ApplicationStatePersistenceStrategySourceImpl(
58: configuration);
59:
60: try {
61: source.get("aether");
62: unreachable();
63: } catch (RuntimeException ex) {
64: assertEquals(
65: ex.getMessage(),
66: "No application state persistence strategy is available with name 'aether'. Available strategies: application, session.");
67: }
68:
69: verify();
70:
71: }
72: }
|