Skip to content

Commit

Permalink
**Brief description of the PR.**
Browse files Browse the repository at this point in the history
With a fix for a certain REST API bug (preventing users to change their account settings) in PR eclipse-kapua#2946 and PR eclipse-kapua#2954 the unit tests for services (tags, users, jobs, scheduling,...) started to fail.
I have fixed this by introducing a mocked account that is used as basis for the service creation.
I have already ran PR on my Travis and everything was fine. CodeCov should report 0% increased/decreased coverage, since all the changes made are in the ignored folders.

Signed-off-by: Leonardo Gaube <leonardo.gaube@comtrade.com>

**Related Issue**
This PR fixes problems with unit tests in PR eclipse-kapua#2947 and PR eclipse-kapua#2954.

**Description of the solution adopted:**
I have added a mocked AccountService and mocked AccountFactory classes to the existing unit tests, so that the check does not fail. This is  achieved with Mockito's "spy" method. The necessary Account methods are injected in the _CucumberWithProeprtiesFor(Service)_ file.

@lorthirk can you please look at the solution adopted and see if it's ok? After you merge this PR into develop, just rebase your PRs to develop and the tests should be passing normally.
**Screenshots**
N/A

**Any side note on the changes made**
N/A

Signed-off-by: Leonardo Gaube <leonardo.gaube@comtrade.com>
  • Loading branch information
Leonardo Gaube committed May 5, 2020
1 parent 8634719 commit 7837d5d
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 0 deletions.
10 changes: 10 additions & 0 deletions service/job/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,15 @@
<artifactId>kapua-scheduler-quartz</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory;
import org.eclipse.kapua.qa.common.MockedLocator;
import org.eclipse.kapua.qa.common.cucumber.CucumberWithProperties;
import org.eclipse.kapua.service.account.AccountFactory;
import org.eclipse.kapua.service.account.AccountService;
import org.eclipse.kapua.service.account.internal.AccountFactoryImpl;
import org.eclipse.kapua.service.account.internal.AccountServiceImpl;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.Permission;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
Expand Down Expand Up @@ -93,6 +97,10 @@ protected void configure() {
// Set KapuaMetatypeFactory for Metatype configuration
bind(KapuaMetatypeFactory.class).toInstance(new KapuaMetatypeFactoryImpl());

// binding Account related services
bind(AccountService.class).toInstance(Mockito.spy(new AccountServiceImpl()));
bind(AccountFactory.class).toInstance(Mockito.spy(new AccountFactoryImpl()));

// Inject actual Job service related services
JobEntityManagerFactory jobEntityManagerFactory = JobEntityManagerFactory.getInstance();
bind(JobEntityManagerFactory.class).toInstance(jobEntityManagerFactory);
Expand Down
5 changes: 5 additions & 0 deletions service/scheduler/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@
<artifactId>kapua-job-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory;
import org.eclipse.kapua.qa.common.MockedLocator;
import org.eclipse.kapua.qa.common.cucumber.CucumberWithProperties;
import org.eclipse.kapua.service.account.AccountFactory;
import org.eclipse.kapua.service.account.AccountService;
import org.eclipse.kapua.service.account.internal.AccountFactoryImpl;
import org.eclipse.kapua.service.account.internal.AccountServiceImpl;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.Permission;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
Expand Down Expand Up @@ -76,6 +80,10 @@ protected void configure() {
// Set KapuaMetatypeFactory for Metatype configuration
bind(KapuaMetatypeFactory.class).toInstance(new KapuaMetatypeFactoryImpl());

// binding Account related services
bind(AccountService.class).toInstance(Mockito.spy(new AccountServiceImpl()));
bind(AccountFactory.class).toInstance(Mockito.spy(new AccountFactoryImpl()));

// Inject actual Tag service related services
SchedulerEntityManagerFactory schedulerEntityManagerFactory = SchedulerEntityManagerFactory.getInstance();
bind(SchedulerEntityManagerFactory.class).toInstance(schedulerEntityManagerFactory);
Expand Down
20 changes: 20 additions & 0 deletions service/tag/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,25 @@
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory;
import org.eclipse.kapua.qa.common.MockedLocator;
import org.eclipse.kapua.qa.common.cucumber.CucumberWithProperties;
import org.eclipse.kapua.service.account.AccountFactory;
import org.eclipse.kapua.service.account.AccountService;
import org.eclipse.kapua.service.account.internal.AccountFactoryImpl;
import org.eclipse.kapua.service.account.internal.AccountServiceImpl;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.Permission;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
Expand Down Expand Up @@ -68,6 +72,10 @@ protected void configure() {
// Set KapuaMetatypeFactory for Metatype configuration
bind(KapuaMetatypeFactory.class).toInstance(new KapuaMetatypeFactoryImpl());

// binding Account related services
bind(AccountService.class).toInstance(Mockito.spy(new AccountServiceImpl()));
bind(AccountFactory.class).toInstance(Mockito.spy(new AccountFactoryImpl()));

// Inject actual Tag service related services
TagEntityManagerFactory tagEntityManagerFactory = TagEntityManagerFactory.getInstance();
bind(TagEntityManagerFactory.class).toInstance(tagEntityManagerFactory);
Expand Down
10 changes: 10 additions & 0 deletions service/user/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-account-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import org.eclipse.kapua.model.config.metatype.KapuaMetatypeFactory;
import org.eclipse.kapua.qa.common.MockedLocator;
import org.eclipse.kapua.qa.common.cucumber.CucumberWithProperties;
import org.eclipse.kapua.service.account.AccountFactory;
import org.eclipse.kapua.service.account.AccountService;
import org.eclipse.kapua.service.account.internal.AccountFactoryImpl;
import org.eclipse.kapua.service.account.internal.AccountServiceImpl;
import org.eclipse.kapua.service.authorization.AuthorizationService;
import org.eclipse.kapua.service.authorization.permission.Permission;
import org.eclipse.kapua.service.authorization.permission.PermissionFactory;
Expand Down Expand Up @@ -68,6 +72,10 @@ protected void configure() {
// Set KapuaMetatypeFactory for Metatype configuration
bind(KapuaMetatypeFactory.class).toInstance(new KapuaMetatypeFactoryImpl());

// binding Account related services
bind(AccountService.class).toInstance(Mockito.spy(new AccountServiceImpl()));
bind(AccountFactory.class).toInstance(Mockito.spy(new AccountFactoryImpl()));

// Inject actual User service related services
UserEntityManagerFactory userEntityManagerFactory = UserEntityManagerFactory.getInstance();
bind(UserEntityManagerFactory.class).toInstance(userEntityManagerFactory);
Expand Down

0 comments on commit 7837d5d

Please sign in to comment.