Skip to content

Commit 5008c4e

Browse files
committed
devonfw#860 added more tests, fixed bugs
1 parent b480ef0 commit 5008c4e

File tree

5 files changed

+286
-207
lines changed

5 files changed

+286
-207
lines changed

cobigen-templates/templates-devon4j/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/SQLTemplateGenerationTest.java

+33-12
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import com.devonfw.cobigen.templates.devon4j.test.templates.testclasses.SQLTestEntity;
88
import com.devonfw.cobigen.templates.devon4j.test.templates.testclasses.SQLTestEntityDataTypes;
9+
import com.devonfw.cobigen.templates.devon4j.test.templates.testclasses.SQLTestEntityForeignKeys;
910
import com.devonfw.cobigen.templates.devon4j.utils.SQLUtil;
1011

12+
/**
13+
* Test class for SQL template generation
14+
*
15+
*/
1116
public class SQLTemplateGenerationTest extends AbstractJavaTemplateTest {
12-
@Test
13-
public void generateSQLTest() {
14-
15-
String output = process(SQLTestEntity.class);
16-
}
1717

1818
@Override
1919
public Class<?>[] getUtils() {
@@ -28,18 +28,39 @@ public String getTemplatePath() {
2828
}
2929

3030
/**
31-
* Test the correct generation of data types
31+
* Tests the correct generation of the enumerated type, the primary key, and name overriding
32+
*/
33+
@Test
34+
public void testSQLEntity() {
35+
36+
String output = process(SQLTestEntity.class);
37+
assertThat(output).contains("CREATE TABLE SQLTEST").contains("ENUM_TEST_FIELD_NAME_OVERRIDE VARCHAR(420)")
38+
.contains("MY_ID_FIELD BIGINT AUTO_INCREMENT PRIMARY KEY");
39+
}
40+
41+
/**
42+
* Tests the correct generation of data types
3243
*/
3344
@Test
3445
public void testDatatypeMapping() {
3546

3647
String ouptut = process(SQLTestEntityDataTypes.class);
37-
assertThat(ouptut).contains("_timestamp2 TIMESTAMP").contains("_blob2 BLOB").contains("_bit BIT,")
38-
.contains("_date DATE").contains("_tinyint TINYINT").contains("_integer2 INTEGER").contains("_bigint BIGINT")
39-
.contains("_varchar3 VARCHAR").contains("_integer1 INTEGER").contains("_varchar4 VARCHAR")
40-
.contains("_clob CLOB").contains("_blob BLOB").contains("_varchar VARCHAR").contains("_char2 CHAR(1)")
41-
.contains(" _smallint SMALLINT").contains(" _char CHAR(1)").contains("_timestamp TIMESTAMP")
42-
.contains("_time TIME").contains("_numeric NUMERIC").contains("_varchar2 VARCHAR");
48+
assertThat(ouptut).contains("timestamp2 TIMESTAMP").contains("blob2 BLOB").contains("bit BIT,")
49+
.contains("date DATE").contains("tinyint TINYINT").contains("integer2 INTEGER").contains("bigint BIGINT")
50+
.contains("varchar3 VARCHAR").contains("integer1 INTEGER").contains("varchar4 VARCHAR").contains("clob CLOB")
51+
.contains("blob BLOB").contains("varchar VARCHAR").contains("char2 CHAR(1)").contains("smallint SMALLINT")
52+
.contains("char1 CHAR(1)").contains("timestamp TIMESTAMP").contains("time TIME").contains("numeric NUMERIC")
53+
.contains("varchar2 VARCHAR").contains("CREATE TABLE SQLDataTypeTest").contains("varchar5 VARCHAR");
54+
55+
}
56+
57+
/**
58+
* Tests the correct generation of foreign key statements
59+
*/
60+
@Test
61+
public void testForeignKeyStatements() {
4362

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

3-
import javax.persistence.*;
4-
import java.util.List;
5-
3+
import javax.persistence.Column;
4+
import javax.persistence.Entity;
5+
import javax.persistence.EnumType;
6+
import javax.persistence.Enumerated;
7+
import javax.persistence.Id;
8+
import javax.persistence.Table;
9+
10+
/**
11+
* Test entity to test the correct generation of the enumerated type, the primary key, and name overriding
12+
*
13+
*/
614
@Entity
715
@Table(name = "SQLTEST")
816
public class SQLTestEntity {
9-
@Id
10-
@Column(name = "MY_ID_FIELD")
11-
private Long id;
12-
13-
@Column(name = "VALUENAME")
14-
private Integer integerValue;
17+
@Id
18+
@Column(name = "MY_ID_FIELD")
19+
private Long id;
1520

16-
@OneToOne
17-
private ReferenceEntity refEntity;
21+
@Column(name = "VALUENAME")
22+
private Integer integerValue;
1823

19-
@Enumerated(EnumType.STRING)
20-
@Column(length = 420, name = "ENUM_TEST_FIELD_NAME_OVERRIDE")
21-
private EnumForTest enumForTest;
24+
@Enumerated(EnumType.STRING)
25+
@Column(length = 420, name = "ENUM_TEST_FIELD_NAME_OVERRIDE")
26+
private EnumForTest enumForTest;
2227

23-
private List<ReferenceEntity> referenceEntities;
28+
public Long getId() {
2429

25-
public Long getId() {
26-
return id;
27-
}
30+
return this.id;
31+
}
2832

29-
public void setId(Long id) {
30-
this.id = id;
31-
}
33+
public void setId(Long id) {
3234

33-
public Integer getIntegerValue() {
34-
return integerValue;
35-
}
35+
this.id = id;
36+
}
3637

38+
public Integer getIntegerValue() {
3739

38-
public void setIntegerValue(Integer value) {
39-
this.integerValue = value;
40-
}
40+
return this.integerValue;
41+
}
4142

42-
@OneToMany(mappedBy = "I_SHALL_BE_SKIPPED")
43-
public List<ReferenceEntity> getReferenceEntities() {
44-
return referenceEntities;
45-
}
43+
public void setIntegerValue(Integer value) {
4644

47-
public void setReferenceEntities(List<ReferenceEntity> referenceEntities) {
48-
this.referenceEntities = referenceEntities;
49-
}
45+
this.integerValue = value;
46+
}
5047

48+
public EnumForTest getEnumForTest() {
5149

52-
public ReferenceEntity getRefEntity() {
53-
return refEntity;
54-
}
50+
return this.enumForTest;
51+
}
5552

56-
public void setRefEntity(ReferenceEntity refEntity) {
57-
this.refEntity = refEntity;
58-
}
53+
public void setEnumForTest(EnumForTest enumForTest) {
5954

60-
public EnumForTest getEnumForTest() {
61-
return enumForTest;
62-
}
55+
this.enumForTest = enumForTest;
56+
}
6357

64-
public void setEnumForTest(EnumForTest enumForTest) {
65-
this.enumForTest = enumForTest;
66-
}
6758
}

0 commit comments

Comments
 (0)