This is an automated email from the ASF dual-hosted git repository.

cdeppisch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 0b64ac126 chore: Use camel case for Pipe error handler ref
0b64ac126 is described below

commit 0b64ac1264a8e7032d7618edd9ccfca8ac933fd0
Author: Christoph Deppisch <cdeppi...@redhat.com>
AuthorDate: Tue Mar 12 20:45:40 2024 +0100

    chore: Use camel case for Pipe error handler ref
---
 pkg/apis/camel/v1/integration_types_support.go |  5 +++
 pkg/controller/pipe/integration.go             |  5 +--
 pkg/controller/pipe/integration_test.go        | 50 ++++++++++++++++++++++++++
 pkg/trait/error_handler.go                     |  5 ++-
 pkg/trait/error_handler_test.go                | 17 +++++----
 5 files changed, 68 insertions(+), 14 deletions(-)

diff --git a/pkg/apis/camel/v1/integration_types_support.go 
b/pkg/apis/camel/v1/integration_types_support.go
index e124cb71e..3705c5a05 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -116,6 +116,11 @@ func (in *IntegrationSpec) AddDependency(dependency 
string) {
        in.Dependencies = append(in.Dependencies, dependency)
 }
 
+// AddConfigurationProperty adds a new configuration property.
+func (in *IntegrationSpec) AddConfigurationProperty(confValue string) {
+       in.AddConfiguration("property", confValue)
+}
+
 // GetConfigurationProperty returns a configuration property.
 func (in *IntegrationSpec) GetConfigurationProperty(property string) string {
        for _, confSpec := range in.Configuration {
diff --git a/pkg/controller/pipe/integration.go 
b/pkg/controller/pipe/integration.go
index d78928f65..80b06d662 100644
--- a/pkg/controller/pipe/integration.go
+++ b/pkg/controller/pipe/integration.go
@@ -224,10 +224,7 @@ func configureBinding(integration *v1.Integration, 
bindings ...*bindings.Binding
                                return err
                        }
 
-                       integration.Spec.Configuration = 
append(integration.Spec.Configuration, v1.ConfigurationSpec{
-                               Type:  "property",
-                               Value: entry,
-                       })
+                       integration.Spec.AddConfigurationProperty(entry)
                }
 
        }
diff --git a/pkg/controller/pipe/integration_test.go 
b/pkg/controller/pipe/integration_test.go
index 13e16591b..30af04706 100644
--- a/pkg/controller/pipe/integration_test.go
+++ b/pkg/controller/pipe/integration_test.go
@@ -54,6 +54,56 @@ func TestCreateIntegrationForPipe(t *testing.T) {
        assert.Equal(t, expectedNominalRoute(), string(dsl))
 }
 
