From be731feb6b70c1572c86451818dd8a594df171cb Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Tue, 23 Aug 2016 20:01:11 +1200 Subject: [PATCH] No effective change - adjust tests for H2 error vs Postgres truncate with oversized varchar input --- .../avaje/tests/basic/TestMetaAnnotation.java | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/test/java/com/avaje/tests/basic/TestMetaAnnotation.java b/src/test/java/com/avaje/tests/basic/TestMetaAnnotation.java index ad7283ff0..31db7757a 100644 --- a/src/test/java/com/avaje/tests/basic/TestMetaAnnotation.java +++ b/src/test/java/com/avaje/tests/basic/TestMetaAnnotation.java @@ -1,20 +1,22 @@ package com.avaje.tests.basic; -import javax.persistence.PersistenceException; - -import org.junit.Ignore; -import org.junit.Test; - import com.avaje.ebean.BaseTestCase; import com.avaje.ebean.Ebean; import com.avaje.tests.model.basic.Address; import com.avaje.tests.model.basic.metaannotation.SizeMedium; +import org.junit.Test; + +import javax.persistence.PersistenceException; + +import static org.junit.Assert.assertTrue; + /** * Very simple test case to check if Ebean recognizes meta-annotation correctly. * * @author Roland Praml, FOCONIS AG */ public class TestMetaAnnotation extends BaseTestCase { + private static final String spaces100 = new String(new char[100]).replace('\0', ' '); private static final String spaces101 = new String(new char[101]).replace('\0', ' '); @@ -23,7 +25,6 @@ public class TestMetaAnnotation extends BaseTestCase { */ @Test public void testWrite100SpacesToLine1() { - Ebean.createUpdate(Address.class, "delete from address"); Address address = new Address(); address.setLine1(spaces100); @@ -31,41 +32,50 @@ public class TestMetaAnnotation extends BaseTestCase { } /** - * This test writes 101 spaces to "line1" which is annotated with @Size(max=100). - */ - @Test(expected=PersistenceException.class) - @Ignore // Unfortunately, this test does not work with PostGres as DB-Backend, as it does not honor the @Size annotation - public void testWrite101SpacesToLine1() { - Ebean.createUpdate(Address.class, "delete from address"); - - Address address = new Address(); - address.setLine1(spaces101); - Ebean.save(address); - } - - /** - * This test writes 100 spaces to "line1" which is meta-annotated with {@link SizeMedium}. + * This test writes 100 spaces to "line1" which is meta-annotated with {@link SizeMedium}. */ @Test public void testWrite100SpacesToLine2() { - Ebean.createUpdate(Address.class, "delete from address"); Address address = new Address(); address.setLine2(spaces100); Ebean.save(address); } + /** + * This test writes 101 spaces to "line1" which is annotated with @Size(max=100). + */ + @Test + public void testWrite101SpacesToLine1() { + + if (isH2()) { + Address address = new Address(); + address.setLine1(spaces101); + try { + Ebean.save(address); + assertTrue("H2 fails this insert", false); + } catch (PersistenceException e) { + assertTrue(true); + } + } + } + /** * This test writes 101 spaces to "line1" which is meta-annotated with {@link SizeMedium}. */ - @Test(expected=PersistenceException.class) - @Ignore // Unfortunately, this test does not work with PostGres as Backend + @Test public void testWrite101SpacesToLine2() { - Ebean.createUpdate(Address.class, "delete from address"); - Address address = new Address(); - address.setLine2(spaces101); - Ebean.save(address); + if (isH2()) { + Address address = new Address(); + address.setLine2(spaces101); + try { + Ebean.save(address); + assertTrue("H2 fails this insert", false); + } catch (PersistenceException e) { + assertTrue(true); + } + } } }