Skip to content

Instantly share code, notes, and snippets.

@gastaldi
Created July 20, 2018 16:10
Show Gist options
  • Save gastaldi/4a69d7f6eeddd0761d9c85000decd890 to your computer and use it in GitHub Desktop.
Save gastaldi/4a69d7f6eeddd0761d9c85000decd890 to your computer and use it in GitHub Desktop.
package org.jboss.forge.addon.database.tools.generate;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.jboss.forge.addon.database.tools.connections.ConnectionProfile;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*/
public class EntityGeneratorTest
{
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void should_generate_entity() throws Exception
{
GenerateEntitiesCommandDescriptor descriptor = new GenerateEntitiesCommandDescriptor();
ConnectionProfile connectionProfile = new ConnectionProfile();
connectionProfile.setDialect("org.hibernate.dialect.PostgreSQLDialect");
connectionProfile
.setPath("/home/ggastald/.m2/repository/org/postgresql/postgresql/9.4.1212/postgresql-9.4.1212.jar");
connectionProfile.setUrl("jdbc:postgresql://localhost:5432/sampledb");
connectionProfile.setUser("admin");
connectionProfile.setPassword("admin");
descriptor.setConnectionProfile(connectionProfile);
descriptor.setTargetPackage("entities");
String schema = "public";
String catalog = "sampledb";
List<String> tables = Arrays.asList("Teste");
EntityGenerator generator = new EntityGenerator();
File sourceFolder = temporaryFolder.newFolder();
Collection<String> entities = generator.exportSelectedEntities(sourceFolder, descriptor, catalog, schema, tables);
assertThat(new File(sourceFolder, "entities/Teste.java")).exists();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment