1111 distributed under the License is distributed on an "AS IS" BASIS,
1212 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313 See the License for the specific language governing permissions and
14- limitations under the License.
14+ limitations under the License.
1515"""
1616import logging
1717import unittest
@@ -33,11 +33,11 @@ def testPointcutInterface(self):
3333 pointcut = Pointcut ()
3434 self .assertRaises (NotImplementedError , pointcut .class_filter )
3535 self .assertRaises (NotImplementedError , pointcut .method_matcher )
36-
36+
3737 def testMethodMatcherInterface (self ):
3838 methodMatcher = MethodMatcher ()
3939 self .assertRaises (NotImplementedError , methodMatcher .matches_method_and_target , None , None , None )
40-
40+
4141 def testMethodInterceptorInterface (self ):
4242 methodInterceptor = MethodInterceptor ()
4343 self .assertRaises (NotImplementedError , methodInterceptor .invoke , None )
@@ -55,7 +55,7 @@ def testCreatingAProxyFactoryAndAddingAnInterceptorProgrammatically(self):
5555 self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
5656 self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
5757 self .assertEquals ("sample" , service .attribute )
58-
58+
5959 def testCreatingAProxyFactoryAndAddingAnInterceptorIoC (self ):
6060 factory = self .appContext .get_object ("factory" )
6161 service = factory .getProxy ()
@@ -71,7 +71,7 @@ def testWrappingStringFunctionWithInterceptor(self):
7171 self .assertEquals ("This is a sample service." , str (service .target ))
7272 self .assertEquals ("<Wrapped>This is a sample service.</Wrapped>" , str (service ))
7373 self .assertEquals ("<Wrapped>This is a sample service.</Wrapped>" , service .__str__ ())
74-
74+
7575 def testCreatingAProxyFactoryObjectAndAddingAnInterceptorProgrammatically (self ):
7676 service = ProxyFactoryObject ()
7777 service .target = SampleService ()
@@ -95,7 +95,7 @@ def testApplyingTwoConditionalPointcutsIoC(self):
9595 sampleService = self .appContext .get_object ("sampleService2" )
9696 self .assertEquals (sampleService .doSomething (), "BEFORE => <Wrapped>Alright!</Wrapped> <= AFTER" )
9797 self .assertEquals (sampleService .method ("testdata" ), "You made it! => testdata" )
98-
98+
9999 def testApplyingASingleConditionalPointcutProgrammatically (self ):
100100 wrappingAdvice = WrappingInterceptor ()
101101 pointcutAdvisor = RegexpMethodPointcutAdvisor ()
@@ -118,13 +118,32 @@ def testApplyingTwoConditionalPointcutsProgrammatically(self):
118118 sampleService .target = targetService
119119 self .assertEquals (sampleService .doSomething (), "BEFORE => <Wrapped>Alright!</Wrapped> <= AFTER" )
120120 self .assertEquals (sampleService .method ("testdata" ), "You made it! => testdata" )
121-
121+
122122 def testCreatingAProxyFactoryObjectWithAnInterceptorByClassNameInsteadOfInstanceIoC (self ):
123123 service = self .appContext .get_object ("sampleService5" )
124124 self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
125125 self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
126126 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+
128147#class AopProxyFactoryCombinedWithPyroTestCase(unittest.TestCase):
129148# """Tests mixing AOP proxies and Pyro with the point cut on either the client or the server side."""
130149# def __init__(self, methodName='runTest'):
@@ -143,7 +162,7 @@ def testCreatingAProxyFactoryObjectWithAnInterceptorByClassNameInsteadOfInstance
143162#
144163# # TODO: There is some issue with running this and the previous test at the same time. It is some type of unforseeable
145164# # dependency. Each test works fine when the other is commented out. Must resolve.
146- #
165+ #
147166# #def testWrappingPyroProxyOnServerSideIoC(self):
148167# # remoteService = self.appContext.get_object("remoteService2")
149168# # clientService = self.appContext.get_object("service2")
@@ -154,9 +173,9 @@ def testCreatingAProxyFactoryObjectWithAnInterceptorByClassNameInsteadOfInstance
154173class AopProxiedArgumentsTest (unittest .TestCase ):
155174 def testCallingProxiedMethodWithProxiedPositionalArguments (self ):
156175 targetService = SampleService ()
157-
176+
158177 service = ProxyFactoryObject (target = targetService , interceptors = WrappingInterceptor ())
159-
178+
160179 self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
161180 self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
162181 self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
@@ -167,7 +186,7 @@ def testCallingProxiedMethodWithProxiedPositionalArguments(self):
167186 def testCallingProxiedMethodWithProxiedNamedArguments (self ):
168187 targetService = SampleService ()
169188 service = ProxyFactoryObject (target = targetService , interceptors = WrappingInterceptor ())
170-
189+
171190 self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method (data = "test" ))
172191 self .assertEquals ("<Wrapped>Alright!</Wrapped>" , service .doSomething ())
173192 self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
@@ -179,17 +198,17 @@ def testCallingRegExpProxiedMethodThatHasArgumentsWithProxiedPositionalArguments
179198 pointcutAdvisor = RegexpMethodPointcutAdvisor (advice = WrappingInterceptor (),
180199 patterns = ["SampleService.method" ])
181200 service = ProxyFactoryObject (target = SampleService (), interceptors = pointcutAdvisor )
182-
201+
183202 self .assertEquals ("Alright!" , service .doSomething ())
184203 self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method ("test" ))
185204 self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
186205 service .method (service .doSomething ()))
187-
206+
188207 def testCallingRegExpProxiedMethodThatHasArgumentsWithProxiedNamedArguments (self ):
189208 pointcutAdvisor = RegexpMethodPointcutAdvisor (advice = WrappingInterceptor (),
190209 patterns = ["SampleService.method" ])
191210 service = ProxyFactoryObject (target = SampleService (), interceptors = pointcutAdvisor )
192-
211+
193212 self .assertEquals ("<Wrapped>You made it! => test</Wrapped>" , service .method (data = "test" ))
194213 self .assertEquals ("<Wrapped>You made it! => Alright!</Wrapped>" ,
195214 service .method (data = service .doSomething ()))
@@ -203,7 +222,7 @@ def testCallingRegExpProxiedMethodThatHasNoArgumentsWithProxiedPositionalArgumen
203222 self .assertEquals ("You made it! => test" , service .method ("test" ))
204223 self .assertEquals ("You made it! => <Wrapped>Alright!</Wrapped>" ,
205224 service .method (service .doSomething ()))
206-
225+
207226 def testCallingRegExpProxiedMethodThatHasNoArgumentsWithProxiedNamedArguments (self ):
208227 pointcutAdvisor = RegexpMethodPointcutAdvisor (advice = WrappingInterceptor (),
209228 patterns = ["SampleService.doSomething" ])
@@ -219,7 +238,7 @@ def testCallingRegExpProxiedMethodThatHasNoArgumentsWithProxiedNamedArguments(se
219238 logger .setLevel (loggingLevel )
220239 ch = logging .StreamHandler ()
221240 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" )
223242 ch .setFormatter (formatter )
224243 logger .addHandler (ch )
225244
0 commit comments