Skip to content

Commit 62e36d2

Browse files
committed
test : add integration tests for ODM document generation
1 parent 4873b96 commit 62e36d2

4 files changed

Lines changed: 202 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package mocka.odm;
2+
3+
import mocka.odm.document.Member;
4+
import mocka.odm.generator.DocumentGenerator;
5+
import mocka.odm.generator.DocumentGeneratorFactory;
6+
import mocka.odm.generator.ODMResolver;
7+
import mocka.odm.generator.odm.ODMCreator;
8+
import org.junit.jupiter.api.DisplayName;
9+
import org.junit.jupiter.api.Test;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.boot.test.context.SpringBootTest;
12+
import org.springframework.test.context.ActiveProfiles;
13+
14+
import java.util.List;
15+
16+
import static org.assertj.core.api.Assertions.*;
17+
18+
@ActiveProfiles("test")
19+
@SpringBootTest(classes = MockaOdmTestApplication.class)
20+
@DisplayName("mocka-odm Main Test Code")
21+
public class MockaOdmMainTest {
22+
23+
@Autowired
24+
private DocumentGeneratorInitializer initializer;
25+
26+
@Autowired
27+
private DocumentGeneratorFactory generatorFactory;
28+
29+
@Test
30+
@DisplayName("Set ODM scan range by the value of 'mocka.odm.odmType in application.yaml. If no settings, use bean definition.")
31+
void get_odmType() {
32+
ODMResolver odmResolver = initializer.getOdmSelector();
33+
List<ODMCreator> creators = odmResolver.getCreators();
34+
35+
for (ODMCreator odmCreator : creators) {
36+
System.out.println("odmCreator = " + odmCreator);
37+
assertThat(odmCreator).isNotNull();
38+
}
39+
}
40+
41+
@Test
42+
@DisplayName("Verify Document instance generation from Document.class generator")
43+
void create_document_instance() {
44+
DocumentGenerator<Member> generator = generatorFactory.getGenerator(Member.class);
45+
46+
Member member = generator.get();
47+
System.out.println("document = " + member.toString());
48+
assertThat(member.getId()).isNotNull();
49+
assertThat(member.getName()).isNotNull();
50+
51+
List<Class<?>> generatorNames = generatorFactory.getDocumentGeneratorNames();
52+
System.out.println("generatorNames = " + generatorNames);
53+
assertThat(Member.class).isIn(generatorNames);
54+
}
55+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package mocka.odm;
2+
3+
import mocka.core.annotation.EnableMocka;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.test.context.ActiveProfiles;
7+
8+
@EnableMocka
9+
@ActiveProfiles("test")
10+
@SpringBootApplication
11+
public class MockaOdmTestApplication {
12+
13+
public static void main(String[] args) {
14+
SpringApplication.run(MockaOdmTestApplication.class, args);
15+
}
16+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package mocka.odm.document;
2+
3+
import org.bson.types.*;
4+
import org.springframework.data.annotation.Id;
5+
import org.springframework.data.geo.Box;
6+
import org.springframework.data.geo.Circle;
7+
import org.springframework.data.geo.Point;
8+
import org.springframework.data.geo.Polygon;
9+
import org.springframework.data.mongodb.core.geo.*;
10+
import org.springframework.data.mongodb.core.mapping.Document;
11+
12+
import java.time.*;
13+
import java.util.*;
14+
15+
@Document
16+
public class Member {
17+
18+
@Id
19+
private String id;
20+
21+
private String name;
22+
23+
private String implicit;
24+
25+
private Boolean typeBoolean;
26+
27+
private Double typeDouble;
28+
29+
private String typeString;
30+
31+
private String[] stringArray;
32+
33+
private float[] floatArray;
34+
35+
36+
// enum
37+
private MemberEnum memberEnum;
38+
39+
// UUID
40+
private UUID uuid;
41+
42+
// org.bson
43+
private Binary typeBinary;
44+
private ObjectId typeObjectId;
45+
private BSONTimestamp typeTimestamp;
46+
private Decimal128 typeDecimal128;
47+
48+
49+
// java.time & java.sql
50+
private Date typeDate;
51+
private LocalDate typeLocalDate;
52+
private LocalDateTime typeLocalDateTime;
53+
private LocalTime typeLocalTime;
54+
private Instant typeInstant;
55+
private ZonedDateTime typeZonedDateTime;
56+
private OffsetDateTime typeOffsetDateTime;
57+
58+
59+
// org.springframework.data.geo
60+
private Point typePoint;
61+
private Box typeBox;
62+
private Circle typeCircle;
63+
private Polygon typePolygon;
64+
65+
// org.springframework.data.mongodb.core.geo
66+
private GeoJsonPoint typeGeoJsonPoint;
67+
private GeoJsonPolygon typeGeoJsonPolygon;
68+
private GeoJsonLineString typeGeoJsonLineString;
69+
private GeoJsonMultiPoint typeGeoJsonMultiPoint;
70+
private GeoJsonMultiPolygon typeGeoJsonMultiPolygon;
71+
private GeoJsonMultiLineString typeGeoJsonMultiLineString;
72+
73+
// Collections
74+
private List<String> strings;
75+
private Set<Integer> integers;
76+
private List<Float> floats;
77+
private Collection<Long> longs;
78+
79+
public String getId() {
80+
return id;
81+
}
82+
83+
public String getName() {
84+
return name;
85+
}
86+
87+
@Override
88+
public String toString() {
89+
return "Member{" +
90+
"id='" + id + '\'' + '\n' +
91+
", name='" + name + '\'' + '\n' +
92+
", implicit='" + implicit + '\'' + '\n' +
93+
", typeBoolean=" + typeBoolean + '\n' +
94+
", typeDouble=" + typeDouble + '\n' +
95+
", typeString='" + typeString + '\'' + '\n' +
96+
", stringArray=" + Arrays.toString(stringArray) + '\n' +
97+
", floatArray=" + Arrays.toString(floatArray) + '\n' +
98+
", memberEnum=" + memberEnum + '\n' +
99+
", uuid=" + uuid + '\n' +
100+
", typeBinary=" + typeBinary + '\n' +
101+
", typeObjectId=" + typeObjectId + '\n' +
102+
", typeTimestamp=" + typeTimestamp + '\n' +
103+
", typeDecimal128=" + typeDecimal128 + '\n' +
104+
", typeDate=" + typeDate + '\n' +
105+
", typeLocalDate=" + typeLocalDate + '\n' +
106+
", typeLocalDateTime=" + typeLocalDateTime + '\n' +
107+
", typeLocalTime=" + typeLocalTime + '\n' +
108+
", typeInstant=" + typeInstant + '\n' +
109+
", typeZonedDateTime=" + typeZonedDateTime + '\n' +
110+
", typeOffsetDateTime=" + typeOffsetDateTime + '\n' +
111+
", typePoint=" + typePoint + '\n' +
112+
", typeBox=" + typeBox + '\n' +
113+
", typeCircle=" + typeCircle + '\n' +
114+
", typePolygon=" + typePolygon + '\n' +
115+
", typeGeoJsonPoint=" + typeGeoJsonPoint + '\n' +
116+
", typeGeoJsonPolygon=" + typeGeoJsonPolygon + '\n' +
117+
", typeGeoJsonLineString=" + typeGeoJsonLineString + '\n' +
118+
", typeGeoJsonMultiPolygon=" + typeGeoJsonMultiPolygon + '\n' +
119+
", typeGeoJsonMultiLineString=" + typeGeoJsonMultiLineString + '\n' +
120+
", strings=" + strings + '\n' +
121+
", integers=" + integers + '\n' +
122+
", floats=" + floats + '\n' +
123+
", longs=" + longs +
124+
'}';
125+
}
126+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package mocka.odm.document;
2+
3+
public enum MemberEnum {
4+
A, B, C, D, E, F;
5+
}

0 commit comments

Comments
 (0)