Skip to content

Package: MockSessionProvider

MockSessionProvider

nameinstructionbranchcomplexitylinemethod
MockSessionProvider()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getInstance()
M: 4 C: 4
50%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
getSessionId()
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
registerListenerWithSession(UISessionListener)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setSessionProvider(MockSessionProvider.SessionProviderType)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Neil Mackenzie - initial implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.core.rap.sessionprovider.test;
15:
16: import org.eclipse.emf.ecp.core.rap.SessionProvider;
17: import org.eclipse.rap.rwt.service.UISessionListener;
18:
19: /**
20: * This s a mock session provider for testing, it does not
21: * recieve a web session.
22: *
23: * @author neilmack
24: *
25: */
26: public class MockSessionProvider implements SessionProvider {
27:
28:         /**
29:          *
30:          */
31:         public enum SessionProviderType {
32:                 /**
33:                  * SAME_SESSION_ID relates to test where succesive
34:                  * calls are from the same session, DIFFERENT_SESSION_ID refers to
35:                  * when succesive calls are form different sessions.
36:                  */
37:                 SAME_SESSION_ID, DIFFERENT_SESSION_ID;
38:         }
39:
40:         /**
41:          * session ID.
42:          */
43:         private int sessionId;
44:
45:         /**
46:          * The type od session, types defined in SessionProviderType enum.
47:          */
48:         private static SessionProviderType type;
49:         /**
50:          * THe singleton instance.
51:          */
52:         private static MockSessionProvider instance;
53:
54:         /**
55:          * default constructor.
56:          */
57:         public MockSessionProvider() {
58:                 instance = this;
59:         }
60:
61:         /**
62:          * returns the provider instance.
63:          *
64:          * @return the provider instance
65:          */
66:         public static MockSessionProvider getInstance() {
67:•                if (instance == null) {
68:                         instance = new MockSessionProvider();
69:                 }
70:                 return instance;
71:         }
72:
73:         /**
74:          * sets the type of the session provider. this determines whether
75:          * the provider gives the same id each time it is asked for a sessionID
76:          * or a different one each time.
77:          *
78:          * @param type the type
79:          */
80:         public static void setSessionProvider(SessionProviderType type) {
81:                 MockSessionProvider.type = type;
82:         }
83:
84:         @Override
85:         public final String getSessionId() {
86:•                if (type.equals(SessionProviderType.SAME_SESSION_ID)) {
87:                         return "1212"; //$NON-NLS-1$
88:                 }
89:                 return (++sessionId) + ""; //$NON-NLS-1$
90:
91:         }
92:
93:         /**
94:          * {@inheritDoc}
95:          *
96:          * @see org.eclipse.emf.ecp.core.rap.SessionProvider#registerListenerWithSession(UISessionListener)
97:          */
98:         @Override
99:         public void registerListenerWithSession(UISessionListener listener) {
100:                 // do nothing since this is the Mock inplementation.
101:         }
102:
103: }