Skip to content

Commit 14f89dd

Browse files
committed
Add compiler plugin test cases
1 parent 08484c8 commit 14f89dd

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

Diff for: compiler-plugin-tests/src/test/java/io/ballerina/stdlib/websubhub/CompilerPluginTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.nio.file.Paths;
3737
import java.text.MessageFormat;
3838
import java.util.List;
39+
import java.util.Objects;
3940
import java.util.stream.Collectors;
4041

4142
/**
@@ -408,6 +409,22 @@ public void testCompilerPluginWebsubhubControllerUsage() {
408409
Assert.assertEquals(errorDiagnostics.size(), 0);
409410
}
410411

412+
@Test
413+
public void testCompilerPluginInvalidWebsubhubControllerUsage() {
414+
Package currentPackage = loadPackage("sample_25");
415+
PackageCompilation compilation = currentPackage.getCompilation();
416+
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
417+
List<Diagnostic> errorDiagnostics = diagnosticResult.diagnostics().stream()
418+
.filter(d -> DiagnosticSeverity.ERROR.equals(d.diagnosticInfo().severity()))
419+
.toList();
420+
Assert.assertEquals(errorDiagnostics.size(), 5);
421+
WebSubHubDiagnosticCodes expectedErrCode = WebSubHubDiagnosticCodes.WEBSUBHUB_106;
422+
List<Diagnostic> invalidDiagnosticCodes = errorDiagnostics.stream().filter(e ->
423+
Objects.nonNull(e.diagnosticInfo()) && expectedErrCode.getCode().equals(e.diagnosticInfo().code()))
424+
.toList();
425+
Assert.assertEquals(invalidDiagnosticCodes.size(), 0);
426+
}
427+
411428
private void validateErrorsForInvalidReadonlyTypes(WebSubHubDiagnosticCodes expectedCode, Diagnostic diagnostic,
412429
String typeDesc, String remoteMethodName) {
413430
DiagnosticInfo info = diagnostic.diagnosticInfo();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
org = "websubhub_test"
3+
name = "sample_25"
4+
version = "0.1.0"
5+
6+
[build-options]
7+
observabilityIncluded = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2021 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2+
//
3+
// WSO2 Inc. licenses this file to you under the Apache License,
4+
// Version 2.0 (the "License"); you may not use this file except
5+
// in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing,
11+
// software distributed under the License is distributed on an
12+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13+
// KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations
15+
// under the License.
16+
17+
import ballerina/websubhub;
18+
19+
@websubhub:ServiceConfig {
20+
autoVerifySubscription: true
21+
}
22+
service /websubhub on new websubhub:Listener(9090) {
23+
isolated remote function onRegisterTopic(websubhub:TopicRegistration message, websubhub:Controller hubController)
24+
returns websubhub:TopicRegistrationSuccess {
25+
return websubhub:TOPIC_REGISTRATION_SUCCESS;
26+
}
27+
28+
isolated remote function onDeregisterTopic(websubhub:TopicDeregistration message, websubhub:Controller hubController)
29+
returns websubhub:TopicDeregistrationSuccess {
30+
return websubhub:TOPIC_DEREGISTRATION_SUCCESS;
31+
}
32+
33+
isolated remote function onUpdateMessage(websubhub:UpdateMessage msg, websubhub:Controller hubController) returns websubhub:Acknowledgement {
34+
return websubhub:ACKNOWLEDGEMENT;
35+
}
36+
37+
isolated remote function onSubscriptionIntentVerified(websubhub:VerifiedSubscription msg, websubhub:Controller hubController) {}
38+
39+
isolated remote function onUnsubscriptionIntentVerified(websubhub:VerifiedUnsubscription msg, websubhub:Controller hubController){}
40+
}

0 commit comments

Comments
 (0)