diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 0e83626..663ab68 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,16 +1,16 @@ -[package] -distribution = "2201.8.0" -org = "ballerinax" -name = "googleapis.gcalendar" -version = "4.0.1" -license = ["Apache-2.0"] -authors = ["Ballerina"] -keywords = ["Productivity/Calendars", "Cost/Free", "Vendor/Google", "Collaboration", "Enterprise IT", "Management"] -icon = "icon.png" -repository = "https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar" - -[build-options] -observabilityIncluded = true - -[platform.java17] -graalvmCompatible = true +[package] +distribution = "2201.8.0" +org = "ballerinax" +name = "googleapis.gcalendar" +version = "4.0.1" +license = ["Apache-2.0"] +authors = ["Ballerina"] +keywords = ["Productivity/Calendars", "Cost/Free", "Vendor/Google", "Collaboration", "Enterprise IT", "Management"] +icon = "icon.png" +repository = "https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar" + +[build-options] +observabilityIncluded = true + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 0c7bddb..0a15a62 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -1,100 +1,100 @@ -/* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * 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 org.apache.tools.ant.taskdefs.condition.Os - -plugins { - id 'io.ballerina.plugin' -} - -description = 'Calendar - Ballerina' - -def packageName = "googleapis.gcalendar" -def packageOrg = "ballerinax" -def tomlVersion = stripBallerinaExtensionVersion("${project.version}") -def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") -def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") - -def stripBallerinaExtensionVersion(String extVersion) { - if (extVersion.matches(project.ext.timestampedVersionRegex)) { - def splitVersion = extVersion.split('-') - if (splitVersion.length > 3) { - def strippedValues = splitVersion[0..-4] - return strippedValues.join('-') - } else { - return extVersion - } - } else { - return extVersion.replace("${project.ext.snapshotVersion}", "") - } -} - -ballerina { - packageOrganization = packageOrg - module = packageName - testCoverageParam = "--code-coverage --coverage-format=xml" - isConnector = true - platform = "any" -} - -task updateTomlFiles { - doLast { - def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) - newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion) - ballerinaTomlFile.text = newBallerinaToml - } -} - -task commitTomlFiles { - doLast { - project.exec { - ignoreExitValue true - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'cmd', '/c', "git commit -m \"[Automated] Update the toml files\" Ballerina.toml Dependencies.toml" - } else { - commandLine 'sh', '-c', "git commit -m '[Automated] Update the toml files' Ballerina.toml Dependencies.toml" - } - } - } -} - -publishing { - publications { - maven(MavenPublication) { - artifact source: createArtifactZip, extension: 'zip' - } - } - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ballerina-platform/module-${packageOrg}-${packageName}") - credentials { - username = System.getenv("publishUser") - password = System.getenv("publishPAT") - } - } - } -} - -clean { - delete 'build' -} - -build.dependsOn "generatePomFileForMavenPublication" -publishToMavenLocal.dependsOn build -publish.dependsOn build +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * 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 org.apache.tools.ant.taskdefs.condition.Os + +plugins { + id 'io.ballerina.plugin' +} + +description = 'Calendar - Ballerina' + +def packageName = "googleapis.gcalendar" +def packageOrg = "ballerinax" +def tomlVersion = stripBallerinaExtensionVersion("${project.version}") +def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") +def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") + +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-') + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } +} + +ballerina { + packageOrganization = packageOrg + module = packageName + testCoverageParam = "--code-coverage --coverage-format=xml" + isConnector = true + platform = "any" +} + +task updateTomlFiles { + doLast { + def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) + newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion) + ballerinaTomlFile.text = newBallerinaToml + } +} + +task commitTomlFiles { + doLast { + project.exec { + ignoreExitValue true + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "git commit -m \"[Automated] Update the toml files\" Ballerina.toml Dependencies.toml" + } else { + commandLine 'sh', '-c', "git commit -m '[Automated] Update the toml files' Ballerina.toml Dependencies.toml" + } + } + } +} + +publishing { + publications { + maven(MavenPublication) { + artifact source: createArtifactZip, extension: 'zip' + } + } + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ballerina-platform/module-${packageOrg}-${packageName}") + credentials { + username = System.getenv("publishUser") + password = System.getenv("publishPAT") + } + } + } +} + +clean { + delete 'build' +} + +build.dependsOn "generatePomFileForMavenPublication" +publishToMavenLocal.dependsOn build +publish.dependsOn build diff --git a/ballerina/error.bal b/ballerina/error.bal index 4194c01..e7cb9de 100644 --- a/ballerina/error.bal +++ b/ballerina/error.bal @@ -1,18 +1,18 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. -// -// 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. - -# Represents any error related to the `gcalendar` module. -public type Error distinct error; +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. +// +// 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. + +# Represents any error related to the `gcalendar` module. +public type Error distinct error; diff --git a/ballerina/tests/README.md b/ballerina/tests/README.md index 497b1a4..0cb574e 100644 --- a/ballerina/tests/README.md +++ b/ballerina/tests/README.md @@ -1,37 +1,37 @@ -# Running Tests - -There are two test environments for the Google Calendar connector. The default test environment is the mock server for Calendar API. The other test environment is testing against the actual Calendar API endpoint. You can run the tests in either of these environments. - -## Running Tests against the Mock Server - -To execute the tests on the mock server, ensure that the `IS_TEST_ON_LIVE_SERVER` environment variable is either set to false or unset before initiating the tests. - -You can set your authentication credentials as environment variables: - -```bash -export IS_TEST_ON_LIVE_SERVER=false -``` - -Then, run the following command to run the tests: - -```bash - ./gradlew clean test -``` - -## Running Tests against the Live Endpoint - -You can set your authentication credentials as environment variables: - -```bash -export IS_TEST_ON_LIVE_SERVER=true -export CLIENT_ID="" -export CLIENT_SECRET="" -export REFRESH_TOKEN="" -export REFRESH_URL="" -``` - -Then, run the following command to run the tests: - -```bash - ./gradlew clean test -``` +# Running Tests + +There are two test environments for the Google Calendar connector. The default test environment is the mock server for Calendar API. The other test environment is testing against the actual Calendar API endpoint. You can run the tests in either of these environments. + +## Running Tests against the Mock Server + +To execute the tests on the mock server, ensure that the `IS_TEST_ON_LIVE_SERVER` environment variable is either set to false or unset before initiating the tests. + +You can set your authentication credentials as environment variables: + +```bash +export IS_TEST_ON_LIVE_SERVER=false +``` + +Then, run the following command to run the tests: + +```bash + ./gradlew clean test +``` + +## Running Tests against the Live Endpoint + +You can set your authentication credentials as environment variables: + +```bash +export IS_TEST_ON_LIVE_SERVER=true +export CLIENT_ID="" +export CLIENT_SECRET="" +export REFRESH_TOKEN="" +export REFRESH_URL="" +``` + +Then, run the following command to run the tests: + +```bash + ./gradlew clean test +``` diff --git a/ballerina/tests/test_client.bal b/ballerina/tests/test_client.bal index 6633823..9e90361 100644 --- a/ballerina/tests/test_client.bal +++ b/ballerina/tests/test_client.bal @@ -1,842 +1,842 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. -// -// 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 ballerinax/googleapis.gcalendar.mock as _; -import ballerina/os; -import ballerina/test; - -configurable boolean isTestOnLiveServer = os:getEnv("IS_TEST_ON_LIVE_SERVER") == "true"; - -Client calendarClient = test:mock(Client); - -configurable string mockClientId = ?; -configurable string mockClientSecret = ?; -configurable string mockRefreshToken = ?; -configurable string mockRefreshUrl = ?; - -@test:BeforeSuite -function initializeClientsForCalendarServer () returns error? { - if isTestOnLiveServer { - calendarClient = check new({ - auth: { - clientId: os:getEnv("CLIENT_ID"), - clientSecret: os:getEnv("CLIENT_SECRET"), - refreshToken: os:getEnv("REFRESH_TOKEN"), - refreshUrl: os:getEnv("REFRESH_URL") - } - }); - } else { - calendarClient = check new ( - { - timeout: 100000, - auth: { - refreshToken: mockRefreshToken, - clientId: mockClientId, - clientSecret: mockClientSecret, - refreshUrl: mockRefreshUrl - } - }, - serviceUrl = "http://localhost:9090/calendar/v3" - ); - } -} - -function verifyAndReturnId(string? id) returns string|error { - if id is () { - return error("id is nil"); - } - return id; -} - -@test:Config {} -function testCreateAndDeleteCalendar() returns error? { - string summary = "Test Calendar 1"; - Calendar cal = { - summary: summary - }; - Calendar calendar = check calendarClient->/calendars.post(cal); - test:assertEquals(calendar.summary, summary); - - string id = check verifyAndReturnId(calendar.id); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarGet() returns error? { - string summary = "calendar summary"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string id = check verifyAndReturnId(createdCal.id); - Calendar retrievedCal = check calendarClient->/calendars/[id].get(); - test:assertEquals(retrievedCal.summary, summary); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarUpdate() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string newSummary = "Updated Test Calendar"; - createdCal.summary = newSummary; - string id = check verifyAndReturnId(createdCal.id); - Calendar updatedCal = check calendarClient->/calendars/[id].put(createdCal); - test:assertEquals(updatedCal.summary, newSummary); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarPatch() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string newSummary = "Patched Test Calendar"; - createdCal.summary = newSummary; - string id = check verifyAndReturnId(createdCal.id); - Calendar patchedCal = check calendarClient->/calendars/[id].patch(createdCal); - test:assertEquals(patchedCal.summary, newSummary); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarAclGet() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string id = check verifyAndReturnId(createdCal.id); - Acl acl = check calendarClient->/calendars/[id]/acl.get(); - AclRule[]? aclRules = acl.items; - if aclRules !is () { - test:assertTrue(aclRules.length() > 0); - } - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarEventsGet() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); - test:assertEquals(createdEvent.summary, eventSummary); - Events events = check calendarClient->/calendars/[id]/events.get(); - Event[]? eventItems = events.items; - test:assertNotEquals(eventItems, ()); - string? eventId = createdEvent.id; - test:assertTrue(createdEvent.id is string); - if eventId is string { - check calendarClient->/calendars/[id]/events/[eventId].delete(); - } -} - -@test:Config {} -function testCalendarEventGet() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); - string eventId = check verifyAndReturnId(createdEvent.id); - Event retrievedEvent = check calendarClient->/calendars/[id]/events/[eventId].get(); - test:assertEquals(retrievedEvent.summary, eventSummary); - check calendarClient->/calendars/[id]/events/[eventId].delete(); -} - -@test:Config {} -function testCalendarEventCreate() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); - string eventId = check verifyAndReturnId(createdEvent.id); - Event retrievedEvent = check calendarClient->/calendars/[id]/events/[eventId].get(); - test:assertEquals(retrievedEvent.summary, eventSummary); - check calendarClient->/calendars/[id]/events/[eventId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarEventUpdate() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); - string eventId = check verifyAndReturnId(createdEvent.id); - string newSummary = "Updated Test Event"; - createdEvent.summary = newSummary; - Event updatedEvent = check calendarClient->/calendars/[id]/events/[eventId].put(createdEvent); - test:assertEquals(updatedEvent.summary, newSummary); - check calendarClient->/calendars/[id]/events/[eventId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarEventPatch() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); - string newSummary = "Patched Test Event"; - createdEvent.summary = newSummary; - string eventId = check verifyAndReturnId(createdEvent.id); - Event patchedEvent = check calendarClient->/calendars/[id]/events/[eventId].patch(createdEvent); - test:assertEquals(patchedEvent.summary, newSummary); - check calendarClient->/calendars/[id]/events/[eventId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarEventDelete() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); - string eventId = check verifyAndReturnId(createdEvent.id); - check calendarClient->/calendars/[id]/events/[eventId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testEventCreate() returns error? { - - string summary = "Test Meeting 110"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - Event payload = { - "start": { - "dateTime": "2023-10-19T03:00:00+05:30", - "timeZone": "Asia/Colombo" - }, - "end": { - "dateTime": "2023-10-19T03:30:00+05:30", - "timeZone": "Asia/Colombo" - }, - "summary": summary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); - test:assertEquals(createdEvent.summary, summary); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testEventImport() returns error? { - - string summary = "Test Meeting 110"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - Event payload = { - "start": { - "dateTime": "2023-10-19T03:00:00+05:30", - "timeZone": "Asia/Colombo" - }, - "end": { - "dateTime": "2023-10-19T03:30:00+05:30", - "timeZone": "Asia/Colombo" - }, - "summary": summary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); - test:assertEquals(createdEvent.summary, summary); - payload = { - "iCalUID": id, - "start": { - "dateTime": "2023-10-19T03:00:00+05:30", - "timeZone": "Asia/Colombo" - }, - "end": { - "dateTime": "2023-10-19T03:30:00+05:30", - "timeZone": "Asia/Colombo" - }, - "summary": summary - }; - Event importedEvent = check calendarClient->/calendars/[id]/events/'import.post(payload); - test:assertEquals(importedEvent.summary, summary); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testEventUpdate() returns error? { - - string summary = "Test Meeting 110"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - Event payload = { - "start": { - "dateTime": "2023-10-19T03:00:00+05:30", - "timeZone": "Asia/Colombo" - }, - "end": { - "dateTime": "2023-10-19T03:30:00+05:30", - "timeZone": "Asia/Colombo" - }, - "summary": summary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); - string newSummary = "Updated Test Meeting 110"; - createdEvent.summary = newSummary; - string eventId = check verifyAndReturnId(createdEvent.id); - Event updatedEvent = check calendarClient->/calendars/[id]/events/[eventId].put(createdEvent); - test:assertEquals(updatedEvent.summary, newSummary); - test:assertEquals(updatedEvent.summary, newSummary); - check calendarClient->/calendars/[id]/events/[eventId].delete(); -} - -@test:Config {} -function testEventPatch() returns error? { - - string summary = "Test Meeting 110"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - Event payload = { - "start": { - "dateTime": "2023-10-19T03:00:00+05:30", - "timeZone": "Asia/Colombo" - }, - "end": { - "dateTime": "2023-10-19T03:30:00+05:30", - "timeZone": "Asia/Colombo" - }, - "summary": summary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); - string newSummary = "Patched Test Meeting 110"; - createdEvent.summary = newSummary; - string eventId = check verifyAndReturnId(createdEvent.id); - Event patchedEvent = check calendarClient->/calendars/[id]/events/[eventId].patch(createdEvent); - test:assertEquals(patchedEvent.summary, newSummary); - check calendarClient->/calendars/[id]/events/[eventId].delete(); -} - -@test:Config {} -function testEventGet() returns error? { - string summary = "Test Event"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - Event payload = { - "start": { - "dateTime": "2023-10-19T03:00:00+05:30", - "timeZone": "Asia/Colombo" - }, - "end": { - "dateTime": "2023-10-19T03:30:00+05:30", - "timeZone": "Asia/Colombo" - }, - "summary": summary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); - string eventId = check verifyAndReturnId(createdEvent.id); - Event retrievedEvent = check calendarClient->/calendars/[id]/events/[eventId].get(); - test:assertEquals(retrievedEvent.summary, summary); - check calendarClient->/calendars/[id]/events/[eventId].delete(); -} - -@test:Config {} -function testEventDelete() returns error? { - - string summary = "Test Meeting 110"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - Event payload = { - "start": { - "dateTime": "2023-10-19T03:00:00+05:30", - "timeZone": "Asia/Colombo" - }, - "end": { - "dateTime": "2023-10-19T03:30:00+05:30", - "timeZone": "Asia/Colombo" - }, - "summary": summary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); - string eventId = check verifyAndReturnId(createdEvent.id); - check calendarClient->/calendars/[id]/events/[eventId].delete(); -} - -@test:Config {} -function testPostCalendarAcl() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - json acl = { - role: "owner", - scope: { - 'type: "user", - value: "user@example.com" - } - }; - string id = check verifyAndReturnId(createdCal.id); - AclRule res = check calendarClient->/calendars/[id]/acl.post(check acl.cloneWithType(AclRule)); - test:assertEquals(res.role, check acl.role); - AclRuleScope? scope = res.scope; - if scope is AclRuleScope { - test:assertEquals(scope.value, check acl.scope.value); - check calendarClient->/calendars/[id].delete(); - } -} - -@test:Config {} -function testAclRuleCreate() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string id = check verifyAndReturnId(createdCal.id); - AclRule aclRule = { - id: id, - role: "reader", - scope: { - 'type: "user", - value: "testuser@gmail.com" - } - }; - AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); - Acl acl = check calendarClient->/calendars/[id]/acl.get(); - boolean aclRuleFound = false; - AclRule[]? aclItems = acl.items; - if aclItems != () { - foreach AclRule acl_item in aclItems { - if acl_item.id == createdAclRule.id { - aclRuleFound = true; - break; - } - } - } - test:assertTrue(aclRuleFound, "Retrieved ACL does not contain the created ACL rule"); - string aclRuleId = check verifyAndReturnId(createdAclRule.id); - check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testAclRuleGet() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string id = check verifyAndReturnId(createdCal.id); - AclRule aclRule = { - id: id, - role: "reader", - scope: { - 'type: "user", - value: "testuser@gmail.com" - } - }; - AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); - test:assertEquals(createdAclRule.role, aclRule.role); - string aclRuleId = check verifyAndReturnId(createdAclRule.id); - AclRule getAclRule = check calendarClient->/calendars/[id]/acl/[aclRuleId].get(); - test:assertEquals(getAclRule.role, aclRule.role); - check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testAclRuleUpdate() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string id = check verifyAndReturnId(createdCal.id); - AclRule aclRule = { - id: id, - role: "reader", - scope: { - 'type: "user", - value: "testuser@gmail.com" - } - }; - AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); - test:assertEquals(createdAclRule.role, aclRule.role); - string aclRuleId = check verifyAndReturnId(createdAclRule.id); - aclRule = { - role: "writer", - scope: { - 'type: "user", - value: "testuser@gmail.com" - } - }; - AclRule updateAclRule = check calendarClient->/calendars/[id]/acl/[aclRuleId].put(aclRule); - test:assertEquals(updateAclRule.role, aclRule.role); - check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testAclRulePatch() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string id = check verifyAndReturnId(createdCal.id); - AclRule aclRule = { - id: id, - role: "reader", - scope: { - 'type: "user", - value: "testuser@gmail.com" - } - }; - AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); - test:assertEquals(createdAclRule.role, aclRule.role); - string aclRuleId = check verifyAndReturnId(createdAclRule.id); - aclRule = { - role: "writer", - scope: { - 'type: "user", - value: "testuser@gmail.com" - } - }; - AclRule updateAclRule = check calendarClient->/calendars/[id]/acl/[aclRuleId].patch(aclRule); - test:assertEquals(updateAclRule.role, aclRule.role); - check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarEventInstancesGet() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); - string eventId = check verifyAndReturnId(createdEvent.id); - Events instances = check calendarClient->/calendars/[id]/events/[eventId]/instances.get(); - test:assertNotEquals(instances.items, ()); - check calendarClient->/calendars/[id]/events/[eventId].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarEventMove() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string summary2 = "Test Calendar 2"; - Calendar cal2 = { - summary: summary2 - }; - Calendar createdCal2 = check calendarClient->/calendars.post(cal2); - string eventSummary = "Test Event"; - Event event = { - 'start: { - dateTime: "2023-10-28T03:00:00+05:30", - timeZone: "Asia/Colombo" - }, - end: { - dateTime: "2023-10-28T03:30:00+05:30", - timeZone: "Asia/Colombo" - }, - summary: eventSummary - }; - string calId = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[calId]/events.post(event); - string eventId = check verifyAndReturnId(createdEvent.id); - string calId2 = check verifyAndReturnId(createdCal2.id); - Event moveEvent = check calendarClient->/calendars/[calId]/events/[eventId]/move.post(calId2); - test:assertEquals(moveEvent.summary, eventSummary); - check calendarClient->/calendars/[calId2]/events/[eventId].delete(); - check calendarClient->/calendars/[calId2].delete(); - check calendarClient->/calendars/[calId].delete(); -} - -@test:Config {} -function testCalendarFromListDelete() returns error? { - - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCalendar = check calendarClient->/calendars.post(cal); - CalendarListEntry response = check calendarClient->/users/me/calendarList.post({id: createdCalendar.id}); - test:assertEquals(response.id, createdCalendar.id); - string id = check verifyAndReturnId(createdCalendar.id); - check calendarClient->/users/me/calendarList/[id].delete(); - check calendarClient->/calendars/[id].delete(); -} - -@test:Config {} -function testCalendarListEntryPatch() returns error? { - - string summary = "Test Calendar List Entry"; - Calendar cal = { - summary: summary - }; - Calendar calendar = check calendarClient->/calendars.post(cal); - test:assertEquals(calendar.summary, summary); - CalendarListEntry calendarListEntry = { - summary: summary, - id: calendar.id - }; - CalendarListEntry calendarUpdate = check calendarClient->/users/me/calendarList.post(calendarListEntry); - test:assertEquals(calendarUpdate.summary, summary); - string updateId = check verifyAndReturnId(calendarUpdate.id); - CalendarListEntry updatedEntry = check calendarClient->/users/me/calendarList/[updateId].patch(calendarListEntry); - test:assertEquals(updatedEntry.id, calendarUpdate.id); - check calendarClient->/users/me/calendarList/[updateId].delete(); -} - -@test:Config {} -function testPostCalendarList() returns error? { - string summary = "Test Calendar List Entry"; - Calendar cal = { - summary: summary - }; - Calendar calendar = check calendarClient->/calendars.post(cal); - test:assertEquals(calendar.summary, summary); - CalendarListEntry calendarListEntry = { - summary: summary, - id: calendar.id - }; - CalendarListEntry calendarUpdate = check calendarClient->/users/me/calendarList.post(calendarListEntry); - test:assertEquals(calendarUpdate.summary, summary); - string updateId = check verifyAndReturnId(calendarUpdate.id); - check calendarClient->/users/me/calendarList/[updateId].delete(); -} - -@test:Config {} -function testCalendarListEntryGet() returns error? { - string summary = "Calendar Summary"; - Calendar cal = { - summary: summary - }; - Calendar calendar = check calendarClient->/calendars.post(cal); - test:assertEquals(calendar.summary, summary); - CalendarListEntry calendarListEntry = { - id: calendar.id - }; - CalendarListEntry createdCalendarListEntry = check calendarClient->/users/me/calendarList.post(calendarListEntry); - string id = check verifyAndReturnId(createdCalendarListEntry.id); - CalendarListEntry retrievedCalendarListEntry = check calendarClient->/users/me/calendarList/[id].get(); - test:assertEquals(retrievedCalendarListEntry.summary, summary); - check calendarClient->/users/me/calendarList/[id].delete(); -} - -@test:Config {} -function testCalendarListEntryUpdate() returns error? { - string summary = "Test Calendar List Entry"; - Calendar cal = { - summary: summary - }; - Calendar calendar = check calendarClient->/calendars.post(cal); - test:assertEquals(calendar.summary, summary); - CalendarListEntry calendarListEntry = { - summary: summary, - id: calendar.id - }; - CalendarListEntry calendarUpdate = check calendarClient->/users/me/calendarList.post(calendarListEntry); - test:assertEquals(calendarUpdate.summary, summary); - string updateId = check verifyAndReturnId(calendarUpdate.id); - CalendarListEntry updatedEntry = check calendarClient->/users/me/calendarList/[updateId].put(calendarListEntry); - test:assertEquals(updatedEntry.id, calendarUpdate.id); - check calendarClient->/users/me/calendarList/[updateId].delete(); -} - -@test:Config {} -function testCalendarListGet() returns error? { - - CalendarList calendarList = check calendarClient->/users/me/calendarList.get(); - test:assertNotEquals(calendarList, ()); - CalendarListEntry[]? calendarListEntries = calendarList.items; - test:assertTrue(calendarListEntries is () || calendarListEntries.length() > 0); -} - -@test:Config {} -function testColorsGet() returns error? { - - Colors colors = check calendarClient->/colors.get(); - test:assertNotEquals(colors.calendar, ()); - test:assertNotEquals(colors.event, ()); - test:assertEquals(colors.kind, "calendar#colors"); -} - -@test:Config {} -function testFreeBusy() returns error? { - - FreeBusyRequest freeBusyRequest = { - timeMin: "2022-01-01T00:00:00Z", - timeMax: "2022-01-02T00:00:00Z", - timeZone: "UTC", - items: [ - { - id: "primary" - } - ] - }; - FreeBusyResponse freeBusyResponse = check calendarClient->/freeBusy.post(freeBusyRequest); - test:assertNotEquals(freeBusyResponse.kind, ()); - test:assertNotEquals(freeBusyResponse.calendars, ()); -} - -@test:Config {} -function testCalendarEventQuickAdd() returns error? { - string summary = "Test Calendar"; - Calendar cal = { - summary: summary - }; - Calendar createdCal = check calendarClient->/calendars.post(cal); - string eventText = "Event created using quickAdd"; - string id = check verifyAndReturnId(createdCal.id); - Event createdEvent = check calendarClient->/calendars/[id]/events/quickAdd.post(eventText); - test:assertEquals(createdEvent.summary, eventText); - string eventId = check verifyAndReturnId(createdEvent.id); - check calendarClient->/calendars/[id]/events/[eventId].delete(); - check calendarClient->/calendars/[id].delete(); -} +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com) All Rights Reserved. +// +// 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 ballerinax/googleapis.gcalendar.mock as _; +import ballerina/os; +import ballerina/test; + +configurable boolean isTestOnLiveServer = os:getEnv("IS_TEST_ON_LIVE_SERVER") == "true"; + +Client calendarClient = test:mock(Client); + +configurable string mockClientId = ?; +configurable string mockClientSecret = ?; +configurable string mockRefreshToken = ?; +configurable string mockRefreshUrl = ?; + +@test:BeforeSuite +function initializeClientsForCalendarServer () returns error? { + if isTestOnLiveServer { + calendarClient = check new({ + auth: { + clientId: os:getEnv("CLIENT_ID"), + clientSecret: os:getEnv("CLIENT_SECRET"), + refreshToken: os:getEnv("REFRESH_TOKEN"), + refreshUrl: os:getEnv("REFRESH_URL") + } + }); + } else { + calendarClient = check new ( + { + timeout: 100000, + auth: { + refreshToken: mockRefreshToken, + clientId: mockClientId, + clientSecret: mockClientSecret, + refreshUrl: mockRefreshUrl + } + }, + serviceUrl = "http://localhost:9090/calendar/v3" + ); + } +} + +function verifyAndReturnId(string? id) returns string|error { + if id is () { + return error("id is nil"); + } + return id; +} + +@test:Config {} +function testCreateAndDeleteCalendar() returns error? { + string summary = "Test Calendar 1"; + Calendar cal = { + summary: summary + }; + Calendar calendar = check calendarClient->/calendars.post(cal); + test:assertEquals(calendar.summary, summary); + + string id = check verifyAndReturnId(calendar.id); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarGet() returns error? { + string summary = "calendar summary"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string id = check verifyAndReturnId(createdCal.id); + Calendar retrievedCal = check calendarClient->/calendars/[id].get(); + test:assertEquals(retrievedCal.summary, summary); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarUpdate() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string newSummary = "Updated Test Calendar"; + createdCal.summary = newSummary; + string id = check verifyAndReturnId(createdCal.id); + Calendar updatedCal = check calendarClient->/calendars/[id].put(createdCal); + test:assertEquals(updatedCal.summary, newSummary); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarPatch() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string newSummary = "Patched Test Calendar"; + createdCal.summary = newSummary; + string id = check verifyAndReturnId(createdCal.id); + Calendar patchedCal = check calendarClient->/calendars/[id].patch(createdCal); + test:assertEquals(patchedCal.summary, newSummary); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarAclGet() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string id = check verifyAndReturnId(createdCal.id); + Acl acl = check calendarClient->/calendars/[id]/acl.get(); + AclRule[]? aclRules = acl.items; + if aclRules !is () { + test:assertTrue(aclRules.length() > 0); + } + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarEventsGet() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); + test:assertEquals(createdEvent.summary, eventSummary); + Events events = check calendarClient->/calendars/[id]/events.get(); + Event[]? eventItems = events.items; + test:assertNotEquals(eventItems, ()); + string? eventId = createdEvent.id; + test:assertTrue(createdEvent.id is string); + if eventId is string { + check calendarClient->/calendars/[id]/events/[eventId].delete(); + } +} + +@test:Config {} +function testCalendarEventGet() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); + string eventId = check verifyAndReturnId(createdEvent.id); + Event retrievedEvent = check calendarClient->/calendars/[id]/events/[eventId].get(); + test:assertEquals(retrievedEvent.summary, eventSummary); + check calendarClient->/calendars/[id]/events/[eventId].delete(); +} + +@test:Config {} +function testCalendarEventCreate() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); + string eventId = check verifyAndReturnId(createdEvent.id); + Event retrievedEvent = check calendarClient->/calendars/[id]/events/[eventId].get(); + test:assertEquals(retrievedEvent.summary, eventSummary); + check calendarClient->/calendars/[id]/events/[eventId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarEventUpdate() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); + string eventId = check verifyAndReturnId(createdEvent.id); + string newSummary = "Updated Test Event"; + createdEvent.summary = newSummary; + Event updatedEvent = check calendarClient->/calendars/[id]/events/[eventId].put(createdEvent); + test:assertEquals(updatedEvent.summary, newSummary); + check calendarClient->/calendars/[id]/events/[eventId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarEventPatch() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); + string newSummary = "Patched Test Event"; + createdEvent.summary = newSummary; + string eventId = check verifyAndReturnId(createdEvent.id); + Event patchedEvent = check calendarClient->/calendars/[id]/events/[eventId].patch(createdEvent); + test:assertEquals(patchedEvent.summary, newSummary); + check calendarClient->/calendars/[id]/events/[eventId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarEventDelete() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); + string eventId = check verifyAndReturnId(createdEvent.id); + check calendarClient->/calendars/[id]/events/[eventId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testEventCreate() returns error? { + + string summary = "Test Meeting 110"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + Event payload = { + "start": { + "dateTime": "2023-10-19T03:00:00+05:30", + "timeZone": "Asia/Colombo" + }, + "end": { + "dateTime": "2023-10-19T03:30:00+05:30", + "timeZone": "Asia/Colombo" + }, + "summary": summary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); + test:assertEquals(createdEvent.summary, summary); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testEventImport() returns error? { + + string summary = "Test Meeting 110"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + Event payload = { + "start": { + "dateTime": "2023-10-19T03:00:00+05:30", + "timeZone": "Asia/Colombo" + }, + "end": { + "dateTime": "2023-10-19T03:30:00+05:30", + "timeZone": "Asia/Colombo" + }, + "summary": summary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); + test:assertEquals(createdEvent.summary, summary); + payload = { + "iCalUID": id, + "start": { + "dateTime": "2023-10-19T03:00:00+05:30", + "timeZone": "Asia/Colombo" + }, + "end": { + "dateTime": "2023-10-19T03:30:00+05:30", + "timeZone": "Asia/Colombo" + }, + "summary": summary + }; + Event importedEvent = check calendarClient->/calendars/[id]/events/'import.post(payload); + test:assertEquals(importedEvent.summary, summary); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testEventUpdate() returns error? { + + string summary = "Test Meeting 110"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + Event payload = { + "start": { + "dateTime": "2023-10-19T03:00:00+05:30", + "timeZone": "Asia/Colombo" + }, + "end": { + "dateTime": "2023-10-19T03:30:00+05:30", + "timeZone": "Asia/Colombo" + }, + "summary": summary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); + string newSummary = "Updated Test Meeting 110"; + createdEvent.summary = newSummary; + string eventId = check verifyAndReturnId(createdEvent.id); + Event updatedEvent = check calendarClient->/calendars/[id]/events/[eventId].put(createdEvent); + test:assertEquals(updatedEvent.summary, newSummary); + test:assertEquals(updatedEvent.summary, newSummary); + check calendarClient->/calendars/[id]/events/[eventId].delete(); +} + +@test:Config {} +function testEventPatch() returns error? { + + string summary = "Test Meeting 110"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + Event payload = { + "start": { + "dateTime": "2023-10-19T03:00:00+05:30", + "timeZone": "Asia/Colombo" + }, + "end": { + "dateTime": "2023-10-19T03:30:00+05:30", + "timeZone": "Asia/Colombo" + }, + "summary": summary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); + string newSummary = "Patched Test Meeting 110"; + createdEvent.summary = newSummary; + string eventId = check verifyAndReturnId(createdEvent.id); + Event patchedEvent = check calendarClient->/calendars/[id]/events/[eventId].patch(createdEvent); + test:assertEquals(patchedEvent.summary, newSummary); + check calendarClient->/calendars/[id]/events/[eventId].delete(); +} + +@test:Config {} +function testEventGet() returns error? { + string summary = "Test Event"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + Event payload = { + "start": { + "dateTime": "2023-10-19T03:00:00+05:30", + "timeZone": "Asia/Colombo" + }, + "end": { + "dateTime": "2023-10-19T03:30:00+05:30", + "timeZone": "Asia/Colombo" + }, + "summary": summary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); + string eventId = check verifyAndReturnId(createdEvent.id); + Event retrievedEvent = check calendarClient->/calendars/[id]/events/[eventId].get(); + test:assertEquals(retrievedEvent.summary, summary); + check calendarClient->/calendars/[id]/events/[eventId].delete(); +} + +@test:Config {} +function testEventDelete() returns error? { + + string summary = "Test Meeting 110"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + Event payload = { + "start": { + "dateTime": "2023-10-19T03:00:00+05:30", + "timeZone": "Asia/Colombo" + }, + "end": { + "dateTime": "2023-10-19T03:30:00+05:30", + "timeZone": "Asia/Colombo" + }, + "summary": summary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(payload = payload); + string eventId = check verifyAndReturnId(createdEvent.id); + check calendarClient->/calendars/[id]/events/[eventId].delete(); +} + +@test:Config {} +function testPostCalendarAcl() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + json acl = { + role: "owner", + scope: { + 'type: "user", + value: "user@example.com" + } + }; + string id = check verifyAndReturnId(createdCal.id); + AclRule res = check calendarClient->/calendars/[id]/acl.post(check acl.cloneWithType(AclRule)); + test:assertEquals(res.role, check acl.role); + AclRuleScope? scope = res.scope; + if scope is AclRuleScope { + test:assertEquals(scope.value, check acl.scope.value); + check calendarClient->/calendars/[id].delete(); + } +} + +@test:Config {} +function testAclRuleCreate() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string id = check verifyAndReturnId(createdCal.id); + AclRule aclRule = { + id: id, + role: "reader", + scope: { + 'type: "user", + value: "testuser@gmail.com" + } + }; + AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); + Acl acl = check calendarClient->/calendars/[id]/acl.get(); + boolean aclRuleFound = false; + AclRule[]? aclItems = acl.items; + if aclItems != () { + foreach AclRule acl_item in aclItems { + if acl_item.id == createdAclRule.id { + aclRuleFound = true; + break; + } + } + } + test:assertTrue(aclRuleFound, "Retrieved ACL does not contain the created ACL rule"); + string aclRuleId = check verifyAndReturnId(createdAclRule.id); + check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testAclRuleGet() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string id = check verifyAndReturnId(createdCal.id); + AclRule aclRule = { + id: id, + role: "reader", + scope: { + 'type: "user", + value: "testuser@gmail.com" + } + }; + AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); + test:assertEquals(createdAclRule.role, aclRule.role); + string aclRuleId = check verifyAndReturnId(createdAclRule.id); + AclRule getAclRule = check calendarClient->/calendars/[id]/acl/[aclRuleId].get(); + test:assertEquals(getAclRule.role, aclRule.role); + check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testAclRuleUpdate() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string id = check verifyAndReturnId(createdCal.id); + AclRule aclRule = { + id: id, + role: "reader", + scope: { + 'type: "user", + value: "testuser@gmail.com" + } + }; + AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); + test:assertEquals(createdAclRule.role, aclRule.role); + string aclRuleId = check verifyAndReturnId(createdAclRule.id); + aclRule = { + role: "writer", + scope: { + 'type: "user", + value: "testuser@gmail.com" + } + }; + AclRule updateAclRule = check calendarClient->/calendars/[id]/acl/[aclRuleId].put(aclRule); + test:assertEquals(updateAclRule.role, aclRule.role); + check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testAclRulePatch() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string id = check verifyAndReturnId(createdCal.id); + AclRule aclRule = { + id: id, + role: "reader", + scope: { + 'type: "user", + value: "testuser@gmail.com" + } + }; + AclRule createdAclRule = check calendarClient->/calendars/[id]/acl.post(aclRule); + test:assertEquals(createdAclRule.role, aclRule.role); + string aclRuleId = check verifyAndReturnId(createdAclRule.id); + aclRule = { + role: "writer", + scope: { + 'type: "user", + value: "testuser@gmail.com" + } + }; + AclRule updateAclRule = check calendarClient->/calendars/[id]/acl/[aclRuleId].patch(aclRule); + test:assertEquals(updateAclRule.role, aclRule.role); + check calendarClient->/calendars/[id]/acl/[aclRuleId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarEventInstancesGet() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events.post(event); + string eventId = check verifyAndReturnId(createdEvent.id); + Events instances = check calendarClient->/calendars/[id]/events/[eventId]/instances.get(); + test:assertNotEquals(instances.items, ()); + check calendarClient->/calendars/[id]/events/[eventId].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarEventMove() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string summary2 = "Test Calendar 2"; + Calendar cal2 = { + summary: summary2 + }; + Calendar createdCal2 = check calendarClient->/calendars.post(cal2); + string eventSummary = "Test Event"; + Event event = { + 'start: { + dateTime: "2023-10-28T03:00:00+05:30", + timeZone: "Asia/Colombo" + }, + end: { + dateTime: "2023-10-28T03:30:00+05:30", + timeZone: "Asia/Colombo" + }, + summary: eventSummary + }; + string calId = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[calId]/events.post(event); + string eventId = check verifyAndReturnId(createdEvent.id); + string calId2 = check verifyAndReturnId(createdCal2.id); + Event moveEvent = check calendarClient->/calendars/[calId]/events/[eventId]/move.post(calId2); + test:assertEquals(moveEvent.summary, eventSummary); + check calendarClient->/calendars/[calId2]/events/[eventId].delete(); + check calendarClient->/calendars/[calId2].delete(); + check calendarClient->/calendars/[calId].delete(); +} + +@test:Config {} +function testCalendarFromListDelete() returns error? { + + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCalendar = check calendarClient->/calendars.post(cal); + CalendarListEntry response = check calendarClient->/users/me/calendarList.post({id: createdCalendar.id}); + test:assertEquals(response.id, createdCalendar.id); + string id = check verifyAndReturnId(createdCalendar.id); + check calendarClient->/users/me/calendarList/[id].delete(); + check calendarClient->/calendars/[id].delete(); +} + +@test:Config {} +function testCalendarListEntryPatch() returns error? { + + string summary = "Test Calendar List Entry"; + Calendar cal = { + summary: summary + }; + Calendar calendar = check calendarClient->/calendars.post(cal); + test:assertEquals(calendar.summary, summary); + CalendarListEntry calendarListEntry = { + summary: summary, + id: calendar.id + }; + CalendarListEntry calendarUpdate = check calendarClient->/users/me/calendarList.post(calendarListEntry); + test:assertEquals(calendarUpdate.summary, summary); + string updateId = check verifyAndReturnId(calendarUpdate.id); + CalendarListEntry updatedEntry = check calendarClient->/users/me/calendarList/[updateId].patch(calendarListEntry); + test:assertEquals(updatedEntry.id, calendarUpdate.id); + check calendarClient->/users/me/calendarList/[updateId].delete(); +} + +@test:Config {} +function testPostCalendarList() returns error? { + string summary = "Test Calendar List Entry"; + Calendar cal = { + summary: summary + }; + Calendar calendar = check calendarClient->/calendars.post(cal); + test:assertEquals(calendar.summary, summary); + CalendarListEntry calendarListEntry = { + summary: summary, + id: calendar.id + }; + CalendarListEntry calendarUpdate = check calendarClient->/users/me/calendarList.post(calendarListEntry); + test:assertEquals(calendarUpdate.summary, summary); + string updateId = check verifyAndReturnId(calendarUpdate.id); + check calendarClient->/users/me/calendarList/[updateId].delete(); +} + +@test:Config {} +function testCalendarListEntryGet() returns error? { + string summary = "Calendar Summary"; + Calendar cal = { + summary: summary + }; + Calendar calendar = check calendarClient->/calendars.post(cal); + test:assertEquals(calendar.summary, summary); + CalendarListEntry calendarListEntry = { + id: calendar.id + }; + CalendarListEntry createdCalendarListEntry = check calendarClient->/users/me/calendarList.post(calendarListEntry); + string id = check verifyAndReturnId(createdCalendarListEntry.id); + CalendarListEntry retrievedCalendarListEntry = check calendarClient->/users/me/calendarList/[id].get(); + test:assertEquals(retrievedCalendarListEntry.summary, summary); + check calendarClient->/users/me/calendarList/[id].delete(); +} + +@test:Config {} +function testCalendarListEntryUpdate() returns error? { + string summary = "Test Calendar List Entry"; + Calendar cal = { + summary: summary + }; + Calendar calendar = check calendarClient->/calendars.post(cal); + test:assertEquals(calendar.summary, summary); + CalendarListEntry calendarListEntry = { + summary: summary, + id: calendar.id + }; + CalendarListEntry calendarUpdate = check calendarClient->/users/me/calendarList.post(calendarListEntry); + test:assertEquals(calendarUpdate.summary, summary); + string updateId = check verifyAndReturnId(calendarUpdate.id); + CalendarListEntry updatedEntry = check calendarClient->/users/me/calendarList/[updateId].put(calendarListEntry); + test:assertEquals(updatedEntry.id, calendarUpdate.id); + check calendarClient->/users/me/calendarList/[updateId].delete(); +} + +@test:Config {} +function testCalendarListGet() returns error? { + + CalendarList calendarList = check calendarClient->/users/me/calendarList.get(); + test:assertNotEquals(calendarList, ()); + CalendarListEntry[]? calendarListEntries = calendarList.items; + test:assertTrue(calendarListEntries is () || calendarListEntries.length() > 0); +} + +@test:Config {} +function testColorsGet() returns error? { + + Colors colors = check calendarClient->/colors.get(); + test:assertNotEquals(colors.calendar, ()); + test:assertNotEquals(colors.event, ()); + test:assertEquals(colors.kind, "calendar#colors"); +} + +@test:Config {} +function testFreeBusy() returns error? { + + FreeBusyRequest freeBusyRequest = { + timeMin: "2022-01-01T00:00:00Z", + timeMax: "2022-01-02T00:00:00Z", + timeZone: "UTC", + items: [ + { + id: "primary" + } + ] + }; + FreeBusyResponse freeBusyResponse = check calendarClient->/freeBusy.post(freeBusyRequest); + test:assertNotEquals(freeBusyResponse.kind, ()); + test:assertNotEquals(freeBusyResponse.calendars, ()); +} + +@test:Config {} +function testCalendarEventQuickAdd() returns error? { + string summary = "Test Calendar"; + Calendar cal = { + summary: summary + }; + Calendar createdCal = check calendarClient->/calendars.post(cal); + string eventText = "Event created using quickAdd"; + string id = check verifyAndReturnId(createdCal.id); + Event createdEvent = check calendarClient->/calendars/[id]/events/quickAdd.post(eventText); + test:assertEquals(createdEvent.summary, eventText); + string eventId = check verifyAndReturnId(createdEvent.id); + check calendarClient->/calendars/[id]/events/[eventId].delete(); + check calendarClient->/calendars/[id].delete(); +} diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 61585eb..8eee152 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -1,16 +1,16 @@ -[package] -distribution = "2201.8.0" -org = "ballerinax" -name = "googleapis.gcalendar" -version = "@toml.version@" -license = ["Apache-2.0"] -authors = ["Ballerina"] -keywords = ["Productivity/Calendars", "Cost/Free", "Vendor/Google", "Collaboration", "Enterprise IT", "Management"] -icon = "icon.png" -repository = "https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar" - -[build-options] -observabilityIncluded = true - -[platform.java17] -graalvmCompatible = true +[package] +distribution = "2201.8.0" +org = "ballerinax" +name = "googleapis.gcalendar" +version = "@toml.version@" +license = ["Apache-2.0"] +authors = ["Ballerina"] +keywords = ["Productivity/Calendars", "Cost/Free", "Vendor/Google", "Collaboration", "Enterprise IT", "Management"] +icon = "icon.png" +repository = "https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar" + +[build-options] +observabilityIncluded = true + +[platform.java17] +graalvmCompatible = true diff --git a/changelog.md b/changelog.md index ce247ea..b0d3809 100644 --- a/changelog.md +++ b/changelog.md @@ -1,24 +1,24 @@ -# Changelog - -This file contains all the notable changes done to the Ballerina `googleapis.gcalendar` package through the releases. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -### Added - -### Changed - -## [4.0.1] - 2024-02-14 - -### Changed - -- Improve documentation - -## [4.0.0] - 2023-01-12 - -### Added - -- [Revamp Calendar connector](https://github.com/ballerina-platform/ballerina-library/issues/5712) +# Changelog + +This file contains all the notable changes done to the Ballerina `googleapis.gcalendar` package through the releases. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +### Changed + +## [4.0.1] - 2024-02-14 + +### Changed + +- Improve documentation + +## [4.0.0] - 2023-01-12 + +### Added + +- [Revamp Calendar connector](https://github.com/ballerina-platform/ballerina-library/issues/5712) diff --git a/examples/README.md b/examples/README.md index 88109bb..1cf2e07 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,55 +1,55 @@ -# Examples - -The Google Calendar connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar/tree/main/examples), covering use cases like creating calendar, scheduling meeting events, and adding reminders. - -1. [Project management with Calendar API](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar/tree/main/examples/project-management-with-calendar) - This example shows how to use Google Calendar APIs to efficiently manage work schedule of a person. It interacts with the API for various tasks related to scheduling and organizing work-related events and meetings. -2. [Work schedule management with Calendar API](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar/tree/main/examples/work-schedule-management-with-calendar) - This example shows how to use Google Calendar APIs to managing personal project schedule and collaborating with team members. - -## Prerequisites - -1. Follow the [instructions](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar#set-up-guide) to set up the Calendar API. - -2. For each example, create a `Config.toml` file with your OAuth2 tokens, client ID, and client secret. Here's an example of how your `Config.toml` file should look: - - ```toml - clientId="" - clientSecret="" - refreshToken="" - refreshUrl="" - ``` - -## Running an Example - -Execute the following commands to build an example from the source: - -* To build an example: - - ```bash - bal build - ``` - -* To run an example: - - ```bash - bal run - ``` - -## Building the Examples with the Local Module - -**Warning**: Due to the absence of support for reading local repositories for single Ballerina files, the Bala of the module is manually written to the central repository as a workaround. Consequently, the bash script may modify your local Ballerina repositories. - -Execute the following commands to build all the examples against the changes you have made to the module locally: - -* To build all the examples: - - ```bash - ./build.sh build - ``` - -* To run all the examples: - - ```bash - ./build.sh run - ``` +# Examples + +The Google Calendar connector provides practical examples illustrating usage in various scenarios. Explore these [examples](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar/tree/main/examples), covering use cases like creating calendar, scheduling meeting events, and adding reminders. + +1. [Project management with Calendar API](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar/tree/main/examples/project-management-with-calendar) + This example shows how to use Google Calendar APIs to efficiently manage work schedule of a person. It interacts with the API for various tasks related to scheduling and organizing work-related events and meetings. +2. [Work schedule management with Calendar API](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar/tree/main/examples/work-schedule-management-with-calendar) + This example shows how to use Google Calendar APIs to managing personal project schedule and collaborating with team members. + +## Prerequisites + +1. Follow the [instructions](https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar#set-up-guide) to set up the Calendar API. + +2. For each example, create a `Config.toml` file with your OAuth2 tokens, client ID, and client secret. Here's an example of how your `Config.toml` file should look: + + ```toml + clientId="" + clientSecret="" + refreshToken="" + refreshUrl="" + ``` + +## Running an Example + +Execute the following commands to build an example from the source: + +* To build an example: + + ```bash + bal build + ``` + +* To run an example: + + ```bash + bal run + ``` + +## Building the Examples with the Local Module + +**Warning**: Due to the absence of support for reading local repositories for single Ballerina files, the Bala of the module is manually written to the central repository as a workaround. Consequently, the bash script may modify your local Ballerina repositories. + +Execute the following commands to build all the examples against the changes you have made to the module locally: + +* To build all the examples: + + ```bash + ./build.sh build + ``` + +* To run all the examples: + + ```bash + ./build.sh run + ``` diff --git a/examples/build.gradle b/examples/build.gradle index afbbaf7..45408b8 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2023, 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 org.apache.tools.ant.taskdefs.condition.Os - -apply plugin: 'java' - -def graalvmFlag = "" - -task testExamples { - if (project.hasProperty("balGraalVMTest")) { - graalvmFlag = "--graalvm" - } - doLast { - try { - exec { - workingDir project.projectDir - println("Working dir: ${workingDir}") - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'sh', "/c", "chmod +x ./build.sh && ./build.sh run && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', "-c", "chmod +x ./build.sh && ./build.sh run" - } - } - } catch (Exception e) { - println("Example Build failed: " + e.message) - throw e - } - } -} - -task buildExamples { - gradle.taskGraph.whenReady { graph -> - if (graph.hasTask(":googleapis.gcalendar-examples:test")) { - buildExamples.enabled = false - } else { - testExamples.enabled = false - } - } - doLast { - try { - exec { - workingDir project.projectDir - println("Working dir: ${workingDir}") - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'sh', "/c", "chmod +x ./build.sh && ./build.sh build && exit %%ERRORLEVEL%%" - } else { - commandLine 'sh', "-c", "chmod +x ./build.sh && ./build.sh build" - } - } - } catch (Exception e) { - println("Example Build failed: " + e.message) - throw e - } - } -} - -buildExamples.dependsOn ":googleapis.gcalendar-ballerina:build" -testExamples.dependsOn ":googleapis.gcalendar-ballerina:build" - -build.dependsOn buildExamples +/* + * Copyright (c) 2023, 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 org.apache.tools.ant.taskdefs.condition.Os + +apply plugin: 'java' + +def graalvmFlag = "" + +task testExamples { + if (project.hasProperty("balGraalVMTest")) { + graalvmFlag = "--graalvm" + } + doLast { + try { + exec { + workingDir project.projectDir + println("Working dir: ${workingDir}") + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'sh', "/c", "chmod +x ./build.sh && ./build.sh run && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', "-c", "chmod +x ./build.sh && ./build.sh run" + } + } + } catch (Exception e) { + println("Example Build failed: " + e.message) + throw e + } + } +} + +task buildExamples { + gradle.taskGraph.whenReady { graph -> + if (graph.hasTask(":googleapis.gcalendar-examples:test")) { + buildExamples.enabled = false + } else { + testExamples.enabled = false + } + } + doLast { + try { + exec { + workingDir project.projectDir + println("Working dir: ${workingDir}") + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'sh', "/c", "chmod +x ./build.sh && ./build.sh build && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', "-c", "chmod +x ./build.sh && ./build.sh build" + } + } + } catch (Exception e) { + println("Example Build failed: " + e.message) + throw e + } + } +} + +buildExamples.dependsOn ":googleapis.gcalendar-ballerina:build" +testExamples.dependsOn ":googleapis.gcalendar-ballerina:build" + +build.dependsOn buildExamples diff --git a/gradle.properties b/gradle.properties index 37aa011..0259233 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,13 @@ -org.gradle.caching=true -group=io.ballerina.stdlib -version=4.0.2-SNAPSHOT - -checkstylePluginVersion=10.12.0 -spotbugsPluginVersion=5.0.14 -shadowJarPluginVersion=8.1.1 -downloadPluginVersion=5.4.0 -releasePluginVersion=2.8.0 -testngVersion=7.6.1 -eclipseLsp4jVersion=0.12.0 -ballerinaGradlePluginVersion=2.2.1 -ballerinaLangVersion=2201.8.4 +org.gradle.caching=true +group=io.ballerina.stdlib +version=4.0.2-SNAPSHOT + +checkstylePluginVersion=10.12.0 +spotbugsPluginVersion=5.0.14 +shadowJarPluginVersion=8.1.1 +downloadPluginVersion=5.4.0 +releasePluginVersion=2.8.0 +testngVersion=7.6.1 +eclipseLsp4jVersion=0.12.0 +ballerinaGradlePluginVersion=2.2.1 +ballerinaLangVersion=2201.8.4