Skip to content

Commit c436464

Browse files
authored
Merge pull request #78 from marcschumacher/master
Test for List<EnumType>
2 parents bf69bdb + a9dcb92 commit c436464

File tree

8 files changed

+121
-0
lines changed

8 files changed

+121
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATE TYPE example_enum_domain_object AS (
2+
id INT,
3+
enum_array ztest_schema1.example_enum[]
4+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE TABLE enum_table (
2+
et_id serial primary key,
3+
et_enum_array ztest_schema1.example_enum[]
4+
);
5+
6+
INSERT INTO enum_table ( et_id, et_enum_array )
7+
VALUES (1, '{}'),
8+
(2, NULL),
9+
(3, '{ENUM_CONST_2}'),
10+
(4, '{ENUM_CONST_1, ENUM_CONST_2}');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE OR REPLACE FUNCTION get_example_enum_domain_object(IN param_id INT)
2+
RETURNS example_enum_domain_object AS
3+
$BODY$
4+
5+
SELECT et_id,
6+
et_enum_array
7+
FROM enum_table
8+
WHERE et_id = $1;
9+
10+
$BODY$
11+
LANGUAGE 'sql' VOLATILE
12+
SECURITY DEFINER
13+
COST 100;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE OR REPLACE FUNCTION list_example_enum_domain_objects()
2+
RETURNS SETOF example_enum_domain_object AS
3+
$BODY$
4+
5+
SELECT et_id,
6+
et_enum_array
7+
FROM enum_table;
8+
9+
$BODY$
10+
LANGUAGE 'sql' VOLATILE
11+
SECURITY DEFINER
12+
COST 100;

src/test/java/org/zalando/sprocwrapper/SimpleIT.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.zalando.sprocwrapper.example.ExampleDomainObjectWithSimpleTransformer;
5656
import org.zalando.sprocwrapper.example.ExampleDomainObjectWithValidation;
5757
import org.zalando.sprocwrapper.example.ExampleEnum;
58+
import org.zalando.sprocwrapper.example.ExampleEnumDomainObject;
5859
import org.zalando.sprocwrapper.example.ExampleNamespacedSProcService;
5960
import org.zalando.sprocwrapper.example.ExampleSProcService;
6061
import org.zalando.sprocwrapper.example.ExampleValidationSProcService;
@@ -1089,4 +1090,34 @@ public void testNullComplexParam() throws Exception {
10891090
public void testNullEnumParam() {
10901091
exampleSProcService.useEnumParam(null);
10911092
}
1093+
1094+
@Test
1095+
public void testEnumListNoEntry() {
1096+
ExampleEnumDomainObject result = exampleSProcService.getExampleEnumDomainObject(1);
1097+
assertEquals(Lists.newArrayList(), result.getEnumArray());
1098+
}
1099+
1100+
@Test
1101+
public void testEnumListNullEntry() {
1102+
ExampleEnumDomainObject result = exampleSProcService.getExampleEnumDomainObject(2);
1103+
assertNull(result.getEnumArray());
1104+
}
1105+
1106+
@Test
1107+
public void testEnumListOneEntry() {
1108+
ExampleEnumDomainObject result = exampleSProcService.getExampleEnumDomainObject(3);
1109+
assertEquals(Lists.newArrayList(ExampleEnum.ENUM_CONST_2), result.getEnumArray());
1110+
}
1111+
1112+
@Test
1113+
public void testEnumListTwoEntries() {
1114+
ExampleEnumDomainObject result = exampleSProcService.getExampleEnumDomainObject(4);
1115+
assertEquals(Lists.newArrayList(ExampleEnum.ENUM_CONST_1, ExampleEnum.ENUM_CONST_2), result.getEnumArray());
1116+
}
1117+
1118+
@Test
1119+
public void testEnumListSet() {
1120+
List<ExampleEnumDomainObject> result = exampleSProcService.listExampleEnumDomainObjects();
1121+
System.out.println(result);
1122+
}
10921123
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.zalando.sprocwrapper.example;
2+
3+
import java.util.List;
4+
5+
import org.zalando.typemapper.annotations.DatabaseField;
6+
import org.zalando.typemapper.annotations.DatabaseType;
7+
8+
/**
9+
* @author mschumacher
10+
*/
11+
@DatabaseType
12+
public class ExampleEnumDomainObject {
13+
14+
@DatabaseField
15+
private Integer id;
16+
17+
@DatabaseField
18+
private List<ExampleEnum> enumArray;
19+
20+
public Integer getId() {
21+
return id;
22+
}
23+
24+
public void setId(Integer id) {
25+
this.id = id;
26+
}
27+
28+
public List<ExampleEnum> getEnumArray() {
29+
return enumArray;
30+
}
31+
32+
public void setEnumArray(List<ExampleEnum> enumArray) {
33+
this.enumArray = enumArray;
34+
}
35+
}

src/test/java/org/zalando/sprocwrapper/example/ExampleSProcService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,10 @@ int createOrder(@SProcParam String orderNumber, @SProcParam OrderMonetaryAmount
286286
@SProcCall
287287
PartialObject getPartialObject(@SProcParam NotPartialObject partialObject);
288288

289+
@SProcCall
290+
ExampleEnumDomainObject getExampleEnumDomainObject(@SProcParam Integer id);
291+
292+
@SProcCall
293+
List<ExampleEnumDomainObject> listExampleEnumDomainObjects();
294+
289295
}

src/test/java/org/zalando/sprocwrapper/example/ExampleSProcServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,14 @@ public PartialObject getPartialObject(final PartialObject partialObject) {
454454
public PartialObject getPartialObject(final NotPartialObject notPartialObject) {
455455
return sproc.getPartialObject(notPartialObject);
456456
}
457+
458+
@Override
459+
public ExampleEnumDomainObject getExampleEnumDomainObject(Integer id) {
460+
return sproc.getExampleEnumDomainObject(id);
461+
}
462+
463+
@Override
464+
public List<ExampleEnumDomainObject> listExampleEnumDomainObjects() {
465+
return sproc.listExampleEnumDomainObjects();
466+
}
457467
}

0 commit comments

Comments
 (0)