Skip to content

Commit 26e9ce5

Browse files
committed
Add tests for FOR JSON and FOR XML output verification.
[#209] Signed-off-by: Mark Paluch <mpaluch@vmware.com>
1 parent cdbfc59 commit 26e9ce5

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.r2dbc.mssql;
18+
19+
import io.r2dbc.mssql.util.IntegrationTestSupport;
20+
import org.junit.jupiter.api.Test;
21+
import reactor.test.StepVerifier;
22+
23+
/**
24+
* Integration tests using JSON as return type.
25+
*
26+
* @author Mark Paluch
27+
*/
28+
class JsonIntegrationTests extends IntegrationTestSupport {
29+
30+
@Test
31+
void shouldExecuteForJsonSimple() {
32+
33+
connection.createStatement("select 1 as a for json path").fetchSize(0).execute()
34+
.flatMap(result -> result.map((row, rowMetadata) -> row.get(0)))
35+
.as(StepVerifier::create)
36+
.expectNext("[{\"a\":1}]")
37+
.verifyComplete();
38+
}
39+
40+
@Test
41+
void shouldExecuteForJsonParametrized() {
42+
43+
connection.createStatement("select 1 as a where @P0 = @P0 for json path").bind("@P0", true).fetchSize(0).execute()
44+
.flatMap(result -> result.map((row, rowMetadata) -> row.get(0)))
45+
.as(StepVerifier::create)
46+
.expectNext("[{\"a\":1}]")
47+
.verifyComplete();
48+
}
49+
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2019-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.r2dbc.mssql;
18+
19+
import io.r2dbc.mssql.util.IntegrationTestSupport;
20+
import org.junit.jupiter.api.Test;
21+
import reactor.test.StepVerifier;
22+
23+
/**
24+
* Integration tests using XML as return type.
25+
*
26+
* @author Mark Paluch
27+
*/
28+
class XmlIntegrationTests extends IntegrationTestSupport {
29+
30+
@Test
31+
void shouldExecuteForXmlSimple() {
32+
33+
connection.createStatement("select 1 as a for xml path").fetchSize(0).execute()
34+
.flatMap(result -> result.map((row, rowMetadata) -> row.get(0)))
35+
.as(StepVerifier::create)
36+
.expectNext("<row><a>1</a></row>")
37+
.verifyComplete();
38+
}
39+
40+
@Test
41+
void shouldExecuteForXmlParametrized() {
42+
43+
connection.createStatement("select 1 as a where @P0 = @P0 for xml path").bind("@P0", true).fetchSize(0).execute()
44+
.flatMap(result -> result.map((row, rowMetadata) -> row.get(0)))
45+
.as(StepVerifier::create)
46+
.expectNext("<row><a>1</a></row>")
47+
.verifyComplete();
48+
}
49+
50+
}

0 commit comments

Comments
 (0)