View Javadoc

1   package com.github.smokestack.jca.cci;
2   
3   import static org.hamcrest.MatcherAssert.assertThat;
4   
5   import javax.resource.ResourceException;
6   import javax.resource.cci.Connection;
7   import javax.resource.cci.Interaction;
8   import javax.resource.cci.InteractionSpec;
9   import javax.resource.cci.Record;
10  import javax.resource.cci.ResourceWarning;
11  
12  import com.github.smokestack.exception.NeedsMockDefinitionException;
13  
14  import org.apache.commons.lang.builder.ReflectionToStringBuilder;
15  import org.apache.commons.lang.builder.ToStringStyle;
16  import org.hamcrest.core.Is;
17  
18  public class MockInteraction implements Interaction {
19  
20  	protected MockConnection mockConnection;
21  
22  	public enum InteractionState {NEW, CLOSE};
23  	
24  	protected InteractionState interactionState=InteractionState.NEW;
25  	
26  	public MockInteraction(MockConnection mockConnection) {
27  		this.mockConnection=mockConnection;
28  	}
29  
30  	/* (non-Javadoc)
31  	 * @see javax.resource.cci.Interaction#clearWarnings()
32  	 */
33  	public void clearWarnings() throws ResourceException {
34  		_clearWarnings();
35  	}
36  
37  	public void _clearWarnings() throws ResourceException {
38  		throw new NeedsMockDefinitionException();
39  	}
40  
41  	/* (non-Javadoc)
42  	 * @see javax.resource.cci.Interaction#close()
43  	 */
44  	public void close() throws ResourceException {
45  		assertThat("interactionState", interactionState, Is.is(InteractionState.NEW));
46  		interactionState=InteractionState.CLOSE;
47  		_close();
48  	}
49  
50  	public void _close() throws ResourceException {
51  	}
52  
53  	/* (non-Javadoc)
54  	 * @see javax.resource.cci.Interaction#execute(javax.resource.cci.InteractionSpec, javax.resource.cci.Record)
55  	 */
56  	public Record execute(InteractionSpec interactionSpec, Record record) throws ResourceException {
57  		assertThat("interactionState", interactionState, Is.is(InteractionState.NEW));
58  		return _execute(interactionSpec, record);
59  	}
60  
61  	public Record _execute(InteractionSpec interactionSpec, Record record) throws ResourceException {
62  		throw new NeedsMockDefinitionException();
63  	}
64  
65  	/* (non-Javadoc)
66  	 * @see javax.resource.cci.Interaction#execute(javax.resource.cci.InteractionSpec, javax.resource.cci.Record, javax.resource.cci.Record)
67  	 */
68  	public boolean execute(InteractionSpec interactionSpec, Record record1, Record record2) throws ResourceException {
69  		assertThat("interactionState", interactionState, Is.is(InteractionState.NEW));
70  		return _execute(interactionSpec, record1, record2);
71  	}
72  
73  	public boolean _execute(InteractionSpec interactionSpec, Record record1, Record record2) throws ResourceException {
74  		throw new NeedsMockDefinitionException();
75  	}
76  
77  	/* (non-Javadoc)
78  	 * @see javax.resource.cci.Interaction#getConnection()
79  	 */
80  	public Connection getConnection() {
81  		assertThat("interactionState", interactionState, Is.is(InteractionState.NEW));
82  		_getConnection();
83  		return mockConnection;
84  	}
85  
86  	public Connection _getConnection() {
87  		return null;
88  	}
89  
90  	/* (non-Javadoc)
91  	 * @see javax.resource.cci.Interaction#getWarnings()
92  	 */
93  	public ResourceWarning getWarnings() throws ResourceException {
94  		return _getWarnings();
95  	}
96  	
97  	public ResourceWarning _getWarnings() throws ResourceException {
98  		throw new NeedsMockDefinitionException();
99  	}
100 	
101 	public InteractionState getMockInteractionState() {
102 		_getMockInteractionState();
103 		return interactionState;
104 	}
105 	
106 	public InteractionState _getMockInteractionState() {
107 		return null;
108 	}
109 
110 	public void validateMockComplete(){
111 		assertThat("connectionState", interactionState, Is.is(InteractionState.CLOSE));	
112 	}
113 
114 	public String toString(){
115 		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
116 	}
117 }