11
11
distributed under the License is distributed on an "AS IS" BASIS,
12
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
See the License for the specific language governing permissions and
14
- limitations under the License.
14
+ limitations under the License.
15
15
"""
16
16
import logging
17
17
import unittest
@@ -33,11 +33,11 @@ def testPointcutInterface(self):
33
33
pointcut = Pointcut ()
34
34
self .assertRaises (NotImplementedError , pointcut .class_filter )
35
35
self .assertRaises (NotImplementedError , pointcut .method_matcher )
36
-
36
+
37
37
def testMethodMatcherInterface (self ):
38
38
methodMatcher = MethodMatcher ()
39
39
self .assertRaises (NotImplementedError , methodMatcher .matches_method_and_target , None , None , None )
40
-
40
+
41
41
def testMethodInterceptorInterface (self ):
42
42
methodInterceptor = MethodInterceptor ()
43
43
self .assertRaises (NotImplementedError , methodInterceptor .invoke , None )
@@ -55,7 +55,7 @@ def testCreatingAProxyFactoryAndAddingAnInterceptorProgrammatically(self):
55
55
self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
56
56
self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
57
57
self .assertEquals ("sample" , service .attribute )
58
-
58
+
59
59
def testCreatingAProxyFactoryAndAddingAnInterceptorIoC (self ):
60
60
factory = self .appContext .get_object ("factory" )
61
61
service = factory .getProxy ()
@@ -71,7 +71,7 @@ def testWrappingStringFunctionWithInterceptor(self):
71
71
self .assertEquals ("This is a sample service." , str (service .target ))
72
72
self .assertEquals ("<Wrapped>This is a sample service.</Wrapped>" , str (service ))
73
73
self .assertEquals ("<Wrapped>This is a sample service.</Wrapped>" , service .__str__ ())
74
-
74
+
75
75
def testCreatingAProxyFactoryObjectAndAddingAnInterceptorProgrammatically (self ):
76
76
service = ProxyFactoryObject ()
77
77
service .target = SampleService ()
@@ -95,7 +95,7 @@ def testApplyingTwoConditionalPointcutsIoC(self):
95
95
sampleService = self .appContext .get_object ("sampleService2" )
96
96
self .assertEquals (sampleService .doSomething (), "BEFORE => <Wrapped>Alright!</Wrapped> <= AFTER" )
97
97
self .assertEquals (sampleService .method ("testdata" ), "You made it! => testdata" )
98
-
98
+
99
99
def testApplyingASingleConditionalPointcutProgrammatically (self ):
100
100
wrappingAdvice = WrappingInterceptor ()
101
101
pointcutAdvisor = RegexpMethodPointcutAdvisor ()
@@ -118,13 +118,32 @@ def testApplyingTwoConditionalPointcutsProgrammatically(self):
118
118
sampleService .target = targetService
119
119
self .assertEquals (sampleService .doSomething (), "BEFORE => <Wrapped>Alright!</Wrapped> <= AFTER" )
120
120
self .assertEquals (sampleService .method ("testdata" ), "You made it! => testdata" )
121
-
121
+
122
122
def testCreatingAProxyFactoryObjectWithAnInterceptorByClassNameInsteadOfInstanceIoC (self ):
123
123
service = self .appContext .get_object ("sampleService5" )
124
124
self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
125
125
self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
126
126
self .assertEquals ("sample" , service .attribute )
127
-
127
+
128
+ def testProxyFactoryObjectInterceptorsNotWrappedInAList (self ):
129
+ service = ProxyFactoryObject ()
130
+ service .target = SampleService ()
131
+
132
+ # Note that it isn't wrapped in a list.
133
+ service .interceptors = WrappingInterceptor ()
134
+
135
+ self .assertEquals ("This is a sample service." , service .target .__str__ ())
136
+ self .assertEquals ("This is a sample service." , str (service .target ))
137
+ self .assertEquals ("<Wrapped>This is a sample service.</Wrapped>" , str (service ))
138
+ self .assertEquals ("<Wrapped>This is a sample service.</Wrapped>" , service .__str__ ())
139
+
140
+ # sampleService6 has an interceptor which isn't wrapped in a list
141
+ # inside its XMLConfig.
142
+ service = self .appContext .get_object ("sampleService6" )
143
+ self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
144
+ self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
145
+ self .assertEquals ("sample" , service .attribute )
146
+
128
147
#class AopProxyFactoryCombinedWithPyroTestCase(unittest.TestCase):
129
148
# """Tests mixing AOP proxies and Pyro with the point cut on either the client or the server side."""
130
149
# def __init__(self, methodName='runTest'):
@@ -143,7 +162,7 @@ def testCreatingAProxyFactoryObjectWithAnInterceptorByClassNameInsteadOfInstance
143
162
#
144
163
# # TODO: There is some issue with running this and the previous test at the same time. It is some type of unforseeable
145
164
# # dependency. Each test works fine when the other is commented out. Must resolve.
146
- #
165
+ #
147
166
# #def testWrappingPyroProxyOnServerSideIoC(self):
148
167
# # remoteService = self.appContext.get_object("remoteService2")
149
168
# # clientService = self.appContext.get_object("service2")
@@ -154,9 +173,9 @@ def testCreatingAProxyFactoryObjectWithAnInterceptorByClassNameInsteadOfInstance
154
173
class AopProxiedArgumentsTest (unittest .TestCase ):
155
174
def testCallingProxiedMethodWithProxiedPositionalArguments (self ):
156
175
targetService = SampleService ()
157
-
176
+
158
177
service = ProxyFactoryObject (target = targetService , interceptors = WrappingInterceptor ())
159
-
178
+
160
179
self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
161
180
self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
162
181
self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
@@ -167,7 +186,7 @@ def testCallingProxiedMethodWithProxiedPositionalArguments(self):
167
186
def testCallingProxiedMethodWithProxiedNamedArguments (self ):
168
187
targetService = SampleService ()
169
188
service = ProxyFactoryObject (target = targetService , interceptors = WrappingInterceptor ())
170
-
189
+
171
190
self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method (data = "test" ))
172
191
self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
173
192
self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
@@ -179,17 +198,17 @@ def testCallingRegExpProxiedMethodThatHasArgumentsWithProxiedPositionalArguments
179
198
pointcutAdvisor = RegexpMethodPointcutAdvisor (advice = WrappingInterceptor (),
180
199
patterns = ["SampleService.method" ])
181
200
service = ProxyFactoryObject (target = SampleService (), interceptors = pointcutAdvisor )
182
-
201
+
183
202
self .assertEquals ("Alright!" , service .doSomething ())
184
203
self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
185
204
self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
186
205
service .method (service .doSomething ()))
187
-
206
+
188
207
def testCallingRegExpProxiedMethodThatHasArgumentsWithProxiedNamedArguments (self ):
189
208
pointcutAdvisor = RegexpMethodPointcutAdvisor (advice = WrappingInterceptor (),
190
209
patterns = ["SampleService.method" ])
191
210
service = ProxyFactoryObject (target = SampleService (), interceptors = pointcutAdvisor )
192
-
211
+
193
212
self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method (data = "test" ))
194
213
self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
195
214
service .method (data = service .doSomething ()))
@@ -203,7 +222,7 @@ def testCallingRegExpProxiedMethodThatHasNoArgumentsWithProxiedPositionalArgumen
203
222
self .assertEquals ("You made it! => test" , service .method ("test" ))
204
223
self .assertEquals ("You made it! => <Wrapped>Alright!</Wrapped>" ,
205
224
service .method (service .doSomething ()))
206
-
225
+
207
226
def testCallingRegExpProxiedMethodThatHasNoArgumentsWithProxiedNamedArguments (self ):
208
227
pointcutAdvisor = RegexpMethodPointcutAdvisor (advice = WrappingInterceptor (),
209
228
patterns = ["SampleService.doSomething" ])
@@ -219,7 +238,7 @@ def testCallingRegExpProxiedMethodThatHasNoArgumentsWithProxiedNamedArguments(se
219
238
logger .setLevel (loggingLevel )
220
239
ch = logging .StreamHandler ()
221
240
ch .setLevel (loggingLevel )
222
- formatter = logging .Formatter ("%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
241
+ formatter = logging .Formatter ("%(asctime)s - %(name)s - %(levelname)s - %(message)s" )
223
242
ch .setFormatter (formatter )
224
243
logger .addHandler (ch )
225
244
0 commit comments