List of usage examples for org.aspectj.lang ProceedingJoinPoint getSignature
Signature getSignature();
getStaticPart().getSignature()
returns the same object From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java
License:Open Source License
@Test public void testLoadOrRetrieveAny() throws Throwable { checkCredentialsSet();/*from ww w . j ava 2 s . co m*/ cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.ANY); cacheAspect.getCache(Artifact.class).removeAll(); String base = api.getServerApiAddress(); Signature jpSig = createSignatureMock(); Artifact a1 = new Artifact(); a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907")); a1.setLimsid("2-1771911"); Object[] a1args = { a1.getUri(), a1.getClass() }; ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3); EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp1.proceed()).andReturn(a1).once(); EasyMock.replay(pjp1, jpSig); Object returned = cacheAspect.retrieve(pjp1); EasyMock.verify(pjp1, jpSig); assertSame("Did not return a1", a1, returned); // Asking for a later state in ANY mode will just return what it has. Object[] a2args = { base + "/artifacts/2-1771911?state=1500000", a1.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3); EasyMock.replay(pjp2, jpSig); returned = cacheAspect.retrieve(pjp2); assertSame("Did not return a1", a1, returned); EasyMock.verify(pjp2, jpSig); // With an earlier state, it'll be the same object again. Object[] a3args = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp3 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp3.getArgs()).andReturn(a3args).times(3); EasyMock.replay(pjp3, jpSig); returned = cacheAspect.retrieve(pjp3); EasyMock.verify(pjp3, jpSig); assertSame("Did not return a1", a1, returned); // With no state, expect whichever version is in the cache. Object[] a4args = { base + "/artifacts/2-1771911", Artifact.class }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp4 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp4.getArgs()).andReturn(a4args).times(3); EasyMock.replay(pjp4, jpSig); returned = cacheAspect.retrieve(pjp4); EasyMock.verify(pjp4, jpSig); assertSame("Did not return a1", a1, returned); }
From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java
License:Open Source License
@Test public void testLoadOrRetrieveWithOverride() throws Throwable { checkCredentialsSet();// w w w. j a va 2s . com cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.LATEST); cacheAspect.getCache(Artifact.class).removeAll(); String base = api.getServerApiAddress(); Signature jpSig = createSignatureMock(); Artifact a1 = new Artifact(); a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907")); a1.setLimsid("2-1771911"); a1.setQCFlag(QCFlag.FAILED); Object[] a1args = { a1.getUri(), a1.getClass() }; ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3); EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp1.proceed()).andReturn(a1).once(); EasyMock.replay(pjp1, jpSig); Object returned = cacheAspect.retrieve(pjp1); EasyMock.verify(pjp1, jpSig); assertSame("Did not return a1", a1, returned); // With an earlier state, it would normally return the same object. Object[] a2args = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3); EasyMock.replay(pjp2, jpSig); returned = cacheAspect.retrieve(pjp2); EasyMock.verify(pjp2, jpSig); assertSame("Did not return a1", a1, returned); // With an override, we should get an equivalent object back but with a different state. Artifact a3 = new Artifact(); a3.setUri(new URI(base + "/artifacts/2-1771911?state=1101002")); a3.setLimsid("2-1771911"); a3.setQCFlag(QCFlag.PASSED); Object[] a3aargs = { CacheStatefulBehaviour.EXACT }; Object[] a3bargs = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() }; jpSig = createSignatureMock(); ProceedingJoinPoint pjp3a = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp3a.getArgs()).andReturn(a3aargs).once(); EasyMock.expect(pjp3a.proceed()).andReturn(null).once(); ProceedingJoinPoint pjp3b = EasyMock.createStrictMock(ProceedingJoinPoint.class); EasyMock.expect(pjp3b.getArgs()).andReturn(a3bargs).times(3); EasyMock.expect(pjp3b.getSignature()).andReturn(jpSig).times(0, 1); EasyMock.expect(pjp3b.proceed()).andReturn(a3).once(); JoinPoint pjp3c = EasyMock.createStrictMock(JoinPoint.class); EasyMock.expect(pjp3c.getSignature()).andReturn(jpSig).once(); EasyMock.replay(pjp3a, pjp3b, pjp3c, jpSig); cacheAspect.overrideBehaviour(pjp3a); returned = cacheAspect.retrieve(pjp3b); cacheAspect.resetBehaviour(pjp3c); EasyMock.verify(pjp3a, pjp3b, pjp3c, jpSig); assertSame("Did not return a3", a3, returned); }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code get} operations. * Logs the URI being fetched and the reply received. * * @param pjp The AspectJ join point object. * * @return The reply object.//from ww w.jav a 2 s. c o m * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#getForEntity(java.net.URI, Class) * @see RestTemplate#getForObject(java.net.URI, Class) */ public Object checkGet(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; Class<?> type = (Class<?>) pjp.getArgs()[1]; if (logger.isDebugEnabled()) { logger.debug("Requesting a {} with {} from {}", ClassUtils.getShortClassName(type), pjp.getSignature().getName(), uri); } try { Object reply = pjp.proceed(); if (logger.isDebugEnabled()) { displayAfter(reply); } return reply; } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code put} and {@code post} operations. * Logs the XML being sent and the reply received. * * @param pjp The AspectJ join point object. * * @return The reply object./* www .j a v a 2s . co m*/ * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#put(java.net.URI, Object) * @see RestTemplate#postForEntity(java.net.URI, Object, Class) * @see RestTemplate#postForObject(java.net.URI, Object, Class) */ public Object checkPutOrPost(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; Object request = pjp.getArgs()[1]; if (logger.isDebugEnabled()) { logger.debug("Calling {} to {}", pjp.getSignature().getName(), uri); displayBefore(request); } try { Object reply = pjp.proceed(); if (logger.isDebugEnabled()) { displayAfter(reply); } return reply; } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code exchange} operations. * Logs the XML being sent and the reply received. * * @param pjp The AspectJ join point object. * * @return The reply object.// ww w .j av a 2 s . c om * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#exchange(java.net.URI, HttpMethod, HttpEntity, Class) */ public Object checkExchange(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; HttpMethod method = (HttpMethod) pjp.getArgs()[1]; HttpEntity<?> entity = (HttpEntity<?>) pjp.getArgs()[2]; Object request = entity.getBody(); if (logger.isDebugEnabled()) { logger.debug("Calling {} via {} to {}", pjp.getSignature().getName(), method, uri); displayBefore(request); } try { Object reply = pjp.proceed(); if (logger.isDebugEnabled()) { displayAfter(reply); } return reply; } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cruk.genologics.api.debugging.RestClientSnoopingAspect.java
License:Open Source License
/** * Join point for the rest template's {@code exchange} operations. * Logs the URI being deleted.//from www.jav a 2 s . co m * * @param pjp The AspectJ join point object. * * @return The reply object. * * @throws Throwable if there is any failure from the operation. * This is also logged if logging is set to DEBUG. * * @see RestTemplate#delete(java.net.URI) */ public Object checkDelete(ProceedingJoinPoint pjp) throws Throwable { Object uri = pjp.getArgs()[0]; if (logger.isDebugEnabled()) { logger.debug("Deleting with {} from {}", pjp.getSignature().getName(), uri); } try { return pjp.proceed(); } catch (Throwable e) { fail(e); throw e; } }
From source file:org.cybercat.automation.core.DataProviderAspect.java
License:Apache License
public Object applyData(ProceedingJoinPoint pjp) throws AutomationFrameworkException { String methodName = pjp.getSignature().getName(); Method[] methods = pjp.getTarget().getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(methodName)) { System.out.println("found"); try { Object[] arg = createData(methods[i], pjp.getArgs()); return pjp.proceed(arg); } catch (Throwable e) { throw new PageObjectException(e); }/*from w w w. j a v a 2 s . co m*/ } } return null; }
From source file:org.cybercat.automation.core.SoapServicesAspect.java
License:Apache License
private Method getMethod(ProceedingJoinPoint pjp) { String methodName = pjp.getSignature().getName(); Method[] methods = pjp.getTarget().getClass().getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(methodName)) { return methods[i]; }//www. j a v a 2 s. co m } return null; }
From source file:org.cyclop.validation.AopValidator.java
License:Apache License
private void executeResponseValidation(ProceedingJoinPoint pjp, Object response) { MethodSignature sig = (MethodSignature) pjp.getSignature(); Method method = sig.getMethod(); BeanValidator validator = null;//from w w w. j av a 2 s . co m for (Annotation respAnnotatioin : method.getDeclaredAnnotations()) { if (respAnnotatioin.annotationType().isAssignableFrom(NotNull.class) || (respAnnotatioin.annotationType().isAssignableFrom(Valid.class) && response != null)) { if (validator == null) { validator = createValidator(pjp); } validator.add("METHOD_RETURN_VALUE", response); } } if (validator != null) { validator.validate(); } }
From source file:org.cyclop.validation.AopValidator.java
License:Apache License
private void executeParamValidation(ProceedingJoinPoint pjp) { Object[] args = pjp.getArgs(); MethodSignature sig = (MethodSignature) pjp.getSignature(); Method method = sig.getMethod(); Annotation[][] allParamAnnotations = method.getParameterAnnotations(); BeanValidator validator = null;//from ww w .ja v a 2 s . c om for (int paramIdx = 0; paramIdx < allParamAnnotations.length; paramIdx++) { Annotation[] paramAnnotations = allParamAnnotations[paramIdx]; if (paramAnnotations == null || paramAnnotations.length == 0) { continue; } Object obj = args[paramIdx]; if (contains(paramAnnotations, NotNull.class) || (contains(paramAnnotations, Valid.class) && obj != null)) { if (validator == null) { validator = createValidator(pjp); } validator.add("METHOD_PARAM_INDEX_" + paramIdx, obj); } } if (validator != null) { validator.validate(); } }