This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
forked from informatici/openhospital-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,434 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/test/java/org/isf/permissions/TestGroupPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Open Hospital (www.open-hospital.org) | ||
* Copyright © 2006-2024 Informatici Senza Frontiere ([email protected]) | ||
* | ||
* Open Hospital is a free and open source software for healthcare data management. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* https://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.isf.permissions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.isf.OHCoreTestCase; | ||
import org.isf.menu.model.UserGroup; | ||
import org.isf.permissions.model.GroupPermission; | ||
import org.isf.permissions.model.Permission; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class TestGroupPermission extends OHCoreTestCase { | ||
|
||
@Test | ||
void testModel() throws Exception { | ||
GroupPermission groupPermission = new GroupPermission(); | ||
|
||
groupPermission.setId(-1); | ||
assertThat(groupPermission.getId()).isEqualTo(-1); | ||
|
||
Permission permission = new Permission(); | ||
permission.setId(-1); | ||
groupPermission.setPermission(permission); | ||
assertThat(groupPermission.getPermission().getId()).isEqualTo(-1); | ||
|
||
UserGroup userGroup = new UserGroup(); | ||
userGroup.setCode("code"); | ||
groupPermission.setUserGroup(userGroup); | ||
assertThat(groupPermission.getUserGroup().getCode()).isEqualTo("code"); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/org/isf/permissions/TestGroupPermissionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Open Hospital (www.open-hospital.org) | ||
* Copyright © 2006-2024 Informatici Senza Frontiere ([email protected]) | ||
* | ||
* Open Hospital is a free and open source software for healthcare data management. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* https://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.isf.permissions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.isf.OHCoreTestCase; | ||
import org.isf.permissions.manager.GroupPermissionManager; | ||
import org.isf.permissions.model.GroupPermission; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class TestGroupPermissionManager extends OHCoreTestCase { | ||
|
||
@Autowired | ||
GroupPermissionManager groupPermissionManager; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
cleanH2InMemoryDb(); | ||
executeSQLScript("LoadPermissionTables.sql"); | ||
} | ||
|
||
@Test | ||
void testFindByIdIn() throws Exception { | ||
List<Integer> listIds = new ArrayList<>(); | ||
listIds.add(1); | ||
listIds.add(10); | ||
List<GroupPermission> groupPermissionList = groupPermissionManager.findByIdIn(listIds); | ||
assertThat(groupPermissionList).isNotEmpty(); | ||
assertThat(groupPermissionList).hasSize(2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Open Hospital (www.open-hospital.org) | ||
* Copyright © 2006-2024 Informatici Senza Frontiere ([email protected]) | ||
* | ||
* Open Hospital is a free and open source software for healthcare data management. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* https://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.isf.permissions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.isf.OHCoreTestCase; | ||
import org.isf.permissions.model.GroupPermission; | ||
import org.isf.permissions.model.Permission; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class TestPermission extends OHCoreTestCase { | ||
|
||
@Test | ||
void testModel() throws Exception { | ||
Permission permission = new Permission(); | ||
|
||
permission.setId(-1); | ||
assertThat(permission.getId()).isEqualTo(-1); | ||
|
||
permission.setDescription("description"); | ||
assertThat(permission.getDescription()).isEqualTo("description"); | ||
|
||
permission.setName("name"); | ||
assertThat(permission.getName()).isEqualTo("name"); | ||
|
||
List<GroupPermission> groupPermissions = new ArrayList<>(); | ||
groupPermissions.add(new GroupPermission()); | ||
permission.setGroupPermission(groupPermissions); | ||
assertThat(permission.getGroupPermission()).hasSize(1); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/test/java/org/isf/permissions/TestPermissionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Open Hospital (www.open-hospital.org) | ||
* Copyright © 2006-2024 Informatici Senza Frontiere ([email protected]) | ||
* | ||
* Open Hospital is a free and open source software for healthcare data management. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* https://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.isf.permissions; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.isf.OHCoreTestCase; | ||
import org.isf.permissions.manager.PermissionManager; | ||
import org.isf.permissions.model.Permission; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class TestPermissionManager extends OHCoreTestCase { | ||
|
||
@Autowired | ||
PermissionManager permissionManager; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
cleanH2InMemoryDb(); | ||
executeSQLScript("LoadPermissionTables.sql"); | ||
} | ||
|
||
@Test | ||
void testRetrieveByGroupCode() throws Exception { | ||
List<Permission> permissions = permissionManager.retrievePermissionsByGroupCode("doctor"); | ||
assertThat(permissions).isNotEmpty(); | ||
assertThat(permissions.get(0).getName()).isEqualTo("admissions.create"); | ||
assertThat(permissions.get(0).getDescription()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testRetrieveByUsername() throws Exception { | ||
List<Permission> permissions = permissionManager.retrievePermissionsByUsername("admin"); | ||
assertThat(permissions).isNotEmpty(); | ||
assertThat(permissions.get(0).getName()).isEqualTo("admissions.create"); | ||
assertThat(permissions.get(0).getDescription()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testRetrieveById() throws Exception { | ||
Permission permission = permissionManager.retrievePermissionById(3); | ||
assertThat(permission).isNotNull(); | ||
assertThat(permission.getName()).isEqualTo("admissions.update"); | ||
assertThat(permission.getDescription()).isEmpty(); | ||
assertThat(permission.getId()).isEqualTo(3); | ||
assertThat(permission.getGroupPermission()).isNotNull(); | ||
} | ||
|
||
@Test | ||
void testRetrieveByName() throws Exception { | ||
Permission permission = permissionManager.retrievePermissionByName("admissions.create"); | ||
assertThat(permission).isNotNull(); | ||
assertThat(permission.getName()).isEqualTo("admissions.create"); | ||
assertThat(permission.getDescription()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testRetrieveAllPermissions() throws Exception { | ||
List<Permission> permissions = permissionManager.retrieveAllPermissions(); | ||
assertThat(permissions).isNotEmpty(); | ||
assertThat(permissions.get(0).getName()).isEqualTo("admissions.create"); | ||
assertThat(permissions.get(0).getDescription()).isEmpty(); | ||
|
||
assertThat(permissions).hasSize(30); | ||
} | ||
|
||
@Test | ||
void testExists() throws Exception { | ||
Permission permission = permissionManager.retrievePermissionById(3); | ||
assertThat(permission).isNotNull(); | ||
assertThat(permissionManager.exists(5)).isTrue(); | ||
assertThat(permissionManager.exists(-999)).isFalse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Open Hospital (www.open-hospital.org) | ||
* Copyright © 2006-2024 Informatici Senza Frontiere ([email protected]) | ||
* | ||
* Open Hospital is a free and open source software for healthcare data management. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* https://www.gnu.org/licenses/gpl-3.0-standalone.html | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.isf.utils.db; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
|
||
import org.isf.menu.manager.Context; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.context.ApplicationContext; | ||
|
||
class TestDbJpaUtil { | ||
|
||
@Mock | ||
EntityManagerFactory entityManagerFactoryMock; | ||
@Mock | ||
EntityManager entityManagerMock; | ||
@Mock | ||
ApplicationContext applicationContextMock; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
Context.setApplicationContext(applicationContextMock); | ||
when(applicationContextMock.getBean("entityManagerFactory", EntityManagerFactory.class)).thenReturn(entityManagerFactoryMock); | ||
} | ||
|
||
@Test | ||
void testNew() throws Exception { | ||
DbJpaUtil dbJpaUtil = new DbJpaUtil(); | ||
assertThat(dbJpaUtil).isNotNull(); | ||
} | ||
|
||
@Test | ||
void testOpen() throws Exception { | ||
DbJpaUtil dbJpaUtil = new DbJpaUtil(); | ||
when(entityManagerFactoryMock.createEntityManager()).thenReturn(entityManagerMock); | ||
dbJpaUtil.open(); | ||
} | ||
|
||
} |
Oops, something went wrong.