diff --git a/als-server/shared/src/test/resources/diagnostics/avro/async26-imports-invalid-avro.yaml b/als-server/shared/src/test/resources/diagnostics/avro/async26-imports-invalid-avro.yaml new file mode 100644 index 000000000..8e8bb6b18 --- /dev/null +++ b/als-server/shared/src/test/resources/diagnostics/avro/async26-imports-invalid-avro.yaml @@ -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 \ No newline at end of file diff --git a/als-server/shared/src/test/resources/diagnostics/avro/async26-imports-valid-avro.yaml b/als-server/shared/src/test/resources/diagnostics/avro/async26-imports-valid-avro.yaml new file mode 100644 index 000000000..3776f14b7 --- /dev/null +++ b/als-server/shared/src/test/resources/diagnostics/avro/async26-imports-valid-avro.yaml @@ -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 \ No newline at end of file diff --git a/als-server/shared/src/test/resources/diagnostics/avro/schemas/avro-user/avrotoavro.avsc b/als-server/shared/src/test/resources/diagnostics/avro/schemas/avro-user/avrotoavro.avsc new file mode 100644 index 000000000..4d560fa65 --- /dev/null +++ b/als-server/shared/src/test/resources/diagnostics/avro/schemas/avro-user/avrotoavro.avsc @@ -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" + } + ] + }} + ] +} \ No newline at end of file diff --git a/als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-invalid-payload.avsc b/als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-invalid-payload.avsc new file mode 100644 index 000000000..24f929f5c --- /dev/null +++ b/als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-invalid-payload.avsc @@ -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"}] + } + } + ] +} \ No newline at end of file diff --git a/als-server/shared/src/test/resources/diagnostics/avro/union-type-payload-error.avsc b/als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-payload-error.avsc similarity index 100% rename from als-server/shared/src/test/resources/diagnostics/avro/union-type-payload-error.avsc rename to als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-payload-error.avsc diff --git a/als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-payload.avsc b/als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-payload.avsc new file mode 100644 index 000000000..07cd0fb76 --- /dev/null +++ b/als-server/shared/src/test/resources/diagnostics/avro/schemas/union-type-payload.avsc @@ -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"}] + } + } + ] +} \ No newline at end of file diff --git a/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/BasicCleanDiagnosticTest.scala b/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/BasicCleanDiagnosticTest.scala index 62e06ca4a..2535e5401 100644 --- a/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/BasicCleanDiagnosticTest.scala +++ b/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/BasicCleanDiagnosticTest.scala @@ -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 @@ -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 = { diff --git a/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/support/async/Async26CleanDiagnosticTest.scala b/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/support/async/Async26CleanDiagnosticTest.scala new file mode 100644 index 000000000..93efea05b --- /dev/null +++ b/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/support/async/Async26CleanDiagnosticTest.scala @@ -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) + } + } + } +} diff --git a/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/support/avro/AvroCleanDiagnosticTest.scala b/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/support/avro/AvroCleanDiagnosticTest.scala new file mode 100644 index 000000000..3352bedb5 --- /dev/null +++ b/als-server/shared/src/test/scala/org/mulesoft/als/server/modules/diagnostic/support/avro/AvroCleanDiagnosticTest.scala @@ -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) + } + } + } +}