Skip to content

Commit

Permalink
devonfw#860 added more tests, fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylesto committed Nov 10, 2022
1 parent b480ef0 commit 5008c4e
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import com.devonfw.cobigen.templates.devon4j.test.templates.testclasses.SQLTestEntity;
import com.devonfw.cobigen.templates.devon4j.test.templates.testclasses.SQLTestEntityDataTypes;
import com.devonfw.cobigen.templates.devon4j.test.templates.testclasses.SQLTestEntityForeignKeys;
import com.devonfw.cobigen.templates.devon4j.utils.SQLUtil;

/**
* Test class for SQL template generation
*
*/
public class SQLTemplateGenerationTest extends AbstractJavaTemplateTest {
@Test
public void generateSQLTest() {

String output = process(SQLTestEntity.class);
}

@Override
public Class<?>[] getUtils() {
Expand All @@ -28,18 +28,39 @@ public String getTemplatePath() {
}

/**
* Test the correct generation of data types
* Tests the correct generation of the enumerated type, the primary key, and name overriding
*/
@Test
public void testSQLEntity() {

String output = process(SQLTestEntity.class);
assertThat(output).contains("CREATE TABLE SQLTEST").contains("ENUM_TEST_FIELD_NAME_OVERRIDE VARCHAR(420)")
.contains("MY_ID_FIELD BIGINT AUTO_INCREMENT PRIMARY KEY");
}

/**
* Tests the correct generation of data types
*/
@Test
public void testDatatypeMapping() {

String ouptut = process(SQLTestEntityDataTypes.class);
assertThat(ouptut).contains("_timestamp2 TIMESTAMP").contains("_blob2 BLOB").contains("_bit BIT,")
.contains("_date DATE").contains("_tinyint TINYINT").contains("_integer2 INTEGER").contains("_bigint BIGINT")
.contains("_varchar3 VARCHAR").contains("_integer1 INTEGER").contains("_varchar4 VARCHAR")
.contains("_clob CLOB").contains("_blob BLOB").contains("_varchar VARCHAR").contains("_char2 CHAR(1)")
.contains(" _smallint SMALLINT").contains(" _char CHAR(1)").contains("_timestamp TIMESTAMP")
.contains("_time TIME").contains("_numeric NUMERIC").contains("_varchar2 VARCHAR");
assertThat(ouptut).contains("timestamp2 TIMESTAMP").contains("blob2 BLOB").contains("bit BIT,")
.contains("date DATE").contains("tinyint TINYINT").contains("integer2 INTEGER").contains("bigint BIGINT")
.contains("varchar3 VARCHAR").contains("integer1 INTEGER").contains("varchar4 VARCHAR").contains("clob CLOB")
.contains("blob BLOB").contains("varchar VARCHAR").contains("char2 CHAR(1)").contains("smallint SMALLINT")
.contains("char1 CHAR(1)").contains("timestamp TIMESTAMP").contains("time TIME").contains("numeric NUMERIC")
.contains("varchar2 VARCHAR").contains("CREATE TABLE SQLDataTypeTest").contains("varchar5 VARCHAR");

}

/**
* Tests the correct generation of foreign key statements
*/
@Test
public void testForeignKeyStatements() {

String output = process(SQLTestEntityForeignKeys.class);
assertThat(output).contains("test_id BIGINT, FOREIGN KEY (test_id) REFERENCES SQLTEST(id)");
}
}
Original file line number Diff line number Diff line change
@@ -1,67 +1,58 @@
package com.devonfw.cobigen.templates.devon4j.test.templates.testclasses;

import javax.persistence.*;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* Test entity to test the correct generation of the enumerated type, the primary key, and name overriding
*
*/
@Entity
@Table(name = "SQLTEST")
public class SQLTestEntity {
@Id
@Column(name = "MY_ID_FIELD")
private Long id;

@Column(name = "VALUENAME")
private Integer integerValue;
@Id
@Column(name = "MY_ID_FIELD")
private Long id;

@OneToOne
private ReferenceEntity refEntity;
@Column(name = "VALUENAME")
private Integer integerValue;

@Enumerated(EnumType.STRING)
@Column(length = 420, name = "ENUM_TEST_FIELD_NAME_OVERRIDE")
private EnumForTest enumForTest;
@Enumerated(EnumType.STRING)
@Column(length = 420, name = "ENUM_TEST_FIELD_NAME_OVERRIDE")
private EnumForTest enumForTest;

private List<ReferenceEntity> referenceEntities;
public Long getId() {

public Long getId() {
return id;
}
return this.id;
}

public void setId(Long id) {
this.id = id;
}
public void setId(Long id) {

public Integer getIntegerValue() {
return integerValue;
}
this.id = id;
}

public Integer getIntegerValue() {

public void setIntegerValue(Integer value) {
this.integerValue = value;
}
return this.integerValue;
}

@OneToMany(mappedBy = "I_SHALL_BE_SKIPPED")
public List<ReferenceEntity> getReferenceEntities() {
return referenceEntities;
}
public void setIntegerValue(Integer value) {

public void setReferenceEntities(List<ReferenceEntity> referenceEntities) {
this.referenceEntities = referenceEntities;
}
this.integerValue = value;
}

public EnumForTest getEnumForTest() {

public ReferenceEntity getRefEntity() {
return refEntity;
}
return this.enumForTest;
}

public void setRefEntity(ReferenceEntity refEntity) {
this.refEntity = refEntity;
}
public void setEnumForTest(EnumForTest enumForTest) {

public EnumForTest getEnumForTest() {
return enumForTest;
}
this.enumForTest = enumForTest;
}

public void setEnumForTest(EnumForTest enumForTest) {
this.enumForTest = enumForTest;
}
}
Loading

0 comments on commit 5008c4e

Please sign in to comment.