From 6d5007f93c2b00de7858a94ccbe65b39309f21af Mon Sep 17 00:00:00 2001 From: vpapez Date: Tue, 5 Aug 2014 13:16:12 +0200 Subject: [PATCH 01/10] Create README.md --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..2cd6242b --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +h1. EEGBase + +h2. An database portal specialized for EEG/ERP experiments + +h3. eegdatabase.kiv.zcu.cz + +EEG Database enables community researchers to store, update, download and search data and metadata from EEG/ERP experiments. The system is developed as a standalone product; the database access is available through a web interface. + +h2. Technical Overview + +EEGBase as a web application uses modern web and database technologies: +* SQL and NoSQL databases +** PostgreSQL +** Elasticsearch +* Application +** Spring MVC architecture +** Hibernate JPA +** Wicket framework +* Web Server +** Jetty + +h2. Getting Started +* Prerequisites +** Installed PostgreSQL v9.2 (http://www.postgresql.org/) +** Installed Jetty web server and servlet container v7.5.0 (http://www.eclipse.org/jetty/) +** Installed Java SE 6 JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html) +** Installed Elasticsearch v1.0 (http://www.elasticsearch.org/) +** Installed your favourite IDE (Eclipse, Netbeans, IntelliJ etc.) with configured GIT +* EEG Database +** Create new database in PostgreSQL (default name is "eeg"); tables will be created automatically by Hibernate framework +** Clone eegdatabase GITHub repository to local destination +** Open eegdatabase Maven project in your IDE and let the Maven to download dependencies +** Edit database accesses in @eeb-database/src/main/webapp/WEB-INF/db.properties.sample@ and save the file as @db.properties@ +** Set-up run and deployment configuration +*** Select Jetty as a main deploying server +*** Edit Jetty start up options; increase permanent generation memory size @-XX:MaxPermSize=256m@ +*** Set-up deployment artefacts +** Set-up Java SE 6 JDK as a default project SDK +* Frequent problems +** Ensure you have set JAVA_HOME variable in system environment variables +** Elasticsearch requires JAVA 7. +** Jetty port (8080 by default) is occupied by another service application (e.g. Apache Tomcat, Glassfish). +** db.properties file is not set properly. +** DB user has not enough privileges to the database schema. + +h1. License +
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+specific language governing permissions and limitations under the License.
+

From 3eb230c1a6d8ea39d4a957114e547fe2abd25c6d Mon Sep 17 00:00:00 2001
From: vpapez 
Date: Tue, 5 Aug 2014 13:18:01 +0200
Subject: [PATCH 02/10] Rename README.md to README.textile

---
 README.md => README.textile | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename README.md => README.textile (100%)

diff --git a/README.md b/README.textile
similarity index 100%
rename from README.md
rename to README.textile

From 80bf0a6e33f7d65d472da8acc309ae0f9f763ee3 Mon Sep 17 00:00:00 2001
From: vpapez 
Date: Tue, 5 Aug 2014 13:21:52 +0200
Subject: [PATCH 03/10] Update README.textile

---
 README.textile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/README.textile b/README.textile
index 2cd6242b..d95bc818 100644
--- a/README.textile
+++ b/README.textile
@@ -47,10 +47,8 @@ h1. License
 
 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
-
  http://www.apache.org/licenses/LICENSE-2.0
-
 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 specific language governing permissions and limitations under the License.
-
+
From 53345385f307daf46283c897aac660a8a2db7b2b Mon Sep 17 00:00:00 2001 From: vpapez Date: Tue, 5 Aug 2014 13:26:50 +0200 Subject: [PATCH 04/10] Update README.textile --- README.textile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.textile b/README.textile index d95bc818..0963abfc 100644 --- a/README.textile +++ b/README.textile @@ -2,7 +2,7 @@ h1. EEGBase h2. An database portal specialized for EEG/ERP experiments -h3. eegdatabase.kiv.zcu.cz +h3. "http://eegdatabase.kiv.zcu.cz":http://eegdatabase.kiv.zcu.cz EEG Database enables community researchers to store, update, download and search data and metadata from EEG/ERP experiments. The system is developed as a standalone product; the database access is available through a web interface. @@ -44,11 +44,19 @@ h2. Getting Started ** DB user has not enough privileges to the database schema. h1. License +
-Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
-Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
-an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
-specific language governing permissions and limitations under the License.
+This software is licensed under the Apache 2 license, quoted below.
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not 
+use this file except in compliance with the License. You may obtain a copy of 
+the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software 
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
+License for the specific language governing permissions and limitations under 
+the License.
 
From 13e307db3cbbdb3622bfe7c1d94879c68f3a5101 Mon Sep 17 00:00:00 2001 From: vpapez Date: Tue, 5 Aug 2014 14:06:38 +0200 Subject: [PATCH 05/10] Update README.textile --- README.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.textile b/README.textile index 0963abfc..b190782d 100644 --- a/README.textile +++ b/README.textile @@ -24,7 +24,7 @@ h2. Getting Started ** Installed PostgreSQL v9.2 (http://www.postgresql.org/) ** Installed Jetty web server and servlet container v7.5.0 (http://www.eclipse.org/jetty/) ** Installed Java SE 6 JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html) -** Installed Elasticsearch v1.0 (http://www.elasticsearch.org/) +** Installed and "configured":https://github.com/INCF/eeg-database/wiki Elasticsearch v1.0 (http://www.elasticsearch.org/); ** Installed your favourite IDE (Eclipse, Netbeans, IntelliJ etc.) with configured GIT * EEG Database ** Create new database in PostgreSQL (default name is "eeg"); tables will be created automatically by Hibernate framework From b6820a69641cd5af6c4c1895ec8b28e0487e35f8 Mon Sep 17 00:00:00 2001 From: vpapez Date: Tue, 5 Aug 2014 14:07:55 +0200 Subject: [PATCH 06/10] Update README.textile --- README.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.textile b/README.textile index b190782d..d7afd9d5 100644 --- a/README.textile +++ b/README.textile @@ -24,7 +24,7 @@ h2. Getting Started ** Installed PostgreSQL v9.2 (http://www.postgresql.org/) ** Installed Jetty web server and servlet container v7.5.0 (http://www.eclipse.org/jetty/) ** Installed Java SE 6 JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html) -** Installed and "configured":https://github.com/INCF/eeg-database/wiki Elasticsearch v1.0 (http://www.elasticsearch.org/); +** Installed and "configured":https://github.com/INCF/eeg-database/wiki/Elasticsearch Elasticsearch v1.0 (http://www.elasticsearch.org/); ** Installed your favourite IDE (Eclipse, Netbeans, IntelliJ etc.) with configured GIT * EEG Database ** Create new database in PostgreSQL (default name is "eeg"); tables will be created automatically by Hibernate framework From b641f7eef2defc8cf32032dd12d948f9603e320d Mon Sep 17 00:00:00 2001 From: jezekp Date: Tue, 5 Aug 2014 14:10:24 +0200 Subject: [PATCH 07/10] Update README.textile --- README.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.textile b/README.textile index d7afd9d5..61d889e5 100644 --- a/README.textile +++ b/README.textile @@ -24,7 +24,7 @@ h2. Getting Started ** Installed PostgreSQL v9.2 (http://www.postgresql.org/) ** Installed Jetty web server and servlet container v7.5.0 (http://www.eclipse.org/jetty/) ** Installed Java SE 6 JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html) -** Installed and "configured":https://github.com/INCF/eeg-database/wiki/Elasticsearch Elasticsearch v1.0 (http://www.elasticsearch.org/); +** Installed and "configured":https://github.com/INCF/eeg-database/wiki/Elasticsearch Elasticsearch v1.3 (http://www.elasticsearch.org/); ** Installed your favourite IDE (Eclipse, Netbeans, IntelliJ etc.) with configured GIT * EEG Database ** Create new database in PostgreSQL (default name is "eeg"); tables will be created automatically by Hibernate framework From a537ade6a3dc46acc8c8c813e0cdb6e5ad94960a Mon Sep 17 00:00:00 2001 From: stebjan Date: Tue, 5 Aug 2014 14:22:30 +0200 Subject: [PATCH 08/10] PersonService test created. Minor fix - userNameInGroup method now recognises owners of groups. --- .../eegdatabase/data/dao/SimplePersonDao.java | 4 +- .../services/PersonServiceTest.java | 138 ++++++++++++++++++ src/test/resources/test-context.xml | 13 +- 3 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/PersonServiceTest.java diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java index ae95a935..63db10a1 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java @@ -171,10 +171,12 @@ public Map getInfoForAccountOverview(Person loggedPerson) { public boolean userNameInGroup(String userName, int groupId) { String hqlQuery = "select p.personId from Person p left join p.researchGroupMemberships rgm where p.username = :userName and rgm.researchGroup.researchGroupId = :groupId"; + String ownerGroupQuery = "from ResearchGroup r where r.researchGroupId = :groupId and r.person.username = :userName"; String[] paramNames = {"userName", "groupId"}; Object[] values = {userName, groupId}; List list = getHibernateTemplate().findByNamedParam(hqlQuery, paramNames, values); - return (list.size() > 0); + List ownerList = getHibernateTemplate().findByNamedParam(ownerGroupQuery, paramNames,values); + return (list.size() > 0 || ownerList.size() > 0); } public List getPersonSearchResults(List requests) throws NumberFormatException { diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/PersonServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/PersonServiceTest.java new file mode 100644 index 00000000..e16c8d6e --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/PersonServiceTest.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * PersonServiceTest.java, 2014/08/01 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.LicenseDao; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.License; +import cz.zcu.kiv.eegdatabase.data.pojo.LicenseType; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.person.PersonService; +import org.apache.wicket.util.tester.WicketTester; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Created by stebjan on 1.8.2014. + */ +@Transactional +public class PersonServiceTest extends AbstractServicesTest { + + @Autowired + private ResearchGroupDao researchGroupDao; + + @Autowired + private LicenseDao licenseDao; + + @Autowired + private PersonService personService; + + private ResearchGroup researchGroup; + + private Person person; + + @Autowired + private PersonDao personDao; + + @Before + public void setUp() { + + person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_READER); + License license = new License(); + license.setDescription("junit@test.description"); + license.setLicenseId(-231); + license.setPrice(-1000f); + license.setTitle("title"); + license.setLicenseType(LicenseType.OPEN_DOMAIN); + licenseDao.create(license); + + + } + + @Test + public void testCreatePerson() { + int count = personService.getCountRecords(); + personDao.create(person); + assertEquals(count + 1, personService.getCountRecords()); + assertEquals(count + 1, personService.getCountForList()); + assertNotNull(personService.getPerson("test@test.com")); + } + + @Test + public void testGetPersonForDetail() { + + int id = personDao.create(person); + Person fromDB = personService.getPersonForDetail(id); + assertEquals("test@test.com", fromDB.getUsername()); + assertEquals("test-surname", fromDB.getSurname()); + assertEquals("test-name", fromDB.getGivenname()); + assertEquals('M', fromDB.getGender()); + + } + + @Test + public void testChangeUserPassword() { + + personDao.create(person); + personService.changeUserPassword(person.getUsername(), "newPassword"); + + assertTrue(personService.isPasswordEquals(person.getUsername(), "newPassword")); + + } + + @Test + public void testUsernameExists() { + + personDao.create(person); + + assertFalse(personService.usernameExists("xxxt@test.com")); + assertTrue(personService.usernameExists("test@test.com")); + + } + + @Test + public void testUsernameInGroup() { + + personDao.create(person); + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + + int groupId = researchGroupDao.create(researchGroup); + Assert.assertTrue(personService.userNameInGroup(person.getUsername(), groupId)); + + } +} diff --git a/src/test/resources/test-context.xml b/src/test/resources/test-context.xml index 1b478840..c041ab77 100644 --- a/src/test/resources/test-context.xml +++ b/src/test/resources/test-context.xml @@ -361,7 +361,7 @@ - + @@ -372,11 +372,20 @@ - + + + + + + + + + From b8fceec55742c38a7e7c9a30a8762d1e6cc1bd52 Mon Sep 17 00:00:00 2001 From: stebjan Date: Wed, 13 Aug 2014 08:56:34 +0200 Subject: [PATCH 09/10] Test cases of lists created, minor fix - researchGroupService now creates the membershipId if it does not exist (NPE fix). --- .../core/group/ResearchGroupServiceImpl.java | 4 + .../services/ArtifactServiceTest.java | 97 ++++++++++++ .../services/DiseaseServiceTest.java | 111 ++++++++++++++ .../services/HardwareServiceTest.java | 144 ++++++++++++++++++ .../services/KeywordsServiceTest.java | 92 +++++++++++ .../services/PharmaceuticalServiceTest.java | 111 ++++++++++++++ .../services/ProjectTypeServiceTest.java | 111 ++++++++++++++ .../services/ResearchGroupServiceTest.java | 20 +-- .../services/SoftwareServiceTest.java | 129 ++++++++++++++++ .../services/StimulusServiceTest.java | 70 +++++++++ .../services/WeatherServiceTest.java | 143 +++++++++++++++++ src/test/resources/test-context.xml | 28 ++++ 12 files changed, 1050 insertions(+), 10 deletions(-) create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/ArtifactServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/DiseaseServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/HardwareServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/KeywordsServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/PharmaceuticalServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/ProjectTypeServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/SoftwareServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/StimulusServiceTest.java create mode 100644 src/test/java/cz/zcu/kiv/eegdatabase/services/WeatherServiceTest.java diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java index 8e6c0fb1..cbff7aa1 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java @@ -302,6 +302,10 @@ public List getUnique(ResearchGroup example) { @Override @Transactional public ResearchGroupMembershipId createMemberhip(ResearchGroupMembership newInstance) { + if (newInstance.getId() == null) { + ResearchGroupMembershipId id = new ResearchGroupMembershipId(newInstance.getPerson().getPersonId(), newInstance.getResearchGroup().getResearchGroupId()); + newInstance.setId(id); + } return membershipDao.create(newInstance); } diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/ArtifactServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/ArtifactServiceTest.java new file mode 100644 index 00000000..99e04a8f --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/ArtifactServiceTest.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArtifactServiceTest.java, 2014/08/10 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Artifact; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.ArtifactService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 10.8.14. + */ +@Transactional +public class ArtifactServiceTest extends AbstractServicesTest { + + @Autowired + private ArtifactService artifactService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private Artifact artifact; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + artifact = new Artifact(); + artifact.setCompensation("test comp"); + artifact.setRejectCondition("test condition"); + } + + @Test + public void testCreateArtifact() { + int artifactCountBefore = artifactService.getAllRecords().size(); + int id = artifactService.create(artifact); + assertEquals(artifactCountBefore + 1, artifactService.getAllRecords().size()); + assertEquals(id, artifact.getArtifactId()); + } + + + @Test + public void testCreateArtifactGroupRel() { + int artifactCountBefore = artifactService.getAllRecords().size(); + int artifactGroupBefore = artifactService.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + int id = artifactService.create(artifact); + assertEquals(artifactCountBefore + 1, artifactService.getAllRecords().size()); + + List list = artifactService.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(artifactGroupBefore, list.size()); + assertFalse(artifactService.hasGroupRel(id)); + } + +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/DiseaseServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/DiseaseServiceTest.java new file mode 100644 index 00000000..ef638e78 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/DiseaseServiceTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * DiseaseServiceTest.java, 2014/08/08 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Disease; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.DiseaseService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 8.8.14. + */ +@Transactional +public class DiseaseServiceTest extends AbstractServicesTest { + + @Autowired + private DiseaseService diseaseService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private Disease disease; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + disease = createDisease("new Disease"); + } + + @Test + public void testCreateDisease() { + int diseaseCountBefore = diseaseService.getAllRecords().size(); + int diseaseID = diseaseService.create(disease); + assertEquals(diseaseCountBefore + 1, diseaseService.getAllRecords().size()); + assertEquals(diseaseID, disease.getDiseaseId()); + } + + + @Test + public void testCreateDiseaseGroupRel() { + int diseaseCountBefore = diseaseService.getAllRecords().size(); + int diseaseGroupBefore = diseaseService.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + diseaseService.createGroupRel(disease, researchGroup); + int id = diseaseService.create(disease); + assertEquals(diseaseCountBefore + 1, diseaseService.getAllRecords().size()); + + List list = diseaseService.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(diseaseGroupBefore + 1, list.size()); + assertTrue(diseaseService.hasGroupRel(id)); + } + + + @Test + public void testCanSaveTitle() { + diseaseService.createGroupRel(disease, researchGroup); + int id = diseaseService.create(disease); + assertTrue(diseaseService.canSaveTitle(disease.getTitle(), researchGroup.getResearchGroupId(), id)); + assertFalse(diseaseService.canSaveTitle(disease.getTitle(), researchGroup.getResearchGroupId(), -1)); + } + + private Disease createDisease(String title) { + Disease newDisease = new Disease(); + newDisease.setTitle(title); + newDisease.setDescription("This is new testing Disease"); + return newDisease; + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/HardwareServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/HardwareServiceTest.java new file mode 100644 index 00000000..204587e5 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/HardwareServiceTest.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * HardwareServiceTest.java, 2014/08/07 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Hardware; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.HardwareService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 7.8.14. + */ +@Transactional +public class HardwareServiceTest extends AbstractServicesTest { + + @Autowired + private HardwareService hardwareService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private Hardware hardware; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + hardware = createHW("new HW"); + } + + @Test + public void testCreateHardware() { + int hardwareCountBefore = hardwareService.getAllRecords().size(); + int hardwareID = hardwareService.create(hardware); + assertEquals(hardwareCountBefore + 1, hardwareService.getAllRecords().size()); + assertEquals(hardwareID, hardware.getHardwareId()); + } + + @Test + public void testCreateDefaultHardware() { + int hardwareCountBefore = hardwareService.getAllRecords().size(); + hardware.setDefaultNumber(1); + hardwareService.createDefaultRecord(hardware); + assertEquals(hardwareCountBefore + 1, hardwareService.getAllRecords().size()); + + assertTrue(hardwareService.isDefault(hardware.getHardwareId())); + } + @Test + public void testCreateHardwareGroupRel() { + int hardwareCountBefore = hardwareService.getAllRecords().size(); + int hardwareGroupBefore = hardwareService.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + hardwareService.createGroupRel(hardware, researchGroup); + int id = hardwareService.create(hardware); + assertEquals(hardwareCountBefore + 1, hardwareService.getAllRecords().size()); + + List list = hardwareService.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(hardwareGroupBefore + 1, list.size()); + assertTrue(hardwareService.hasGroupRel(id)); + } + + @Test + public void testGetDefaultRecords() { + int hardwareCountBefore = hardwareService.getAllRecords().size(); + int hardwareDefaultBefore = hardwareService.getDefaultRecords().size(); + //This is not a default HW + int id = hardwareService.create(hardware); + + Hardware newHW = createHW("new HW2"); + newHW.setDefaultNumber(1); + hardwareService.createDefaultRecord(newHW); + assertEquals(hardwareCountBefore + 2, hardwareService.getAllRecords().size()); + + assertEquals(hardwareDefaultBefore + 1, hardwareService.getDefaultRecords().size()); + + assertFalse(hardwareService.hasGroupRel(newHW.getHardwareId())); + } + + @Test + public void testCanSaveTitle() { + hardwareService.createGroupRel(hardware, researchGroup); + int id = hardwareService.create(hardware); + assertTrue(hardwareService.canSaveDefaultTitle(hardware.getTitle(), -1)); + assertTrue(hardwareService.canSaveTitle(hardware.getTitle(), researchGroup.getResearchGroupId(), id)); + assertFalse(hardwareService.canSaveTitle(hardware.getTitle(), researchGroup.getResearchGroupId(), -1)); + + Hardware newHw = createHW("new HW2"); + newHw.setDefaultNumber(1); + hardwareService.createDefaultRecord(newHw); + assertFalse(hardwareService.canSaveDefaultTitle(newHw.getTitle(), -1)); + assertTrue(hardwareService.canSaveDefaultTitle(newHw.getTitle(), newHw.getHardwareId())); + } + + private Hardware createHW(String title) { + Hardware newHw = new Hardware(); + newHw.setTitle(title); + newHw.setDescription("This is new testing HW"); + newHw.setType("HW type"); + newHw.setDefaultNumber(0); + return newHw; + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/KeywordsServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/KeywordsServiceTest.java new file mode 100644 index 00000000..56939cf9 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/KeywordsServiceTest.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * KeywordsServiceTest.java, 2014/08/10 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Keywords; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.KeywordsService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 10.8.14. + */ +@Transactional +public class KeywordsServiceTest extends AbstractServicesTest { + + @Autowired + private KeywordsService keywordsService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private Keywords keywords; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + keywords = new Keywords(); + keywords.setKeywordsText("keyword"); + keywords.setResearchGroup(researchGroup); + } + + @Test + public void testCreateArtifact() { + int keywordsCountBefore = keywordsService.getAllRecords().size(); + int id = keywordsService.create(keywords); + assertEquals(keywordsCountBefore + 1, keywordsService.getAllRecords().size()); + assertEquals(id, keywords.getKeywordsId()); + } + + + @Test + public void testGetKeywords() { + int keywordsCountBefore = keywordsService.getAllRecords().size(); + + keywordsService.create(keywords); + assertEquals(keywordsCountBefore + 1, keywordsService.getAllRecords().size()); + assertEquals("keyword", keywordsService.getKeywords(researchGroup.getResearchGroupId())); + } + +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/PharmaceuticalServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/PharmaceuticalServiceTest.java new file mode 100644 index 00000000..df879bab --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/PharmaceuticalServiceTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * PharmaceuticalServiceTest.java, 2014/08/08 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.Pharmaceutical; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.PharmaceuticalService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 8.8.14. + */ +@Transactional +public class PharmaceuticalServiceTest extends AbstractServicesTest { + + @Autowired + private PharmaceuticalService pharmaceuticalService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private Pharmaceutical pharmaceutical; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + pharmaceutical = createPharmaceutical("new Disease"); + } + + @Test + public void testCreatePharmaceutical() { + int pharmaCountBefore = pharmaceuticalService.getAllRecords().size(); + int pharmaceuticalID = pharmaceuticalService.create(pharmaceutical); + assertEquals(pharmaCountBefore + 1, pharmaceuticalService.getAllRecords().size()); + assertEquals(pharmaceuticalID, pharmaceutical.getPharmaceuticalId()); + } + + + @Test + public void testCreatePharmaceuticalGroupRel() { + int pharmaCountBefore = pharmaceuticalService.getAllRecords().size(); + int pharmaGroupBefore = pharmaceuticalService.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + pharmaceuticalService.createGroupRel(pharmaceutical, researchGroup); + int id = pharmaceuticalService.create(pharmaceutical); + assertEquals(pharmaCountBefore + 1, pharmaceuticalService.getAllRecords().size()); + + List list = pharmaceuticalService.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(pharmaGroupBefore + 1, list.size()); + assertTrue(pharmaceuticalService.hasGroupRel(id)); + } + + + @Test + public void testCanSaveTitle() { + pharmaceuticalService.createGroupRel(pharmaceutical, researchGroup); + int id = pharmaceuticalService.create(pharmaceutical); + assertTrue(pharmaceuticalService.canSaveTitle(pharmaceutical.getTitle(), researchGroup.getResearchGroupId(), id)); + assertFalse(pharmaceuticalService.canSaveTitle(pharmaceutical.getTitle(), researchGroup.getResearchGroupId(), -1)); + } + + private Pharmaceutical createPharmaceutical(String title) { + Pharmaceutical newPharmaceutical = new Pharmaceutical(); + newPharmaceutical.setTitle(title); + newPharmaceutical.setDescription("This is new testing pharma"); + return newPharmaceutical; + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/ProjectTypeServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/ProjectTypeServiceTest.java new file mode 100644 index 00000000..f525f1c5 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/ProjectTypeServiceTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ProjectTypeServiceTest.java, 2014/08/08 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ProjectType; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.ProjectTypeService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 8.8.14. + */ +@Transactional +public class ProjectTypeServiceTest extends AbstractServicesTest { + + @Autowired + private ProjectTypeService projectTypeService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private ProjectType projectType; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + projectType = createProjectType("new Disease"); + } + + @Test + public void testCreateProjectType() { + int pTCountBefore = projectTypeService.getAllRecords().size(); + int id = projectTypeService.create(projectType); + assertEquals(pTCountBefore + 1, projectTypeService.getAllRecords().size()); + assertEquals(id, projectType.getProjectTypeId()); + } + + + @Test + public void testCreateProjectGroupRel() { + int pTCountBefore = projectTypeService.getAllRecords().size(); + int diseaseGroupBefore = projectTypeService.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + projectTypeService.createGroupRel(projectType, researchGroup); + int id = projectTypeService.create(projectType); + assertEquals(pTCountBefore + 1, projectTypeService.getAllRecords().size()); + + List list = projectTypeService.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(diseaseGroupBefore + 1, list.size()); + assertTrue(projectTypeService.hasGroupRel(id)); + } + + + @Test + public void testCanSaveTitle() { + projectTypeService.createGroupRel(projectType, researchGroup); + int id = projectTypeService.create(projectType); + assertTrue(projectTypeService.canSaveTitle(projectType.getTitle(), researchGroup.getResearchGroupId(), id)); + assertFalse(projectTypeService.canSaveTitle(projectType.getTitle(), researchGroup.getResearchGroupId(), -1)); + } + + private ProjectType createProjectType(String title) { + ProjectType newPT = new ProjectType(); + newPT.setTitle(title); + newPT.setDescription("This is new testing PT"); + return newPT; + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/ResearchGroupServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/ResearchGroupServiceTest.java index 86f8eb0a..e4095770 100644 --- a/src/test/java/cz/zcu/kiv/eegdatabase/services/ResearchGroupServiceTest.java +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/ResearchGroupServiceTest.java @@ -101,11 +101,11 @@ public void testCreateMembership() { membership.setPerson(tmp); membership.setResearchGroup(researchGroup); membership.setAuthority(Util.GROUP_ADMIN); - ResearchGroupMembershipId membershipId = new ResearchGroupMembershipId(); - membershipId.setPersonId(tmp.getPersonId()); - membershipId.setResearchGroupId(researchGroup.getResearchGroupId()); - - membership.setId(membershipId); +// ResearchGroupMembershipId membershipId = new ResearchGroupMembershipId(); +// membershipId.setPersonId(tmp.getPersonId()); +// membershipId.setResearchGroupId(researchGroup.getResearchGroupId()); +// +// membership.setId(membershipId); researchGroupService.createMemberhip(membership); assertTrue(count > 0); assertEquals(count + 1, researchGroupService.getListOfGroupMembers(id).size()); @@ -128,11 +128,11 @@ public void testGetResearchGroupsWhereUserIsGroupAdmin() { membership.setPerson(tmp); membership.setResearchGroup(researchGroup); membership.setAuthority(Util.GROUP_ADMIN); - ResearchGroupMembershipId membershipId = new ResearchGroupMembershipId(); - membershipId.setPersonId(tmp.getPersonId()); - membershipId.setResearchGroupId(researchGroup.getResearchGroupId()); - - membership.setId(membershipId); +// ResearchGroupMembershipId membershipId = new ResearchGroupMembershipId(); +// membershipId.setPersonId(tmp.getPersonId()); +// membershipId.setResearchGroupId(researchGroup.getResearchGroupId()); +// +// membership.setId(membershipId); researchGroupService.createMemberhip(membership); ResearchGroup newGroup = new ResearchGroup(); diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/SoftwareServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/SoftwareServiceTest.java new file mode 100644 index 00000000..888c350a --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/SoftwareServiceTest.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * SoftwareServiceTest.java, 2014/08/07 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Software; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.SoftwareService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 7.8.14. + */ +@Transactional +public class SoftwareServiceTest extends AbstractServicesTest { + + @Autowired + private SoftwareService softwareService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private Software software; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + software = createSW("new SW"); + } + + @Test + public void testCreateSoftware() { + int softwareCountBefore = softwareService.getAllRecords().size(); + int softwareID = softwareService.create(software); + assertEquals(softwareCountBefore + 1, softwareService.getAllRecords().size()); + assertEquals(softwareID, software.getSoftwareId()); + } + @Test + public void testCreateDefaultSoftware() { + //TODO add this method to the Service class +// int softwareCountBefore = softwareService.getAllRecords().size(); +// software.setDefaultNumber(1); +// int softwareID = softwareService.createDefaultRecord(software); +// assertEquals(softwareCountBefore + 1, softwareService.getAllRecords().size()); +// assertEquals(softwareID, software.getSoftwareId()); + } + + + + @Test + public void testCreateSoftwareGroupRel() { + int SoftwareCountBefore = softwareService.getAllRecords().size(); + int SoftwareGroupBefore = softwareService.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + softwareService.createGroupRel(software, researchGroup); + int id = softwareService.create(software); + assertEquals(SoftwareCountBefore + 1, softwareService.getAllRecords().size()); + + List list = softwareService.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(SoftwareGroupBefore + 1, list.size()); + assertTrue(softwareService.hasGroupRel(id)); + } + + + @Test + public void testCanSaveTitle() { + softwareService.createGroupRel(software, researchGroup); + int id = softwareService.create(software); + assertTrue(softwareService.canSaveDefaultTitle(software.getTitle(), -1)); + assertTrue(softwareService.canSaveTitle(software.getTitle(), researchGroup.getResearchGroupId(), id)); + assertFalse(softwareService.canSaveTitle(software.getTitle(), researchGroup.getResearchGroupId(), -1)); + + Software newSW = createSW("new SW2"); + newSW.setDefaultNumber(1); + softwareService.create(newSW); + assertFalse(softwareService.canSaveDefaultTitle(newSW.getTitle(), -1)); + assertTrue(softwareService.canSaveDefaultTitle(newSW.getTitle(), newSW.getSoftwareId())); + } + + private Software createSW(String title) { + Software newSw = new Software(); + newSw.setTitle(title); + newSw.setDescription("This is new testing SW"); + newSw.setDefaultNumber(0); + return newSw; + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/StimulusServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/StimulusServiceTest.java new file mode 100644 index 00000000..1e78cff3 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/StimulusServiceTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * StimulusServiceTest.java, 2014/08/12 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.pojo.Stimulus; +import cz.zcu.kiv.eegdatabase.wui.core.common.StimulusService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 12.8.14. + */ +@Transactional +public class StimulusServiceTest extends AbstractServicesTest { + + @Autowired + private StimulusService stimulusService; + + private Stimulus stimulus; + + @Before + public void setUp() throws Exception { + + stimulus = new Stimulus(); + stimulus.setDescription("test description"); + } + + @Test + public void testCreateStimulus() { + int stimulusCountBefore = stimulusService.getAllRecords().size(); + int id = stimulusService.create(stimulus); + assertEquals(stimulusCountBefore + 1, stimulusService.getAllRecords().size()); + assertEquals(id, stimulus.getStimulusId()); + } + + @Test + public void testCanSaveDescription() { + stimulusService.create(stimulus); + int id = stimulusService.create(stimulus); + assertFalse(stimulusService.canSaveDescription(stimulus.getDescription())); + } + +} + diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/WeatherServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/WeatherServiceTest.java new file mode 100644 index 00000000..dccadabd --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/WeatherServiceTest.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * WeatherServiceTest.java, 2014/08/07 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.data.pojo.Weather; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.common.WeatherService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Created by Honza on 7.8.14. + */ +@Transactional +public class WeatherServiceTest extends AbstractServicesTest { + + @Autowired + private WeatherService weatherService; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private Weather weather; + private ResearchGroup researchGroup; + + @Before + public void setUp() throws Exception { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + + personDao.create(person); + + researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + weather = createWeather("new Weather"); + } + + @Test + public void testCreateWeather() { + int weatherCountBefore = weatherService.getAllRecords().size(); + int weatherID = weatherService.create(weather); + assertEquals(weatherCountBefore + 1, weatherService.getAllRecords().size()); + assertEquals(weatherID, weather.getWeatherId()); + } + + @Test + public void testCreateDefaultWeather() { + int weatherCountBefore = weatherService.getAllRecords().size(); + weather.setDefaultNumber(1); + weatherService.createDefaultRecord(weather); + assertEquals(weatherCountBefore + 1, weatherService.getAllRecords().size()); + + assertTrue(weatherService.isDefault(weather.getWeatherId())); + } + @Test + public void testCreateWeatherGroupRel() { + int weatherCountBefore = weatherService.getAllRecords().size(); + int weatherGroupBefore = weatherService.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + weatherService.createGroupRel(weather, researchGroup); + int id = weatherService.create(weather); + assertEquals(weatherCountBefore + 1, weatherService.getAllRecords().size()); + + List list = weatherService.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(weatherGroupBefore + 1, list.size()); + assertTrue(weatherService.hasGroupRel(id)); + } + + @Test + public void testGetDefaultRecords() { + int weatherCountBefore = weatherService.getAllRecords().size(); + int weatherDefaultBefore = weatherService.getDefaultRecords().size(); + //This is not a default Weaher + int id = weatherService.create(weather); + + Weather newWeather = createWeather("new weather2"); + newWeather.setDefaultNumber(1); + weatherService.createDefaultRecord(newWeather); + assertEquals(weatherCountBefore + 2, weatherService.getAllRecords().size()); + + assertEquals(weatherDefaultBefore + 1, weatherService.getDefaultRecords().size()); + + assertFalse(weatherService.hasGroupRel(newWeather.getWeatherId())); + } + + @Test + public void testCanSaveTitle() { + weatherService.createGroupRel(weather, researchGroup); + int id = weatherService.create(weather); + assertTrue(weatherService.canSaveDefaultTitle(weather.getTitle(), -1)); + assertTrue(weatherService.canSaveTitle(weather.getTitle(), researchGroup.getResearchGroupId(), id)); + assertFalse(weatherService.canSaveTitle(weather.getTitle(), researchGroup.getResearchGroupId(), -1)); + + Weather newWeather = createWeather("new Weather2"); + newWeather.setDefaultNumber(1); + weatherService.createDefaultRecord(newWeather); + assertFalse(weatherService.canSaveDefaultTitle(newWeather.getTitle(), -1)); + assertTrue(weatherService.canSaveDefaultTitle(newWeather.getTitle(), newWeather.getWeatherId())); + } + + private Weather createWeather(String title) { + Weather newWeather = new Weather(); + newWeather.setTitle(title); + newWeather.setDescription("This is new testing Weather"); + newWeather.setDefaultNumber(0); + return newWeather; + } +} diff --git a/src/test/resources/test-context.xml b/src/test/resources/test-context.xml index c041ab77..e80cd974 100644 --- a/src/test/resources/test-context.xml +++ b/src/test/resources/test-context.xml @@ -365,6 +365,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + From cd523da4d2575160e9c84ac357f109ce24a99a1b Mon Sep 17 00:00:00 2001 From: JardaHosek Date: Fri, 15 Aug 2014 08:21:48 +0200 Subject: [PATCH 10/10] added layout-generator annotations --- src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Artifact.java | 1 + src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Digitization.java | 1 + .../java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeConf.java | 1 + .../java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeSystem.java | 1 + src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java | 1 + .../java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java | 1 + src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Scenario.java | 1 + src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/SubjectGroup.java | 1 + src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Weather.java | 1 + 9 files changed, 9 insertions(+) diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Artifact.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Artifact.java index e1ebf453..16492ee2 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Artifact.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Artifact.java @@ -39,6 +39,7 @@ /** * Artifact generated by hbm2java */ +@Form @Entity @Table(name = "ARTEFACT") public class Artifact implements java.io.Serializable { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Digitization.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Digitization.java index 4b09fc3e..bd6cf735 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Digitization.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Digitization.java @@ -37,6 +37,7 @@ /** * Digitization generated by hbm2java */ +@Form @Entity @Table(name = "DIGITIZATION") public class Digitization implements Serializable { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeConf.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeConf.java index 8dd6621e..1b8e4e6d 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeConf.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeConf.java @@ -38,6 +38,7 @@ /** * ElectrodeConf generated by hbm2java */ +@Form @Entity @Table(name = "ELECTRODE_CONF") public class ElectrodeConf implements Serializable { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeSystem.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeSystem.java index d38ba051..d7066174 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeSystem.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ElectrodeSystem.java @@ -41,6 +41,7 @@ /** * ElectrodeSystem generated by hbm2java */ +@Form @Entity @Table(name = "ELECTRODE_SYSTEM") public class ElectrodeSystem implements Serializable { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java index 88b66d88..10279b99 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java @@ -53,6 +53,7 @@ /** * Person generated by hbm2java */ +@Form @Entity @Table(name = "PERSON") public class Person implements Serializable, Comparable, IAutoCompletable { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java index 1ea81268..9df6e9a8 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java @@ -47,6 +47,7 @@ /** * ResearchGroup generated by hbm2java */ +@Form @Entity @Table(name = "RESEARCH_GROUP") public class ResearchGroup implements java.io.Serializable { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Scenario.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Scenario.java index fb7f302a..e4eff783 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Scenario.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Scenario.java @@ -55,6 +55,7 @@ /** * Scenario generated by hbm2java */ +@Form @Entity @Table(name = "SCENARIO") @XmlRootElement diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/SubjectGroup.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/SubjectGroup.java index 8f8a2038..0387371d 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/SubjectGroup.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/SubjectGroup.java @@ -44,6 +44,7 @@ /** * SubjectGroup generated by hbm2java */ +@Form @Entity @Table(name = "SUBJECT_GROUP") public class SubjectGroup implements java.io.Serializable { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Weather.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Weather.java index 55264d23..59d462e4 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Weather.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Weather.java @@ -47,6 +47,7 @@ /** * Weather generated by hbm2java */ +@Form @Entity @Table(name = "WEATHER") public class Weather implements java.io.Serializable {