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

fix(webhook): incorrect type check resulting in missing return data #2442

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private List<ActiveInboundConnectorResponse> getActiveInboundConnectors(

private Map<String, Object> getData(ActiveExecutableResponse connector) {
Map<String, Object> data = Map.of();
if (WebhookConnectorExecutable.class.equals(connector.executableClass())) {
if (WebhookConnectorExecutable.class.isAssignableFrom(connector.executableClass())) {
chillleader marked this conversation as resolved.
Show resolved Hide resolved
try {
var properties = connector.elements().getFirst().rawPropertiesWithoutKeywords();
var contextPath = properties.get("inbound.context");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.inbound;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.camunda.connector.api.inbound.Health;
import io.camunda.connector.api.inbound.ProcessElement;
import io.camunda.connector.api.inbound.webhook.WebhookConnectorExecutable;
import io.camunda.connector.api.inbound.webhook.WebhookProcessingPayload;
import io.camunda.connector.api.inbound.webhook.WebhookResult;
import io.camunda.connector.runtime.core.inbound.InboundConnectorElement;
import io.camunda.connector.runtime.core.inbound.correlation.MessageCorrelationPoint.StandaloneMessageCorrelationPoint;
import io.camunda.connector.runtime.inbound.controller.InboundConnectorRestController;
import io.camunda.connector.runtime.inbound.executable.ActiveExecutableResponse;
import io.camunda.connector.runtime.inbound.executable.InboundExecutableRegistry;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;

public class InboundEndpointTest {

static class TestWebhookExecutable implements WebhookConnectorExecutable {

@Override
public WebhookResult triggerWebhook(WebhookProcessingPayload payload) throws Exception {
return null;
}
}

@Test
public void testDataReturnedForWebhookConnectorExecutableSubclass() {
var executableRegistry = mock(InboundExecutableRegistry.class);

when(executableRegistry.query(any()))
.thenReturn(
List.of(
new ActiveExecutableResponse(
UUID.randomUUID(),
TestWebhookExecutable.class,
List.of(
new InboundConnectorElement(
Map.of("inbound.context", "myPath", "inbound.type", "webhook"),
new StandaloneMessageCorrelationPoint(
"myPath", "=expression", "=myPath", null),
new ProcessElement("", 1, 1, "", ""))),
Health.up(),
Collections.emptyList())));

InboundConnectorRestController statusController =
new InboundConnectorRestController(executableRegistry);

var response = statusController.getActiveInboundConnectors(null, null, null);
assertEquals(1, response.size());
assertEquals("myPath", response.get(0).data().get("path"));
}
}