citrusframework / yaks

YAKS is a platform to enable Cloud Native BDD testing on Kubernetes
Apache License 2.0
82 stars 28 forks source link

Yaks should not parse Kamelets #263

Closed nicolaferraro closed 3 years ago

nicolaferraro commented 3 years ago

I'm using a complex integration:

apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: earthquake-source
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: Earthquake Source
    description: |-
      Get data about current earthquake events happening in the world using the USGS API
    properties:
      period:
        title: Period between polls
        description: The interval between fetches to the earthquake API in milliseconds
        type: integer
        default: 60000
      lookAhead:
        title: Look-ahead minutes
        description: The amount of minutes to look ahead when starting the integration afresh
        type: integer
        default: 120
  types:
    out:
      mediaType: application/json
  dependencies:
    - camel-quarkus:caffeine
    - camel-quarkus:http
  flow:
    from:
      uri: "timer:earthquake"
      parameters:
        period: "{{period}}"
      steps:
      - set-header:
          name: CamelCaffeineAction
          constant: GET
      - tod: "caffeine-cache:cache-${routeId}?key=lastUpdate"
      - choice:
          when:
          - simple: "${header.CamelCaffeineActionHasResult}"
            steps:
            - set-property:
                name: lastUpdate
                simple: "${body}"
          otherwise:
            steps:
            - set-property:
                name: lastUpdate
                simple: "${date-with-timezone:now-{{lookAhead}}m:UTC:yyyy-MM-dd'T'HH:mm:ss.SSS}"
      - set-header:
          name: CamelHttpMethod
          constant: GET
      - tod: "https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&updatedafter=${exchangeProperty.lastUpdate}&orderby=time-asc"
      - unmarshal:
          json: {}
      - set-property:
          name: generated
          simple: "${body[metadata][generated]}"
      - set-property:
          name: lastUpdate
          simple: "${date-with-timezone:exchangeProperty.generated:UTC:yyyy-MM-dd'T'HH:mm:ss.SSS}"
      - claim-check:
          operation: Push
      - set-body:
          exchange-property: lastUpdate
      - set-header:
          name: CamelCaffeineAction
          constant: PUT
      - tod: "caffeine-cache:cache-${routeId}?key=lastUpdate"
      - claim-check:
          operation: Pop
      - split:
          jsonpath: "$.features[*]"
          steps:
            - marshal:
                json: {}
            - to: "kamelet:sink"

When creating it in a scenario:


  Scenario: Create Kamelet from file
    Given load Kamelet earthquake-source.kamelet.yaml
    Then Kamelet earthquake-source should be available

Then it fails because it tries to parse the simple language:

test-earthquake-c14aael3jdhso6oogsu0-5fjtc test [ERROR] Errors: 
test-earthquake-c14aael3jdhso6oogsu0-5fjtc test [ERROR]   Unknown variable 'routeId'

I think the Kamelet in general do not need to contain context-specific settings, so we can disable processing on them.

christophd commented 3 years ago

This is the test variable processing that replaces variable placeholders. I think this is in general a good feature.

You can escape the variable expression so Citrus will not try to replace the variable.

${//escaped//}

nicolaferraro commented 3 years ago

This is the test variable processing that replaces variable placeholders. I think this is in general a good feature.

You can escape the variable expression so Citrus will not try to replace the variable.

${//escaped//}

Yeah, but the same file wouldn't work in Camel then. I guess I need to escape it the Camel way, which should be using $simple{routeId} instead of ${routeId}.

christophd commented 3 years ago

@nicolaferraro are you ok with the escape of simple language the Camel way?

nicolaferraro commented 3 years ago

@nicolaferraro are you ok with the escape of simple language the Camel way?

Yeah, sounds good