Skip to content

Commit

Permalink
Add compiler plugin test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed Feb 19, 2025
1 parent 08484c8 commit 14f89dd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -408,6 +409,22 @@ public void testCompilerPluginWebsubhubControllerUsage() {
Assert.assertEquals(errorDiagnostics.size(), 0);
}

@Test
public void testCompilerPluginInvalidWebsubhubControllerUsage() {
Package currentPackage = loadPackage("sample_25");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
List<Diagnostic> errorDiagnostics = diagnosticResult.diagnostics().stream()
.filter(d -> DiagnosticSeverity.ERROR.equals(d.diagnosticInfo().severity()))
.toList();
Assert.assertEquals(errorDiagnostics.size(), 5);
WebSubHubDiagnosticCodes expectedErrCode = WebSubHubDiagnosticCodes.WEBSUBHUB_106;
List<Diagnostic> invalidDiagnosticCodes = errorDiagnostics.stream().filter(e ->
Objects.nonNull(e.diagnosticInfo()) && expectedErrCode.getCode().equals(e.diagnosticInfo().code()))
.toList();
Assert.assertEquals(invalidDiagnosticCodes.size(), 0);
}

private void validateErrorsForInvalidReadonlyTypes(WebSubHubDiagnosticCodes expectedCode, Diagnostic diagnostic,
String typeDesc, String remoteMethodName) {
DiagnosticInfo info = diagnostic.diagnosticInfo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
org = "websubhub_test"
name = "sample_25"
version = "0.1.0"

[build-options]
observabilityIncluded = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2021 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/websubhub;

@websubhub:ServiceConfig {
autoVerifySubscription: true
}
service /websubhub on new websubhub:Listener(9090) {
isolated remote function onRegisterTopic(websubhub:TopicRegistration message, websubhub:Controller hubController)
returns websubhub:TopicRegistrationSuccess {
return websubhub:TOPIC_REGISTRATION_SUCCESS;
}

isolated remote function onDeregisterTopic(websubhub:TopicDeregistration message, websubhub:Controller hubController)
returns websubhub:TopicDeregistrationSuccess {
return websubhub:TOPIC_DEREGISTRATION_SUCCESS;
}

isolated remote function onUpdateMessage(websubhub:UpdateMessage msg, websubhub:Controller hubController) returns websubhub:Acknowledgement {
return websubhub:ACKNOWLEDGEMENT;
}

isolated remote function onSubscriptionIntentVerified(websubhub:VerifiedSubscription msg, websubhub:Controller hubController) {}

isolated remote function onUnsubscriptionIntentVerified(websubhub:VerifiedUnsubscription msg, websubhub:Controller hubController){}
}

0 comments on commit 14f89dd

Please sign in to comment.