eclipse / jnosql

Eclipse JNoSQL is a framework which has the goal to help Java developers to create Jakarta EE applications with NoSQL.
Other
231 stars 72 forks source link

Injecting repository during JerseyTest #239

Closed donatellosantoro closed 4 years ago

donatellosantoro commented 4 years ago

Hi, we are trying to executing a simple test using JerseyTest. However we notice that the CDI is not able to properly injecting the Repository implementation. In particular, we are using:

In this case, in a simple test like the following, the Repository is never bind to any implementation.

public class TestJerseyRepository extends JerseyTest {
    protected Application configure() {
        return new ResourceConfig(UserRepository.class);
    }
    @Test
    public void testSelect() {
        UserRepository userRepository = CDI.current().select(UserRepository.class).get();
    }
}

we got the exception: org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001334: Unsatisfied dependencies for type UserRepository with qualifiers

Other beans are instead injected fine. And also running the app in Tomcat works as expected.

In beans.xml we also enabled bean-discovery-mode="all"

Are we missing something? Thanks

otaviojava commented 4 years ago

The cod looks ok, it version are you using? Btw: I'll release the newest version this weekend.

otaviojava commented 4 years ago

Ciao Donatello, como está?

Could you update to the newest version and tell me if that works? Thank you.

donatellosantoro commented 4 years ago

Ciao Otávio! Thanks for your time and update! JNoSql is really helping us!

We tried the latest version, but we still have the same issue. Currently, we are using

We also prepared a very small project, to test the issue. If you have time you can have a look here https://github.com/donatellosantoro/jsersey-test

There is a single resource (HelloWorldResource) that needs a repository (UserRepository). Deploying the app on tomcat (./gradlew war) works fine. However, if we try to inject the repository inside tests we still have the WELD-001408 exception. You can easily test using the command ./gradlew test --info

Thanks in advance

otaviojava commented 4 years ago

I trying, I'm not familiar with this tool, but so far what I know is it is not scanning the JNoSQL extensions. It supposed to load the entity and I did not find a log such this:

INFO: Scanned com.example.User loaded with time 13 ms

Furthermore, It does not find the Repository with a log like this:

INFO: Starting to process on documents: 0 databases crud 1 
donatellosantoro commented 4 years ago

Thanks anyway Otávio. In the output log, I can see the message

org.eclipse.jnosql.artemis.document.spi.DocumentExtension onAfterBeanDiscovery
INFO: Starting to process on documents: 0 databases crud 0

So it seems that the extension is loaded, but then it was not able to find any bean to handle.

donatellosantoro commented 4 years ago

Hi Otávio, we tried to remove JNoSQL from the example, asking to inject only the User bean into HelloWorldResource and we still have the same issue during test.

So it is not a problem of JNoSQL. We can close the issue. Thanks again