-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement mock server for Candid tests
- Loading branch information
1 parent
261cde2
commit 0ac36f4
Showing
19 changed files
with
595 additions
and
22 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
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
47 changes: 47 additions & 0 deletions
47
ballerina/modules/charitycheckpdf/tests/test_w_mock_server.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,47 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). | ||
// | ||
// 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 candid.mock as _; | ||
|
||
import ballerina/log; | ||
import ballerina/http; | ||
import ballerina/test; | ||
|
||
const EIN = "13-1837418"; | ||
|
||
Client charityCheckPDFForMockServer = test:mock(Client); | ||
|
||
@test:BeforeGroups { | ||
value: ["mock"] | ||
} | ||
function initializeClientsForMockServer() returns error? { | ||
log:printInfo("Initializing client for mock server"); | ||
charityCheckPDF = check new ( | ||
apiKeyConfig = { | ||
subscriptionKey: "6006e88b7fc2e0c31fbcb744cca10cafa280341758cd1db45fc1b29b05305dc0" | ||
}, | ||
serviceUrl = "http://localhost:9090/charitycheckpdf" | ||
); | ||
} | ||
|
||
@test:Config { | ||
groups: ["mock"] | ||
} | ||
function testCharitycheckpdfMock() returns error? { | ||
log:printInfo("charityCheckPDFForMockServer -> testCharitycheckpdfMock()"); | ||
http:Response result = check charityCheckPDF->/v1/pdf/[EIN]; | ||
test:assertEquals(result.getContentType(), "application/pdf"); | ||
} |
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
142 changes: 142 additions & 0 deletions
142
ballerina/modules/essentials/tests/test_w_mock_server.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,142 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). | ||
// | ||
// 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 candid.mock as _; | ||
|
||
import ballerina/log; | ||
import ballerina/test; | ||
|
||
const SEARCH_TERM = "candid"; | ||
const FILTER_NAME = "ntee_major"; | ||
const KEY_OR_VALUE = "C00"; | ||
|
||
Client essentialsMockServer = test:mock(Client); | ||
|
||
@test:BeforeGroups { | ||
value: ["mock"] | ||
} | ||
function initializeClientsForMockServer() returns error? { | ||
log:printInfo("Initializing client for mock server"); | ||
essentialsMockServer = check new ( | ||
apiKeyConfig = { | ||
subscriptionKey: "6006e88b7fc2e0c31fbcb744cca10cafa280341758cd1db45fc1b29b05305dc0" | ||
}, | ||
serviceUrl = "http://localhost:9090/essentials" | ||
); | ||
} | ||
|
||
@test:Config { | ||
groups: ["mock"] | ||
} | ||
function testEssentialsV1Mock() returns error? { | ||
log:printInfo("essentialsMockServer -> testEssentialsV1Mock()"); | ||
Query query = { | ||
search_terms: SEARCH_TERM | ||
}; | ||
V1EssentialsResponse result = check essentialsMockServer->/v1.post(query); | ||
V1EssentialsResponse_data? data = result?.data; | ||
if data is V1EssentialsResponse_data { | ||
V1EssentialsResponse_data_hits[]? hits = data?.hits; | ||
if hits is V1EssentialsResponse_data_hits[] { | ||
test:assertEquals(hits.length(), 25); | ||
} else { | ||
test:assertFail(); | ||
} | ||
} else { | ||
test:assertFail(); | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["mock"] | ||
} | ||
function testEssentialsV2Mock() returns error? { | ||
log:printInfo("essentialsMockServer -> testEssentialsV2Mock()"); | ||
Query query = { | ||
search_terms: SEARCH_TERM | ||
}; | ||
V2EssentialsResponse result = check essentialsMockServer->/v2.post(query); | ||
V2EssentialsResponse_data? data = result?.data; | ||
if data is V2EssentialsResponse_data { | ||
V2EssentialsResponse_data_hits[]? hits = data?.hits; | ||
if hits is V2EssentialsResponse_data_hits[] { | ||
test:assertEquals(hits.length(), 25); | ||
} else { | ||
test:assertFail(); | ||
} | ||
} else { | ||
test:assertFail(); | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["mock"] | ||
} | ||
function testEssentialsV3Mock() returns error? { | ||
log:printInfo("essentialsMockServer -> testEssentialsV3Mock()"); | ||
V3Query query = { | ||
search_terms: SEARCH_TERM | ||
}; | ||
V3EssentialsResponse result = check essentialsMockServer->/v3.post(query); | ||
V3EssentialsResponse_hits[]? hits = result?.hits; | ||
if hits is V3EssentialsResponse_hits[] { | ||
test:assertEquals(hits.length(), 25); | ||
} else { | ||
test:assertFail(); | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["mock"] | ||
} | ||
function testEssentialsLookupMock() returns error? { | ||
log:printInfo("essentialsMockServer -> testEssentialsLookupMock()"); | ||
EssentialsLookupResponse result = check essentialsMockServer->/lookup; | ||
string[]? data = result?.data; | ||
if data is string[] { | ||
test:assertTrue(data.some(val => val == FILTER_NAME)); | ||
} else { | ||
test:assertFail(); | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["mock"] | ||
} | ||
function testEssentialsLookupFilterNameMock() returns error? { | ||
log:printInfo("essentialsMockServer -> testEssentialsLookupFilterNameMock()"); | ||
EssentialsFilteredLookupResponse result = check essentialsMockServer->/lookup/[FILTER_NAME]; | ||
EssentialsFilteredLookupResponse_data[]? data = result?.data; | ||
if data is EssentialsFilteredLookupResponse_data[] { | ||
test:assertTrue(data.some(val => val?.'key == KEY_OR_VALUE)); | ||
} else { | ||
test:assertFail(); | ||
} | ||
} | ||
|
||
@test:Config { | ||
groups: ["mock"] | ||
} | ||
function testEssentialsLookupFilterNameKeyOrValueMock() returns error? { | ||
log:printInfo("essentialsMockServer -> testEssentialsLookupFilterNameKeyOrValueMock()"); | ||
EssentialsFilteredLookupResponse result = check essentialsMockServer->/lookup/[FILTER_NAME]/[KEY_OR_VALUE]; | ||
EssentialsFilteredLookupResponse_data[]? data = result?.data; | ||
if data is EssentialsFilteredLookupResponse_data[] { | ||
test:assertTrue(data.some(val => val?.'key == KEY_OR_VALUE)); | ||
} else { | ||
test:assertFail(); | ||
} | ||
} |
Oops, something went wrong.