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

CAMEL-10013: Implemented test validating syntax of endpoint #3023

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,14 +16,20 @@
*/
package org.apache.camel.catalog;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class CamelCatalogJsonSchemaTest {

Expand All @@ -46,6 +52,38 @@ public void testValidateJsonComponent() throws Exception {
assertTrue(name, tree.has("component"));
assertTrue(name, tree.has("componentProperties"));
assertTrue(name, tree.has("properties"));

validateComponentSyntax(name, tree);
}
}

private void validateComponentSyntax(String name, JsonNode tree) {
String syntax = tree.get("component").get("syntax").textValue();
assertFalse("Empty syntax for component " + name, syntax.isEmpty());
List<String> pathProperties = new ArrayList<>();
List<String> requiredProperties = new ArrayList<>();

Iterator<Map.Entry<String, JsonNode>> it = tree.get("properties").fields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> property = it.next();
if ("path".equals(property.getValue().get("kind").textValue())) {
pathProperties.add(property.getKey());
if (property.getValue().get("required").booleanValue()) {
requiredProperties.add(property.getKey());
}
}
}
List<String> syntaxParts = Arrays.asList(syntax.split("[/:#.]"));
Assert.assertEquals("Syntax must start with component name", name, syntaxParts.get(0));

for (String part : syntaxParts.subList(1, syntaxParts.size())) {
if (!part.isEmpty()) {
Assert.assertTrue(String.format("Component %s. Syntax %s. Part %s is not defined as UriPath", name, syntax, part), pathProperties.contains(part));
}
}

for (String requiredPart : requiredProperties) {
Assert.assertTrue(String.format("Component %s. Syntax %s. Required param %s is not defined in syntax", name, syntax, requiredPart), syntaxParts.contains(requiredPart));
}
}

Expand Down
Expand Up @@ -54,7 +54,7 @@ The ChatScript component supports 2 options, which are listed below.
The ChatScript endpoint is configured using URI syntax:

----
chatscript:host:port/botname
chatscript:host:port/botName
----

