0

I am preparing a new template project for Jakarta EE 10, https://github.com/hantsy/jakartaee10-starter-boilerplate

  • Java 17
  • Jakarta EE 10
  • OpenLiberty 23.0.0.5

I tried to add tests for CDI repository and EJB stateless bean. https://github.com/hantsy/jakartaee10-starter-boilerplate/blob/master/src/test/java/com/example/it/CdiTodoRepositoryTest.java

@ExtendWith(ArquillianExtension.class)
public class CdiTodoRepositoryTest {
    private final static Logger LOGGER = Logger.getLogger(CdiTodoRepositoryTest.class.getName());

    @Deployment
    public static WebArchive createDeployment() {
        return ShrinkWrap.create(WebArchive.class, "test.war")
                .addPackage(Todo.class.getPackage())
                .addClasses(CdiTodoRepository.class, CrudRepository.class)
                .addClass(DbUtil.class)
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    }

    @Inject
    CdiTodoRepository todos;

    @PersistenceContext
    EntityManager entityManager;

    @Resource(lookup = "java:comp/DefaultDataSource")
    DataSource dataSource;

    @Inject
    UserTransaction utx;

    private DbUtil dbUtil;

    @BeforeEach()
    public void setup() throws Exception {
        utx.begin();
        dbUtil = new DbUtil(dataSource);
        dbUtil.clearTables();
        utx.commit();
    }

    @Test
    public void testNewTodo() throws Exception {
        utx.begin();
        LOGGER.log(Level.INFO, "new todo ... ");
        Todo todo = Todo.of("test");
        var saved = todos.save(todo);
        utx.commit();

        dbUtil.assertCount("todos", 1);
        var getById = entityManager.find(Todo.class, saved.getId());
        assertNotNull(getById);
        assertEquals("test", saved.getTitle());
    }
    
}

The above entityManger.find throws a NPE.

The test get passed on GlassFish v7 and WildFly v28, only OpenLiberty encountered this issue, check my Github actions run result. https://github.com/hantsy/jakartaee10-starter-boilerplate/actions/runs/5235222832/jobs/9451902412

If you encountered the same issue, please vote https://github.com/OpenLiberty/liberty-arquillian/issues/134

Hantsy
  • 8,006
  • 7
  • 64
  • 109

0 Answers0