JAVA-29283 | added missing code for article (#15459)
This commit is contained in:
parent
37bddcdfce
commit
750cc9b748
|
@ -31,20 +31,34 @@
|
|||
<artifactId>jooq-codegen</artifactId>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.15.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${postgresql.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>${h2.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jooq.version>3.18.7</jooq.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<java.version>17</java.version>
|
||||
<jooq.version>3.19.0</jooq.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,75 @@
|
|||
package com.baeldung.jooq;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.codegen.GenerationTool;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.jooq.model.tables.Article;
|
||||
import com.baeldung.jooq.model.tables.Author;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
public class CodeGenerationIntegrationTest {
|
||||
|
||||
static DSLContext context;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws SQLException {
|
||||
Connection conn = DriverManager.getConnection("jdbc:h2:mem:tes;INIT=CREATE SCHEMA IF NOT EXISTS \"public\"");
|
||||
context = DSL.using(conn, SQLDialect.H2);
|
||||
|
||||
context.createTable(Author.AUTHOR)
|
||||
.columns(
|
||||
Author.AUTHOR.ID,
|
||||
Author.AUTHOR.FIRST_NAME,
|
||||
Author.AUTHOR.LAST_NAME,
|
||||
Author.AUTHOR.AGE
|
||||
)
|
||||
.execute();
|
||||
context.createTable(Article.ARTICLE)
|
||||
.columns(
|
||||
Article.ARTICLE.ID,
|
||||
Article.ARTICLE.TITLE,
|
||||
Article.ARTICLE.DESCRIPTION,
|
||||
Article.ARTICLE.AUTHOR_ID
|
||||
)
|
||||
.execute();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() throws IOException {
|
||||
File generatedDirectory = new File("src/main/java/com/baeldung/jooq/generated");
|
||||
FileUtils.deleteDirectory(generatedDirectory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassGenerationFromExistingDatabase() throws Exception {
|
||||
|
||||
File generatedDirectory = new File("src/main/java/com/baeldung/jooq/generated");
|
||||
|
||||
assertFalse(generatedDirectory.exists());
|
||||
|
||||
URL jooqConfigURL = getClass().getClassLoader().getResource("jooq-config.xml");
|
||||
assertNotNull(jooqConfigURL);
|
||||
File file = new File(jooqConfigURL.getFile());
|
||||
GenerationTool.generate(Files.readString(file.toPath()));
|
||||
|
||||
assertTrue(generatedDirectory.exists());
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CrudLiveTest {
|
||||
public class CrudIntegrationTest {
|
||||
|
||||
static DSLContext context;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
|
||||
|
||||
<jdbc>
|
||||
<driver>org.h2.Driver</driver>
|
||||
<url>jdbc:h2:mem:tes</url>
|
||||
<user></user>
|
||||
<password></password>
|
||||
</jdbc>
|
||||
|
||||
<generator>
|
||||
<name>org.jooq.codegen.JavaGenerator</name>
|
||||
|
||||
<database>
|
||||
<name>org.jooq.meta.h2.H2Database</name>
|
||||
<inputSchema>public</inputSchema>
|
||||
<includes>.*</includes>
|
||||
<excludes></excludes>
|
||||
</database>
|
||||
|
||||
<target>
|
||||
<packageName>com.baeldung.jooq.generated</packageName>
|
||||
<directory>src/main/java</directory>
|
||||
</target>
|
||||
</generator>
|
||||
</configuration>
|
Loading…
Reference in New Issue