+func TestCreateIntegrationForPipeWithSinkErrorHandler(t *testing.T) {
+       client, err := test.NewFakeClient()
+       require.NoError(t, err)
+
+       pipe := nominalPipe("my-error-handler-pipe")
+       pipe.Spec.ErrorHandler = &v1.ErrorHandlerSpec{
+               RawMessage: []byte(`{"sink": {"endpoint": {"uri": 
"someUri"}}}`),
+       }
+
+       it, err := CreateIntegrationFor(context.TODO(), client, &pipe)
+       require.NoError(t, err)
+       assert.Equal(t, "my-error-handler-pipe", it.Name)
+       assert.Equal(t, "default", it.Namespace)
+       assert.Equal(t, "camel.apache.org/v1", it.OwnerReferences[0].APIVersion)
+       assert.Equal(t, "Pipe", it.OwnerReferences[0].Kind)
+       assert.Equal(t, "my-error-handler-pipe", it.OwnerReferences[0].Name)
+       assert.Len(t, it.Spec.Configuration, 3)
+       assert.Equal(t, 
"#class:org.apache.camel.builder.DeadLetterChannelBuilder", 
it.Spec.GetConfigurationProperty("camel.beans.defaultErrorHandler"))
+       assert.Equal(t, "someUri", 
it.Spec.GetConfigurationProperty("camel.beans.defaultErrorHandler.deadLetterUri"))
+       assert.Equal(t, "defaultErrorHandler", 
it.Spec.GetConfigurationProperty(v1.ErrorHandlerRefName))
+       dsl, err := dsl.ToYamlDSL(it.Spec.Flows)
+       require.NoError(t, err)
+       assert.Equal(t, expectedNominalRoute(), string(dsl))
+}
+
+func TestCreateIntegrationForPipeWithLogErrorHandler(t *testing.T) {
+       client, err := test.NewFakeClient()
+       require.NoError(t, err)
+
+       pipe := nominalPipe("my-error-handler-pipe")
+       pipe.Spec.ErrorHandler = &v1.ErrorHandlerSpec{
+               RawMessage: []byte(`{"log": {"parameters": {"showHeaders": 
"true"}}}`),
+       }
+
+       it, err := CreateIntegrationFor(context.TODO(), client, &pipe)
+       require.NoError(t, err)
+       assert.Equal(t, "my-error-handler-pipe", it.Name)
+       assert.Equal(t, "default", it.Namespace)
+       assert.Equal(t, "camel.apache.org/v1", it.OwnerReferences[0].APIVersion)
+       assert.Equal(t, "Pipe", it.OwnerReferences[0].Kind)
+       assert.Equal(t, "my-error-handler-pipe", it.OwnerReferences[0].Name)
+       assert.Len(t, it.Spec.Configuration, 3)
+       assert.Equal(t, 
"#class:org.apache.camel.builder.DefaultErrorHandlerBuilder", 
it.Spec.GetConfigurationProperty("camel.beans.defaultErrorHandler"))
+       assert.Equal(t, "true", 
it.Spec.GetConfigurationProperty("camel.beans.defaultErrorHandler.showHeaders"))
+       assert.Equal(t, "defaultErrorHandler", 
it.Spec.GetConfigurationProperty(v1.ErrorHandlerRefName))
+       dsl, err := dsl.ToYamlDSL(it.Spec.Flows)
+       require.NoError(t, err)
+       assert.Equal(t, expectedNominalRoute(), string(dsl))
+}
+
 func TestCreateIntegrationForPipeDataType(t *testing.T) {
        client, err := test.NewFakeClient()
        require.NoError(t, err)
diff --git a/pkg/trait/error_handler.go b/pkg/trait/error_handler.go
index 98fecde4e..c37388e69 100644
--- a/pkg/trait/error_handler.go
+++ b/pkg/trait/error_handler.go
@@ -25,7 +25,6 @@ import (
 
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
        traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait"
-
        "github.com/apache/camel-k/v2/pkg/util"
 )
 
@@ -86,8 +85,8 @@ func (t *errorHandlerTrait) addErrorHandlerDependencies(e 
*Environment, uri stri
 
 func (t *errorHandlerTrait) addGlobalErrorHandlerAsSource(e *Environment) 
error {
        flowErrorHandler := map[string]interface{}{
-               "error-handler": map[string]string{
-                       "ref-error-handler": t.ErrorHandlerRef,
+               "errorHandler": map[string]string{
+                       "refErrorHandler": t.ErrorHandlerRef,
                },
        }
        encodedFlowErrorHandler, err := 
yaml.Marshal([]map[string]interface{}{flowErrorHandler})
diff --git a/pkg/trait/error_handler_test.go b/pkg/trait/error_handler_test.go
index 114222844..d5579aa95 100644
--- a/pkg/trait/error_handler_test.go
+++ b/pkg/trait/error_handler_test.go
@@ -25,7 +25,6 @@ import (
        "github.com/stretchr/testify/require"
 
        v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
-
        "github.com/apache/camel-k/v2/pkg/util/camel"
 )
 
@@ -34,7 +33,7 @@ func TestErrorHandlerConfigureFromIntegrationProperty(t 
*testing.T) {
                Catalog:     NewEnvironmentTestCatalog(),
                Integration: &v1.Integration{},
        }
-       e.Integration.Spec.AddConfiguration("property", fmt.Sprintf("%v = %s", 
v1.ErrorHandlerRefName, "defaultErrorHandler"))
+       e.Integration.Spec.AddConfigurationProperty(fmt.Sprintf("%v = %s", 
v1.ErrorHandlerRefName, "defaultErrorHandler"))
 
        trait := newErrorHandlerTrait()
        enabled, condition, err := trait.Configure(e)
@@ -72,8 +71,8 @@ func TestErrorHandlerApplySource(t *testing.T) {
 
        err = trait.Apply(e)
        require.NoError(t, err)
-       assert.Equal(t, `- error-handler:
-    ref-error-handler: defaultErrorHandler
+       assert.Equal(t, `- errorHandler:
+    refErrorHandler: defaultErrorHandler
 `, e.Integration.Status.GeneratedSources[0].Content)
 }
 
@@ -85,9 +84,9 @@ func TestErrorHandlerApplyDependency(t *testing.T) {
                CamelCatalog: c,
                Integration:  &v1.Integration{},
        }
-       e.Integration.Spec.AddConfiguration("property", 
"camel.beans.defaultErrorHandler = 
#class:org.apache.camel.builder.DeadLetterChannelBuilder")
-       e.Integration.Spec.AddConfiguration("property", 
"camel.beans.defaultErrorHandler.deadLetterUri = log:info")
-       e.Integration.Spec.AddConfiguration("property", fmt.Sprintf("%v = %s", 
v1.ErrorHandlerRefName, "defaultErrorHandler"))
+       
e.Integration.Spec.AddConfigurationProperty("camel.beans.defaultErrorHandler = 
#class:org.apache.camel.builder.DeadLetterChannelBuilder")
+       
e.Integration.Spec.AddConfigurationProperty("camel.beans.defaultErrorHandler.deadLetterUri
 = log:info")
+       e.Integration.Spec.AddConfigurationProperty(fmt.Sprintf("%v = %s", 
v1.ErrorHandlerRefName, "defaultErrorHandler"))
        e.Integration.Status.Phase = v1.IntegrationPhaseInitialization
 
        trait := newErrorHandlerTrait()
@@ -98,5 +97,9 @@ func TestErrorHandlerApplyDependency(t *testing.T) {
 
        err = trait.Apply(e)
        require.NoError(t, err)
+       assert.Len(t, e.Integration.Spec.Configuration, 3)
+       assert.Equal(t, 
"#class:org.apache.camel.builder.DeadLetterChannelBuilder", 
e.Integration.Spec.GetConfigurationProperty("camel.beans.defaultErrorHandler"))
+       assert.Equal(t, "log:info", 
e.Integration.Spec.GetConfigurationProperty("camel.beans.defaultErrorHandler.deadLetterUri"))
+       assert.Equal(t, "defaultErrorHandler", 
e.Integration.Spec.GetConfigurationProperty(v1.ErrorHandlerRefName))
        assert.Equal(t, "camel:log", e.Integration.Status.Dependencies[0])
 }

Reply via email to