@Uri("") @Produces @Typed(MockEndpoint.class) // Qualifiers are dynamically added in CdiCamelExtension private static MockEndpoint mockEndpointFromUri(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { Uri uri = getQualifierByType(ip, Uri.class).get(); try { CamelContext context = uri.context().isEmpty() ? selectContext(ip, instance, extension) : selectContext(uri.context(), instance); return context.getEndpoint(uri.value(), MockEndpoint.class); } catch (Exception cause) { throw new InjectionException("Error injecting mock endpoint annotated with " + uri + " into " + ip, cause); } }
private Set<Type> calcBeanTypes(Type implTpye) { Set<Type> beanTypes = Sets.newHashSet(); if (implTpye instanceof ParameterizedType) { beanTypes.add((ParameterizedType) implTpye); } else { Typed typedAnnotation = ((Class<?>) implTpye).getAnnotation(Typed.class); if (typedAnnotation != null) { for (Class<?> cls : typedAnnotation.value()) { beanTypes.add(cls); } } else { beanTypes.addAll(getTypeClasses((Class<?>) implTpye)); } } return beanTypes; }
@Produces @Typed(MockEndpoint.class) // Qualifiers are dynamically added in CdiCamelExtension private static MockEndpoint mockEndpointFromMember(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { String uri = "mock:" + ip.getMember().getName(); try { return selectContext(ip, instance, extension).getEndpoint(uri, MockEndpoint.class); } catch (Exception cause) { throw new InjectionException("Error injecting mock endpoint into " + ip, cause); } }
@Mock @Produces @Typed(MockEndpoint.class) // Qualifiers are dynamically added in CdiCamelExtension private static MockEndpoint createMockEndpoint(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { Mock mock = getQualifierByType(ip, Mock.class).get(); try { CamelContext context = mock.context().isEmpty() ? selectContext(ip, instance, extension) : selectContext(mock.context(), instance); return context.getEndpoint(mock.value(), MockEndpoint.class); } catch (Exception cause) { throw new InjectionException("Error injecting mock endpoint annotated with " + mock + " into " + ip, cause); } }
boolean equalsAsTyped(BeanType given) { if (!equalsWithoutType(given)) { return false; } for (Class<?> t : type.getAnnotation(Typed.class).value()) { if (given.getType() == t) { return true; } } return false; }
/** * Producer method for the ClientDataRequest. */ @Produces @PortletRequestScoped @Named("clientDataRequest") @Typed(ClientDataRequest.class) public static ClientDataRequest produceClientDataRequest() { PortletArtifactProducer pap = producers.get(); assert pap != null; ClientDataRequest req = null; if (pap.req instanceof ClientDataRequest) { req = (ClientDataRequest) pap.req; } return req; }
/** * Producer method for the MimeResponse. */ @Produces @PortletRequestScoped @Named("mimeResponse") @Typed(MimeResponse.class) public static MimeResponse produceMimeResponse() { PortletArtifactProducer pap = producers.get(); assert pap != null; MimeResponse resp = null; if (pap.resp instanceof MimeResponse) { resp = (MimeResponse) pap.resp; } return resp; }
/** * Producer method for the StateAwareResponse. */ @Produces @PortletRequestScoped @Named("stateAwareResponse") @Typed(StateAwareResponse.class) public static StateAwareResponse produceStateAwareResponse() { PortletArtifactProducer pap = producers.get(); assert pap != null; StateAwareResponse resp = null; if (pap.resp instanceof StateAwareResponse) { resp = (StateAwareResponse) pap.resp; } return resp; }
/** * Producer method for the ActionRequest. */ @Produces @PortletRequestScoped @Named("actionRequest") @Typed(ActionRequest.class) public static ActionRequest produceActionRequest() { PortletArtifactProducer pap = producers.get(); assert pap != null; ActionRequest req = null; if (pap.req instanceof ActionRequest) { req = (ActionRequest) pap.req; } return req; }
/** * Producer method for the ActionResponse. */ @Produces @PortletRequestScoped @Named("actionResponse") @Typed(ActionResponse.class) public static ActionResponse produceActionResponse() { PortletArtifactProducer pap = producers.get(); assert pap != null; ActionResponse resp = null; if (pap.resp instanceof ActionResponse) { resp = (ActionResponse) pap.resp; } return resp; }
/** * Producer method for the HeaderRequest. */ @Produces @PortletRequestScoped @Named("headerRequest") @Typed(HeaderRequest.class) public static HeaderRequest produceHeaderRequest() { PortletArtifactProducer pap = producers.get(); assert pap != null; HeaderRequest req = null; if (pap.req instanceof HeaderRequest) { req = (HeaderRequest) pap.req; } return req; }
/** * Producer method for the HeaderResponse. */ @Produces @PortletRequestScoped @Named("headerResponse") @Typed(HeaderResponse.class) public static HeaderResponse produceHeaderResponse() { PortletArtifactProducer pap = producers.get(); assert pap != null; HeaderResponse resp = null; if (pap.resp instanceof HeaderResponse) { resp = (HeaderResponse) pap.resp; } return resp; }
/** * Producer method for the RenderRequest. */ @Produces @PortletRequestScoped @Named("renderRequest") @Typed(RenderRequest.class) public static RenderRequest produceRenderRequest() { PortletArtifactProducer pap = producers.get(); assert pap != null; RenderRequest req = null; if ((pap.req instanceof RenderRequest) && !(pap.req instanceof HeaderRequest)) { req = (RenderRequest) pap.req; } return req; }
/** * Producer method for the RenderResponse. */ @Produces @PortletRequestScoped @Named("renderResponse") @Typed(RenderResponse.class) public static RenderResponse produceRenderResponse() { PortletArtifactProducer pap = producers.get(); assert pap != null; RenderResponse resp = null; if (pap.resp instanceof RenderResponse) { resp = (RenderResponse) pap.resp; } return resp; }
/** * Producer method for the EventRequest. */ @Produces @PortletRequestScoped @Named("eventRequest") @Typed(EventRequest.class) public static EventRequest produceEventRequest() { PortletArtifactProducer pap = producers.get(); assert pap != null; EventRequest req = null; if (pap.req instanceof EventRequest) { req = (EventRequest) pap.req; } return req; }
/** * Producer method for the EventResponse. * @return */ @Produces @PortletRequestScoped @Named("eventResponse") @Typed(EventResponse.class) public static EventResponse produceEventResponse() { PortletArtifactProducer pap = producers.get(); assert pap != null; EventResponse resp = null; if (pap.resp instanceof EventResponse) { resp = (EventResponse) pap.resp; } return resp; }
/** * Producer method for the ResourceRequest. * @return */ @Produces @PortletRequestScoped @Named("resourceRequest") @Typed(ResourceRequest.class) public static ResourceRequest produceResourceRequest() { PortletArtifactProducer pap = producers.get(); assert pap != null; ResourceRequest req = null; if (pap.req instanceof ResourceRequest) { req = (ResourceRequest) pap.req; } return req; }
/** * Producer method for the ResourceResponse. */ @Produces @PortletRequestScoped @Named("resourceResponse") @Typed(ResourceResponse.class) public static ResourceResponse produceResourceResponse() { PortletArtifactProducer pap = producers.get(); assert pap != null; ResourceResponse resp = null; if (pap.resp instanceof ResourceResponse) { resp = (ResourceResponse) pap.resp; } return resp; }
/** * Producer method for the render paramters. */ @Produces @PortletRequestScoped @Named("renderParams") @Typed(RenderParameters.class) public static RenderParameters getRenderParameters() { PortletArtifactProducer pap = producers.get(); assert pap != null; return pap.req.getRenderParameters(); }
/** * Producer method for the mutable render parameters. */ @Produces @PortletRequestScoped @Named("mutableRenderParams") @Typed(MutableRenderParameters.class) public static MutableRenderParameters getMutableRenderParameters() { PortletArtifactProducer pap = producers.get(); assert pap != null; MutableRenderParameters obj = null; if (pap.resp instanceof StateAwareResponse) { obj = ((StateAwareResponse)pap.resp).getRenderParameters(); } return obj; }
/** * Producer method for the action parameters. */ @Produces @PortletRequestScoped @Named("actionParams") @Typed(ActionParameters.class) public static ActionParameters getActionParameters() { PortletArtifactProducer pap = producers.get(); assert pap != null; ActionParameters obj = null; if (pap.req instanceof ActionRequest) { obj = ((ActionRequest)pap.req).getActionParameters(); } return obj; }
/** * Producer method for the resource parameters. */ @Produces @PortletRequestScoped @Named("resourceParams") @Typed(ResourceParameters.class) public static ResourceParameters getResourceParameters() { PortletArtifactProducer pap = producers.get(); assert pap != null; ResourceParameters obj = null; if (pap.req instanceof ResourceRequest) { obj = ((ResourceRequest)pap.req).getResourceParameters(); } return obj; }
@Produces @Typed(MockEndpoint.class) // Alternative is dynamically added in CdiCamelExtension private static MockEndpoint mockEndpointFromMember(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { String uri = "mock:" + ip.getMember().getName(); return selectContext(ip, instance, extension).getEndpoint(uri, MockEndpoint.class); }
@Uri("") @Produces @Typed(MockEndpoint.class) // Alternative is dynamically added in CdiCamelExtension private static MockEndpoint mockEndpointFromUri(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) { Uri uri = getQualifierByType(ip, Uri.class).get(); return selectContext(ip, instance, extension).getEndpoint(uri.value(), MockEndpoint.class); }
private static void addApiTypes(final Collection<Type> clazzes, final Class<?> beanClass) { final Typed typed = beanClass.getAnnotation(Typed.class); if (typed == null || typed.value().length == 0) { Type current = beanClass; while (current != null && Object.class != current) { clazzes.add(current); // TODO: better loop current = Class.class.isInstance(current) ? Class.class.cast(current).getGenericSuperclass() : null; } } else { Collections.addAll(clazzes, typed.value()); } }
@Produces @RequestScoped @Typed({T1.class, T2.class}) public TypedBean1and2 produce1and2() { return new TypedBean1and2(); }
@Produces @RequestScoped @Typed(T3.class) public TypedBean3 produce3() { return new TypedBean3(); }
@Produces @Typed(HttpServletRequest.class) @DeltaSpike @RequestScoped public HttpServletRequest getHttpServletRequest() { ServletRequest request = RequestResponseHolder.REQUEST.get(); if (request instanceof HttpServletRequest) { return (HttpServletRequest) request; } throw new IllegalStateException("The current request is not a HttpServletRequest"); }
@Produces @Typed(HttpServletResponse.class) @DeltaSpike @RequestScoped public HttpServletResponse getHttpServletResponse() { ServletResponse response = RequestResponseHolder.RESPONSE.get(); if (response instanceof HttpServletResponse) { return (HttpServletResponse) response; } throw new IllegalStateException("The current response is not a HttpServletResponse"); }
@Test public void testAdditionOfAnnotation() { final AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>(); builder.readFromType(Cat.class, true); builder.addToClass(new TypedLiteral()); final AnnotatedType<Cat> catAnnotatedType = builder.create(); assertThat(catAnnotatedType.isAnnotationPresent(Typed.class), is(true)); }
private static boolean typedBean(Entry<BeanType, Bean<?>> e) { return e.getKey().getType().isAnnotationPresent(Typed.class); }
public boolean needsBeanLocalViewAddedToTypes() { return beanContext.isLocalbean() && beanContext.getBeanClass().getAnnotation(Typed.class) == null; }
public <X> void onProcessInjectionTarget(@Observes ProcessInjectionTarget<X> processInjectionTarget, BeanManager beanManager) { if (!isActivated) { return; } for (MockFilter mockFilter : mockFilters) { if (!mockFilter.isMockedImplementationSupported(beanManager, processInjectionTarget.getAnnotatedType())) { return; } } List<Annotation> qualifiers = new ArrayList<Annotation>(); for (Annotation annotation : processInjectionTarget.getAnnotatedType().getAnnotations()) { if (beanManager.isQualifier(annotation.annotationType())) { qualifiers.add(annotation); } } Typed typed = processInjectionTarget.getAnnotatedType().getAnnotation(Typed.class); List<Type> foundTypes = new ArrayList<Type>(); if (typed != null) { Collections.addAll(foundTypes, typed.value()); } else { foundTypes.addAll(extractTypes(processInjectionTarget.getAnnotatedType().getJavaClass())); } if (foundTypes.isEmpty()) { return; } final InjectionTarget<X> originalInjectionTarget = processInjectionTarget.getInjectionTarget(); processInjectionTarget.setInjectionTarget(new MockAwareInjectionTargetWrapper<X>( beanManager, originalInjectionTarget, foundTypes, qualifiers)); }
public <X, T> void onProcessProducer(@Observes ProcessProducer<X, T> processProducer, BeanManager beanManager) { if (!isActivated) { return; } for (MockFilter mockFilter : mockFilters) { if (!mockFilter.isMockedImplementationSupported(beanManager, processProducer.getAnnotatedMember())) { return; } } final Producer<T> originalProducer = processProducer.getProducer(); AnnotatedMember<X> annotatedMember = processProducer.getAnnotatedMember(); List<Annotation> qualifiers = new ArrayList<Annotation>(); for (Annotation annotation : annotatedMember.getAnnotations()) { if (beanManager.isQualifier(annotation.annotationType())) { qualifiers.add(annotation); } } Typed typed = annotatedMember.getAnnotation(Typed.class); List<Type> foundTypes = new ArrayList<Type>(); if (typed != null) { Collections.addAll(foundTypes, typed.value()); } else if (annotatedMember.getBaseType() instanceof Class) { foundTypes.addAll(extractTypes((Class)annotatedMember.getBaseType())); } if (foundTypes.isEmpty()) { return; } processProducer.setProducer(new MockAwareProducerWrapper<T>( beanManager, originalProducer, foundTypes, qualifiers)); }
@Override public void addMock(Object mockInstance, Annotation... qualifiers) { //check if this method gets used without changing the default-config if (!TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS && !TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS) { throw new IllegalStateException("The support for mocked CDI-Beans is disabled " + "due to a reduced portability across different CDI-implementations. " + "Please set '" + TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS_KEY + "' and/or '" + TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS_KEY + "' to 'true' " + "(in 'META-INF/apache-deltaspike.properties') on your test-classpath."); } Class<?> mockClass = mockInstance.getClass(); Class<?> beanClass = mockClass.getSuperclass(); if (beanClass == null) { beanClass = mockClass; } if (Object.class.equals(beanClass)) { throw new IllegalArgumentException(mockInstance.getClass().getName() + " isn't a supported approach for mocking -> please extend from the original class."); } TypedMock typedMock = mockClass.getAnnotation(TypedMock.class); if (typedMock == null) { typedMock = beanClass.getAnnotation(TypedMock.class); } Class[] specifiedTypes = null; if (typedMock != null) { specifiedTypes = typedMock.value(); } else { Typed typed = mockClass.getAnnotation(Typed.class); if (typed == null || typed.value().length == 0) { typed = beanClass.getAnnotation(Typed.class); } if (typed != null && typed.value().length > 0) { specifiedTypes = typed.value(); } } if (specifiedTypes != null) { for (Class typedClass : specifiedTypes) { this.registeredMocks.put(new BeanCacheKey(typedClass, qualifiers), mockInstance); } } else { this.registeredMocks.put(new BeanCacheKey(beanClass, qualifiers), mockInstance); } }
/** * Returns the {@link ProcessInstance} currently associated or 'null' * * @throws ProcessEngineCdiException * if no {@link Execution} is associated. Use * {@link BusinessProcess#isAssociated()} to check whether an * association exists. */ /* Makes the current ProcessInstance available for injection */ @Produces @Named @Typed(ProcessInstance.class) public ProcessInstance getProcessInstance() { return businessProcess.getProcessInstance(); }