Skip to content

Commit

Permalink
Fixed Account tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Dec 12, 2022
1 parent 19e3c07 commit 8db173d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ public void delete(KapuaId scopeId, KapuaId accountId) throws KapuaException {
entityManagerSession.doTransactedAction(
EntityManagerContainer.<Account>create()
.onResultHandler(em -> {
// Entity needs to be loaded in the context of the same EntityManger to be able to delete it afterwards
Account account = AccountDAO.find(em, scopeId, accountId);
Account account = scopeId.equals(accountId) ?
AccountDAO.find(em, KapuaId.ANY, accountId) :
AccountDAO.find(em, scopeId, accountId);

if (account == null) {
throw new KapuaEntityNotFoundException(Account.TYPE, accountId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.eclipse.kapua.service.account.AccountQuery;
import org.eclipse.kapua.service.account.AccountListResult;
import org.eclipse.kapua.service.account.AccountAttributes;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -469,19 +470,17 @@ public void deleteAccountWithName(String name)
}
}

@When("^I try to delete the system account$")
public void deleteSystemAccount()
throws Exception {

String adminUserName = SystemSetting.getInstance().getString(SystemSettingKey.SYS_ADMIN_USERNAME);
Account tmpAcc = accountService.findByName(adminUserName);
@When("I try to delete the system account")
public void deleteSystemAccount() throws Exception {
String adminAccountName = SystemSetting.getInstance().getString(SystemSettingKey.SYS_ADMIN_ACCOUNT);
Account adminAccount = accountService.findByName(adminAccountName);

assertNotNull(tmpAcc);
assertNotNull(tmpAcc.getId());
Assert.assertNotNull(adminAccount);
Assert.assertNotNull(adminAccount.getId());

try {
primeException();
accountService.delete(SYS_SCOPE_ID, tmpAcc.getId());
accountService.delete(KapuaId.ANY, adminAccount.getId());
} catch (KapuaException ex) {
verifyException(ex);
}
Expand Down Expand Up @@ -962,8 +961,8 @@ public void findMyAccountById() throws Exception {
@When("^I look for my account by id and scope id$")
public void findMyAccountByIdAndScopeId() throws Exception {
Account account = (Account) stepData.get(LAST_ACCOUNT);
Account selfAccount = accountService.find(account.getId(), account.getScopeId());
stepData.put(LAST_ACCOUNT,selfAccount);
Account selfAccount = accountService.find(account.getId(), account.getId());
stepData.put(LAST_ACCOUNT, selfAccount);
}

@When("^I look for my account by name$")
Expand Down

0 comments on commit 8db173d

Please sign in to comment.