diff --git a/.gitignore b/.gitignore index 00ba9db4..b275dfae 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ target *.iml bin .project +src/main/webapp/WEB-INF/db.properties .classpath .settings src/main/webapp/files/js/messages-en.json diff --git a/pom.xml b/pom.xml index 3c19e0a1..70e56c21 100644 --- a/pom.xml +++ b/pom.xml @@ -792,6 +792,8 @@ maven-surefire-plugin 2.17 + 1 + -Xmx1024m diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java index d409f5d8..911f7b65 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java @@ -60,7 +60,7 @@ public List
getArticlesForUser(Person person) { } else { // We need to load only articles which can be viewed by the logged user. // That is, we need to load only public articles or articles from the groups the logged user is member of. - query = "select DISTINCT a from Article a left join fetch a.articleComments where " + + query = "select DISTINCT a from Article a left join fetch a.articleComments where a.person.personId = :personId or " + "a.researchGroup.researchGroupId is null or " + "a.researchGroup.researchGroupId in " + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId) " + @@ -122,7 +122,7 @@ public int getArticleCountForPerson(Person person) { if (person.getAuthority().equals("ROLE_ADMIN")) { return ((Long) getSession().createQuery("select count(*) from Article").uniqueResult()).intValue(); } - String query = "select count(*) from Article a where " + + String query = "select count(*) from Article a where a.person.personId = :personId or " + "a.researchGroup.researchGroupId is null or " + "a.researchGroup.researchGroupId in " + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId)"; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/zip/ZipGenerator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/zip/ZipGenerator.java index 36e3a541..f715d687 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/zip/ZipGenerator.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/logic/zip/ZipGenerator.java @@ -88,7 +88,7 @@ public File generate(Experiment exp, MetadataCommand mc, Set dataFiles ZipEntry entry; - if (mc.isScenFile()) { + if (mc.isScenFile() && scen.getScenarioFile() != null) { try { log.debug("saving scenario file (" + scen.getScenarioName() + ") into a zip file"); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/table/TimestampConverter.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/table/TimestampConverter.java index 64a1fc65..64366581 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/table/TimestampConverter.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/table/TimestampConverter.java @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.wicket.util.convert.ConversionException; import org.apache.wicket.util.convert.IConverter; import com.ibm.icu.text.SimpleDateFormat; @@ -67,11 +68,13 @@ public TimestampConverter(String formatPattern, String parsePattern) { @Override public Timestamp convertToObject(String value, Locale locale) { try { - return new Timestamp(new SimpleDateFormat(getParsePattern()).parse(value).getTime()); + + long time = new SimpleDateFormat(getParsePattern()).parse(value).getTime(); + return new Timestamp(time); + } catch (ParseException e) { - - log.error(e.getMessage(), e); - return null; + log.info(e.getMessage(), e); + throw new ConversionException("Wrong Date Format: " + parsePattern); } } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html index 61c827a5..d4e5a9c9 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html @@ -47,9 +47,10 @@

- - +
+ +

diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.java index c76aebcd..f2d15e8c 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.java @@ -45,6 +45,7 @@ import cz.zcu.kiv.eegdatabase.wui.core.person.PersonFacade; import cz.zcu.kiv.eegdatabase.wui.ui.groups.ResearchGroupsDetailPage; import cz.zcu.kiv.eegdatabase.wui.ui.home.HomePage; +import cz.zcu.kiv.eegdatabase.wui.ui.people.form.PersonFormPage; /** * Account overview page with logged user information @@ -99,6 +100,9 @@ protected void populateItem(ListItem item) { } }; groups.setVisibilityAllowed(!emptyGroups); - add(groups, noGroups); + + BookmarkablePageLink editAccount = new BookmarkablePageLink("editLink", PersonFormPage.class, PageParametersUtils.getDefaultPageParameters(user.getPersonId())); + + add(groups, noGroups, editAccount); } } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackageManagePanel.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackageManagePanel.java index a478a809..ad3e9f11 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackageManagePanel.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackageManagePanel.java @@ -22,49 +22,53 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.ui.experiments.components; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentPackage; -import cz.zcu.kiv.eegdatabase.data.pojo.License; -import cz.zcu.kiv.eegdatabase.data.pojo.LicenseType; -import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampPropertyColumn; -import cz.zcu.kiv.eegdatabase.wui.components.table.ViewLinkPanel; -import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; -import cz.zcu.kiv.eegdatabase.wui.core.experiments.ExperimentsFacade; -import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ExperimentsDetailPage; -import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ListExperimentsDataProvider; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; import org.apache.wicket.extensions.ajax.markup.html.repeater.data.table.AjaxFallbackDefaultDataTable; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.extensions.model.AbstractCheckBoxModel; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.IModel; +import org.apache.wicket.model.LoadableDetachableModel; import org.apache.wicket.model.Model; import org.apache.wicket.model.PropertyModel; import org.apache.wicket.model.StringResourceModel; import org.apache.wicket.spring.injection.annot.SpringBean; + +import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; +import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentPackage; +import cz.zcu.kiv.eegdatabase.data.pojo.License; +import cz.zcu.kiv.eegdatabase.data.pojo.LicenseType; import cz.zcu.kiv.eegdatabase.wui.components.table.CheckBoxColumn; +import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampPropertyColumn; +import cz.zcu.kiv.eegdatabase.wui.components.table.ViewLinkPanel; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; import cz.zcu.kiv.eegdatabase.wui.core.experimentpackage.ExperimentPackageFacade; +import cz.zcu.kiv.eegdatabase.wui.core.experiments.ExperimentsFacade; import cz.zcu.kiv.eegdatabase.wui.core.license.LicenseFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ExperimentsDetailPage; +import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ListExperimentsDataProvider; import cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.LicenseEditForm; import cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.PublicPrivateLicensePanel; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; -import org.apache.wicket.extensions.model.AbstractCheckBoxModel; -import org.apache.wicket.markup.html.form.Form; -import org.apache.wicket.markup.html.link.Link; -import org.apache.wicket.markup.html.list.ListItem; -import org.apache.wicket.markup.html.list.ListView; -import org.apache.wicket.model.LoadableDetachableModel; /** * Panel for experiment package management. Adding/removing experiments and @@ -73,6 +77,8 @@ * @author Jakub Danek */ public class ExperimentPackageManagePanel extends Panel { + + protected Log log = LogFactory.getLog(getClass()); private static final int EXPERIMENTS_PER_PAGE = 10; @SpringBean @@ -348,7 +354,7 @@ protected List load() { protected void onSubmitAction(IModel model, AjaxRequestTarget target, Form form) { License obj = model.getObject(); if (obj.getLicenseId() == 0) { - if(!obj.getTitle().equals(selectedBlueprintModel.getObject().getTitle())) { + if(selectedBlueprintModel.getObject() != null && !obj.getTitle().equals(selectedBlueprintModel.getObject().getTitle())) { obj.setTemplate(true); obj.setResearchGroup(epModel.getObject().getResearchGroup()); licenseFacade.create(obj); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackagePanel.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackagePanel.java index f1ba8dba..a36e5d79 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackagePanel.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/components/ExperimentPackagePanel.java @@ -223,9 +223,6 @@ protected void onConfigure() { cont.add(ddc); cont.add(licenseBuyLink); - - // XXX HIDE LICENSE DROP DOWN CHOICE FOR NOW. FIX EXCEPTION !!! - cont.setVisibilityAllowed(false); } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/ScenarioForm.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/ScenarioForm.java index cf351e6c..c1da5ba3 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/ScenarioForm.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/ScenarioForm.java @@ -22,16 +22,12 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.ui.experiments.forms; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; -import cz.zcu.kiv.eegdatabase.data.pojo.ScenarioSchemas; -import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; -import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; -import cz.zcu.kiv.eegdatabase.wui.core.CoreConstants; -import cz.zcu.kiv.eegdatabase.wui.core.common.StimulusFacade; -import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; -import cz.zcu.kiv.eegdatabase.wui.core.scenarios.ScenariosFacade; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; @@ -39,7 +35,14 @@ import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.form.*; +import org.apache.wicket.markup.html.form.CheckBox; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.Radio; +import org.apache.wicket.markup.html.form.RadioGroup; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.form.upload.FileUpload; import org.apache.wicket.markup.html.form.upload.FileUploadField; import org.apache.wicket.markup.html.panel.FeedbackPanel; @@ -47,22 +50,25 @@ import org.apache.wicket.model.Model; import org.apache.wicket.model.util.ListModel; import org.apache.wicket.spring.injection.annot.SpringBean; -import org.apache.wicket.validation.IValidatable; -import org.apache.wicket.validation.IValidator; +import org.apache.wicket.util.string.Strings; import org.apache.wicket.validation.validator.RangeValidator; -import org.w3c.dom.Document; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.List; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; +import cz.zcu.kiv.eegdatabase.data.pojo.ScenarioSchemas; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.common.StimulusFacade; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; +import cz.zcu.kiv.eegdatabase.wui.core.scenarios.ScenariosFacade; public class ScenarioForm extends Form { private static final long serialVersionUID = 4355778752386684554L; + protected Log log = LogFactory.getLog(getClass()); + @SpringBean private ScenariosFacade scenariosFacade; @@ -76,7 +82,7 @@ public ScenarioForm(String id, final ModalWindow window) { super(id, new CompoundPropertyModel(new Scenario())); add(new Label("addScenarioHeader", ResourceUtils.getModel("pageTitle.addScenario"))); - + final FeedbackPanel feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true); add(feedback); @@ -96,11 +102,11 @@ public ScenarioForm(String id, final ModalWindow window) { DropDownChoice groups = new DropDownChoice("researchGroup", choices, new ChoiceRenderer( "title")); groups.setRequired(true); - + TextField title = new TextField("title"); title.setLabel(ResourceUtils.getModel("label.scenarioTitle")); title.setRequired(true); - // title.add(new TitleExistsValidator()); + // title.add(new TitleExistsValidator()); TextField length = new TextField("scenarioLength", Integer.class); length.setRequired(true); @@ -183,81 +189,47 @@ protected void onUpdate(AjaxRequestTarget target) { @Override protected void onSubmit(AjaxRequestTarget target, Form form) { - FileUpload fileUpload = file.getFileUpload(); - FileUpload xmlfileUpload = xmlfile.getFileUpload(); - + FileUpload uploadedFile = file.getFileUpload(); Scenario scenario = ScenarioForm.this.getModelObject(); - - target.add(ScenarioForm.this); - - // loading non-XML + if (!scenariosFacade.canSaveTitle(scenario.getTitle(), scenario.getScenarioId())) { error(ResourceUtils.getString("error.titleAlreadyInDatabase")); + target.add(feedback); return; - } - if ((fileUpload != null) && (!(fileUpload.getSize() == 0))) { - // File uploaded - String filename = fileUpload.getClientFileName().replace(" ", "_"); - scenario.setScenarioName(filename); - if (fileUpload.getContentType().length() > CoreConstants.MAX_MIMETYPE_LENGTH) { - int index = filename.lastIndexOf("."); - scenario.setMimetype(filename.substring(index)); - } else { - scenario.setMimetype(fileUpload.getContentType()); - } - try { - scenario.setFileContentStream(fileUpload.getInputStream()); - } catch (IOException e) { - feedback.error(e.getMessage()); - target.add(feedback); - } + } else { + // loading non-XML scenario file + if ((uploadedFile != null) && (!(uploadedFile.getSize() == 0))) { - } + String name = uploadedFile.getClientFileName(); + // when uploading from localhost some browsers will specify the entire path, we strip it + // down to just the file name + name = Strings.lastPathComponent(name, '/'); + name = Strings.lastPathComponent(name, '\\'); - // loading XML - if ((xmlfileUpload != null) && (!(xmlfileUpload.getSize() == 0))) { - // load the XML file to a table with the XMLType column - String filename = xmlfileUpload.getClientFileName().replace(" ", "_"); - scenario.setScenarioName(filename); - - scenario.setMimetype(xmlfileUpload.getContentType()); - - DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder docBuilder; - Document doc = null; - try { - docBuilder = docFactory.newDocumentBuilder(); - InputStream inputStream = xmlfileUpload.getInputStream(); - doc = docBuilder.parse(inputStream); - } catch (Exception e) { - feedback.error(e.getMessage()); - target.add(feedback); - return; - } + // File uploaded + String filename = name.replace(" ", "_"); + scenario.setScenarioName(filename); - // getting the right scenarioType bean - // no schema - binary storage - Boolean isSchemaSelected = schema.getModelObject(); - if (!isSchemaSelected) { - } - // schema selected - structured storage - else { - Class c; + scenario.setMimetype(uploadedFile.getContentType()); try { - c = Class.forName("cz.zcu.kiv.eegdatabase.data.pojo.ScenarioTypeSchema" + schemaList.getModelObject().getSchemaId()); - } catch (Exception e) { - feedback.error(e.getMessage()); + scenario.setFileContentStream(uploadedFile.getInputStream()); + } catch (IOException e) { + log.error(e.getMessage(), e); + error("Error while saving data."); target.add(feedback); - return; } } - } + // Creating new + scenariosFacade.create(scenario); - if (!dataAvailable.getModelObject()) { + /* + * clean up after upload file, and set model to null or will be problem with page serialization when redirect start - DON'T DELETE IT ! + */ + ScenarioForm.this.setModelObject(null); + + window.close(target); } - scenariosFacade.create(scenario); - window.close(target); } @Override diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/form/ScenarioForm.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/form/ScenarioForm.java index f179fa39..1cb02c32 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/form/ScenarioForm.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/form/ScenarioForm.java @@ -63,6 +63,7 @@ public class ScenarioForm extends Form { private static final long serialVersionUID = 1L; + protected Log log = LogFactory.getLog(getClass()); @SpringBean @@ -73,6 +74,7 @@ public class ScenarioForm extends Form { private ResearchGroupFacade researchGroupFacade; public ScenarioForm(String id, IModel model, final FeedbackPanel feedback) { + super(id, new CompoundPropertyModel(model)); setMultiPart(true); @@ -174,47 +176,47 @@ public void onSubmit() { FileUpload uploadedFile = file.getFileUpload(); Scenario scenario = ScenarioForm.this.getModelObject(); - // loading non-XML - if ((uploadedFile != null) && (!(uploadedFile.getSize() == 0))) { - - String name = uploadedFile.getClientFileName(); - // when uploading from localhost some browsers will specify the entire path, we strip it - // down to just the file name - name = Strings.lastPathComponent(name, '/'); - name = Strings.lastPathComponent(name, '\\'); - - // File uploaded - String filename = name.replace(" ", "_"); - scenario.setScenarioName(filename); - - scenario.setMimetype(uploadedFile.getContentType()); - try { - scenario.setFileContentStream(uploadedFile.getInputStream()); - } catch (IOException e) { - log.error(e.getMessage(), e); - } - } - if (!scenariosFacade.canSaveTitle(scenario.getTitle(), scenario.getScenarioId())) { error(ResourceUtils.getString("error.titleAlreadyInDatabase")); return; - } - - if (scenario.getScenarioId() > 0) { - // Editing existing - // scenarioTypeDao.update(scenarioType); - scenariosFacade.update(scenario); } else { - // Creating new - scenariosFacade.create(scenario); - } + // loading non-XML scenario file + if ((uploadedFile != null) && (!(uploadedFile.getSize() == 0))) { + + String name = uploadedFile.getClientFileName(); + // when uploading from localhost some browsers will specify the entire path, we strip it + // down to just the file name + name = Strings.lastPathComponent(name, '/'); + name = Strings.lastPathComponent(name, '\\'); + + // File uploaded + String filename = name.replace(" ", "_"); + scenario.setScenarioName(filename); + + scenario.setMimetype(uploadedFile.getContentType()); + try { + scenario.setFileContentStream(uploadedFile.getInputStream()); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } - /* - * clean up after upload file, and set model to null or will be problem with page serialization when redirect start - DON'T DELETE IT ! - */ - ScenarioForm.this.setModelObject(null); + if (scenario.getScenarioId() > 0) { + // Editing existing + // scenarioTypeDao.update(scenarioType); + scenariosFacade.update(scenario); + } else { + // Creating new + scenariosFacade.create(scenario); + } + /* + * clean up after upload file, and set model to null or will be problem with page serialization when redirect start - DON'T DELETE IT ! + */ + ScenarioForm.this.setModelObject(null); + + setResponsePage(ScenarioDetailPage.class, PageParametersUtils.getDefaultPageParameters(scenario.getScenarioId())); + } - setResponsePage(ScenarioDetailPage.class, PageParametersUtils.getDefaultPageParameters(scenario.getScenarioId())); } }; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/security/RegistrationPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/security/RegistrationPage.html index 392441b1..a14fdd08 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/security/RegistrationPage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/security/RegistrationPage.html @@ -47,6 +47,7 @@

+
diff --git a/src/main/webapp/WEB-INF/db.properties.sample b/src/main/webapp/WEB-INF/db.properties.sample new file mode 100644 index 00000000..92e0493c --- /dev/null +++ b/src/main/webapp/WEB-INF/db.properties.sample @@ -0,0 +1,36 @@ + +# +# * ******************************************************************************************************************** +# *

+# * This file is part of the eegdatabase project +# *

+# * ========================================== +# *

+# * Copyright (C) 2014 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. +# *

+# * ********************************************************************************************************************** +# *

+# * aaa, 2014/07/30 16:10 petr-jezek +# *

+# * ******************************************************************************************************************** +# */ + +#dev PG database +jdbc.url=jdbc:postgresql://localhost/eeg +jdbc.username=eeg +jdbc.password=eeg + +#dev ES database +elasticsearch.url=localhost:9300 +elasticsearch.clusterName=es-eeg-dev diff --git a/src/main/webapp/WEB-INF/persistence.xml b/src/main/webapp/WEB-INF/persistence.xml index c9c8e17d..2bfe013b 100644 --- a/src/main/webapp/WEB-INF/persistence.xml +++ b/src/main/webapp/WEB-INF/persistence.xml @@ -60,6 +60,7 @@ /WEB-INF/project.properties + /WEB-INF/db.properties /WEB-INF/facebook.properties /WEB-INF/linkedin.properties diff --git a/src/main/webapp/WEB-INF/project.properties b/src/main/webapp/WEB-INF/project.properties index faf07016..b7d7f63a 100644 --- a/src/main/webapp/WEB-INF/project.properties +++ b/src/main/webapp/WEB-INF/project.properties @@ -24,21 +24,12 @@ db.dialect=org.hibernate.dialect.PostgreSQLDialect jdbc.driverClassName=org.postgresql.Driver -#dev PG database -jdbc.url=jdbc:postgresql://eeg2.kiv.zcu.cz/eeg -jdbc.username=eeg -jdbc.password=eeg - hibernate.show_sql=true # create/validate/create-drop/update hibernate.hbm2ddl.auto=update hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider hibernate.connection.pool_size=10 -#dev ES database -elasticsearch.url=eeg2.kiv.zcu.cz:9300 -elasticsearch.clusterName=es-eeg-dev - encoding=UTF-8 objects=cz.zcu.kiv.eegdatabase.data.xmlObjects measured=measured diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ArticleCommentDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ArticleCommentDaoTest.java new file mode 100644 index 00000000..51b1d7c4 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ArticleCommentDaoTest.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * ArticleCommentDaoTest.java, 2014/07/09 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.logic.Util; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; + +import static org.junit.Assert.assertEquals; + +/** + * Created by stebjan on 9.7.14. + */ +@Transactional +public class ArticleCommentDaoTest extends AbstractDataAccessTest { + + @Autowired + private PersonDao personDao; + + @Autowired + private ArticleDao articleDao; + + @Autowired + private ArticleCommentDao commentDao; + + + private Article article; + private Person personReader; + private ArticleComment comment; + + @Before + public void setUp() { + personReader = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_READER); + personDao.create(personReader); + + + article = new Article(); + + article.setText("test-text"); + article.setTitle("test-title"); + article.setTime(new Timestamp(System.currentTimeMillis())); + article.setPerson(personReader); + articleDao.create(article); + } + + @Test + public void testCreateComment() { + int commentNumber = articleDao.read(article.getArticleId()).getArticleComments().size(); + comment = createComment(article); + + commentDao.create(comment); + assertEquals(commentNumber + 1, articleDao.read(article.getArticleId()).getArticleComments().size()); + } + + @Test + public void testGetCommentsForArticle() { + int commentNumber = articleDao.read(article.getArticleId()).getArticleComments().size(); + int allCommentNumber = commentDao.getCountRecords(); + comment = createComment(article); + commentDao.create(comment); + + Article article2 = new Article(); + article2.setText("test-text"); + article2.setTitle("test-title2"); + article2.setTime(new Timestamp(System.currentTimeMillis())); + article2.setPerson(personReader); + articleDao.create(article2); + + comment = createComment(article2); + commentDao.create(comment); + assertEquals(commentNumber + 1, articleDao.read(article.getArticleId()).getArticleComments().size()); + assertEquals(allCommentNumber + 2, commentDao.getCountRecords()); + + } + + private ArticleComment createComment(Article article) { + ArticleComment newComment = new ArticleComment(); + newComment.setPerson(personReader); + newComment.setArticle(article); + article.getArticleComments().add(newComment); + articleDao.update(article); + newComment.setTime(new Timestamp(System.currentTimeMillis())); + newComment.setText("test comment"); + return newComment; + + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ArticleDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ArticleDaoTest.java index 3224be86..893aa0ea 100644 --- a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ArticleDaoTest.java +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ArticleDaoTest.java @@ -32,6 +32,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; import java.sql.Timestamp; @@ -43,7 +44,8 @@ * User: Tomas Pokryvka * Date: 20.4.13 */ - +@Transactional +@TransactionConfiguration(defaultRollback = true) public class ArticleDaoTest extends AbstractDataAccessTest { @Autowired @@ -71,7 +73,6 @@ public void setUp() { } @Test - @Transactional public void testCreateArticleReader() { int count = articleDao.getCountRecords(); articleDao.create(article); @@ -79,7 +80,6 @@ public void testCreateArticleReader() { } @Test - @Transactional public void testNotNullTitle() { article.setTitle(null); try { @@ -95,11 +95,6 @@ public void testNotNullTitle() { } } - @After - public void clean() { - articleDao.delete(article); - personDao.delete(personReader); - } // @Test diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/DiseaseDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/DiseaseDaoTest.java new file mode 100644 index 00000000..e198223b --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/DiseaseDaoTest.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * DiseaseDaoTest.java, 2014/07/07 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +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 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; + +/** + * User: Jan Stebetak + * Date: 7.7.14 + */ +public class DiseaseDaoTest extends AbstractDataAccessTest { + + + @Autowired + private SimpleDiseaseDao diseaseDao; + @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 = new Disease(); + disease.setTitle("New Disease"); + disease.setDescription("This is new testing disease"); + } + + + @Test + @Transactional + public void testCreateDisease() { + int diseaseCountBefore = diseaseDao.getAllRecords().size(); + int diseaseID = diseaseDao.create(disease); + assertEquals(diseaseCountBefore + 1, diseaseDao.getAllRecords().size()); + assertEquals(diseaseID, disease.getDiseaseId()); + } + + + + @Test + @Transactional + public void testCreateGroupDisease() { + int diseaseCountBefore = diseaseDao.getAllRecords().size(); + int diseaseGroupBefore = diseaseDao.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + diseaseDao.createGroupRel(disease, researchGroup); + diseaseDao.create(disease); + assertEquals(diseaseCountBefore + 1, diseaseDao.getAllRecords().size()); + + List list = diseaseDao.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(diseaseGroupBefore + 1, list.size()); + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ElectrodeSystemDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ElectrodeSystemDaoTest.java new file mode 100644 index 00000000..decf5174 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ElectrodeSystemDaoTest.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * ElectrodeSystemDaoTest.java, 2014/07/08 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.pojo.ElectrodeSystem; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.Util; +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; + +/** + * Created by stebjan on 8.7.14. + */ +@Transactional +public class ElectrodeSystemDaoTest extends AbstractDataAccessTest { + @Autowired + private SimpleElectrodeSystemDao electrodeSystemDao; + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + private ElectrodeSystem electrodeSystem; + 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); + electrodeSystem = new ElectrodeSystem(); + electrodeSystem.setTitle("New System"); + electrodeSystem.setDescription("This is new testing system"); + electrodeSystem.setDefaultNumber(0); + } + + + @Test + public void testCreateDisease() { + int countBefore = electrodeSystemDao.getAllRecords().size(); + int id = electrodeSystemDao.create(electrodeSystem); + assertEquals(countBefore + 1, electrodeSystemDao.getCountRecords()); + assertEquals(id, electrodeSystem.getElectrodeSystemId()); + } + + + @Test + public void testCreateGroupDisease() { + int countBefore = electrodeSystemDao.getAllRecords().size(); + int croupBefore = electrodeSystemDao.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + electrodeSystemDao.createGroupRel(electrodeSystem, researchGroup); + electrodeSystemDao.create(electrodeSystem); + assertEquals(countBefore + 1, electrodeSystemDao.getAllRecords().size()); + + List list = electrodeSystemDao.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(croupBefore + 1, list.size()); + } + + @Test + public void testCreateDefaultRecord() { + int count = electrodeSystemDao.getCountRecords(); + electrodeSystemDao.createDefaultRecord(electrodeSystem); + assertEquals(count + 1, electrodeSystemDao.getCountRecords()); + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDaoTest.java index fd28c795..1c12f16e 100644 --- a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDaoTest.java +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDaoTest.java @@ -129,12 +129,6 @@ public void testGetExperimentForDetail() { } - @After - public void clean() { - if (person.getUsername() != null) { - personDao.delete(person); - } - } private Person createPerson() { Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_READER); personDao.create(person); diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/HardwareDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/HardwareDaoTest.java new file mode 100644 index 00000000..d7516bb4 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/HardwareDaoTest.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * HardwareDaoTest.java, 2014/30/06 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +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 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; + +/** + * User: Jan Stebetak + * Date: 30.6.14 + */ +public class HardwareDaoTest extends AbstractDataAccessTest { + + + @Autowired + private HardwareDao hardwareDao; + @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 = new Hardware(); + hardware.setTitle("New HW"); + hardware.setDescription("This is new testing HW"); + hardware.setType("HW type"); + hardware.setDefaultNumber(0); + } + + + @Test + @Transactional + public void testCreateHardware() { + int hardwareCountBefore = hardwareDao.getAllRecords().size(); + int hardwareID = hardwareDao.create(hardware); + assertEquals(hardwareCountBefore + 1, hardwareDao.getAllRecords().size()); + assertEquals(hardwareID, hardware.getHardwareId()); + } + + + @Test + @Transactional + public void testCreateDefaultRecord() throws Exception { + int expectedValue = hardwareDao.getDefaultRecords().size(); + hardwareDao.createDefaultRecord(hardware); + assertEquals(expectedValue + 1, hardwareDao.getDefaultRecords().size()); + } + + @Test + @Transactional + public void testCreateGroupHardware() { + int hardwareCountBefore = hardwareDao.getAllRecords().size(); + int hardwareGroupBefore = hardwareDao.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + hardwareDao.createGroupRel(hardware, researchGroup); + hardwareDao.create(hardware); + assertEquals(hardwareCountBefore + 1, hardwareDao.getAllRecords().size()); + + List list = hardwareDao.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(hardwareGroupBefore + 1, list.size()); + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/LicenseDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/LicenseDaoTest.java new file mode 100644 index 00000000..b077ef23 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/LicenseDaoTest.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * LicenseDaoTest.java, 2014/07/07 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +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 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.*; + +@Transactional +public class LicenseDaoTest extends AbstractDataAccessTest { + + @Autowired + private LicenseDao licenseDao; + + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + + private License license; + + @Before + public void setUp() { + license = new License(); + license.setDescription("junit@test.description"); + license.setLicenseId(-231); + license.setPrice(-1000f); + license.setTitle("title"); + license.setLicenseType(LicenseType.OWNER); + + } + + @Test + public void testCreateLicense() { + int count = licenseDao.getCountRecords(); + int id = licenseDao.create(license); + assertNotNull(licenseDao.read(id)); + assertEquals(count + 1, licenseDao.getCountRecords()); + } + + @Test + public void testChangeLicenseType() { + int id = licenseDao.create(license); + assertNotNull(licenseDao.read(id)); + + license = licenseDao.read(id); + license.setLicenseType(LicenseType.ACADEMIC); + licenseDao.update(license); + + license = licenseDao.read(id); + + assertEquals(LicenseType.ACADEMIC, license.getLicenseType()); + } + + @Test + public void testGetLicenseType() { + Person person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_ADMIN); + int count = licenseDao.getCountRecords(); + personDao.create(person); + + ResearchGroup researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(person); + researchGroupDao.create(researchGroup); + license.setResearchGroup(researchGroup); + licenseDao.create(license); + License license2 = new License(); + license2.setLicenseId(-231); + license2.setPrice(-1000f); + license2.setTitle("title"); + license2.setLicenseType(LicenseType.ACADEMIC); + license2.setResearchGroup(researchGroup); + licenseDao.create(license2); + assertEquals(count + 2, licenseDao.getCountRecords()); + assertEquals(count + 1, licenseDao.getLicensesByType(researchGroup.getResearchGroupId(), LicenseType.ACADEMIC).size()); + + + } + + @Test + public void testDeleteLicense() { + int id = licenseDao.create(license); + license = licenseDao.read(id); + + licenseDao.delete(license); + assertNull(licenseDao.read(license.getLicenseId())); + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/PharmaceuticalDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/PharmaceuticalDaoTest.java new file mode 100644 index 00000000..37f12a53 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/PharmaceuticalDaoTest.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. + * + * *********************************************************************************************************************** + * + * PharmaceuticalDaoTest.java, 2014/07/07 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +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 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; + +/** + * User: Jan Stebetak + * Date: 7.7.14 + */ +public class PharmaceuticalDaoTest extends AbstractDataAccessTest { + + + @Autowired + private SimplePharmaceuticalDao pharmaceuticalDao; + @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 = new Pharmaceutical(); + pharmaceutical.setTitle("New pharmaceutical"); + pharmaceutical.setDescription("This is new testing pharmaceutical"); + } + + + @Test + @Transactional + public void testCreatePharmaceutical() { + int pharmaceuticalCountBefore = pharmaceuticalDao.getAllRecords().size(); + int pharmaceuticalID = pharmaceuticalDao.create(pharmaceutical); + assertEquals(pharmaceuticalCountBefore + 1, pharmaceuticalDao.getAllRecords().size()); + assertEquals(pharmaceuticalID, pharmaceutical.getPharmaceuticalId()); + } + + + + @Test + @Transactional + public void testCreateGroupPharmaceutical() { + int pharmaceuticalCountBefore = pharmaceuticalDao.getAllRecords().size(); + int pharmaceuticalGroupBefore = pharmaceuticalDao.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + pharmaceuticalDao.createGroupRel(pharmaceutical, researchGroup); + pharmaceuticalDao.create(pharmaceutical); + assertEquals(pharmaceuticalCountBefore + 1, pharmaceuticalDao.getAllRecords().size()); + + List list = pharmaceuticalDao.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(pharmaceuticalGroupBefore + 1, list.size()); + } +} + diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDaoTest.java index c50a9cf5..ca349afb 100644 --- a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDaoTest.java +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDaoTest.java @@ -31,10 +31,12 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; import static net.sf.ezmorph.test.ArrayAssertions.assertEquals; - +@Transactional +@TransactionConfiguration(defaultRollback = true) public class ResearchGroupDaoTest extends AbstractDataAccessTest { @Autowired @@ -59,7 +61,6 @@ public void setUp() { } @Test - @Transactional public void testCreateResearchGroup() { int count = researchGroupDao.getCountForList(); researchGroupDao.create(researchGroup); @@ -70,7 +71,6 @@ public void testCreateResearchGroup() { } @Test - @Transactional public void testGetGroupsWhereOwner() { int count = researchGroupDao.getResearchGroupsWhereOwner(person).size(); researchGroupDao.create(researchGroup); @@ -84,17 +84,10 @@ public void testGetGroupsWhereOwner() { } @Test - @Transactional public void testGetMembership() { researchGroupDao.create(researchGroup); assertEquals(0, researchGroupDao.getResearchGroupsWhereMember(person).size()); } - @After - public void clean() { - if (person.getUsername() != null) { - personDao.delete(person); - } - } } diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ReservationDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ReservationDaoTest.java new file mode 100644 index 00000000..5e770bd9 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/ReservationDaoTest.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * ReservationDaoTest.java, 2014/07/08 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.data.pojo.Reservation; +import cz.zcu.kiv.eegdatabase.logic.Util; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Created by stebjan on 8.7.14. + */ +@Transactional +public class ReservationDaoTest extends AbstractDataAccessTest { + @Autowired + private ResearchGroupDao researchGroupDao; + @Autowired + private PersonDao personDao; + @Autowired + private ReservationDao reservationDao; + + private ResearchGroup researchGroup; + private Person person; + private Reservation reservation; + + private final long TWO_HOURS_TO_MILLIS = 1000 * 60 * 60 * 2; + private final String DATE = "01/01/2010"; + + @Before + public void setUp() throws ParseException { + 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); + + reservation = createReservation(getDate(DATE)); + + } + + @Test + public void testCreateReservation() { + int countBefore = reservationDao.getCountRecords(); + reservationDao.create(reservation); + assertEquals(countBefore + 1, reservationDao.getCountRecords()); + } + + @Test + public void testEndDateChecking() throws ParseException { + int countBefore = reservationDao.getCountRecords(); + reservationDao.create(reservation); + reservation = createReservation(new Timestamp(getDate(DATE).getTime() + TWO_HOURS_TO_MILLIS)); + reservation.setEndTime(getDate(DATE)); + try { + reservationDao.createChecked(reservation); + } catch (Exception ex) { + assertTrue(ex instanceof DaoException); + } finally { + assertEquals(countBefore + 1, reservationDao.getCountRecords()); + } + } + + @Test + public void testExistingReservation() { + int countBefore = reservationDao.getCountRecords(); + reservationDao.create(reservation); + Reservation reservation2 = createReservation + (reservation.getStartTime()); + try { + reservationDao.createChecked(reservation2); + } catch (Exception ex) { + assertTrue(ex instanceof DaoException); + } finally { + assertEquals(countBefore + 1, reservationDao.getCountRecords()); + } + + } + @Test + public void testGetReservationBetween() throws ParseException { + int countBefore = reservationDao.getCountRecords(); + try { + reservationDao.createChecked(reservation); + reservation = createReservation(new Timestamp((reservation.getEndTime().getTime() + TWO_HOURS_TO_MILLIS))); + reservationDao.createChecked(reservation); + reservation = createReservation(new Timestamp(0)); + + reservationDao.createChecked(reservation); + } catch (Exception ex) { + + } finally { + assertEquals(countBefore + 3, reservationDao.getCountRecords()); + GregorianCalendar calStart = getCalendar("01/01/2010 00:00:01"); + //new GregorianCalendar(2000, 0, 1); + GregorianCalendar calEnd = getCalendar("01/01/2010 23:59:29"); + //new GregorianCalendar(2000, 0, 2); + List list = reservationDao.getReservationsBetween(calStart, calEnd); + assertEquals(countBefore + 2, list.size()); + } + + } + + private Reservation createReservation(Timestamp startTime) { + Reservation reservation = new Reservation(); + reservation.setResearchGroup(researchGroup); + reservation.setPerson(person); + reservation.setCreationTime(new Timestamp(System.currentTimeMillis())); + reservation.setStartTime(startTime); + reservation.setEndTime(new Timestamp(startTime.getTime() + TWO_HOURS_TO_MILLIS)); + return reservation; + } + + private Timestamp getDate(String stringDate) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); + Date date = dateFormat.parse(stringDate); + long time = date.getTime(); + return new Timestamp(time); + } + + private GregorianCalendar getCalendar(String stringDate) throws ParseException { + DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); + GregorianCalendar cal = new GregorianCalendar(); + cal.setTime(dateFormat.parse(stringDate)); + return cal; + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/SoftwareDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/SoftwareDaoTest.java new file mode 100644 index 00000000..1420faaa --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/SoftwareDaoTest.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * SoftwareDaoTest.java, 2014/30/06 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.data.pojo.Software; +import cz.zcu.kiv.eegdatabase.logic.Util; +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; + +/** + * User: Jan Stebetak + * Date: 30.6.14 + */ +public class SoftwareDaoTest extends AbstractDataAccessTest { + + + @Autowired + private SimpleSoftwareDao softwareDao; + @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 = new Software(); + software.setTitle("SW_test"); + software.setDescription("This is new testing SW"); + software.setDefaultNumber(0); + } + + + @Test + @Transactional + public void testCreateSoftware() { + int softwareCountBefore = softwareDao.getAllRecords().size(); + int softwareID = softwareDao.create(software); + assertEquals(softwareCountBefore + 1, softwareDao.getAllRecords().size()); + assertEquals(softwareID, software.getSoftwareId()); + } + + + @Test + @Transactional + public void testCreateDefaultRecord() throws Exception { + int expectedValue = softwareDao.getDefaultRecords().size(); + softwareDao.createDefaultRecord(software); + assertEquals(expectedValue + 1, softwareDao.getDefaultRecords().size()); + } + + @Test + @Transactional + public void testCreateGroupSoftware() { + int softwareCountBefore = softwareDao.getAllRecords().size(); + int softwareGroupBefore = softwareDao.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + softwareDao.createGroupRel(software, researchGroup); + softwareDao.create(software); + assertEquals(softwareCountBefore + 1, softwareDao.getAllRecords().size()); + + List list = softwareDao.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(softwareGroupBefore + 1, list.size()); + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/StimulusDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/StimulusDaoTest.java new file mode 100644 index 00000000..d039712f --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/StimulusDaoTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * StimulusDaoTest.java, 2013/10/02 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.pojo.Stimulus; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Random; + +import static junit.framework.Assert.*; + +/** + * User: Tomas Pokryvka + * Date: 26.4.13 + */ +public class StimulusDaoTest extends AbstractDataAccessTest { + + @Autowired + private StimulusDao stimulusDao; + private Stimulus stimulus; + + + @Before + public void setUp() throws Exception { + stimulus = new Stimulus(); + stimulus.setDescription("test-description"); + } + + @Test + @Transactional + public void testCreateStimulus() throws Exception { + int count = stimulusDao.getCountRecords(); + System.out.println(count); + stimulusDao.create(stimulus); + assertEquals(count + 1, stimulusDao.getAllRecords().size()); + } + + @Test + @Transactional + public void testCanSaveDescription() throws Exception { + stimulusDao.create(stimulus); + assertFalse(stimulusDao.canSaveDescription("test-description")); + assertTrue(stimulusDao.canSaveDescription(String.valueOf(new Random().nextLong()))); + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/WeatherDaoTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/WeatherDaoTest.java new file mode 100644 index 00000000..759d9c35 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/dao/WeatherDaoTest.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * WeatherDaoTest.java, 2014/07/01 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.data.dao; + +import cz.zcu.kiv.eegdatabase.data.AbstractDataAccessTest; +import cz.zcu.kiv.eegdatabase.data.TestUtils; +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 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; + +/** + * User: Jan Stebetak + * Date: 1.7.14 + */ +public class WeatherDaoTest extends AbstractDataAccessTest { + + @Autowired + private WeatherDao weatherDao; + + @Autowired + private PersonDao personDao; + + @Autowired + private ResearchGroupDao researchGroupDao; + + private Weather weather; + + private ResearchGroup researchGroup; + + @Before + public void setUp() { + weather = new Weather(); + weather.setTitle("Test-title"); + weather.setDescription("Test-description"); + weather.setDefaultNumber(0); + + 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); + } + + @Test + @Transactional + public void testCreateWeather() throws Exception { + int weatherCountBefore = weatherDao.getCountRecords(); + int weatherID = weatherDao.create(weather); + assertEquals(weatherCountBefore + 1, weatherDao.getAllRecords().size()); + assertEquals(weatherID, weather.getWeatherId()); + } + + @Test + @Transactional + public void testCreateDefaultRecord() throws Exception { + int expectedValue = weatherDao.getDefaultRecords().size(); + weatherDao.createDefaultRecord(weather); + assertEquals(expectedValue + 1, weatherDao.getDefaultRecords().size()); + } + + @Test + @Transactional + public void testCreateGroupWeather() { + int weatherCountBefore = weatherDao.getAllRecords().size(); + int weatherGroupBefore = weatherDao.getRecordsByGroup(researchGroup.getResearchGroupId()).size(); + weatherDao.createGroupRel(weather, researchGroup); + weatherDao.create(weather); + assertEquals(weatherCountBefore + 1, weatherDao.getAllRecords().size()); + + List list = weatherDao.getRecordsByGroup(researchGroup.getResearchGroupId()); + assertEquals(weatherGroupBefore + 1, list.size()); + } + +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/data/performance/LargeDataTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/data/performance/DataPerformanceTest.java similarity index 97% rename from src/test/java/cz/zcu/kiv/eegdatabase/data/performance/LargeDataTest.java rename to src/test/java/cz/zcu/kiv/eegdatabase/data/performance/DataPerformanceTest.java index 1a828e80..2f8e92e5 100644 --- a/src/test/java/cz/zcu/kiv/eegdatabase/data/performance/LargeDataTest.java +++ b/src/test/java/cz/zcu/kiv/eegdatabase/data/performance/DataPerformanceTest.java @@ -22,7 +22,7 @@ * * *********************************************************************************************************************** * - * LargeDataTest.java, 2014/06/10 20:01 Jan Stebetak + * DataPerformanceTest.java, 2014/06/10 20:01 Jan Stebetak ***************************************************************************** */ package cz.zcu.kiv.eegdatabase.data.performance; @@ -54,7 +54,7 @@ /** * Created by Honza on 10.6.14. */ -public class LargeDataTest extends AbstractDataAccessTest { +public class DataPerformanceTest extends AbstractDataAccessTest { @Autowired private ExperimentDao experimentDao; @@ -93,7 +93,7 @@ public void setUp() { @Transactional public void saveDataTest() throws IOException { try { - createFile(100); + createFile(20); } catch (IOException e) { fail("Data file is null"); return; @@ -133,7 +133,7 @@ public void saveDataRepeatTest() throws IOException { startTime = System.currentTimeMillis(); InputStream ios = null; try { - createFile(30); + createFile(100); } catch (IOException e) { fail("Data file is null"); diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/AbstractServicesTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/AbstractServicesTest.java new file mode 100644 index 00000000..719bf088 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/AbstractServicesTest.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * AbstractServicesTest.java, 2014/07/18 00:01 Jan Stebetak + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.services; + +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Created by Honza on 18.7.14. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:/test-context.xml"}) +public abstract class AbstractServicesTest { + + public AbstractServicesTest() { + changeParserImplementationToXerces(); + } + /** + * If not changed, oracle parser would try to parse hibernate configurations + * and fail with the following error: + * ERROR ErrorLogger - Error parsing XML (31) : http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd: + * XML-20068: (Fatal Error) content model is not deterministic + * org.hibernate.InvalidMappingException: Unable to read XML + * Setting SAXParserFactory and DocumentBuilderFactory will change the parser + * to xerces, enabling Hibernate-based tests + */ + private void changeParserImplementationToXerces() { + System.setProperty("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl"); + System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/ArticleServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/ArticleServiceTest.java new file mode 100644 index 00000000..1095cab1 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/ArticleServiceTest.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * ArticleServiceTest.java, 2014/07/18 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.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +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.article.ArticleService; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import java.sql.Timestamp; +import java.util.Calendar; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Created by Honza on 18.7.14. + */ +@Transactional +public class ArticleServiceTest extends AbstractServicesTest { + + @Autowired + private ArticleService articleService; + + @Autowired + private PersonDao personDao; + + @Autowired + private ResearchGroupDao researchGroupDao; + + private Article article; + private Person person; + private ArticleComment articleComment; + + + @Before + + public void setUp() { + person = TestUtils.createPersonForTesting("test-article@test.com", Util.ROLE_READER); + personDao.create(person); + + + article = new Article(); + + article.setText("test-text"); + article.setTitle("test-title"); + article.setTime(new Timestamp(Calendar.getInstance().getTime().getTime())); + article.setPerson(person); + } + + @Test + public void testCreateArticle() { + int count = articleService.getCountRecords(); + articleService.create(article); + assertEquals(count + 1, articleService.getCountRecords()); + } + + @Test + public void testGetArticlesForUser() { + int countAll = articleService.getCountRecords(); + int count = articleService.getArticlesForUser(person).size(); + articleService.create(article); + Person tmp = TestUtils.createPersonForTesting("test2@test.com", Util.ROLE_READER); + personDao.create(tmp); + //Creating research group and setting it to a new article + ResearchGroup researchGroup = new ResearchGroup(); + researchGroup.setDescription("test-description"); + researchGroup.setTitle("test-title"); + researchGroup.setPerson(tmp); + researchGroupDao.create(researchGroup); + + Article newArticle = new Article(); + + newArticle.setText("test-text2"); + newArticle.setTitle("test-title2"); + newArticle.setTime(new Timestamp(Calendar.getInstance().getTime().getTime())); + newArticle.setPerson(tmp); + newArticle.setResearchGroup(researchGroup); + articleService.create(newArticle); + + assertEquals(countAll + 2, articleService.getAllArticles().size()); + assertEquals(countAll + 2, articleService.getArticleCountForPerson(tmp)); + //the person "person" should see only one article (the second one is not public and belongs to the person "tmp"). + assertEquals(count + 1, articleService.getArticlesForUser(person).size()); + assertEquals(count + 2, articleService.getArticlesForUser(tmp).size()); + } + + @Test + public void testGetArticleDetails() { + + int id = articleService.create(article); + Article fromDB = articleService.read(id); + assertNotNull(fromDB); + assertEquals("test-text", fromDB.getText()); + assertEquals("test-title", fromDB.getTitle()); + } + + @Test + public void testCreateComment() { + int id = articleService.create(article); + int count = articleService.read(id).getArticleComments().size(); + articleComment = createComment(article); + int commentId = articleService.create(articleComment); +// article.getArticleComments().add(articleComment); +// articleService.update(article); + + assertEquals(count + 1, articleService.read(id).getArticleComments().size()); + assertEquals("text-comment", articleService.readComment(commentId).getText()); + assertEquals(count + 1, articleService.getCountCommentRecords()); + } + + @Test + public void testGetCommentsForArticle() { + + articleService.create(article); + Article newArticle = new Article(); + + int countAll = articleService.getCountCommentRecords(); + int countCommentForArticle = articleService.getCommentsForArticle(article.getArticleId()).size(); + + newArticle.setText("test-text2"); + newArticle.setTitle("test-title2"); + newArticle.setTime(new Timestamp(Calendar.getInstance().getTime().getTime())); + newArticle.setPerson(person); + articleService.create(newArticle); + articleComment = createComment(article); + articleService.create(articleComment); + + ArticleComment newComment = createComment(newArticle); + articleService.create(newComment); + + assertEquals(countAll + 2, articleService.getCountCommentRecords()); + assertEquals(countCommentForArticle + 1, articleService.getCommentsForArticle(article.getArticleId()).size()); + } + + private ArticleComment createComment(Article article) { + ArticleComment newComment = new ArticleComment(); + newComment.setPerson(person); + newComment.setArticle(article); + article.getArticleComments().add(newComment); + articleService.update(article); + newComment.setTime(new Timestamp(System.currentTimeMillis())); + newComment.setText("text-comment"); + return newComment; + + } + +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/ResearchGroupServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/ResearchGroupServiceTest.java new file mode 100644 index 00000000..86f8eb0a --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/ResearchGroupServiceTest.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * ResearchGroupServiceTest.java, 2014/07/29 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.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembership; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembershipId; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupService; +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.assertEquals; +import static junit.framework.Assert.assertTrue; + +/** + * Created by stebjan on 29.7.2014. + */ +@Transactional +public class ResearchGroupServiceTest extends AbstractServicesTest { + + @Autowired + private ResearchGroupService researchGroupService; + + @Autowired + private PersonDao personDao; + + private Person person; + private ResearchGroup researchGroup; + + @Before + + public void setUp() { + 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); + } + + @Test + public void testCreateResearchGroup() { + int count = researchGroupService.getCountForList(); + researchGroupService.create(researchGroup); + assertEquals(count + 1, researchGroupService.getCountRecords()); + assertEquals("test-title", researchGroupService.getResearchGroupTitle(researchGroup.getResearchGroupId())); + assertEquals("test@test.com", researchGroupService.read(researchGroup.getResearchGroupId()).getPerson().getUsername()); + + } + + @Test + public void testGetGroupsWhereOwner() { + int count = researchGroupService.getResearchGroupsWhereOwner(person).size(); + researchGroupService.create(researchGroup); + ResearchGroup group2 = new ResearchGroup(); + group2.setDescription("desc"); + group2.setTitle("test"); + group2.setPerson(person); + researchGroupService.create(group2); + assertEquals(count + 2, researchGroupService.getResearchGroupsWhereOwner(person).size()); + + } + @Test + public void testCreateMembership() { + + int id = researchGroupService.create(researchGroup); + int count = researchGroupService.getListOfGroupMembers(id).size(); + int membershipCount = researchGroupService.getCountMemberhipRecords(); + ResearchGroupMembership membership = new ResearchGroupMembership(); + + Person tmp = TestUtils.createPersonForTesting("test@test2.com", Util.ROLE_ADMIN); + personDao.create(tmp); + 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); + researchGroupService.createMemberhip(membership); + assertTrue(count > 0); + assertEquals(count + 1, researchGroupService.getListOfGroupMembers(id).size()); + assertEquals(membershipCount + 1, researchGroupService.getCountMemberhipRecords()); + assertEquals(membershipCount + 1, researchGroupService.getAllMemberhipRecords().size()); + + } + + @Test + public void testGetResearchGroupsWhereUserIsGroupAdmin() { + int count = researchGroupService.getResearchGroupsWhereUserIsGroupAdmin(person).size(); + researchGroupService.create(researchGroup); + + ResearchGroupMembership membership = new ResearchGroupMembership(); + + Person tmp = TestUtils.createPersonForTesting("test@test2.com", Util.ROLE_ADMIN); + personDao.create(tmp); + int tmpCount = researchGroupService.getResearchGroupsWhereUserIsGroupAdmin(tmp).size(); + + 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); + researchGroupService.createMemberhip(membership); + + ResearchGroup newGroup = new ResearchGroup(); + newGroup.setPerson(person); + newGroup.setTitle("new title"); + newGroup.setDescription("desc"); + researchGroupService.create(newGroup); + assertEquals(count + 2, researchGroupService.getResearchGroupsWhereUserIsGroupAdmin(person).size()); + assertEquals(tmpCount + 1, researchGroupService.getResearchGroupsWhereUserIsGroupAdmin(tmp).size()); + + } +} diff --git a/src/test/java/cz/zcu/kiv/eegdatabase/services/ScenariosServiceTest.java b/src/test/java/cz/zcu/kiv/eegdatabase/services/ScenariosServiceTest.java new file mode 100644 index 00000000..265a7ed7 --- /dev/null +++ b/src/test/java/cz/zcu/kiv/eegdatabase/services/ScenariosServiceTest.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * 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. + * + * *********************************************************************************************************************** + * + * ScenarioServicesTest.java, 2014/07/29 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.Scenario; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.core.scenarios.ScenariosService; +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.*; + +/** + * Created by stebjan on 29.7.2014. + */ +@Transactional +public class ScenariosServiceTest extends AbstractServicesTest { + + @Autowired + private ScenariosService scenariosService; + @Autowired + private PersonDao personDao; + @Autowired + private ResearchGroupDao researchGroupDao; + + private Scenario scenario; + private Person person; + + + @Before + public void setUp() throws Exception { + person = TestUtils.createPersonForTesting("test@test.com", Util.ROLE_READER); + + personDao.create(person); + + scenario = createScenario("test_title"); + } + + @Test + public void testCreateScenario() { + int count = scenariosService.getCountRecords(); + scenariosService.create(scenario); + assertEquals(count + 1, scenariosService.getCountRecords()); + assertNotNull(scenariosService.getScenarioByTitle("test_title")); + } + + @Test + public void testGetScenariosWhereOwner() { + int count = scenariosService.getCountRecords(); + int countOfOwner = scenariosService.getScenariosWhereOwner(person).size(); + scenariosService.create(scenario); + Person person1 = TestUtils.createPersonForTesting("test.test2@test.com", Util.ROLE_ADMIN); + personDao.create(person1); + Scenario scen = createScenario("title"); + scen.setPerson(person1); + scenariosService.create(scen); + assertEquals(countOfOwner + 1, scenariosService.getScenariosWhereOwner(person).size()); + assertEquals(count + 2, scenariosService.getCountRecords()); + } + + @Test + public void testCanSaveTitle() { + + scenariosService.create(scenario); + assertTrue(scenariosService.canSaveTitle(scenario.getTitle(), scenario.getScenarioId())); + assertFalse(scenariosService.canSaveTitle(scenario.getTitle(), -1)); + + } + + private Scenario createScenario(String title) { + Scenario scenario = new Scenario(); + scenario.setTitle(title); + scenario.setDescription("test-description-test"); + scenario.setScenarioName("test-scenarioName-test"); + scenario.setAvailableFile(false); + scenario.setScenarioLength(100); + scenario.setPrivateScenario(false); + scenario.setUserMemberOfGroup(false); + scenario.setMimetype("test-mimetype_clone"); + ResearchGroup group; + scenario.setPerson(person); + if (researchGroupDao.getAllRecords().size() == 0) { + group = new ResearchGroup(); + group.setTitle("title"); + group.setDescription("description"); + group.setPerson(person); + researchGroupDao.create(group); + } else { + group = researchGroupDao.getAllRecords().get(0); + } + scenario.setResearchGroup(group); + return scenario; + } +} diff --git a/src/test/resources/test-context.xml b/src/test/resources/test-context.xml index feb8e8c9..1b478840 100644 --- a/src/test/resources/test-context.xml +++ b/src/test/resources/test-context.xml @@ -345,19 +345,37 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +