diff --git a/src/main/java/org/olat/ims/qti/QTI12EditorController.java b/src/main/java/org/olat/ims/qti/QTI12EditorController.java index c8e209b820dd0c050667c29c1603bdaa613de2e4..767b71039b89bdc17455af88eaae56249c4ce300 100644 --- a/src/main/java/org/olat/ims/qti/QTI12EditorController.java +++ b/src/main/java/org/olat/ims/qti/QTI12EditorController.java @@ -91,6 +91,11 @@ public class QTI12EditorController extends BasicController implements QPoolItemE putInitialPanel(mainVC); } + @Override + public boolean isValid() { + return item != null; + } + @Override public QuestionItem getItem() { return qitem; diff --git a/src/main/java/org/olat/ims/qti/qpool/QTIQPoolServiceProvider.java b/src/main/java/org/olat/ims/qti/qpool/QTIQPoolServiceProvider.java index 9370bd32bc30d81f18786a62df017a808ca14707..64a44c4e957c86ff061a2ce281526626df309a05 100644 --- a/src/main/java/org/olat/ims/qti/qpool/QTIQPoolServiceProvider.java +++ b/src/main/java/org/olat/ims/qti/qpool/QTIQPoolServiceProvider.java @@ -30,6 +30,7 @@ import java.util.zip.ZipOutputStream; import javax.xml.XMLConstants; +import org.apache.logging.log4j.Logger; import org.dom4j.Document; import org.dom4j.Element; import org.olat.core.commons.persistence.DB; @@ -41,7 +42,6 @@ import org.olat.core.gui.translator.Translator; import org.olat.core.helpers.Settings; import org.olat.core.id.Identity; import org.olat.core.id.OLATResourceable; -import org.apache.logging.log4j.Logger; import org.olat.core.logging.Tracing; import org.olat.core.util.FileUtils; import org.olat.core.util.Util; @@ -69,6 +69,7 @@ import org.olat.ims.resources.IMSEntityResolver; import org.olat.modules.qpool.ExportFormatOptions; import org.olat.modules.qpool.ExportFormatOptions.Outcome; import org.olat.modules.qpool.QItemFactory; +import org.olat.modules.qpool.QPoolItemEditorController; import org.olat.modules.qpool.QPoolSPI; import org.olat.modules.qpool.QPoolService; import org.olat.modules.qpool.QuestionItem; @@ -381,7 +382,7 @@ public class QTIQPoolServiceProvider implements QPoolSPI { } @Override - public Controller getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item) { + public QPoolItemEditorController getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item) { return new QTI12EditorController(ureq, wControl, item); } diff --git a/src/main/java/org/olat/ims/qti21/pool/QTI21EditorController.java b/src/main/java/org/olat/ims/qti21/pool/QTI21EditorController.java index 8a9243b1bd136b4fcce966777b605af1269e6968..830c573a41d6b4eb332a38fb213365a85f18bcf8 100644 --- a/src/main/java/org/olat/ims/qti21/pool/QTI21EditorController.java +++ b/src/main/java/org/olat/ims/qti21/pool/QTI21EditorController.java @@ -88,6 +88,11 @@ public class QTI21EditorController extends BasicController implements QPoolItemE putInitialPanel(mainVC); } + @Override + public boolean isValid() { + return true; + } + @Override public QuestionItem getItem() { return questionItem; diff --git a/src/main/java/org/olat/ims/qti21/pool/QTI21QPoolServiceProvider.java b/src/main/java/org/olat/ims/qti21/pool/QTI21QPoolServiceProvider.java index f6d6ddbcd2fe5d7f1f39eeaffb7e65974606bb33..d7e05d8982b046c01547f513f972a776c4a1a0bb 100644 --- a/src/main/java/org/olat/ims/qti21/pool/QTI21QPoolServiceProvider.java +++ b/src/main/java/org/olat/ims/qti21/pool/QTI21QPoolServiceProvider.java @@ -39,13 +39,13 @@ import java.util.zip.ZipOutputStream; import javax.xml.XMLConstants; +import org.apache.logging.log4j.Logger; import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.media.MediaResource; import org.olat.core.helpers.Settings; import org.olat.core.id.Identity; -import org.apache.logging.log4j.Logger; import org.olat.core.logging.Tracing; import org.olat.core.util.FileUtils; import org.olat.core.util.StringHelper; @@ -76,6 +76,7 @@ import org.olat.imscp.xml.manifest.ResourceType; import org.olat.modules.qpool.ExportFormatOptions; import org.olat.modules.qpool.ExportFormatOptions.Outcome; import org.olat.modules.qpool.QItemFactory; +import org.olat.modules.qpool.QPoolItemEditorController; import org.olat.modules.qpool.QPoolSPI; import org.olat.modules.qpool.QPoolService; import org.olat.modules.qpool.QuestionItem; @@ -321,7 +322,7 @@ public class QTI21QPoolServiceProvider implements QPoolSPI { } @Override - public Controller getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem qitem) { + public QPoolItemEditorController getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem qitem) { return new QTI21EditorController(ureq, wControl, qitem, false); } @@ -329,7 +330,6 @@ public class QTI21QPoolServiceProvider implements QPoolSPI { public Controller getReadOnlyController(UserRequest ureq, WindowControl wControl, QuestionItem item) { return new QTI21EditorController(ureq, wControl, item, true); } - public QuestionItem createItem(Identity identity, QTI21QuestionType type, String title, Locale locale) { AssessmentItemBuilder itemBuilder = AssessmentItemBuilderFactory.get(type, locale); diff --git a/src/main/java/org/olat/ims/qti21/ui/_i18n/LocalStrings_fr.properties b/src/main/java/org/olat/ims/qti21/ui/_i18n/LocalStrings_fr.properties index 46a32b1831f3e3590cfdba501474a5e5713a0486..b516580424dc9be968c06abf825f4c0c5a9d3ae2 100644 --- a/src/main/java/org/olat/ims/qti21/ui/_i18n/LocalStrings_fr.properties +++ b/src/main/java/org/olat/ims/qti21/ui/_i18n/LocalStrings_fr.properties @@ -103,7 +103,7 @@ drawing.opacity=Opacit\u00E9 error.as.directed=Veuillez r\u00E9pondre \u00E0 la question comme indiqu\u00E9. error.as.directed.kprim=Veuillez r\u00E9pondre \u00E0 la question comme indiqu\u00E9. error.assessment.item=Le fichier n'a pas pu \u00EAtre lu. Il semble soit corrompu soit au mauvais format. -error.assessment.item.missing=Le fichier de la question n'a pas \u00EAtre d\u00E9chiffr\u00E9. +error.assessment.item.missing=Le fichier de la question n'a pas \u00EAtre lu. error.choice=Vous devez choisir une des options suivantes. error.digital.certificate.cannotread=Le certificat n'a pas pu \u00EAtre lu. error.digital.certificate.noPrivateKey=La "cl\u00E9 priv\u00E9e" n'a pas \u00E9t\u00E9 trouv\u00E9e. Elle est obligatoire. diff --git a/src/main/java/org/olat/modules/qpool/QPoolItemEditorController.java b/src/main/java/org/olat/modules/qpool/QPoolItemEditorController.java index a2ed5cfa1d3bcee89ee25a25dc2e9bd0907bed2e..e0b128b22570bd63062144ed2363cfc62cf320e6 100644 --- a/src/main/java/org/olat/modules/qpool/QPoolItemEditorController.java +++ b/src/main/java/org/olat/modules/qpool/QPoolItemEditorController.java @@ -30,5 +30,7 @@ import org.olat.core.gui.control.Controller; public interface QPoolItemEditorController extends Controller { public QuestionItem getItem(); + + public boolean isValid(); } diff --git a/src/main/java/org/olat/modules/qpool/QPoolSPI.java b/src/main/java/org/olat/modules/qpool/QPoolSPI.java index 2b741bc40e01391e9b611b5753aad8d5fd3106ae..0dba226e108de6551ffa00227780f79304cbee6c 100644 --- a/src/main/java/org/olat/modules/qpool/QPoolSPI.java +++ b/src/main/java/org/olat/modules/qpool/QPoolSPI.java @@ -124,7 +124,7 @@ public interface QPoolSPI { * @param item * @return */ - public Controller getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item); + public QPoolItemEditorController getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item); /** * Return the editable controller in a read only modus. This controller is e.g. diff --git a/src/main/java/org/olat/modules/qpool/impl/FileQPoolServiceProvider.java b/src/main/java/org/olat/modules/qpool/impl/FileQPoolServiceProvider.java index 61ed07a21cb5bfad49767b57d50c3a9be58c6d4c..ad98d68a3beb9a5eec952d89ac05dcfff12ffd2c 100644 --- a/src/main/java/org/olat/modules/qpool/impl/FileQPoolServiceProvider.java +++ b/src/main/java/org/olat/modules/qpool/impl/FileQPoolServiceProvider.java @@ -27,6 +27,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.modules.qpool.QItemFactory; +import org.olat.modules.qpool.QPoolItemEditorController; import org.olat.modules.qpool.QPoolService; import org.olat.modules.qpool.QuestionItem; import org.olat.modules.qpool.QuestionType; @@ -86,8 +87,7 @@ public class FileQPoolServiceProvider extends AbstractQPoolServiceProvider { @Override public Controller getPreviewController(UserRequest ureq, WindowControl wControl, QuestionItem item, boolean summary) { - FilePreviewController fileController = new FilePreviewController(ureq, wControl, item); - return fileController; + return new FilePreviewController(ureq, wControl, item); } @Override @@ -96,9 +96,8 @@ public class FileQPoolServiceProvider extends AbstractQPoolServiceProvider { } @Override - public Controller getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item) { - FilePreviewController fileController = new FilePreviewController(ureq, wControl, item); - return fileController; + public QPoolItemEditorController getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item) { + return new FilePreviewController(ureq, wControl, item); } @Override diff --git a/src/main/java/org/olat/modules/qpool/impl/TextQPoolServiceProvider.java b/src/main/java/org/olat/modules/qpool/impl/TextQPoolServiceProvider.java index de5c43b21c6188f8518481bd0143b11e6481a694..cb63334ccd465b69a3998864ecff8e4c0081564b 100644 --- a/src/main/java/org/olat/modules/qpool/impl/TextQPoolServiceProvider.java +++ b/src/main/java/org/olat/modules/qpool/impl/TextQPoolServiceProvider.java @@ -27,6 +27,7 @@ import org.olat.core.gui.UserRequest; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.WindowControl; import org.olat.modules.qpool.QItemFactory; +import org.olat.modules.qpool.QPoolItemEditorController; import org.olat.modules.qpool.QPoolService; import org.olat.modules.qpool.QuestionItem; import org.olat.modules.qpool.QuestionType; @@ -84,8 +85,7 @@ public class TextQPoolServiceProvider extends AbstractQPoolServiceProvider { @Override public Controller getPreviewController(UserRequest ureq, WindowControl wControl, QuestionItem item, boolean summary) { - TextPreviewController txtController = new TextPreviewController(ureq, wControl, item, summary); - return txtController; + return new TextPreviewController(ureq, wControl, item, summary); } @Override @@ -94,9 +94,8 @@ public class TextQPoolServiceProvider extends AbstractQPoolServiceProvider { } @Override - public Controller getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item) { - TextPreviewController txtController = new TextPreviewController(ureq, wControl, item, false); - return txtController; + public QPoolItemEditorController getEditableController(UserRequest ureq, WindowControl wControl, QuestionItem item) { + return new TextPreviewController(ureq, wControl, item, false); } @Override diff --git a/src/main/java/org/olat/modules/qpool/ui/FilePreviewController.java b/src/main/java/org/olat/modules/qpool/ui/FilePreviewController.java index 9803027ab9466b94d3302b4304efff773b0f63be..8b6cb9fdceea6eadfbb4de767a834e40f46de9bc 100644 --- a/src/main/java/org/olat/modules/qpool/ui/FilePreviewController.java +++ b/src/main/java/org/olat/modules/qpool/ui/FilePreviewController.java @@ -27,8 +27,9 @@ import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; import org.olat.core.util.vfs.VFSLeaf; -import org.olat.modules.qpool.QuestionItem; +import org.olat.modules.qpool.QPoolItemEditorController; import org.olat.modules.qpool.QPoolService; +import org.olat.modules.qpool.QuestionItem; /** * @@ -36,12 +37,15 @@ import org.olat.modules.qpool.QPoolService; * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com * */ -public class FilePreviewController extends BasicController { +public class FilePreviewController extends BasicController implements QPoolItemEditorController { private final VelocityContainer mainVC; + + private final QuestionItem qitem; public FilePreviewController(UserRequest ureq, WindowControl wControl, QuestionItem qitem) { super(ureq, wControl); + this.qitem = qitem; QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class); mainVC = createVelocityContainer("file_preview"); @@ -53,6 +57,16 @@ public class FilePreviewController extends BasicController { putInitialPanel(mainVC); } + @Override + public QuestionItem getItem() { + return qitem; + } + + @Override + public boolean isValid() { + return true; + } + @Override protected void doDispose() { // diff --git a/src/main/java/org/olat/modules/qpool/ui/QuestionItemDetailsController.java b/src/main/java/org/olat/modules/qpool/ui/QuestionItemDetailsController.java index 58229966c926252f546933d6f4b0fff2bdee9bb8..2616db26074d89dbea30f1ed349107df7470b7e1 100644 --- a/src/main/java/org/olat/modules/qpool/ui/QuestionItemDetailsController.java +++ b/src/main/java/org/olat/modules/qpool/ui/QuestionItemDetailsController.java @@ -54,6 +54,7 @@ import org.olat.group.model.BusinessGroupSelectionEvent; import org.olat.group.ui.main.SelectBusinessGroupController; import org.olat.ims.qti.QTIConstants; import org.olat.modules.qpool.Pool; +import org.olat.modules.qpool.QPoolItemEditorController; import org.olat.modules.qpool.QPoolSPI; import org.olat.modules.qpool.QPoolSecurityCallback; import org.olat.modules.qpool.QPoolService; @@ -132,6 +133,7 @@ public class QuestionItemDetailsController extends BasicController implements To private final int numberOfItems; private Boolean showMetadatas; private LockResult lock; + private boolean valid = true; private boolean questionEdited = false; @Autowired @@ -195,9 +197,12 @@ public class QuestionItemDetailsController extends BasicController implements To showWarning("locked.readonly", new String[] {displayName}); } + if (spi != null) { if (canEditContent) { - questionCtrl = spi.getEditableController(ureq, getWindowControl(), item); + QPoolItemEditorController editQuestionCtrl = spi.getEditableController(ureq, getWindowControl(), item); + valid = editQuestionCtrl.isValid(); + questionCtrl = editQuestionCtrl; } else { questionCtrl = spi.getReadOnlyController(ureq, getWindowControl(), item); } @@ -211,7 +216,11 @@ public class QuestionItemDetailsController extends BasicController implements To listenTo(questionCtrl); if(mainVC != null) { - mainVC.put("type_specifics", questionCtrl.getInitialComponent()); + if(valid) { + mainVC.put("type_specifics", questionCtrl.getInitialComponent()); + } else { + mainVC.contextPut("corrupted", Boolean.TRUE); + } } } @@ -247,7 +256,7 @@ public class QuestionItemDetailsController extends BasicController implements To copyItemLink.setIconLeftCSS("o_icon o_icon-fw o_icon_qitem_copy"); commandDropdown.addComponent(copyItemLink); - if (QTIConstants.QTI_12_FORMAT.equals(metadatasCtrl.getItem().getFormat())) { + if (QTIConstants.QTI_12_FORMAT.equals(metadatasCtrl.getItem().getFormat()) && valid) { convertItemLink = LinkFactory.createToolLink("convert", translate("convert.item"), this); convertItemLink.setIconLeftCSS("o_icon o_icon-fw o_icon_qitem_convert"); commandDropdown.addComponent(convertItemLink); diff --git a/src/main/java/org/olat/modules/qpool/ui/TextPreviewController.java b/src/main/java/org/olat/modules/qpool/ui/TextPreviewController.java index c49e34f8e084e4ba72a4754fa5b0e9372884999d..75e58515b5692f0b54ab404f5db28ee588282f9e 100644 --- a/src/main/java/org/olat/modules/qpool/ui/TextPreviewController.java +++ b/src/main/java/org/olat/modules/qpool/ui/TextPreviewController.java @@ -23,8 +23,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringWriter; -import org.apache.commons.io.IOUtils; -import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.velocity.VelocityContainer; @@ -32,8 +30,10 @@ import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.controller.BasicController; import org.olat.core.util.vfs.VFSLeaf; -import org.olat.modules.qpool.QuestionItem; +import org.olat.modules.qpool.QPoolItemEditorController; import org.olat.modules.qpool.QPoolService; +import org.olat.modules.qpool.QuestionItem; +import org.springframework.beans.factory.annotation.Autowired; /** * @@ -41,14 +41,15 @@ import org.olat.modules.qpool.QPoolService; * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com * */ -public class TextPreviewController extends BasicController { +public class TextPreviewController extends BasicController implements QPoolItemEditorController { private final VelocityContainer mainVC; - private final QPoolService qpoolService; + + @Autowired + private QPoolService qpoolService; public TextPreviewController(UserRequest ureq, WindowControl wControl, QuestionItem qitem, boolean summary) { super(ureq, wControl); - qpoolService = CoreSpringFactory.getImpl(QPoolService.class); mainVC = createVelocityContainer("text_preview"); VFSLeaf leaf = qpoolService.getRootLeaf(qitem); @@ -64,34 +65,41 @@ public class TextPreviewController extends BasicController { putInitialPanel(mainVC); } + @Override + public QuestionItem getItem() { + return null; + } + + @Override + public boolean isValid() { + return true; + } + @Override protected void doDispose() { // } protected String readSummary(VFSLeaf leaf) { - StringWriter out = new StringWriter(); - InputStream in = leaf.getInputStream(); - InputStreamReader inr = new InputStreamReader(in); - try { + StringWriter out = new StringWriter(); + + try( InputStream in = leaf.getInputStream(); + InputStreamReader inr = new InputStreamReader(in)) { char[] buffer = new char[4096]; int count = 0; - int n = 0; - while (-1 != (n = inr.read(buffer))) { - out.write(buffer, 0, n); - count += n; - if(count >= 10000) { - break; - } - } + int n = 0; + while (-1 != (n = inr.read(buffer))) { + out.write(buffer, 0, n); + count += n; + if(count >= 10000) { + break; + } + } } catch (Exception e) { logError("", e); - } finally { - IOUtils.closeQuietly(inr); - IOUtils.closeQuietly(in); } - return out.toString(); + return out.toString(); } @Override diff --git a/src/main/java/org/olat/modules/qpool/ui/_content/item_details.html b/src/main/java/org/olat/modules/qpool/ui/_content/item_details.html index 91228600d8fe2e45ab2bb745f6e38d31326dad3a..a6edb9efbccd5edf4aa5256e2aec0380c0a030af 100644 --- a/src/main/java/org/olat/modules/qpool/ui/_content/item_details.html +++ b/src/main/java/org/olat/modules/qpool/ui/_content/item_details.html @@ -13,7 +13,11 @@ <div class="row"> #if($metadataSwitch) <div class="col-md-8"> - $r.render("type_specifics") + #if($r.isTrue($corrupted)) + <div class="o_error">$r.translate("error.corrupted.question")</div> + #elseif($r.available("type_specifics")) + $r.render("type_specifics") + #end $r.render("comments") </div> <div class="col-md-4"> @@ -21,7 +25,11 @@ </div> #else <div class="col-md-12"> - $r.render("type_specifics") + #if($r.isTrue($corrupted)) + <div class="o_error">$r.translate("error.corrupted.question")</div> + #elseif($r.available("type_specifics")) + $r.render("type_specifics") + #end $r.render("comments") </div> #end diff --git a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_de.properties index 810a9eb0e7e710e75feb0b49044ed1235c988655..93a2c38898d8eb1db0d59127296f837df4939c68 100644 --- a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_de.properties @@ -60,6 +60,7 @@ educational.learningTime.day=d educational.learningTime.hour=h educational.learningTime.minute=m educational.learningTime.second=s +error.corrupted.question=Die Datei der Frage konnte nicht gelesen werden. error.input.toolong=Leider ist Ihr gerade eingegebener Text mit {1} Zeichen zu lang. Bitte beschr\u00E4nken Sie sich auf maximal {0} Zeichen. error.qti.deprecated=Diese Version von QTI wird nicht mehr unterst\u00FCtzt. Bitte auf das neue QTI 2.1 konvertieren. error.select.one=Sie m\u00FCssen mindestens eine Frage w\u00E4hlen. diff --git a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_en.properties index 26396d809ec00e6f96637eee5625471c47752e9a..1045cc6a1e70ef815adc4ca46a46244f840710e3 100644 --- a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_en.properties @@ -60,6 +60,7 @@ educational.learningTime.day=d educational.learningTime.hour=h educational.learningTime.minute=m educational.learningTime.second=s +error.corrupted.question=The file of the question cannot be read. error.input.toolong=The text you entered is to long ({1} characters). Only {1} characters are allowed. error.qti.deprecated=This version of QTI is deprecated. Please consider to convert your test to QTI 2.1. error.select.one=You need to select at least one question. diff --git a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_fr.properties b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_fr.properties index 3cebff480b2bdb9b29174c38caed67d97b2c94ec..c9bc01c6dd12ed312c7a1f30d94b6020e54c70b9 100644 --- a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_fr.properties +++ b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_fr.properties @@ -60,6 +60,7 @@ educational.learningTime.day=j educational.learningTime.hour=h educational.learningTime.minute=m educational.learningTime.second=s +error.corrupted.question=Le fichier de la question n'a pas \u00EAtre lu. error.input.toolong=Le texte que vous avez entr\u00E9 est trop long ({1} caract\u00E8res). Limitez-vous s'il vous pla\u00EEt \u00E0 {1} caract\u00E8res. error.qti.deprecated=Cette version de QTI est obsol\u00E8te. Pensez s'il vous pla\u00EEt \u00E0 convertir votre test au format QTI 2.1. error.select.one=Vous devez s\u00E9lectionner au moins une question. diff --git a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_pt_BR.properties b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_pt_BR.properties index ee89e22fc044a548c48dc5398db92ac9d8cebf3e..6338518c8e83cea06d1256891ce397b4322e85e6 100644 --- a/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_pt_BR.properties +++ b/src/main/java/org/olat/modules/qpool/ui/_i18n/LocalStrings_pt_BR.properties @@ -61,6 +61,7 @@ educational.learningTime.day=d educational.learningTime.hour=h educational.learningTime.minute=m educational.learningTime.second=s +error.corrupted.question=O arquivo da pergunta n\u00E3o pode ser lido. error.input.toolong=O texto que voc\u00EA digitou \u00E9 muito grande ({1} caracteres). Apenas {1} caracteres s\u00E3o permitidos. error.qti.deprecated=Esta vers\u00E3o do QTI est\u00E1 obsoleta. Por favor, considere converter seu teste para o QTI 2.1. error.select.one=Voc\u00EA precisa selecionar pelo menos uma quest\u00E3o. diff --git a/src/test/java/org/olat/commons/calendar/CalendarImportTest.java b/src/test/java/org/olat/commons/calendar/CalendarImportTest.java index 4503e60483dcf7bf43936791d27911cdfa2610fd..7c88badde4269aba4920e3f34d4371cc7c661ddc 100644 --- a/src/test/java/org/olat/commons/calendar/CalendarImportTest.java +++ b/src/test/java/org/olat/commons/calendar/CalendarImportTest.java @@ -28,7 +28,6 @@ import java.util.Date; import java.util.Iterator; import org.apache.logging.log4j.Logger; -import org.junit.Ignore; import org.junit.Test; import org.olat.core.logging.Tracing; @@ -40,7 +39,6 @@ import net.fortuna.ical4j.model.Period; import net.fortuna.ical4j.model.PeriodList; import net.fortuna.ical4j.model.component.VEvent; import net.fortuna.ical4j.model.property.RecurrenceId; -import net.fortuna.ical4j.util.CompatibilityHints; /** * @@ -104,9 +102,8 @@ public class CalendarImportTest { Calendar calendar = builder.build(in); assertNotNull(calendar); } - */ - - @Test @Ignore + + @Test public void testImportFromFGiCal() throws IOException, ParserException { //default settings in olat System.setProperty(CompatibilityHints.KEY_RELAXED_UNFOLDING, "true"); @@ -117,6 +114,7 @@ public class CalendarImportTest { Calendar calendar = builder.build(in); assertNotNull(calendar); } + */ @Test public void testImportRecurringCal() throws IOException, ParserException { diff --git a/src/test/java/org/olat/core/util/i18n/I18nTest.java b/src/test/java/org/olat/core/util/i18n/I18nTest.java index 347e40817ffc120a976a3b066a6bf0fc7bb883cc..a1971d19e6c949c41a8e3938be3e13b93d27edb5 100644 --- a/src/test/java/org/olat/core/util/i18n/I18nTest.java +++ b/src/test/java/org/olat/core/util/i18n/I18nTest.java @@ -43,7 +43,6 @@ import java.util.regex.Pattern; import org.apache.logging.log4j.Logger; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.olat.core.gui.render.StringOutput; import org.olat.core.gui.render.URLBuilder; @@ -469,73 +468,11 @@ public class I18nTest extends OlatTestCase { } } - /** - * Test methods i18nManager.getProperties(), i18nManager.saveOrUpdateProperties() and i18nManager.deleteProperties() - */ - @Ignore - @Test public void testGetSaveOrUpdateAndDeleteProperties() { - // test with existing files - Properties props = i18nMgr.getResolvedProperties(i18nMgr.getLocaleOrDefault("de"), "org.olat.core"); - assertNotNull(props); - assertTrue(props.size() > 0); - // test with non existing files - String testNewBundle = "org.olat.core.util.i18n.junittestdata.new"; - Locale testLocale = i18nMgr.getLocaleOrDefault("de"); - File baseDir = i18nModule.getPropertyFilesBaseDir(testLocale, testNewBundle); - File testFile = i18nMgr.getPropertiesFile(testLocale, testNewBundle, baseDir); - // clean first existing files from previous broken testcase - if (testFile.exists()) { - i18nMgr.deleteProperties(testLocale, testNewBundle); - } - props = i18nMgr.getResolvedProperties(testLocale, testNewBundle); - assertNotNull(props); - assertEquals(0, props.size()); - // test deleting of non existing - assertFalse(testFile.exists()); - i18nMgr.deleteProperties(testLocale, testNewBundle); - assertFalse(testFile.exists()); - // test saving of non existing - props.setProperty("test.key", "Hello wörld !"); - i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle); - assertTrue(testFile.exists()); - assertEquals("Hello wörld !", i18nMgr.getLocalizedString(testNewBundle, "test.key", null, testLocale, false, false)); - // test saving of existing - props = new Properties(); - props.setProperty("hello.world", "&%çest françias, ê alors"); - i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle); - assertTrue(testFile.exists()); - assertEquals("&%çest françias, ê alors", i18nMgr.getLocalizedString(testNewBundle, "hello.world", null, testLocale, false, false)); - assertFalse("Hello wörld !".equals(i18nMgr.getLocalizedString(testNewBundle, "test.key", null, testLocale, false, false))); - // test various special cases - props.setProperty("chinesetest", "è¯·é€‰æ‹©ä½ çš„å¤§å¦"); - props.setProperty("specialtest", "that's like \"really\" bad"); - props.setProperty("multiline", "bla\tbla\nsecond line"); - props.setProperty("html", "<h1>Hello World</h1>"); - props.setProperty("empty.property", ""); - i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle); - i18nMgr.clearCaches(); - assertEquals("è¯·é€‰æ‹©ä½ çš„å¤§å¦", i18nMgr.getLocalizedString(testNewBundle, "chinesetest", null, testLocale, false, false)); - assertEquals("that's like \"really\" bad", i18nMgr.getLocalizedString(testNewBundle, "specialtest", null, testLocale, false, false)); - assertEquals("bla\tbla\nsecond line", i18nMgr.getLocalizedString(testNewBundle, "multiline", null, testLocale, false, false)); - assertEquals("<h1>Hello World</h1>", i18nMgr.getLocalizedString(testNewBundle, "html", null, testLocale, false, false)); - assertEquals("", i18nMgr.getLocalizedString(testNewBundle, "empty.property", null, testLocale, false, false)); - assertEquals(null, i18nMgr.getLocalizedString(testNewBundle, "not.existing.property", null, testLocale, false, false)); - // test deleting of existing - i18nMgr.deleteProperties(testLocale, testNewBundle); - assertFalse(testFile.exists()); - assertFalse("Hello wörld !".equals(i18nMgr.getLocalizedString(testNewBundle, "test.key", null, testLocale, false, false))); - assertFalse("&%çest françias, ê alors".equals(i18nMgr.getLocalizedString(testNewBundle, "hello.world", null, testLocale, false, false))); - // clean up - if (testFile.exists()) { - i18nMgr.deleteProperties(testLocale, testNewBundle); - } - if (testFile.getParentFile().exists()) testFile.getParentFile().delete(); - } - /** * Test methods i18nManager.getBundlePriority(), i18nManager.getKeyPriority() */ - @Test public void testGetBundleAndKeyPriority() { + @Test + public void testGetBundleAndKeyPriority() { // existing bundle prios String bundleName = "org.olat.core.util.i18n.junittestdata"; Properties metadataProperties = i18nMgr.getPropertiesWithoutResolvingRecursively(null, bundleName); @@ -555,7 +492,8 @@ public class I18nTest extends OlatTestCase { /** * Test methods i18nManager.getAnnotation() */ - @Test public void testGetAnnotation() { + @Test + public void testGetAnnotation() { // existing bundle prios String bundleName = "org.olat.core.util.i18n.junittestdata"; Locale testLocale = i18nMgr.getLocaleOrDefault("de"); @@ -569,61 +507,12 @@ public class I18nTest extends OlatTestCase { } } } - - /** - * Test methods i18nManager.countI18nItems() and i18nManager.countBundles() - */ - @Ignore - @Test public void testCountI18nItemsAndBundles() { - i18nModule.initBundleNames(); // remove dirty stuff from previous tests - int bundleCounter = i18nModule.getBundleNamesContainingI18nFiles().size(); - String testNewBundle = "org.olat.core.util.i18n.junittestdata.new"; - Locale testLocale = i18nMgr.getLocaleOrDefault("de"); - File baseDir = i18nModule.getPropertyFilesBaseDir(testLocale, testNewBundle); - File testFile = i18nMgr.getPropertiesFile(testLocale, testNewBundle, baseDir); - // clean first existing files from previous broken testcase - if (testFile.exists()) { - i18nMgr.deleteProperties(testLocale, testNewBundle); - } - Properties props = i18nMgr.getResolvedProperties(testLocale, testNewBundle); - assertEquals(0, i18nMgr.countI18nItems(testLocale, testNewBundle, true)); - assertEquals(0, i18nMgr.countI18nItems(testLocale, testNewBundle, false)); - props.setProperty("key.1", "1"); - props.setProperty("key.2", "2"); - i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle); - assertEquals(2, i18nMgr.countI18nItems(testLocale, testNewBundle, false)); - assertEquals(0, i18nMgr.countI18nItems(i18nMgr.getLocaleOrDefault("en"), testNewBundle, false)); - assertEquals(bundleCounter + 1, i18nModule.getBundleNamesContainingI18nFiles().size()); - // test all bundles - int allCount = i18nMgr.countI18nItems(testLocale, null, true); - assertEquals(allCount, i18nMgr.countI18nItems(testLocale, null, false)); - props.remove("key.1"); - i18nMgr.saveOrUpdateProperties(props, testLocale, testNewBundle); - assertEquals(allCount-1, i18nMgr.countI18nItems(testLocale, null, false)); - i18nMgr.deleteProperties(testLocale, testNewBundle); - assertEquals(allCount-2, i18nMgr.countI18nItems(testLocale, null, false)); - assertEquals(bundleCounter, i18nModule.getBundleNamesContainingI18nFiles().size()); - // count bundles tests - assertEquals(0, i18nMgr.countBundles("org.olat.core.util.i18n.nonexisting", true)); - assertEquals(1, i18nMgr.countBundles("org.olat.core.util.i18n.ui", true)); - // finds 4: regular: i18n.devtools, i18n.ui; - assertEquals(2, i18nMgr.countBundles("org.olat.core.util.i18n", true)); - assertEquals(0, i18nMgr.countBundles("org.olat.core.util.i18n", false)); - assertEquals(1, i18nMgr.countBundles("org.olat.core.util.i18n.ui", false)); - assertTrue(0 < i18nMgr.countBundles(null, false)); - // clean up - if (testFile.exists()) { - i18nMgr.deleteProperties(testLocale, testNewBundle); - } - if (testFile.getParentFile().exists()) { - testFile.getParentFile().delete(); - } - } /** * Test methods i18nManager.findInKeys() i18nManager.findInValues() */ - @Test public void testFindInKeysAndFindInValues() { + @Test + public void testFindInKeysAndFindInValues() { Locale testLocale = i18nMgr.getLocaleOrDefault("de"); // in keys speedtest long start = System.currentTimeMillis(); diff --git a/src/test/java/org/olat/core/util/mail/manager/MailManagerTest.java b/src/test/java/org/olat/core/util/mail/manager/MailManagerTest.java index 78a95a83d04aeba38191b74e9b302625ba34da6d..afb32ba144da6549c5ad75f439083bf63d0e8c0f 100644 --- a/src/test/java/org/olat/core/util/mail/manager/MailManagerTest.java +++ b/src/test/java/org/olat/core/util/mail/manager/MailManagerTest.java @@ -19,15 +19,8 @@ */ package org.olat.core.util.mail.manager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import javax.mail.Address; import javax.mail.MessagingException; @@ -37,12 +30,9 @@ import javax.mail.internet.MimeMessage; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; -import org.apache.logging.log4j.Logger; -import org.olat.core.logging.Tracing; import org.olat.core.util.WebappHelper; import org.olat.core.util.mail.ContactList; import org.olat.core.util.mail.MailBundle; @@ -63,8 +53,7 @@ import com.dumbster.smtp.SmtpMessage; * */ public class MailManagerTest extends OlatTestCase { - private static final Logger log = Tracing.createLoggerFor(MailManagerTest.class); - + @Autowired private MailManager mailManager; @Autowired @@ -237,48 +226,6 @@ public class MailManagerTest extends OlatTestCase { Assert.assertEquals(incomingMail, incomingsMails_3.get(0)); } - - @Test @Ignore // not really needed anymore, the subscribe process is asynchrone and serial - public void testParalellSubscribers() { - final int NUM_OF_THREADS = 10; - final int NUM_OF_USERS = 10; - final int NUM_OF_REDONDANCY = 50; - - List<Identity> identities = new ArrayList<>(); - for(int i=0; i<NUM_OF_USERS; i++) { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("fci-" + i + "-" + UUID.randomUUID()); - for(int j=0; j<NUM_OF_REDONDANCY; j++) { - identities.add(id); - } - } - - final CountDownLatch finishCount = new CountDownLatch(NUM_OF_THREADS); - List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1)); - List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1)); - List<SubscribeThread> threads = new ArrayList<>(); - for(int i=0; i<NUM_OF_THREADS; i++) { - List<Identity> ids = new ArrayList<>(identities); - SubscribeThread thread = new SubscribeThread(ids, exceptionHolder, statusList, finishCount); - threads.add(thread); - } - - for(SubscribeThread thread:threads) { - thread.start(); - } - - // sleep until threads should have terminated/excepted - try { - sleep(30000);// eat all JMS events - finishCount.await(120, TimeUnit.SECONDS); - } catch (InterruptedException e) { - log.error("", e); - Assert.fail(); - } - - assertTrue("It throws an exception in test", exceptionHolder.isEmpty()); - assertEquals("Thread(s) did not finish", NUM_OF_THREADS, statusList.size()); - } - @Test public void sendExternMessage() { Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("mailman-1"); @@ -336,39 +283,4 @@ public class MailManagerTest extends OlatTestCase { msg3.getFrom()[0].equals(fromx)); Assert.assertNotNull(result3); } - - private class SubscribeThread extends Thread { - - private final List<Identity> ids; - private final List<Exception> exceptionHolder; - private final List<Boolean> statusList; - private final CountDownLatch countDown; - - public SubscribeThread(List<Identity> ids, List<Exception> exceptionHolder, List<Boolean> statusList, CountDownLatch countDown) { - this.ids = ids; - this.exceptionHolder = exceptionHolder; - this.statusList = statusList; - this.countDown = countDown; - } - - @Override - public void run() { - try { - Thread.sleep(10); - for(int i=5; i-->0; ) { - for(Identity id:ids) { - mailManager.subscribe(id); - } - } - statusList.add(Boolean.TRUE); - } catch (Exception ex) { - ex.printStackTrace(); - log.error("", ex); - exceptionHolder.add(ex);// no exception should happen - } finally { - countDown.countDown(); - dbInstance.closeSession(); - } - } - } } diff --git a/src/test/java/org/olat/course/nodes/en/EnrollmentManagerConcurrentTest.java b/src/test/java/org/olat/course/nodes/en/EnrollmentManagerConcurrentTest.java index d56bad298670c1729e184cd3c36e8ec920a7057b..5319aee0885e05428d385e66080db9d329f0148a 100644 --- a/src/test/java/org/olat/course/nodes/en/EnrollmentManagerConcurrentTest.java +++ b/src/test/java/org/olat/course/nodes/en/EnrollmentManagerConcurrentTest.java @@ -41,7 +41,6 @@ import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.Logger; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.GroupRoles; @@ -311,76 +310,7 @@ public class EnrollmentManagerConcurrentTest extends OlatTestCase implements Win } - @Test @Ignore - public void testConcurrentEnrollmentWithWaitingList_big() { - List<Identity> ids = new ArrayList<>(100); - for(int i=0; i<100; i++) { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("enroll-a-" + i + "-" + UUID.randomUUID().toString()); - ids.add(id); - } - - Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("enroller"); - RepositoryEntry addedEntry = JunitTestHelper.deployBasicCourse(author); - - ENCourseNode enNode1 = new ENCourseNode(); - ENCourseNode enNode2 = new ENCourseNode(); - ENCourseNode enNode3 = new ENCourseNode(); - ENCourseNode enNode4 = new ENCourseNode(); - ENCourseNode enNode5 = new ENCourseNode(); - - CourseEnvironment cenv = CourseFactory.loadCourse(addedEntry).getCourseEnvironment(); - BusinessGroup group1 = businessGroupService.createBusinessGroup(author, "Enrollment 1", "Enroll 1", new Integer(1), new Integer(8), true, true, addedEntry); - BusinessGroup group2 = businessGroupService.createBusinessGroup(author, "Enrollment 2", "Enroll 2", new Integer(1), new Integer(10), true, true, addedEntry); - BusinessGroup group3 = businessGroupService.createBusinessGroup(author, "Enrollment 3", "Enroll 3", new Integer(1), new Integer(4), true, true, addedEntry); - BusinessGroup group4 = businessGroupService.createBusinessGroup(author, "Enrollment 4", "Enroll 4", new Integer(1), new Integer(10), true, true, addedEntry); - BusinessGroup group5 = businessGroupService.createBusinessGroup(author, "Enrollment 5", "Enroll 5", new Integer(1), new Integer(9), true, true, addedEntry); - dbInstance.commitAndCloseSession(); - - EnrollThread[] threads = new EnrollThread[100]; - - final CountDownLatch doneSignal = new CountDownLatch(ids.size()); - int t = 0; - for(int i=0; i<30; i++) { - threads[t++] = new EnrollThread(ids.get(i), addedEntry, group1, enNode1, cenv, doneSignal); - } - for(int i=30; i<50; i++) { - threads[t++] = new EnrollThread(ids.get(i), addedEntry, group2, enNode2, cenv, doneSignal); - } - for(int i=50; i<70; i++) { - threads[t++] = new EnrollThread(ids.get(i), addedEntry, group3, enNode3, cenv, doneSignal); - } - for(int i=70; i<90; i++) { - threads[t++] = new EnrollThread(ids.get(i), addedEntry, group4, enNode4, cenv, doneSignal); - } - for(int i=90; i<100; i++) { - threads[t++] = new EnrollThread(ids.get(i), addedEntry, group5, enNode5, cenv, doneSignal); - } - - for(EnrollThread thread:threads) { - thread.start(); - } - - try { - boolean interrupt = doneSignal.await(360, TimeUnit.SECONDS); - assertTrue("Test takes too long (more than 10s)", interrupt); - } catch (InterruptedException e) { - fail("" + e.getMessage()); - } - - dbInstance.commitAndCloseSession(); - - List<Identity> enrolled_1_Ids = businessGroupService.getMembers(group1, GroupRoles.participant.name()); - Assert.assertEquals(8, enrolled_1_Ids.size()); - List<Identity> enrolled_2_Ids = businessGroupService.getMembers(group2, GroupRoles.participant.name()); - Assert.assertEquals(10, enrolled_2_Ids.size()); - List<Identity> enrolled_3_Ids = businessGroupService.getMembers(group3, GroupRoles.participant.name()); - Assert.assertEquals(4, enrolled_3_Ids.size()); - List<Identity> enrolled_4_Ids = businessGroupService.getMembers(group4, GroupRoles.participant.name()); - Assert.assertEquals(10, enrolled_4_Ids.size()); - List<Identity> enrolled_5_Ids = businessGroupService.getMembers(group5, GroupRoles.participant.name()); - Assert.assertEquals(9, enrolled_5_Ids.size()); - } - + private class EnrollThread extends Thread { private final ENCourseNode enNode; private final Identity identity; diff --git a/src/test/java/org/olat/course/statistic/WeeklyStatisticUpdateManagerTest.java b/src/test/java/org/olat/course/statistic/WeeklyStatisticUpdateManagerTest.java index 5686fce92954e92f9db3224a0af560eea004d09e..7f0a4f2fe595df882f374f703e8964d025c613e7 100644 --- a/src/test/java/org/olat/course/statistic/WeeklyStatisticUpdateManagerTest.java +++ b/src/test/java/org/olat/course/statistic/WeeklyStatisticUpdateManagerTest.java @@ -25,7 +25,6 @@ import java.util.Locale; import java.util.Map; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.olat.core.gui.util.SyntheticUserRequest; import org.olat.core.id.Identity; @@ -49,7 +48,7 @@ public class WeeklyStatisticUpdateManagerTest extends AbstractStatisticUpdateMan private final WeeklyStatisticManager weeklyStatisticManager = new WeeklyStatisticManager(); - @Test @Ignore + @Test public void statistics_weekly() { statisticUpdateManager.setEnabled(true); diff --git a/src/test/java/org/olat/group/test/BGAreaManagerTest.java b/src/test/java/org/olat/group/test/BGAreaManagerTest.java index ccebfd85b751177dcb6eb0c7cd17757d7ad1e336..4aefb6377aec6c823eadb48fdc935eeee5bbbee5 100644 --- a/src/test/java/org/olat/group/test/BGAreaManagerTest.java +++ b/src/test/java/org/olat/group/test/BGAreaManagerTest.java @@ -825,7 +825,7 @@ public class BGAreaManagerTest extends OlatTestCase { @Test public void testSynchronisationUpdateBGArea() { - final int maxLoop = 75; // => 400 x 100ms => 40sec => finished in 50sec + final int maxLoop = 30; final String areaName = "BGArea_2"; final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1)); diff --git a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java index 913201c09da942ae5766054deada837be985fbdc..cf2a0208d7100fc914660d08d95f8258764ac583 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupServiceTest.java @@ -36,7 +36,6 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.FixMethodOrder; -import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; import org.olat.basesecurity.BaseSecurity; @@ -1286,15 +1285,15 @@ public class BusinessGroupServiceTest extends OlatTestCase { Assert.assertFalse(contactList.contains(adminIdentity3)); } - @Ignore @Test + @Test public void parallelRemoveParticipants() { mailModule.setInterSystem(true); businessGroupModule.setMandatoryEnrolmentEmailFor(OrganisationRoles.user, "true"); Identity admin = JunitTestHelper.createAndPersistIdentityAsRndUser("remove-p1-1"); - int NUM_OF_THREADS = 20; - int NUM_OF_GROUPS = 50; + int NUM_OF_THREADS = 5; + int NUM_OF_GROUPS = 5; int NUM_OF_PARTICIPANTS = 10; //create the members diff --git a/src/test/java/org/olat/resource/lock/pessimistic/PLockTest.java b/src/test/java/org/olat/resource/lock/pessimistic/PLockTest.java index b10d1fd37c7fc1d9e2af72f4a2cb16e33e004176..de5b51ec43fe0425a6df62d49c0246ba6999ea7c 100644 --- a/src/test/java/org/olat/resource/lock/pessimistic/PLockTest.java +++ b/src/test/java/org/olat/resource/lock/pessimistic/PLockTest.java @@ -29,7 +29,6 @@ package org.olat.resource.lock.pessimistic; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; import java.util.ArrayList; import java.util.Collections; @@ -38,6 +37,7 @@ import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.apache.logging.log4j.Logger; import org.junit.Assert; import org.junit.Test; import org.olat.basesecurity.SecurityGroup; @@ -46,7 +46,6 @@ import org.olat.core.commons.persistence.DB; import org.olat.core.commons.services.lock.pessimistic.PLock; import org.olat.core.commons.services.lock.pessimistic.PessimisticLockManager; import org.olat.core.id.Identity; -import org.apache.logging.log4j.Logger; import org.olat.core.logging.Tracing; import org.olat.test.JunitTestHelper; import org.olat.test.OlatTestCase; @@ -177,89 +176,6 @@ public class PLockTest extends OlatTestCase { } assertTrue("exception in test => see sysout", exceptionHolder.size() == 0); } - - @Test public void testLockWaitTimout() { - //Ignore Test if DB is PostgreSQL. PostgreSQL has not lock timeout - assumeTrue(!isPostgresqlConfigured() && !isOracleConfigured()); - - final String asset = "testLockWaitTimout"; - - log.info("testing if holding a lock timeouts"); - // make sure all three row entries for the locks are created, otherwise the system-wide locking - // applied on lock-row-creation cannot support row-level-locking by definition. - - PLock pc3 = pessimisticLockManager.findOrPersistPLock("blibli"); - assertNotNull(pc3); - dbInstance.closeSession(); - - /** - * t1 t2 - * .. bli - * .. .. - * .. .. - * .. .. - * bli .. - * .. - * .. - * .... hold for longer than 30 secs - * - */ - - - final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1)); - final CountDownLatch finishCount = new CountDownLatch(2); - - // t1 - new Thread(new Runnable() { - public void run() { - try { - sleep(500); - PLock p3 = pessimisticLockManager.findOrPersistPLock(asset); - assertNotNull(p3); - } catch (Exception e) { - exceptionHolder.add(e); - } finally { - finishCount.countDown(); - try { - dbInstance.closeSession(); - } catch (Exception e) { - // ignore - } - } - }}).start(); - - // t2 - new Thread(new Runnable() { - public void run() { - try { - PLock p2 = pessimisticLockManager.findOrPersistPLock(asset); - assertNotNull(p2); - sleep(55000); - // holding the lock for more than the transaction timeout - // (normally 30secs, configured where? hib) should cause a lock timeout - // if the db is configured so (innodb_lock_wait_timeout). - } catch (Exception e) { - exceptionHolder.add(e); - } finally { - finishCount.countDown(); - try { - dbInstance.closeSession(); - } catch (Exception e) { - // ignore - } - } - }}).start(); - - // sleep until t1 and t2 should have terminated/excepted - try { - log.info("Sleep 55s"); - finishCount.await(60, TimeUnit.SECONDS); - } catch (InterruptedException e) { - Assert.fail(""); - } - - Assert.assertEquals("expected a lock wait timeout exceeded exception", 1, exceptionHolder.size()); - } @Test public void testSingleRowLockingSupported() { diff --git a/src/test/java/org/olat/restapi/CurriculumElementsWebServiceTest.java b/src/test/java/org/olat/restapi/CurriculumElementsWebServiceTest.java index 28e1e685fd3f8fa05bae2873dd898978b68da09c..4dbd9b3d39232f13c0478f5f2a5d5e4f7430bcd7 100644 --- a/src/test/java/org/olat/restapi/CurriculumElementsWebServiceTest.java +++ b/src/test/java/org/olat/restapi/CurriculumElementsWebServiceTest.java @@ -42,8 +42,8 @@ import org.apache.http.client.methods.HttpPut; import org.apache.http.util.EntityUtils; import org.hamcrest.Matchers; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; +import org.olat.basesecurity.OrganisationRoles; import org.olat.basesecurity.OrganisationService; import org.olat.core.commons.persistence.DB; import org.olat.core.id.Identity; @@ -522,7 +522,7 @@ public class CurriculumElementsWebServiceTest extends OlatRestTestCase { Assert.assertEquals(curriculum, savedElement.getCurriculum()); } - @Test @Ignore + @Test public void updateCurriculumElement_notAuthorized() throws IOException, URISyntaxException { Organisation defOrganisation = organisationService.getDefaultOrganisation(); @@ -532,9 +532,15 @@ public class CurriculumElementsWebServiceTest extends OlatRestTestCase { null, null, null, null, CurriculumCalendars.disabled, CurriculumLectures.disabled, curriculum); Curriculum otherCurriculum = curriculumService.createCurriculum("REST-Curriculum-elements", "REST Curriculum", "A curriculum accessible by REST API for elemets", organisation); dbInstance.commitAndCloseSession(); - + + // other administration organisation + Organisation adminOrganisation = organisationService.createOrganisation("REST Admin Organisation", "REST-p-4admin-organisation", "", defOrganisation, null); + Identity admin = JunitTestHelper.createAndPersistIdentityAsRndUser("p-4admin"); + organisationService.addMember(adminOrganisation, admin, OrganisationRoles.administrator); + dbInstance.commitAndCloseSession(); + RestConnection conn = new RestConnection(); - assertTrue(conn.login("administrator", "openolat")); + assertTrue(conn.login(admin.getName(), JunitTestHelper.PWD)); CurriculumElementVO vo = CurriculumElementVO.valueOf(element); vo.setExternalId("REST-CEL-10"); @@ -546,7 +552,7 @@ public class CurriculumElementsWebServiceTest extends OlatRestTestCase { conn.addJsonEntity(method, vo); HttpResponse response = conn.execute(method); - Assert.assertEquals(409, response.getStatusLine().getStatusCode()); + Assert.assertEquals(401, response.getStatusLine().getStatusCode()); EntityUtils.consume(response.getEntity()); } diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index fdf73c7a45ca6193bdbaac0dd84456dea6861436..e8caa56e1788561655804685c3ab933e3d026bab 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -185,7 +185,7 @@ import org.junit.runners.Suite; org.olat.course.statistic.DailyStatisticUpdateManagerTest.class, org.olat.course.statistic.DayOfWeekStatisticUpdateManagerTest.class, org.olat.course.statistic.HourOfDayStatisticUpdateManagerTest.class, - org.olat.course.statistic.WeeklyStatisticUpdateManagerTest.class, + // org.olat.course.statistic.WeeklyStatisticUpdateManagerTest.class, org.olat.modules.assessment.manager.AssessmentEntryDAOTest.class, org.olat.course.certificate.manager.CertificatesManagerTest.class, org.olat.course.config.CourseConfigManagerImplTest.class, diff --git a/src/test/java/org/olat/test/OlatTestCase.java b/src/test/java/org/olat/test/OlatTestCase.java index bf272297b793ccb1e131c3e4bb55fb3e423b32c8..f23525943140127958da86a5e5e1e86dfede47af 100644 --- a/src/test/java/org/olat/test/OlatTestCase.java +++ b/src/test/java/org/olat/test/OlatTestCase.java @@ -42,6 +42,7 @@ import org.olat.core.commons.persistence.DBFactory; import org.olat.core.helpers.Settings; import org.apache.logging.log4j.Logger; import org.olat.core.logging.Tracing; +import org.olat.core.util.CodeHelper; import org.olat.core.util.WebappHelper; import org.olat.core.util.event.FrameworkStartupEventChannel; import org.springframework.core.io.ClassPathResource; @@ -69,6 +70,7 @@ public abstract class OlatTestCase extends AbstractJUnit4SpringContextTests { private static boolean oracleConfigured = false; private static boolean started = false; private static SimpleSmtpServer dumbster; + private static long timestamp; @Rule public TestName currentTestName = new TestName(); @@ -89,6 +91,7 @@ public abstract class OlatTestCase extends AbstractJUnit4SpringContextTests { @Before public void printBanner() { + timestamp = System.nanoTime(); log.info("Method run: " + currentTestName.getMethodName() + "(" + this.getClass().getCanonicalName() + ")"); if(started) { @@ -121,7 +124,8 @@ public abstract class OlatTestCase extends AbstractJUnit4SpringContextTests { @After public void closeConnectionAfter() { - log.info("Method test finished: " + currentTestName.getMethodName() + "(" + this.getClass().getCanonicalName() + ")"); + long time = CodeHelper.nanoToMilliTime(timestamp); + log.info("Method test finished: {} ({}) takes (ms): {}", currentTestName.getMethodName(), this.getClass().getCanonicalName(), time); try { DBFactory.getInstance().commitAndCloseSession(); } catch (Exception e) {