with the following path and query parameters:
Expand Down
Expand Up @@ -36,7 +36,7 @@
/**
* Represents a ChatScript endpoint.
*/
@UriEndpoint(firstVersion = "3.0.0", scheme = "chatscript", title = "ChatScript", syntax = "chatscript:host:port/botname", producerOnly = true, label = "ai,chatscript")
@UriEndpoint(firstVersion = "3.0.0", scheme = "chatscript", title = "ChatScript", syntax = "chatscript:host:port/botName", producerOnly = true, label = "ai,chatscript")
public class ChatScriptEndpoint extends DefaultEndpoint {
@UriPath (description = "Hostname or IP of the server on which CS server is running")
@Metadata(required = true)
Expand Down
Expand Up @@ -76,7 +76,7 @@ The Google BigQuery component supports 5 options, which are listed below.
The Google BigQuery endpoint is configured using URI syntax:

----
google-bigquery:projectId:datasetId:tableName
google-bigquery:projectId:datasetId:tableId
----

with the following path and query parameters:
Expand Down
Expand Up @@ -92,7 +92,7 @@ The Google BigQuery Standard SQL component supports 4 options, which are listed
The Google BigQuery Standard SQL endpoint is configured using URI syntax:

----
google-bigquery-sql:query
google-bigquery-sql:projectId:query
----

with the following path and query parameters:
Expand All @@ -103,8 +103,8 @@ with the following path and query parameters:
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *projectId* | *Required* Google Cloud Project Id | | String
| *query* | *Required* BigQuery standard SQL query | | String
| *projectId* | *Required* Google Cloud Project Id | | String
|===


Expand Down
Expand Up @@ -40,7 +40,7 @@
* Another consideration is that exceptions are not handled within the class. They are expected to bubble up and be handled
* by Camel.
*/
@UriEndpoint(firstVersion = "2.20.0", scheme = "google-bigquery", title = "Google BigQuery", syntax = "google-bigquery:projectId:datasetId:tableName",
@UriEndpoint(firstVersion = "2.20.0", scheme = "google-bigquery", title = "Google BigQuery", syntax = "google-bigquery:projectId:datasetId:tableId",
label = "cloud,messaging", producerOnly = true)
public class GoogleBigQueryEndpoint extends DefaultEndpoint {

Expand Down
Expand Up @@ -41,7 +41,7 @@
* Another consideration is that exceptions are not handled within the class. They are expected to bubble up and be handled
* by Camel.
*/
@UriEndpoint(firstVersion = "2.23.0", scheme = "google-bigquery-sql", title = "Google BigQuery Standard SQL", syntax = "google-bigquery-sql:query", label = "cloud,messaging", producerOnly = true)
@UriEndpoint(firstVersion = "2.23.0", scheme = "google-bigquery-sql", title = "Google BigQuery Standard SQL", syntax = "google-bigquery-sql:projectId:query", label = "cloud,messaging", producerOnly = true)
public class GoogleBigQuerySQLEndpoint extends DefaultEndpoint {

@UriParam
Expand Down
6 changes: 4 additions & 2 deletions components/camel-ipfs/src/main/docs/ipfs-component.adoc
Expand Up @@ -44,17 +44,19 @@ The IPFS component supports 2 options, which are listed below.
The IPFS endpoint is configured using URI syntax:

----
ipfs:host:port/cmd
ipfs:ipfsHost:ipfsPort/ipfsCmd
----

with the following path and query parameters:

==== Path Parameters (1 parameters):
==== Path Parameters (3 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *ipfsHost* | The ipfs host | | String
| *ipfsPort* | The ipfs port | | int
| *ipfsCmd* | The ipfs command | | String
|===

Expand Down
Expand Up @@ -32,14 +32,15 @@ public class IPFSConfiguration {
public enum IPFSCommand {
add, cat, get, version
}

@UriPath(description = "The ipfs command")
private String ipfsCmd;
@UriParam(description = "The ipfs output directory")
private Path outdir;

@UriPath(description = "The ipfs host")
private String ipfsHost = "127.0.0.1";
@UriPath(description = "The ipfs port")
private int ipfsPort = 5001;
@UriPath(description = "The ipfs command", enums = "add,cat,get,version")
private String ipfsCmd;
@UriParam(description = "The ipfs output directory")
private Path outdir;

public IPFSConfiguration(IPFSComponent component) {
ObjectHelper.notNull(component, "component");
Expand Down
Expand Up @@ -46,7 +46,7 @@
* The camel-ipfs component provides access to the Interplanetary File System
* (IPFS).
*/
@UriEndpoint(firstVersion = "2.23.0", scheme = "ipfs", title = "IPFS", syntax = "ipfs:host:port/cmd", producerOnly = true, label = "file,ipfs")
@UriEndpoint(firstVersion = "2.23.0", scheme = "ipfs", title = "IPFS", syntax = "ipfs:ipfsHost:ipfsPort/ipfsCmd", producerOnly = true, label = "file,ipfs")
public class IPFSEndpoint extends DefaultEndpoint {

public static final long DEFAULT_TIMEOUT = 10000L;
Expand Down
Expand Up @@ -54,7 +54,7 @@ The PostgresSQL Replication Slot component supports 2 options, which are listed
The PostgresSQL Replication Slot endpoint is configured using URI syntax:

----
pg-replication-slot:host:port/database/slot:plugin
pg-replication-slot:host:port/database/slot:outputPlugin
----

with the following path and query parameters:
Expand Down
Expand Up @@ -40,7 +40,7 @@
* Consumer endpoint to receive from PostgreSQL Replication Slot.
*/
@UriEndpoint(firstVersion = "3.0.0", scheme = "pg-replication-slot", title = "PostgresSQL Replication Slot",
syntax = "pg-replication-slot:host:port/database/slot:plugin", label = "database,sql", consumerOnly = true)
syntax = "pg-replication-slot:host:port/database/slot:outputPlugin", label = "database,sql", consumerOnly = true)
public class PgReplicationSlotEndpoint extends ScheduledPollEndpoint {

private static final Pattern URI_PATTERN = Pattern.compile(
Expand Down
Expand Up @@ -67,7 +67,7 @@ The Soroush component supports 3 options, which are listed below.
The Soroush endpoint is configured using URI syntax:

----
soroush:action/authorizationToken
soroush:action
----

with the following path and query parameters:
Expand Down
Expand Up @@ -55,7 +55,7 @@
/**
* To integrate with the Soroush chat bot.
*/
@UriEndpoint(firstVersion = "3.0", scheme = "soroush", title = "Soroush", syntax = "soroush:action/authorizationToken", label = "chat")
@UriEndpoint(firstVersion = "3.0", scheme = "soroush", title = "Soroush", syntax = "soroush:action", label = "chat")
public class SoroushBotEndpoint extends DefaultEndpoint {

private static final Logger LOG = LoggerFactory.getLogger(SoroushBotEndpoint.class);
Expand Down
Expand Up @@ -27,7 +27,7 @@ The Wordpress component supports 3 options, which are listed below.
The Wordpress endpoint is configured using URI syntax:

----
wordpress:operationDetail
wordpress:operation
----

with the following path and query parameters:
Expand Down
Expand Up @@ -45,7 +45,7 @@
/**
* Integrates Camel with Wordpress.
*/
@UriEndpoint(firstVersion = "2.21.0", scheme = "wordpress", title = "Wordpress", syntax = "wordpress:operationDetail", label = "cms")
@UriEndpoint(firstVersion = "2.21.0", scheme = "wordpress", title = "Wordpress", syntax = "wordpress:operation", label = "cms")
public class WordpressEndpoint extends DefaultEndpoint {

public static final String ENDPOINT_SERVICE_POST = "post, user";
Expand Down
14 changes: 7 additions & 7 deletions components/readme.adoc
Expand Up @@ -161,7 +161,7 @@ Number of Components: 297 in 234 JAR artifacts (0 deprecated)
`cql:beanRef:hosts:port/keyspace` | 2.15 | The cql component aims at integrating Cassandra 2.0 using the CQL3 API (not the Thrift API).

| link:camel-chatscript/src/main/docs/chatscript-component.adoc[ChatScript] (camel-chatscript) +
`chatscript:host:port/botname` | 3.0 | Represents a ChatScript endpoint.
`chatscript:host:port/botName` | 3.0 | Represents a ChatScript endpoint.

| link:camel-chunk/src/main/docs/chunk-component.adoc[Chunk] (camel-chunk) +
`chunk:resourceUri` | 2.15 | Transforms the message using a Chunk template.
Expand Down Expand Up @@ -299,10 +299,10 @@ Number of Components: 297 in 234 JAR artifacts (0 deprecated)
`github:type/branchName` | 2.15 | The github component is used for integrating Camel with github.

| link:camel-google-bigquery/src/main/docs/google-bigquery-component.adoc[Google BigQuery] (camel-google-bigquery) +
`google-bigquery:projectId:datasetId:tableName` | 2.20 | Google BigQuery data warehouse for analytics.
`google-bigquery:projectId:datasetId:tableId` | 2.20 | Google BigQuery data warehouse for analytics.

| link:camel-google-bigquery/src/main/docs/google-bigquery-sql-component.adoc[Google BigQuery Standard SQL] (camel-google-bigquery) +
`google-bigquery-sql:query` | 2.23 | Google BigQuery data warehouse for analytics (using SQL queries).
`google-bigquery-sql:projectId:query` | 2.23 | Google BigQuery data warehouse for analytics (using SQL queries).

| link:camel-google-calendar/src/main/docs/google-calendar-component.adoc[Google Calendar] (camel-google-calendar) +
`google-calendar:apiName/methodName` | 2.15 | The google-calendar component provides access to Google Calendar.
Expand Down Expand Up @@ -422,7 +422,7 @@ Number of Components: 297 in 234 JAR artifacts (0 deprecated)
`iota:name` | 2.23 | Component for integrate IOTA DLT

| link:camel-ipfs/src/main/docs/ipfs-component.adoc[IPFS] (camel-ipfs) +
`ipfs:host:port/cmd` | 2.23 | The camel-ipfs component provides access to the Interplanetary File System (IPFS).
`ipfs:ipfsHost:ipfsPort/ipfsCmd` | 2.23 | The camel-ipfs component provides access to the Interplanetary File System (IPFS).

| link:camel-irc/src/main/docs/irc-component.adoc[IRC] (camel-irc) +
`irc:hostname:port` | 1.1 | The irc component implements an IRC (Internet Relay Chat) transport.
Expand Down Expand Up @@ -668,7 +668,7 @@ Number of Components: 297 in 234 JAR artifacts (0 deprecated)
`pgevent:host:port/database/channel` | 2.15 | The pgevent component allows for producing/consuming PostgreSQL events related to the listen/notify commands.

| link:camel-pg-replication-slot/src/main/docs/pg-replication-slot-component.adoc[PostgresSQL Replication Slot] (camel-pg-replication-slot) +
`pg-replication-slot:host:port/database/slot:plugin` | 3.0 | Consumer endpoint to receive from PostgreSQL Replication Slot.
`pg-replication-slot:host:port/database/slot:outputPlugin` | 3.0 | Consumer endpoint to receive from PostgreSQL Replication Slot.

| link:camel-printer/src/main/docs/lpr-component.adoc[Printer] (camel-printer) +
`lpr:hostname:port/printername` | 2.1 | The printer component is used for sending messages to printers as print jobs.
Expand Down Expand Up @@ -767,7 +767,7 @@ Number of Components: 297 in 234 JAR artifacts (0 deprecated)
`solr:url` | 2.9 | The solr component allows you to interface with an Apache Lucene Solr server.

| link:camel-soroush/src/main/docs/soroush-component.adoc[Soroush] (camel-soroush) +
`soroush:action/authorizationToken` | 3.0 | To integrate with the Soroush chat bot.
`soroush:action` | 3.0 | To integrate with the Soroush chat bot.

| link:camel-spark-rest/src/main/docs/spark-rest-component.adoc[Spark Rest] (camel-spark-rest) +
`spark-rest:verb:path` | 2.14 | The spark-rest component is used for hosting REST services which has been defined using Camel rest-dsl.
Expand Down Expand Up @@ -869,7 +869,7 @@ Number of Components: 297 in 234 JAR artifacts (0 deprecated)
`webhook:endpointUri` | 3.0 | The webhook component allows other Camel components that can receive push notifications to expose webhook endpoints and automatically register them with their own webhook provider.

| link:camel-wordpress/src/main/docs/wordpress-component.adoc[Wordpress] (camel-wordpress) +
`wordpress:operationDetail` | 2.21 | Integrates Camel with Wordpress.
`wordpress:operation` | 2.21 | Integrates Camel with Wordpress.

| link:camel-xchange/src/main/docs/xchange-component.adoc[XChange] (camel-xchange) +
`xchange:name` | 2.21 | The camel-xchange component provide access to many bitcoin and altcoin exchanges for trading and accessing market data.
Expand Down
Expand Up @@ -144,7 +144,7 @@ default AdvancedChatScriptEndpointBuilder synchronous(String synchronous) {
* Available as of version: 3.0
* Maven coordinates: org.apache.camel:camel-chatscript
*
* Syntax: <code>chatscript:host:port/botname</code>
* Syntax: <code>chatscript:host:port/botName</code>
*
* Path parameter: host (required)
* Hostname or IP of the server on which CS server is running
Expand Down
Expand Up @@ -150,7 +150,7 @@ default AdvancedGoogleBigQueryEndpointBuilder synchronous(
* Available as of version: 2.20
* Maven coordinates: org.apache.camel:camel-google-bigquery
*
* Syntax: <code>google-bigquery:projectId:datasetId:tableName</code>
* Syntax: <code>google-bigquery:projectId:datasetId:tableId</code>
*
* Path parameter: projectId (required)
* Google Cloud Project Id
Expand Down
Expand Up @@ -140,13 +140,13 @@ default AdvancedGoogleBigQuerySQLEndpointBuilder synchronous(
* Available as of version: 2.23
* Maven coordinates: org.apache.camel:camel-google-bigquery
*
* Syntax: <code>google-bigquery-sql:query</code>
*
* Path parameter: projectId (required)
* Google Cloud Project Id
* Syntax: <code>google-bigquery-sql:projectId:query</code>
*
* Path parameter: query (required)
* BigQuery standard SQL query
*
* Path parameter: projectId (required)
* Google Cloud Project Id
*/
default GoogleBigQuerySQLEndpointBuilder googleBigQuerySQL(String path) {
class GoogleBigQuerySQLEndpointBuilderImpl extends AbstractEndpointBuilder implements GoogleBigQuerySQLEndpointBuilder, AdvancedGoogleBigQuerySQLEndpointBuilder {
Expand Down
Expand Up @@ -133,10 +133,17 @@ default AdvancedIPFSEndpointBuilder synchronous(String synchronous) {
* Available as of version: 2.23
* Maven coordinates: org.apache.camel:camel-ipfs
*
* Syntax: <code>ipfs:host:port/cmd</code>
* Syntax: <code>ipfs:ipfsHost:ipfsPort/ipfsCmd</code>
*
* Path parameter: ipfsHost
* The ipfs host
*
* Path parameter: ipfsPort
* The ipfs port
*
* Path parameter: ipfsCmd
* The ipfs command
* The value can be one of: add, cat, get, version
*/
default IPFSEndpointBuilder iPFS(String path) {
class IPFSEndpointBuilderImpl extends AbstractEndpointBuilder implements IPFSEndpointBuilder, AdvancedIPFSEndpointBuilder {
Expand Down
Expand Up @@ -214,7 +214,8 @@ default AdvancedPgReplicationSlotEndpointBuilder synchronous(
* Available as of version: 3.0
* Maven coordinates: org.apache.camel:camel-pg-replication-slot
*
* Syntax: <code>pg-replication-slot:host:port/database/slot:plugin</code>
* Syntax:
* <code>pg-replication-slot:host:port/database/slot:outputPlugin</code>
*
* Path parameter: slot (required)
* Replication slot name.
Expand Down
Expand Up @@ -1256,7 +1256,7 @@ default AdvancedSoroushBotEndpointBuilder synchronous(String synchronous) {
* Available as of version: 3.0
* Maven coordinates: org.apache.camel:camel-soroush
*
* Syntax: <code>soroush:action/authorizationToken</code>
* Syntax: <code>soroush:action</code>
*
* Path parameter: action (required)
* The action to do.
Expand Down
Expand Up @@ -828,7 +828,7 @@ default AdvancedWordpressEndpointBuilder synchronous(String synchronous) {
* Available as of version: 2.21
* Maven coordinates: org.apache.camel:camel-wordpress
*
* Syntax: <code>wordpress:operationDetail</code>
* Syntax: <code>wordpress:operation</code>
*
* Path parameter: operation (required)
* The endpoint operation.
Expand Down
Expand Up @@ -54,7 +54,7 @@ The ChatScript component supports 2 options, which are listed below.
The ChatScript endpoint is configured using URI syntax:

----
chatscript:host:port/botname
chatscript:host:port/botName
----

with the following path and query parameters:
Expand Down
Expand Up @@ -76,7 +76,7 @@ The Google BigQuery component supports 5 options, which are listed below.
The Google BigQuery endpoint is configured using URI syntax:

----
google-bigquery:projectId:datasetId:tableName
google-bigquery:projectId:datasetId:tableId
----

with the following path and query parameters:
Expand Down