|
| 1 | +package org.javawebstack.orm.test.automigrate; |
| 2 | + |
| 3 | +import org.javawebstack.orm.Model; |
| 4 | +import org.javawebstack.orm.ORM; |
| 5 | +import org.javawebstack.orm.ORMConfig; |
| 6 | +import org.javawebstack.orm.annotation.Column; |
| 7 | +import org.javawebstack.orm.exception.ORMConfigurationException; |
| 8 | +import org.javawebstack.orm.test.ORMTestCase; |
| 9 | +import org.javawebstack.orm.test.shared.models.Datatype; |
| 10 | +import org.javawebstack.orm.test.shared.models.JustString; |
| 11 | +import org.javawebstack.orm.test.shared.verification.Field; |
| 12 | +import org.junit.jupiter.api.BeforeEach; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | + |
| 15 | +import java.sql.SQLException; |
| 16 | + |
| 17 | +public class DefaultSizeTest extends ORMTestCase { |
| 18 | + |
| 19 | + final static String tableName = "just_strings"; |
| 20 | + |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testStringUsesDefaultSize() throws ORMConfigurationException, SQLException { |
| 24 | + int[] parameters = {2, 3, 100, 254, 255, 256, 65534, 65535}; |
| 25 | + for( int singleParameter : parameters) { |
| 26 | + setUpWithDefaultSize(JustString.class, singleParameter); |
| 27 | + (new Field("just_strings", "string")).assertType(String.format("varchar(%s)", singleParameter)); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + private void setUpWithDefaultSize(Class<? extends Model> clazz, int defaultSize) throws ORMConfigurationException { |
| 32 | + ORMConfig config = new ORMConfig() |
| 33 | + .setDefaultSize(defaultSize); |
| 34 | + ORM.register(clazz, sql(), config); |
| 35 | + ORM.autoMigrate(true); |
| 36 | + } |
| 37 | +} |
0 commit comments