LoRez commented on code in PR #9191: URL: https://github.com/apache/camel/pull/9191#discussion_r1085325346
########## components/camel-zeebe/src/test/java/org/apache/camel/component/zeebe/ResourceDeploymentIntegrationTest.java: ########## @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); 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 org.apache.camel.component.zeebe; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.component.zeebe.model.DeploymentRequest; +import org.apache.camel.component.zeebe.model.DeploymentResponse; +import org.apache.camel.component.zeebe.model.ProcessDeploymentResponse; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Tag("standalone") +public class ResourceDeploymentIntegrationTest extends CamelTestSupport { + + public static final String RESOURCE_PATH = "data/"; + public static final String RESOURCE_NAME = "test1_definition.bpmn"; + + public static final String INVALID_RESOURCE_NAME = "test1_definition.txt"; + + protected ZeebeComponent component; + + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Test + void testUploadProcessDefinition() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:deployResource"); + mock.expectedMinimumMessageCount(1); + mock.expectedHeaderReceived(ZeebeConstants.IS_SUCCESS, true); + mock.expectedHeaderReceived(ZeebeConstants.RESOURCE_NAME, RESOURCE_NAME); + + DeploymentRequest deploymentRequest = new DeploymentRequest(); + deploymentRequest.setName(RESOURCE_NAME); + deploymentRequest + .setContent(this.getClass().getClassLoader().getResourceAsStream(RESOURCE_PATH + RESOURCE_NAME).readAllBytes()); + + template.sendBody("direct:deployResource", deploymentRequest); + MockEndpoint.assertIsSatisfied(context); + if (!mock.getExchanges().isEmpty()) { + Exchange exchange = mock.getExchanges().get(0); + Object body = exchange.getIn().getBody(); + assertTrue(body instanceof ProcessDeploymentResponse); + assertTrue(((ProcessDeploymentResponse) body).isSuccess()); + assertTrue(exchange.getIn().getHeaders().containsKey(ZeebeConstants.PROCESS_DEFINITION_KEY)); + assertTrue(exchange.getIn().getHeaders().containsKey(ZeebeConstants.BPMN_PROCESS_ID)); + assertTrue(exchange.getIn().getHeaders().containsKey(ZeebeConstants.VERSION)); + } + + // Deploy with resource name in header and resource as byte[] in body + template.sendBodyAndHeader("direct:deployResource", + this.getClass().getClassLoader().getResourceAsStream(RESOURCE_PATH + RESOURCE_NAME).readAllBytes(), + ZeebeConstants.RESOURCE_NAME, RESOURCE_NAME); + MockEndpoint.assertIsSatisfied(context); + if (!mock.getExchanges().isEmpty()) { + Exchange exchange = mock.getExchanges().get(0); + Object body = exchange.getIn().getBody(); + assertTrue(body instanceof ProcessDeploymentResponse); + assertTrue(((ProcessDeploymentResponse) body).isSuccess()); + } + + // Deploy with resource name in header and resource as String in body + template.sendBodyAndHeader("direct:deployResource", + new String(this.getClass().getClassLoader().getResourceAsStream(RESOURCE_PATH + RESOURCE_NAME).readAllBytes()), + ZeebeConstants.RESOURCE_NAME, RESOURCE_NAME); + MockEndpoint.assertIsSatisfied(context); + if (!mock.getExchanges().isEmpty()) { + Exchange exchange = mock.getExchanges().get(0); + Object body = exchange.getIn().getBody(); + assertTrue(body instanceof ProcessDeploymentResponse); + assertTrue(((ProcessDeploymentResponse) body).isSuccess()); + } + } + + @Test + void testUploadProcessDefinitionJSON() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:deployResource_JSON"); + mock.expectedMinimumMessageCount(1); + + DeploymentRequest deploymentRequest = new DeploymentRequest(); + deploymentRequest.setName(RESOURCE_NAME); + deploymentRequest + .setContent(this.getClass().getClassLoader().getResourceAsStream("data/test1_definition.bpmn").readAllBytes()); + + template.sendBody("direct:deployResource_JSON", objectMapper.writeValueAsString(deploymentRequest)); + MockEndpoint.assertIsSatisfied(context); + if (!mock.getExchanges().isEmpty()) { + Exchange exchange = mock.getExchanges().get(0); + String body = exchange.getIn().getBody(String.class); + ProcessDeploymentResponse response = objectMapper.readValue(body, ProcessDeploymentResponse.class); + assertTrue(response.isSuccess()); + } + } + + @Test + void testInvalidUploadProcessDefinition() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:deployResource"); + mock.expectedMinimumMessageCount(1); + mock.expectedHeaderReceived(ZeebeConstants.IS_SUCCESS, false); + + DeploymentRequest deploymentRequest = new DeploymentRequest(); + deploymentRequest.setName(INVALID_RESOURCE_NAME); + deploymentRequest + .setContent(this.getClass().getClassLoader().getResourceAsStream(RESOURCE_PATH + RESOURCE_NAME).readAllBytes()); + + template.sendBody("direct:deployResource", deploymentRequest); + MockEndpoint.assertIsSatisfied(context); + if (!mock.getExchanges().isEmpty()) { + Exchange exchange = mock.getExchanges().get(0); + Object body = exchange.getIn().getBody(); + assertTrue(body instanceof DeploymentResponse); Review Comment: assertObjectIsClass does not exist in JUnit5. It seems it was removed. Stackoverflow recommends instances -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org