Search in sources :

Example 16 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionTransformer method transform.

@Override
public BaseAction transform(BaseAction action, String bridgeId, String customerId, String processorId) {
    String destinationBridgeId = action.getParameters().getOrDefault(SendToBridgeAction.BRIDGE_ID_PARAM, bridgeId);
    Bridge destinationBridge = bridgesService.getReadyBridge(destinationBridgeId, customerId);
    Map<String, String> parameters = new HashMap<>();
    try {
        parameters.put(WebhookAction.ENDPOINT_PARAM, getBridgeWebhookUrl(destinationBridge.getEndpoint()));
        parameters.put(WebhookAction.USE_TECHNICAL_BEARER_TOKEN, "true");
    } catch (MalformedURLException e) {
        throw new ActionProviderException("Can't find events webhook for bridge " + destinationBridgeId);
    }
    BaseAction transformedAction = new BaseAction();
    transformedAction.setType(WebhookAction.TYPE);
    transformedAction.setParameters(parameters);
    return transformedAction;
}
Also used : MalformedURLException(java.net.MalformedURLException) ActionProviderException(com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException) HashMap(java.util.HashMap) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) Bridge(com.redhat.service.bridge.manager.models.Bridge)

Example 17 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorAPITest method assertRequestedAction.

private void assertRequestedAction(ProcessorResponse processorResponse) {
    BaseAction baseAction = processorResponse.getAction();
    assertThat(baseAction).isNotNull();
    assertThat(baseAction.getType()).isEqualTo(KafkaTopicAction.TYPE);
    assertThat(baseAction.getParameters().get(KafkaTopicAction.TOPIC_PARAM)).isEqualTo(TestConstants.DEFAULT_KAFKA_TOPIC);
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction)

Example 18 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorAPITest method addProcessorToBridge_missingActionParameters.

@Test
@TestSecurity(user = TestConstants.DEFAULT_CUSTOMER_ID)
public void addProcessorToBridge_missingActionParameters() {
    BridgeResponse bridgeResponse = createAndDeployBridge();
    BaseAction action = createKafkaAction();
    action.getParameters().clear();
    action.getParameters().put("thisIsNotCorrect", "myTopic");
    Set<BaseFilter> filters = Collections.singleton(new StringEquals("json.key", "value"));
    Response response = TestUtils.addProcessorToBridge(bridgeResponse.getId(), new ProcessorRequest("myProcessor", filters, null, action));
    assertThat(response.getStatusCode()).isEqualTo(400);
}
Also used : StringEquals(com.redhat.service.bridge.infra.models.filters.StringEquals) ProcessorListResponse(com.redhat.service.bridge.manager.api.models.responses.ProcessorListResponse) BridgeResponse(com.redhat.service.bridge.manager.api.models.responses.BridgeResponse) ProcessorResponse(com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse) Response(io.restassured.response.Response) ProcessorRequest(com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) BridgeResponse(com.redhat.service.bridge.manager.api.models.responses.BridgeResponse) BaseFilter(com.redhat.service.bridge.infra.models.filters.BaseFilter) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 19 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionTransformerTest method testActionWithSameBridgeId.

@Test
void testActionWithSameBridgeId() {
    BaseAction inputAction = actionWithBridgeId(bridge.getId());
    BaseAction transformedAction = transformer.transform(inputAction, bridge.getId(), TEST_CUSTOMER_ID, "");
    assertValid(transformedAction, BRIDGE_WEBHOOK);
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 20 with BaseAction

use of com.redhat.service.bridge.infra.models.actions.BaseAction in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionTransformerTest method testActionWithOtherBridgeId.

@Test
void testActionWithOtherBridgeId() {
    BaseAction inputAction = actionWithBridgeId(otherBridge.getId());
    BaseAction transformedAction = transformer.transform(inputAction, bridge.getId(), TEST_CUSTOMER_ID, "");
    assertValid(transformedAction, OTHER_BRIDGE_WEBHOOK);
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)48 Test (org.junit.jupiter.api.Test)20 QuarkusTest (io.quarkus.test.junit.QuarkusTest)15 ProcessorDefinition (com.redhat.service.bridge.infra.models.processors.ProcessorDefinition)13 HashMap (java.util.HashMap)13 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)10 BaseFilter (com.redhat.service.bridge.infra.models.filters.BaseFilter)10 StringEquals (com.redhat.service.bridge.infra.models.filters.StringEquals)9 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)9 Processor (com.redhat.service.bridge.manager.models.Processor)7 Bridge (com.redhat.service.bridge.manager.models.Bridge)6 HashSet (java.util.HashSet)6 CloudEvent (io.cloudevents.CloudEvent)5 ProcessorResponse (com.redhat.service.bridge.manager.api.models.responses.ProcessorResponse)4 ValidationResult (com.redhat.service.bridge.actions.ValidationResult)3 BridgeResponse (com.redhat.service.bridge.manager.api.models.responses.BridgeResponse)3 TestSecurity (io.quarkus.test.security.TestSecurity)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Connector (com.openshift.cloud.api.connector.models.Connector)2 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)2