-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split subscription test suite into sub-modules
- Loading branch information
1 parent
78757f9
commit 5d42785
Showing
35 changed files
with
1,317 additions
and
897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...a-tests/graphql-subscription-test-suite/modules/five/tests/01_subscription_five_tests.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// WSO2 Inc. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/graphql; | ||
import ballerina/graphql_test_common as common; | ||
import ballerina/test; | ||
import ballerina/websocket; | ||
|
||
@test:Config { | ||
groups: ["listener", "subscriptions"] | ||
} | ||
function testAttachServiceWithSubscriptionToHttp2BasedListener() returns error? { | ||
graphql:Error? result = http2BasedListener.attach(subscriptionService); | ||
test:assertTrue(result is graphql:Error); | ||
graphql:Error err = <graphql:Error>result; | ||
string expecctedMessage = string `Websocket listener initialization failed due to the incompatibility of ` + | ||
string `provided HTTP(version 2.0) listener`; | ||
test:assertEquals(err.message(), expecctedMessage); | ||
} | ||
|
||
@test:Config { | ||
groups: ["listener", "subscriptions"] | ||
} | ||
function testAttachServiceWithSubscriptionToHttp1BasedListener() returns error? { | ||
string document = string `subscription { messages }`; | ||
string url = "ws://localhost:9091/service_with_http1"; | ||
websocket:ClientConfiguration config = {subProtocols: [common:GRAPHQL_TRANSPORT_WS]}; | ||
websocket:Client wsClient1 = check new (url, config); | ||
check common:initiateGraphqlWsConnection(wsClient1); | ||
check common:sendSubscriptionMessage(wsClient1, document, "1"); | ||
|
||
websocket:Client wsClient2 = check new (url, config); | ||
check common:initiateGraphqlWsConnection(wsClient2); | ||
check common:sendSubscriptionMessage(wsClient2, document, "2"); | ||
|
||
foreach int i in 1 ..< 4 { | ||
json expectedMsgPayload = {data: {messages: i}}; | ||
check common:validateNextMessage(wsClient1, expectedMsgPayload, id = "1"); | ||
check common:validateNextMessage(wsClient2, expectedMsgPayload, id = "2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
ballerina-tests/graphql-subscription-test-suite/modules/five/tests/listeners.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/graphql; | ||
import ballerina/http; | ||
|
||
listener http:Listener http2Listener = new http:Listener(9090); | ||
listener graphql:Listener http2BasedListener = new (http2Listener); | ||
|
||
listener graphql:Listener subscriptionListener = new (9091); |
45 changes: 45 additions & 0 deletions
45
ballerina-tests/graphql-subscription-test-suite/modules/five/tests/object_types.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
public service class AccountDetails { | ||
final string name; | ||
final int createdYear; | ||
|
||
function init(string name, int createdYear) { | ||
self.name = name; | ||
self.createdYear = createdYear; | ||
} | ||
|
||
resource function get name() returns string { | ||
return self.name; | ||
} | ||
|
||
resource function get createdYear() returns int { | ||
return self.createdYear; | ||
} | ||
} | ||
|
||
public service class Product { | ||
private final string id; | ||
|
||
function init(string id) { | ||
self.id = id; | ||
} | ||
|
||
resource function get id() returns string { | ||
return self.id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
ballerina-tests/graphql-subscription-test-suite/modules/five/tests/services.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). | ||
// | ||
// WSO2 LLC. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/graphql; | ||
import ballerina/http; | ||
|
||
graphql:Service subscriptionService = service object { | ||
isolated resource function get name() returns string { | ||
return "Walter White"; | ||
} | ||
|
||
isolated resource function subscribe messages() returns stream<int, error?> { | ||
int[] intArray = [1, 2, 3, 4, 5]; | ||
return intArray.toStream(); | ||
} | ||
}; | ||
|
||
isolated service /service_with_http1 on subscriptionListener { | ||
isolated resource function get greet() returns string { | ||
return "welcome!"; | ||
} | ||
|
||
isolated resource function subscribe messages() returns stream<int, error?> { | ||
int[] intArray = [1, 2, 3, 4, 5]; | ||
return intArray.toStream(); | ||
} | ||
} | ||
|
||
@graphql:ServiceConfig { | ||
contextInit: | ||
isolated function(http:RequestContext requestContext, http:Request request) returns graphql:Context|error { | ||
graphql:Context context = new; | ||
context.set("scope", check request.getHeader("scope")); | ||
return context; | ||
} | ||
} | ||
service /context on subscriptionListener { | ||
isolated resource function get greet() returns string { | ||
return "welcome!"; | ||
} | ||
|
||
isolated resource function subscribe messages(graphql:Context context) returns stream<int, error?>|error { | ||
var scope = context.get("scope"); | ||
if scope is string && scope == "admin" { | ||
int[] intArray = [1, 2, 3, 4, 5]; | ||
return intArray.toStream(); | ||
} | ||
return error("You don't have permission to retrieve data"); | ||
} | ||
} | ||
|
||
service /constraints on subscriptionListener { | ||
isolated resource function get greet() returns string { | ||
return "welcome!"; | ||
} | ||
|
||
isolated resource function subscribe movie(MovieDetails movie) returns stream<Reviews?, error?> { | ||
return movie.reviews.toStream(); | ||
} | ||
} |
Oops, something went wrong.