Skip to content

Commit

Permalink
Can't set Knative broker name #535
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Oct 26, 2020
1 parent 8e06755 commit 2d422a7
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class Knative {
public static final String KNATIVE_TYPE = "knative.type";
public static final String KNATIVE_EVENT_TYPE = "knative.event.type";
public static final String KNATIVE_KIND = "knative.kind";
public static final String KNATIVE_NAME = "knative.name";
public static final String KNATIVE_API_VERSION = "knative.apiVersion";
public static final String KNATIVE_REPLY = "knative.reply";
public static final String CONTENT_TYPE = "content.type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.knative.KnativeComponent;
import org.apache.camel.component.knative.KnativeEndpoint;
import org.apache.camel.component.knative.spi.CloudEvent;
import org.apache.camel.component.knative.spi.CloudEvents;
import org.apache.camel.component.knative.spi.Knative;
Expand Down Expand Up @@ -1061,7 +1062,7 @@ void testEvents(CloudEvent ce) throws Exception {

@ParameterizedTest
@EnumSource(CloudEvents.class)
void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception {
void testEventsWithResourceRef(CloudEvent ce) throws Exception {
configureKnativeComponent(
context,
ce,
Expand All @@ -1073,27 +1074,42 @@ void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception {
Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
Knative.CONTENT_TYPE, "text/plain",
Knative.KNATIVE_KIND, "MyObject",
Knative.KNATIVE_API_VERSION, "v1"
Knative.KNATIVE_API_VERSION, "v1",
Knative.KNATIVE_NAME, "myName1"
)),
sourceEvent(
"default",
Map.of(
Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
Knative.CONTENT_TYPE, "text/plain",
Knative.KNATIVE_KIND, "MyOtherObject",
Knative.KNATIVE_API_VERSION, "v2"
Knative.KNATIVE_API_VERSION, "v2",
Knative.KNATIVE_NAME, "myName2"
))
);

RouteBuilder.addRoutes(context, b -> {
b.from("direct:source")
.to("knative:event/myEvent?kind=MyObject&apiVersion=v1");
b.from("knative:event/myEvent?kind=MyOtherObject&apiVersion=v2")
.to("knative:event/myEvent?kind=MyObject&apiVersion=v1&name=myName1");
b.from("knative:event/myEvent?kind=MyOtherObject&apiVersion=v2&name=myName2")
.to("mock:ce");
});

context.start();

assertThat(context.getEndpoint("knative:event/myEvent?kind=MyObject&apiVersion=v1&name=myName1", KnativeEndpoint.class)).satisfies(e -> {
assertThat(e.getType()).isEqualTo(Knative.Type.event);
assertThat(e.getTypeId()).isEqualTo("myEvent");
assertThat(e.getConfiguration().getTypeId()).isEqualTo("myEvent");
assertThat(e.getConfiguration().getName()).isEqualTo("myName1");
});
assertThat(context.getEndpoint("knative:event/myEvent?kind=MyOtherObject&apiVersion=v2&name=myName2", KnativeEndpoint.class)).satisfies(e -> {
assertThat(e.getType()).isEqualTo(Knative.Type.event);
assertThat(e.getTypeId()).isEqualTo("myEvent");
assertThat(e.getConfiguration().getTypeId()).isEqualTo("myEvent");
assertThat(e.getConfiguration().getName()).isEqualTo("myName2");
});

MockEndpoint mock = context.getEndpoint("mock:ce", MockEndpoint.class);
mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, ce.version());
mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_TYPE, "myEvent");
Expand All @@ -1110,7 +1126,7 @@ void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception {

@ParameterizedTest
@EnumSource(CloudEvents.class)
void testConsumeContentWithTypeAndVersion(CloudEvent ce) throws Exception {
void testConsumeContentWithResourceRef(CloudEvent ce) throws Exception {
configureKnativeComponent(
context,
ce,
Expand All @@ -1120,25 +1136,34 @@ void testConsumeContentWithTypeAndVersion(CloudEvent ce) throws Exception {
Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
Knative.CONTENT_TYPE, "text/plain",
Knative.KNATIVE_KIND, "MyObject",
Knative.KNATIVE_API_VERSION, "v1"
Knative.KNATIVE_API_VERSION, "v1",
Knative.KNATIVE_NAME, "myName1"
)),
sourceEndpoint(
"myEndpoint",
Map.of(
Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
Knative.CONTENT_TYPE, "text/plain",
Knative.KNATIVE_KIND, "MyObject",
Knative.KNATIVE_API_VERSION, "v2"
Knative.KNATIVE_API_VERSION, "v2",
Knative.KNATIVE_NAME, "myName2"
))
);

RouteBuilder.addRoutes(context, b -> {
b.from("knative:endpoint/myEndpoint?kind=MyObject&apiVersion=v2")
b.from("knative:endpoint/myEndpoint?kind=MyObject&apiVersion=v2&name=myName2")
.to("mock:ce");
});

context.start();

assertThat(context.getEndpoint("knative:endpoint/myEndpoint?kind=MyObject&apiVersion=v2&name=myName2", KnativeEndpoint.class)).satisfies(e -> {
assertThat(e.getType()).isEqualTo(Knative.Type.endpoint);
assertThat(e.getTypeId()).isEqualTo("myEndpoint");
assertThat(e.getConfiguration().getTypeId()).isEqualTo("myEndpoint");
assertThat(e.getConfiguration().getName()).isEqualTo("myName2");
});

MockEndpoint mock = context.getEndpoint("mock:ce", MockEndpoint.class);
mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, ce.version());
mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ public class KnativeComponentConfigurer extends PropertyConfigurerSupport implem
map.put("environment", org.apache.camel.component.knative.spi.KnativeEnvironment.class);
map.put("environmentPath", java.lang.String.class);
map.put("filters", java.util.Map.class);
map.put("serviceName", java.lang.String.class);
map.put("transport", org.apache.camel.component.knative.spi.KnativeTransport.class);
map.put("transportOptions", java.util.Map.class);
map.put("typeId", java.lang.String.class);
map.put("bridgeErrorHandler", boolean.class);
map.put("replyWithCloudEvent", boolean.class);
map.put("reply", java.lang.Boolean.class);
map.put("lazyStartProducer", boolean.class);
map.put("apiVersion", java.lang.String.class);
map.put("basicPropertyBinding", boolean.class);
map.put("kind", java.lang.String.class);
map.put("name", java.lang.String.class);
ALL_OPTIONS = map;
}

Expand Down Expand Up @@ -69,14 +70,15 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "kind": getOrCreateConfiguration(target).setKind(property(camelContext, java.lang.String.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
case "name": getOrCreateConfiguration(target).setName(property(camelContext, java.lang.String.class, value)); return true;
case "reply": getOrCreateConfiguration(target).setReply(property(camelContext, java.lang.Boolean.class, value)); return true;
case "replywithcloudevent":
case "replyWithCloudEvent": getOrCreateConfiguration(target).setReplyWithCloudEvent(property(camelContext, boolean.class, value)); return true;
case "servicename":
case "serviceName": getOrCreateConfiguration(target).setServiceName(property(camelContext, java.lang.String.class, value)); return true;
case "transport": target.setTransport(property(camelContext, org.apache.camel.component.knative.spi.KnativeTransport.class, value)); return true;
case "transportoptions":
case "transportOptions": getOrCreateConfiguration(target).setTransportOptions(property(camelContext, java.util.Map.class, value)); return true;
case "typeid":
case "typeId": getOrCreateConfiguration(target).setTypeId(property(camelContext, java.lang.String.class, value)); return true;
default: return false;
}
}
Expand Down Expand Up @@ -110,14 +112,15 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "kind": return getOrCreateConfiguration(target).getKind();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "name": return getOrCreateConfiguration(target).getName();
case "reply": return getOrCreateConfiguration(target).getReply();
case "replywithcloudevent":
case "replyWithCloudEvent": return getOrCreateConfiguration(target).isReplyWithCloudEvent();
case "servicename":
case "serviceName": return getOrCreateConfiguration(target).getServiceName();
case "transport": return target.getTransport();
case "transportoptions":
case "transportOptions": return getOrCreateConfiguration(target).getTransportOptions();
case "typeid":
case "typeId": return getOrCreateConfiguration(target).getTypeId();
default: return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ public class KnativeEndpointConfigurer extends PropertyConfigurerSupport impleme
static {
Map<String, Object> map = new CaseInsensitiveMap();
map.put("type", org.apache.camel.component.knative.spi.Knative.Type.class);
map.put("name", java.lang.String.class);
map.put("typeId", java.lang.String.class);
map.put("ceOverride", java.util.Map.class);
map.put("cloudEventsSpecVersion", java.lang.String.class);
map.put("cloudEventsType", java.lang.String.class);
map.put("environment", org.apache.camel.component.knative.spi.KnativeEnvironment.class);
map.put("filters", java.util.Map.class);
map.put("serviceName", java.lang.String.class);
map.put("transportOptions", java.util.Map.class);
map.put("bridgeErrorHandler", boolean.class);
map.put("replyWithCloudEvent", boolean.class);
Expand All @@ -36,6 +35,7 @@ public class KnativeEndpointConfigurer extends PropertyConfigurerSupport impleme
map.put("apiVersion", java.lang.String.class);
map.put("basicPropertyBinding", boolean.class);
map.put("kind", java.lang.String.class);
map.put("name", java.lang.String.class);
map.put("synchronous", boolean.class);
ALL_OPTIONS = map;
}
Expand Down Expand Up @@ -65,11 +65,10 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "kind": target.getConfiguration().setKind(property(camelContext, java.lang.String.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
case "name": target.getConfiguration().setName(property(camelContext, java.lang.String.class, value)); return true;
case "reply": target.getConfiguration().setReply(property(camelContext, java.lang.Boolean.class, value)); return true;
case "replywithcloudevent":
case "replyWithCloudEvent": target.getConfiguration().setReplyWithCloudEvent(property(camelContext, boolean.class, value)); return true;
case "servicename":
case "serviceName": target.getConfiguration().setServiceName(property(camelContext, java.lang.String.class, value)); return true;
case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true;
case "transportoptions":
case "transportOptions": target.getConfiguration().setTransportOptions(property(camelContext, java.util.Map.class, value)); return true;
Expand Down Expand Up @@ -107,11 +106,10 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "kind": return target.getConfiguration().getKind();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "name": return target.getConfiguration().getName();
case "reply": return target.getConfiguration().getReply();
case "replywithcloudevent":
case "replyWithCloudEvent": return target.getConfiguration().isReplyWithCloudEvent();
case "servicename":
case "serviceName": return target.getConfiguration().getServiceName();
case "synchronous": return target.isSynchronous();
case "transportoptions":
case "transportOptions": return target.getConfiguration().getTransportOptions();
Expand Down
Loading

0 comments on commit 2d422a7

Please sign in to comment.