17
17
package io .r2dbc .postgresql ;
18
18
19
19
import io .netty .buffer .ByteBuf ;
20
+ import io .r2dbc .postgresql .codec .Codecs ;
20
21
import io .r2dbc .postgresql .codec .MockCodecs ;
21
22
import io .r2dbc .postgresql .message .backend .DataRow ;
22
23
import io .r2dbc .postgresql .message .backend .RowDescription ;
28
29
import java .util .Collections ;
29
30
import java .util .List ;
30
31
import java .util .NoSuchElementException ;
32
+ import java .util .stream .Collectors ;
31
33
32
34
import static io .r2dbc .postgresql .message .Format .FORMAT_BINARY ;
33
35
import static io .r2dbc .postgresql .message .Format .FORMAT_TEXT ;
@@ -51,6 +53,11 @@ final class PostgresqlRowUnitTests {
51
53
new RowDescription .Field ((short ) 400 , 400 , 300 , (short ) 400 , FORMAT_TEXT , "test-name-3" , 500 )
52
54
);
53
55
56
+ private final PostgresqlRowMetadata metadata = new PostgresqlRowMetadata (columns
57
+ .stream ()
58
+ .map (field -> PostgresqlColumnMetadata .toColumnMetadata (mock (Codecs .class ), field ))
59
+ .collect (Collectors .toList ()));
60
+
54
61
private final ByteBuf [] data = new ByteBuf []{TEST .buffer (4 ).writeInt (100 ), TEST .buffer (4 ).writeInt (300 ), null };
55
62
56
63
@ AfterEach
@@ -78,7 +85,7 @@ void getAfterRelease() {
78
85
.decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
79
86
.build ();
80
87
81
- PostgresqlRow row = new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , new ByteBuf [0 ]);
88
+ PostgresqlRow row = new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , new ByteBuf [0 ]);
82
89
row .release ();
83
90
84
91
assertThatIllegalStateException ().isThrownBy (() -> row .get ("test-name-2" , Object .class ))
@@ -93,7 +100,7 @@ void getDefaultType() {
93
100
.decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
94
101
.build ();
95
102
96
- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("test-name-2" )).isSameAs (value );
103
+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("test-name-2" )).isSameAs (value );
97
104
}
98
105
99
106
@ Test
@@ -104,20 +111,20 @@ void getIndex() {
104
111
.decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
105
112
.build ();
106
113
107
- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get (1 , Object .class )).isSameAs (value );
114
+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get (1 , Object .class )).isSameAs (value );
108
115
}
109
116
110
117
@ Test
111
118
void getInvalidIndex () {
112
- assertThatExceptionOfType (IndexOutOfBoundsException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns ,
119
+ assertThatExceptionOfType (IndexOutOfBoundsException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns ,
113
120
new ByteBuf [0 ]).get (3 ,
114
121
Object .class ))
115
122
.withMessage ("Column index 3 is larger than the number of columns 3" );
116
123
}
117
124
118
125
@ Test
119
126
void getInvalidName () {
120
- assertThatExceptionOfType (NoSuchElementException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns ,
127
+ assertThatExceptionOfType (NoSuchElementException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns ,
121
128
new ByteBuf [0 ]).get ("test-name" +
122
129
"-4" , Object .class ))
123
130
.withMessageMatching ("Column name 'test-name-4' does not exist in column names \\ [test-name-[\\ d], test-name-[\\ d], test-name-[\\ d]\\ ]" );
@@ -131,20 +138,20 @@ void getName() {
131
138
.decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
132
139
.build ();
133
140
134
- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("test-name-2" , Object .class )).isSameAs (value );
135
- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("tEsT-nAme-2" , Object .class )).isSameAs (value );
141
+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("test-name-2" , Object .class )).isSameAs (value );
142
+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("tEsT-nAme-2" , Object .class )).isSameAs (value );
136
143
}
137
144
138
145
@ Test
139
146
void getNoIdentifier () {
140
- assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , new ByteBuf [0 ]).get (null ,
147
+ assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns , new ByteBuf [0 ]).get (null ,
141
148
Object .class ))
142
149
.withMessage ("name must not be null" );
143
150
}
144
151
145
152
@ Test
146
153
void getNoType () {
147
- assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , new ByteBuf [0 ]).get ("" , null ))
154
+ assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns , new ByteBuf [0 ]).get ("" , null ))
148
155
.withMessage ("type must not be null" );
149
156
}
150
157
@@ -154,7 +161,7 @@ void getNull() {
154
161
.decoding (null , 400 , FORMAT_TEXT , Object .class , null )
155
162
.build ();
156
163
157
- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("test-name-3" , Object .class )).isNull ();
164
+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("test-name-3" , Object .class )).isNull ();
158
165
}
159
166
160
167
@ Test
0 commit comments