/tags/0.9.21/tests/src/test/java/com/orientechnologies/orient/test/database/auto/CRUDDocumentValidationTest.java

http://orient.googlecode.com/ · Java · 89 lines · 62 code · 12 blank · 15 comment · 0 complexity · 77bdb71056ad60afee72329a16223860 MD5 · raw file

  1. /*
  2. * Copyright 1999-2010 Luca Garulli (l.garulli--at--orientechnologies.com)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.orientechnologies.orient.test.database.auto;
  17. import java.text.ParseException;
  18. import java.text.SimpleDateFormat;
  19. import org.testng.annotations.Parameters;
  20. import org.testng.annotations.Test;
  21. import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
  22. import com.orientechnologies.orient.core.exception.OValidationException;
  23. import com.orientechnologies.orient.core.record.impl.ODocument;
  24. @Test(groups = { "crud", "record-document" }, sequential = true)
  25. public class CRUDDocumentValidationTest {
  26. protected static final int TOT_RECORDS = 100;
  27. protected long startRecordNumber;
  28. private ODatabaseDocumentTx database;
  29. private ODocument record;
  30. private ODocument account;
  31. @Parameters(value = "url")
  32. public CRUDDocumentValidationTest(String iURL) {
  33. database = new ODatabaseDocumentTx(iURL);
  34. }
  35. @Test
  36. public void openDb() {
  37. database.open("admin", "admin");
  38. record = database.newInstance("Whiz");
  39. account = database.browseClass("Profile").begin().next();
  40. }
  41. @Test(dependsOnMethods = "openDb", expectedExceptions = OValidationException.class)
  42. public void validationMandatory() {
  43. record.reset();
  44. record.save();
  45. }
  46. @Test(dependsOnMethods = "validationMandatory", expectedExceptions = OValidationException.class)
  47. public void validationMinString() {
  48. record.reset();
  49. record.field("account", account);
  50. record.field("id", 23723);
  51. record.field("text", "");
  52. record.save();
  53. }
  54. @Test(dependsOnMethods = "validationMinString", expectedExceptions = OValidationException.class, expectedExceptionsMessageRegExp = ".*more.*than.*")
  55. public void validationMaxString() {
  56. record.reset();
  57. record.field("account", account);
  58. record.field("id", 23723);
  59. record
  60. .field(
  61. "text",
  62. "clfdkkjsd hfsdkjhf fjdkghjkfdhgjdfh gfdgjfdkhgfd skdjaksdjf skdjf sdkjfsd jfkldjfkjsdf kljdk fsdjf kldjgjdhjg khfdjgk hfjdg hjdfhgjkfhdgj kfhdjghrjg");
  63. record.save();
  64. }
  65. @Test(dependsOnMethods = "validationMaxString", expectedExceptions = OValidationException.class, expectedExceptionsMessageRegExp = ".*before.*")
  66. public void validationMinDate() throws ParseException {
  67. record.reset();
  68. record.field("account", account);
  69. record.field("date", new SimpleDateFormat("dd/MM/yyyy").parse("01/01/1976"));
  70. record.field("text", "test");
  71. record.save();
  72. }
  73. @Test(dependsOnMethods = "validationMinDate")
  74. public void closeDb() {
  75. database.close();
  76. }
  77. }