This is an automated email from the ASF dual-hosted git repository. shenlin pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/rocketmq-eventbridge.git
commit 42f79ea0cb412564c178c8b69da0ea5d50b11e5b Author: wangkai <wang...@zhongan.com> AuthorDate: Wed Sep 20 12:06:43 2023 +0800 1.修改mvn publish文件 --- .github/workflows/maven-publish.yml | 10 ++- pom.xml | 11 +++ start/pom.xml | 6 +- test/pom.xml | 1 + test/rocketmq-eventbridge-e2etest/pom.xml | 49 +++++++++++ .../rocketmq/eventbridge/e2etest/BaseTest.java | 95 ++++++++++++++++++++++ .../controller/ApplicationTagControllerTest.java | 32 ++++++++ .../rocketmq/eventbridge/e2etest/util/Utils.java | 62 ++++++++++++++ 8 files changed, 262 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 6431cd8..b862f9e 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -17,8 +17,16 @@ jobs: - name: Create RocketMQ container run: | docker pull apache/rocketmq:4.9.4 + echo 'brokerClusterName = DefaultCluster + brokerName = broker-a + brokerId = 0 + deleteWhen = 04 + fileReservedTime = 48 + brokerRole = ASYNC_MASTER + flushDiskType = ASYNC_FLUSH + brokerIP1 =127.0.0.1'>>./broker.conf docker run -d --name rmqnamesrv -p 9876:9876 apache/rocketmq:4.9.4 sh mqnamesrv autoCreateTopicEnable=true - docker run -d --name rmqbroker -p 10911:10911 -p 10909:10909 -e "NAMESRV_ADDR=127.0.0.1:9876" apache/rocketmq:4.9.4 sh mqbroker autoCreateTopicEnable=true + docker run -d --name rmqbroker -p 10911:10911 -p 10909:10909 --link rmqnamesrv:namesrv -v ./broker.conf:/opt/rocketmq:4.9.4/conf/broker.conf -e "NAMESRV_ADDR=rmqnamesrv:9876" apache/rocketmq:4.9.4 sh mqbroker autoCreateTopicEnable=true -c /opt/rocketmq-4.4.0/conf/broker.conf - name: Wait for RocketMQ namesrv container to be ready run: | diff --git a/pom.xml b/pom.xml index f3d1bcb..dd83d24 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,11 @@ <dependencyManagement> <dependencies> <!-- Project Modules--> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-eventbridge-start</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-eventbridge-adapter-persistence</artifactId> @@ -157,6 +162,12 @@ <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-eventbridge-e2etest</artifactId> + <version>${project.version}</version> + </dependency> + <!-- Framework --> <dependency> <groupId>org.springframework.boot</groupId> diff --git a/start/pom.xml b/start/pom.xml index e1e1995..a7e115d 100644 --- a/start/pom.xml +++ b/start/pom.xml @@ -91,7 +91,7 @@ </dependency> </dependencies> - <build> + <!-- <build> <finalName>rocketmq-eventbridge</finalName> <resources> <resource> @@ -125,11 +125,11 @@ <goal>repackage</goal> </goals> <configuration> - <mainClass>org.apache.rocketmq.eventbridge.Main</mainClass> + <mainClass>org.apache.rocketmq.eventbridge.StartMain</mainClass> </configuration> </execution> </executions> </plugin> </plugins> - </build> + </build>--> </project> \ No newline at end of file diff --git a/test/pom.xml b/test/pom.xml index 12f4a80..c51e371 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -23,6 +23,7 @@ <modules> <module>demo</module> + <module>rocketmq-eventbridge-e2etest</module> </modules> </project> \ No newline at end of file diff --git a/test/rocketmq-eventbridge-e2etest/pom.xml b/test/rocketmq-eventbridge-e2etest/pom.xml new file mode 100644 index 0000000..8ded330 --- /dev/null +++ b/test/rocketmq-eventbridge-e2etest/pom.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>rocketmq-eventbridge-test</artifactId> + <groupId>org.apache.rocketmq</groupId> + <version>1.0.0</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <artifactId>rocketmq-eventbridge-e2etest</artifactId> + + <properties> + <maven.compiler.source>8</maven.compiler.source> + <maven.compiler.target>8</maven.compiler.target> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.rocketmq</groupId> + <artifactId>rocketmq-eventbridge-start</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13.2</version> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.ow2.asm</groupId> + <artifactId>asm</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/BaseTest.java b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/BaseTest.java new file mode 100644 index 0000000..5e6248e --- /dev/null +++ b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/BaseTest.java @@ -0,0 +1,95 @@ +package org.apache.rocketmq.eventbridge.e2etest; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.Version; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import org.junit.Assert; +import org.junit.Before; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.io.IOException; +import java.net.URL; +import java.util.Map; + +public class BaseTest { + + protected final static ObjectMapper mapper = new ObjectMapper(); + + static { + SimpleModule m = new SimpleModule("WorkflowJob", Version.unknownVersion()); + mapper.registerModule(m); + + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + protected URL baseUrl; + + @LocalServerPort + protected int port; + + @Autowired + protected TestRestTemplate template; + + @Before + public void setUp() throws Exception { + this.baseUrl = new URL("http://localhost:" + port); + } + + protected <T> T parseDataFromResponse(ResponseEntity<Object> response, Class<T> dataType, Map<Class, Class> modelMapping) { + Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + try { + for (Map.Entry<Class, Class> e : modelMapping.entrySet()) { + SimpleModule model = new SimpleModule(e.getKey().getSimpleName(), Version.unknownVersion()); + model.addAbstractTypeMapping(e.getKey(), e.getValue()); + mapper.registerModule(model); + } + return mapper.readValue(mapper.writeValueAsString(response.getBody()), dataType); + } catch (JsonParseException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } catch (JsonMappingException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } catch (IOException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } + + return null; + } + + protected <T> T parseDataFromResponse(ResponseEntity<Object> response, Class<T> dataType) { + Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); + + try { + return mapper.readValue(mapper.writeValueAsString(response.getBody()), dataType); + } catch (JsonParseException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } catch (JsonMappingException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } catch (JsonProcessingException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } catch (IOException e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } + + return null; + } +} diff --git a/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/controller/ApplicationTagControllerTest.java b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/controller/ApplicationTagControllerTest.java new file mode 100644 index 0000000..0f5446e --- /dev/null +++ b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/controller/ApplicationTagControllerTest.java @@ -0,0 +1,32 @@ +package org.apache.rocketmq.eventbridge.e2etest.controller; + +import org.apache.rocketmq.eventbridge.Main; +import org.apache.rocketmq.eventbridge.e2etest.BaseTest; +import org.apache.rocketmq.eventbridge.e2etest.util.Utils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.HashMap; +import java.util.Map; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Main.class) +public class ApplicationTagControllerTest extends BaseTest { + + @Test + public void testGetAllApplicationTags() { + String url = String.format("%s/bus/createEventBus", baseUrl); + Map<String, String> maps = new HashMap<>(); + maps.put("eventBusName", "demo-bus"); + maps.put("description", "a demo bus."); + ResponseEntity<Void> response = Utils.request(template, url, HttpMethod.POST, maps, Void.class); + Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); + } + + +} diff --git a/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/util/Utils.java b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/util/Utils.java new file mode 100644 index 0000000..cc29fe7 --- /dev/null +++ b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/util/Utils.java @@ -0,0 +1,62 @@ +package org.apache.rocketmq.eventbridge.e2etest.util; + +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import java.io.IOException; +import java.util.Map; + +public class Utils { + + public static <T> ResponseEntity<T> request(TestRestTemplate template, String url, HttpMethod method, Object body, Class<T> clazz) { + HttpHeaders headers = devHeaders(); + + HttpEntity entity = new HttpEntity(body, headers); + return template.exchange(url, method, entity, clazz); + } + + public static <T> ResponseEntity<T> requestByGet(TestRestTemplate template, String url, Map<String,Object> args, Class<T> clazz) { + return template.getForEntity(url, clazz ,args); + } + + public static <T> ResponseEntity<T> requestAsAdmin(TestRestTemplate template, String url, HttpMethod method, Object body, Class<T> clazz) { + HttpHeaders headers = new HttpHeaders(); + headers.add("X-AI-USER", "admin"); + + HttpEntity entity = new HttpEntity(body, headers); + return template.exchange(url, method, entity, clazz); + } + + public static <T> ResponseEntity<T> request(TestRestTemplate template, String url, String fileKey, String file, Class<T> clazz, Object... urlVariables) throws IOException { + HttpHeaders headers = devHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>(); + multipartRequest.add(fileKey, new ClassPathResource(file)); + HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(multipartRequest, headers); + + return template.exchange(url, HttpMethod.POST, entity, clazz, urlVariables); + } + + private static HttpHeaders devHeaders() { + HttpHeaders headers = new HttpHeaders(); + headers.add("X-AI-USER", "developer"); + + return headers; + } + + public static <T> ResponseEntity<T> requestAsWanyaWu(TestRestTemplate template, String url, HttpMethod method, Object body, Class<T> clazz) { + HttpHeaders headers = new HttpHeaders(); + headers.add("X-AI-USER", "vanya.wu"); + + HttpEntity entity = new HttpEntity(body, headers); + return template.exchange(url, method, entity, clazz); + } +}