3

I have Wicket Form and ProjectNameValidator class:

@Inject
ProjectDao dao;

 public ProjectNameValidator() {       
    CdiContainer.get().getNonContextualManager().inject(this);
}

the injection here is because the @Inject annotation works only in Wicket components or Behavior, here is null without the CdiContainer.get().getNonContextualManager().inject(this);

But when I have WicketTester, TestCreateprojectPage:

public class TestCreateProject {

private WicketTester tester;

@Before
public void setUp() throws Exception {
    tester = new WicketTester();
}
@Test
public void createProjectPageRendersSuccessfully() {

    tester.startPage(CreateProject.class);

    tester.assertRenderedPage(CreateProject.class);

} }

I'm getting exception on the Form in the CreateProject.java in ProjectNameValidator on this row:

CdiContainer.get().getNonContextualManager().inject(this);

IllegalStateException: No DCI Context bound to application.

1 Answers1

1

You have a singleton CdiContainer in your application, that is not initialized in a test scope. So CdiContainer.get() is really null. Find out how to initialize CdiContainer test context, it depends on your implementation, and add it to test setUp().

Martin Strejc
  • 4,307
  • 2
  • 23
  • 38