Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-15702938 Added tests for AVRO and AVRO support in async2.6 #1075

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
asyncapi: 2.6.0
info:
title: Market Data API
version: 1.0.0
description: This API provides real-time market data updates.

channels:
m1:
description: Pancho

components:
messages:
m1:
schemaFormat: application/vnd.apache.avro;version=1.9.0
payload:
$ref: schemas/union-type-invalid-payload.avsc
examples:
- payload:
name: John Doe
address:
zipcode: 1355
age: 20
favoriteProgrammingLanguage: Java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
asyncapi: 2.6.0
info:
title: Market Data API
version: 1.0.0
description: This API provides real-time market data updates.
channels:
m1:
description: Pancho

components:
messages:
m1:
schemaFormat: application/vnd.apache.avro;version=1.9.0
payload:
$ref: schemas/union-type-payload.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type" : "record",
"name" : "avrotoavro",
"fields" : [
{"name": "user_user", "type": {
"name": "user",
"type": "record",
"fields": [
{
"name": "username",
"type": "string"
},
{
"name": "age",
"type": "int"
}
]
}}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "record",
"name": "Person",
"fields": [
{"name": "name", "type": "string", "example": "Donkey"},
{"name": "age", "type": ["null", "int"], "default": null},
{
"name": "favoriteProgrammingLanguage",
"type": {"name": "ProgrammingLanguage", "type": "enum", "symbols": ["JS", "Java", "Go", "Rust", "C"]}
},
{
"name": "address",
"type": {
"name": "Address",
"type": "record",
"fields": [{"name": "zipcode", "type": "int"}, {"name": "zipcode", "type": "boolean"}]
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "record",
"name": "Person",
"fields": [
{"name": "name", "type": "string", "example": "Donkey"},
{"name": "age", "type": ["null", "int"], "default": null},
{
"name": "favoriteProgrammingLanguage",
"type": {"name": "ProgrammingLanguage", "type": "enum", "symbols": ["JS", "Java", "Go", "Rust", "C"]}
},
{
"name": "address",
"type": {
"name": "Address",
"type": "record",
"fields": [{"name": "zipcode", "type": "int"}]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.mulesoft.als.server.client.scala.LanguageServerBuilder
import org.mulesoft.als.server.modules.WorkspaceManagerFactoryBuilder
import org.mulesoft.als.server.protocol.LanguageServer
import org.mulesoft.als.server.{LanguageServerBaseTest, MockDiagnosticClientNotifier}
import org.mulesoft.lsp.feature.diagnostic.DiagnosticSeverity

import scala.concurrent.ExecutionContext

Expand All @@ -13,32 +14,6 @@ class BasicCleanDiagnosticTest extends LanguageServerBaseTest {
override implicit def executionContext: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
override def rootPath: String = "diagnostics"

test("async 2.6 with only one error") {
withServer(buildServer()) { server =>
for {
d <- requestCleanDiagnostic(server)(filePath("async26/async-api26-full.yaml"))
} yield {
server.shutdown()
assert(d.size == 1)
assert(d.head.diagnostics.size == 1)
assert(d.head.diagnostics.head.message == "Property 'error' not supported in a ASYNC 2.6 webApi node")
assert(d.head.profile == ProfileNames.ASYNC26)
}
}
}

test("Avro with only one error") {
withServer(buildServer()) { server =>
for {
d <- requestCleanDiagnostic(server)(filePath("avro/union-type-payload-error.avsc"))
} yield {
server.shutdown()
assert(d.size == 1)
assert(d.head.diagnostics.isEmpty)
assert(d.head.profile == ProfileNames.AVROSCHEMA)
}
}
}


def buildServer(): LanguageServer = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.mulesoft.als.server.modules.diagnostic.support.async

import amf.core.client.common.validation.ProfileNames
import org.mulesoft.als.server.client.scala.LanguageServerBuilder
import org.mulesoft.als.server.modules.WorkspaceManagerFactoryBuilder
import org.mulesoft.als.server.modules.diagnostic.BasicCleanDiagnosticTest
import org.mulesoft.als.server.protocol.LanguageServer
import org.mulesoft.als.server.{LanguageServerBaseTest, MockDiagnosticClientNotifier}

import scala.concurrent.ExecutionContext

class Async26CleanDiagnosticTest extends BasicCleanDiagnosticTest {

test("async 2.6 with only one error") {
withServer(buildServer()) { server =>
for {
d <- requestCleanDiagnostic(server)(filePath("async26/async-api26-full.yaml"))
} yield {
server.shutdown()
assert(d.size == 1)
assert(d.head.diagnostics.size == 1)
assert(d.head.diagnostics.head.message == "Property 'error' not supported in a ASYNC 2.6 webApi node")
assert(d.head.profile == ProfileNames.ASYNC26)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.mulesoft.als.server.modules.diagnostic.support.avro

import amf.core.client.common.validation.ProfileNames
import org.mulesoft.als.server.modules.diagnostic.BasicCleanDiagnosticTest
import org.mulesoft.lsp.feature.diagnostic.DiagnosticSeverity


class AvroCleanDiagnosticTest extends BasicCleanDiagnosticTest {

test("Async importing valid Avro") {
withServer(buildServer()) { server =>
for {
d <- requestCleanDiagnostic(server)(filePath("avro/async26-imports-valid-avro.yaml"))
} yield {
server.shutdown()
d.foreach(filediag => assert(filediag.diagnostics.isEmpty))
assert(d.size == 2)
assert(d.head.profile == ProfileNames.ASYNC26)
}
}
}

test("Async importing invalid Avro") {
withServer(buildServer()) { server =>
for {
d <- requestCleanDiagnostic(server)(filePath("avro/async26-imports-invalid-avro.yaml"))
} yield {
server.shutdown()
assert(d.size == 2)
val avroFileDiagnostics = d.find(d => d.uri.contains("avro/async26-imports-invalid-avro.yaml"))
assert(avroFileDiagnostics.isDefined)
assert(avroFileDiagnostics.get.diagnostics.length == 1)
val errorMessage = avroFileDiagnostics.get.diagnostics.head.message.toLowerCase()
assert(errorMessage.contains("duplicate") && errorMessage.contains("address"))
assert(avroFileDiagnostics.get.diagnostics.head.severity.get == DiagnosticSeverity.Error)
assert(avroFileDiagnostics.get.profile == ProfileNames.ASYNC26)
}
}
}


test("valid complex avro") {
withServer(buildServer()) { server =>
for {
d <- requestCleanDiagnostic(server)(filePath("avro/schemas/avro-user/avrotoavro.avsc"))
} yield {
server.shutdown()
assert(d.size == 1)
assert(d.head.diagnostics.isEmpty)
assert(d.head.profile == ProfileNames.AVROSCHEMA)
}
}
}

test("valid avro with unions") {
withServer(buildServer()) { server =>
for {
d <- requestCleanDiagnostic(server)(filePath("avro/schemas/union-type-payload-error.avsc"))
} yield {
server.shutdown()
assert(d.size == 1)
assert(d.head.diagnostics.isEmpty)
assert(d.head.profile == ProfileNames.AVROSCHEMA)
}
}
}
}