2013-05-27 17 views
2

CDI를 사용하여 종속성 주입에 CDI를 사용하는 Wicket 구성 요소를 테스트하려고합니다. 테스트는 이클립스에서 완벽하게 작동하는 것으로 보이지만 메이븐 빌드 중에는 실패하고 힌트와 잘못된 점을 발견 할 수 있습니다.Eclipse에서 WicketTester 및 CDI-Unit을 사용한 단위 테스트는 작동하지만 Maven 빌드 중에는 실패합니다. 내가 뭘 놓치고 있니?

이 나는 ​​간단한 추상 WicketPanel

public abstract class MyPanel extends Panel{ 

    private static final long serialVersionUID = 4132041261965905788L; 

    private final RepeatingView rw; 

    @Inject 
    transient ReflectiveComponentFactory factory; 

    public MyPanel(String id) { 
    super(id); 
    rw = new RepeatingView(OVERLAY_COMPONENT_GROUP_ID); 
    add(rw); 
    } 

    @Override 
    public <CT extends Component> CT addComponent(Class<CT> componentType) { 
    return addComponent(componentType, OVERLAY_COMPONENT_ID); 
    } 

    protected <CT extends Component> CT addComponent(Class<CT> componentType, String overlayComponentId) { 
    WebMarkupContainer collapsableGroup = new WebMarkupContainer(rw.newChildId()); 
    rw.add(collapsableGroup); 

    CT component = factory.createComponent(componentType, overlayComponentId); 
    collapsableGroup.add(component); 

    return component; 
    } 
} 

그리고 사출 공장을 만들었습니다

@ApplicationScoped 
public class ReflectiveComponentFactory implements Serializable{ 
    private static final long serialVersionUID = -4587243549845349456L; 

    public <CT extends Component> CT createComponent(Class<CT> componentType, String componentId){ 
    try { 
     Constructor<CT> constructor = componentType.getConstructor(String.class); 
     return constructor.newInstance(componentId); 
    } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) { 
     throw new ComponentCreationException(e); 
    } 
    } 
} 

을 그리고 CDI-단위를 사용하여 단위 테스트 생성 : 내가 가지고있는

@RunWith(CdiRunner.class) 
@AdditionalClasses(value={ReflectiveComponentFactory.class}) 
public class MyPanelTest { 
    private WicketTester tester; 

    @Inject 
    private BeanManager beanManager; 

    @Before 
    public void setup() { 
    tester = new WicketTester(); 
    new CdiConfiguration(beanManager).setPropagation(ConversationPropagation.NONE).configure(tester.getApplication()); 
    } 

    @Test 
    public void testAddComponentWithClass() { 
    MyPanelTested myPanel = new MyPanelTested("someId"); 
    TestPanel panel1 = myPanel.addComponent(TestPanel.class); 
    TestPanel panel2 = myPanel.addComponent(TestPanel.class); 

    tester.startComponentInPage(myPanel); 
    tester.assertComponent(panel1.getPageRelativePath(), TestPanel.class); 
    tester.assertComponent(panel2.getPageRelativePath(), TestPanel.class); 
    tester.assertComponent(panel1.getPageRelativePath() + ":text", Label.class); 
    tester.assertComponent(panel2.getPageRelativePath() + ":text", Label.class); 
    } 
} 

@SuppressWarnings("serial") 
class MyPanelTested extends MyPanel { 
    public MyPanelTested(String id) { 
    super(id); 
    } 
} 

을 TestPanel은 포함되어 있지 않지만 매우 간단합니다.

Eclipse에서 실행하면 녹색으로 테스트가 통과됩니다! 내가 잘못 뭐하는 거지에

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.Dependent 
    at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:578) 
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:608) 
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:674) 
    at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:136) 
    at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:763) 
    at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:772) 
    at org.jboss.weld.manager.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:106) 
    at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48) 
    at org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:102) 
    at org.apache.wicket.cdi.NonContextual.postConstruct(NonContextual.java:129) 
    at org.apache.wicket.cdi.NonContextualManager.postConstruct(NonContextualManager.java:65) 
    at org.apache.wicket.cdi.DetachEventEmitter.<init>(DetachEventEmitter.java:55) 
    at org.apache.wicket.cdi.CdiConfiguration.configure(CdiConfiguration.java:196) 
    ..... 

모든 단서 :이 메이븐으로 실행하면

나는 다음과 같은거야?

답변

1

이 문제는 cdi-unit 버전 2.0.8의 버그로 인해 발생했습니다. Bryn은 문제를 해결 했으므로 (https://github.com/BrynCooke/cdi-unit/issues/21 참조) cdi-unit 2.0.9 이상을 사용하면 나타나지 않습니다.