Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
timowest committed May 15, 2016
1 parent 1ed4fde commit 2cc4146
Showing 1 changed file with 41 additions and 0 deletions.
Expand Up @@ -13,6 +13,8 @@
*/
package com.querydsl.sql.codegen;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Set;

Expand All @@ -27,8 +29,12 @@
import com.mysema.codegen.SimpleCompiler;
import com.querydsl.codegen.BeanSerializer;
import com.querydsl.sql.AbstractJDBCTest;
import com.querydsl.sql.Configuration;
import com.querydsl.sql.SQLTemplates;
import com.querydsl.sql.types.AbstractType;

public class MetaDataSerializerTest extends AbstractJDBCTest {
public static class CustomNumber {}

@Rule
public TemporaryFolder folder = new TemporaryFolder();
Expand All @@ -41,6 +47,7 @@ public void setUp() throws SQLException, ClassNotFoundException {
statement.execute("drop table survey if exists");
statement.execute("drop table date_test if exists");
statement.execute("drop table date_time_test if exists");
statement.execute("drop table spaces if exists");

// survey
statement.execute("create table survey (id int, name varchar(30), "
Expand Down Expand Up @@ -88,6 +95,40 @@ public void normal_serialization() throws SQLException {
compile(exporter);
}

@Test
public void customized_serialization() throws SQLException {
String namePrefix = "Q";
Configuration conf = new Configuration(SQLTemplates.DEFAULT);
conf.register("EMPLOYEE", "ID", new AbstractType<CustomNumber>(0) {
@Override
public Class<CustomNumber> getReturnedClass() {
return CustomNumber.class;
}

@Override
public CustomNumber getValue(ResultSet rs, int startIndex) throws SQLException {
throw new UnsupportedOperationException();
}

@Override
public void setValue(PreparedStatement st, int startIndex, CustomNumber value) throws SQLException {
throw new UnsupportedOperationException();
}
});
NamingStrategy namingStrategy = new DefaultNamingStrategy();
// customization of serialization
MetaDataExporter exporter = new MetaDataExporter();
exporter.setBeanSerializerClass(BeanSerializer.class);
exporter.setNamePrefix(namePrefix);
exporter.setPackageName("test");
exporter.setTargetFolder(folder.getRoot());
exporter.setNamingStrategy(namingStrategy);
exporter.setConfiguration(conf);
exporter.export(connection.getMetaData());

compile(exporter);
}

private void compile(MetaDataExporter exporter) {
JavaCompiler compiler = new SimpleCompiler();
Set<String> classes = exporter.getClasses();
Expand Down

0 comments on commit 2cc4146

Please sign in to comment.