This is an automated email from the ASF dual-hosted git repository.
hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 4e264b185c [type:test][ISSUE #4540] add all event test cases for admin
(#5263)
4e264b185c is described below
commit 4e264b185c7f3dee13ae1365b574a3d2496f7654
Author: whenelse <[email protected]>
AuthorDate: Fri Nov 3 15:53:05 2023 +0800
[type:test][ISSUE #4540] add all event test cases for admin (#5263)
* [type:test][ISSUE #4540] add plugin test cases for admin
* [type:test][ISSUE #4540] add Apache License for plugin test cases for
admin
* [type:test][ISSUE #4540] add CheckStyle for plugin test cases for admin
* [type:test][ISSUE #4540] add batch plugin test cases for admin
* [type:test][ISSUE #4540] add plugin handle test cases for admin
* [type:test]add metadata test case for admin
* [type:refactor]refactor metadata comment and format
* [type:test]add dict test case for admin
* [type:test]add resource and user test case for admin
* [type:fix]resource test case checkstyle
---------
Co-authored-by: Shibo Xia <[email protected]>
Co-authored-by: moremind <[email protected]>
---
.../event/metadata/BatchMetaDataDeletedEvent.java | 2 +-
.../model/event/metadata/MetaDataChangedEvent.java | 13 ++-
.../event/resource/BatchResourceCreatedEvent.java | 2 +-
.../event/dict/BatchDictChangedEventTest.java | 70 ++++++++++++++++
.../event/dict/BatchDictDeletedEventTest.java | 70 ++++++++++++++++
.../model/event/dict/DictCreatedEventTest.java | 57 +++++++++++++
.../model/event/dict/DictUpdatedEventTest.java | 82 +++++++++++++++++++
.../metadata/BatchMetaDataChangedEventTest.java | 75 +++++++++++++++++
.../metadata/BatchMetaDataDeletedEventTest.java | 75 +++++++++++++++++
.../event/metadata/MetaDataChangedEventTest.java | 61 ++++++++++++++
.../event/metadata/MetaDataCreatedEventTest.java | 62 +++++++++++++++
.../event/metadata/MetadataUpdatedEventTest.java | 93 ++++++++++++++++++++++
.../resource/BatchResourceCreatedEventTest.java | 68 ++++++++++++++++
.../resource/BatchResourceDeletedEventTest.java | 68 ++++++++++++++++
.../event/resource/ResourceChangedEventTest.java | 85 ++++++++++++++++++++
.../event/resource/ResourceCreatedEventTest.java | 56 +++++++++++++
.../event/user/BatchUserDeletedEventTest.java | 67 ++++++++++++++++
.../model/event/user/UserCreatedEventTest.java | 56 +++++++++++++
.../model/event/user/UserUpdatedEventTest.java | 77 ++++++++++++++++++
19 files changed, 1129 insertions(+), 10 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java
index bb141c9038..7cf418d4bc 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEvent.java
@@ -51,7 +51,7 @@ public class BatchMetaDataDeletedEvent extends
BatchMetaDataChangedEvent {
.stream()
.map(s -> ((MetaDataDO) s).getAppName())
.collect(Collectors.joining(","));
- return String.format("the meta data[%s] is %s", metaData,
StringUtils.lowerCase(getType().getType().toString()));
+ return String.format("the meta data [%s] is %s", metaData,
StringUtils.lowerCase(getType().getType().toString()));
}
/**
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java
index b8c471554b..83383b5c5a 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEvent.java
@@ -25,7 +25,7 @@ import
org.apache.shenyu.admin.model.event.AdminDataModelChangedEvent;
import java.util.Objects;
/**
- * MetaDatarChangedEvent.
+ * MetaDataChangedEvent.
*/
public class MetaDataChangedEvent extends AdminDataModelChangedEvent {
@@ -70,9 +70,6 @@ public class MetaDataChangedEvent extends
AdminDataModelChangedEvent {
if (!Objects.equals(before.getPathDesc(), after.getPathDesc())) {
builder.append(String.format("path desc[%s => %s] ",
before.getPathDesc(), after.getPathDesc()));
}
- if (!Objects.equals(before.getEnabled(), after.getEnabled())) {
- builder.append(String.format("enable[%s => %s] ",
before.getEnabled(), after.getEnabled()));
- }
if (!Objects.equals(before.getServiceName(), after.getServiceName())) {
builder.append(String.format("service[%s => %s] ",
before.getServiceName(), after.getServiceName()));
}
@@ -80,16 +77,16 @@ public class MetaDataChangedEvent extends
AdminDataModelChangedEvent {
builder.append(String.format("method[%s => %s] ",
before.getMethodName(), after.getMethodName()));
}
if (!Objects.equals(before.getParameterTypes(),
after.getParameterTypes())) {
- builder.append(String.format("parameter type [%s => %s] ",
before.getParameterTypes(), after.getParameterTypes()));
+ builder.append(String.format("parameter type[%s => %s] ",
before.getParameterTypes(), after.getParameterTypes()));
}
if (!Objects.equals(before.getEnabled(), after.getEnabled())) {
- builder.append(String.format("enable [%s => %s] ",
before.getEnabled(), after.getEnabled()));
+ builder.append(String.format("enable[%s => %s] ",
before.getEnabled(), after.getEnabled()));
}
if (!Objects.equals(before.getRpcType(), after.getRpcType())) {
- builder.append(String.format("rpc type [%s => %s] ",
before.getRpcType(), after.getRpcType()));
+ builder.append(String.format("rpc type[%s => %s] ",
before.getRpcType(), after.getRpcType()));
}
if (!Objects.equals(before.getRpcExt(), after.getRpcExt())) {
- builder.append(String.format("rpc ext [%s => %s] ",
before.getRpcExt(), after.getRpcExt()));
+ builder.append(String.format("rpc ext[%s => %s] ",
before.getRpcExt(), after.getRpcExt()));
}
return builder.toString();
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/resource/BatchResourceCreatedEvent.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/resource/BatchResourceCreatedEvent.java
index 3e3cb42622..27ceb5c0c7 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/resource/BatchResourceCreatedEvent.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/event/resource/BatchResourceCreatedEvent.java
@@ -53,7 +53,7 @@ public class BatchResourceCreatedEvent extends
BatchChangedEvent {
.stream()
.map(s -> ((ResourceDO) s).getTitle())
.collect(Collectors.joining(","));
- return String.format("the resource[%s] is %s", selector,
StringUtils.lowerCase(getType().getType().toString()));
+ return String.format("the resource [%s] is %s", selector,
StringUtils.lowerCase(getType().getType().toString()));
}
/**
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/BatchDictChangedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/BatchDictChangedEventTest.java
new file mode 100644
index 0000000000..30b4a0526e
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/BatchDictChangedEventTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.shenyu.admin.model.event.dict;
+
+import java.util.Arrays;
+import org.apache.shenyu.admin.model.entity.ShenyuDictDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link BatchDictChangedEvent}.
+ */
+public class BatchDictChangedEventTest {
+
+ private ShenyuDictDO one;
+
+ private ShenyuDictDO two;
+
+ @BeforeEach
+ public void setUp() {
+ one = ShenyuDictDO.builder()
+ .id("1")
+ .type("dictOneTest")
+ .dictCode("DICT_TEST")
+ .dictName("one")
+ .dictValue("one")
+ .desc("dict one test desc")
+ .sort(0)
+ .enabled(true)
+ .build();
+ two = ShenyuDictDO.builder()
+ .id("2")
+ .type("dictTwoTest")
+ .dictCode("DICT_TEST")
+ .dictName("two")
+ .dictValue("two")
+ .desc("dict two test desc")
+ .sort(0)
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void batchChangeDictContextTest() {
+ BatchDictChangedEvent batchDictChangedEvent =
+ new BatchDictChangedEvent(Arrays.asList(one, two), null,
EventTypeEnum.DICT_UPDATE, "test-operator");
+
+ String context = String.format("the shenyu dict[%s] is %s", "one,two",
EventTypeEnum.DICT_UPDATE.getType().toString().toLowerCase());
+
+ assertEquals(context, batchDictChangedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/BatchDictDeletedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/BatchDictDeletedEventTest.java
new file mode 100644
index 0000000000..828da68218
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/BatchDictDeletedEventTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.shenyu.admin.model.event.dict;
+
+import java.util.Arrays;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.ShenyuDictDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link BatchDictDeletedEvent}.
+ */
+public class BatchDictDeletedEventTest {
+
+ private ShenyuDictDO one;
+
+ private ShenyuDictDO two;
+
+ @BeforeEach
+ public void setUp() {
+ one = ShenyuDictDO.builder()
+ .id("1")
+ .type("dictOneTest")
+ .dictCode("DICT_TEST")
+ .dictName("one")
+ .dictValue("one")
+ .desc("dict one test desc")
+ .sort(0)
+ .enabled(true)
+ .build();
+ two = ShenyuDictDO.builder()
+ .id("2")
+ .type("dictTwoTest")
+ .dictCode("DICT_TEST")
+ .dictName("two")
+ .dictValue("two")
+ .desc("dict two test desc")
+ .sort(0)
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void batchDeleteDictContextTest() {
+ BatchDictDeletedEvent batchDictDeletedEvent = new
BatchDictDeletedEvent(Arrays.asList(one, two), "test-operator");
+
+ String context = String.format("the dict[%s] is %s", "one,two",
StringUtils.lowerCase(EventTypeEnum.DICT_DELETE.getType().toString()));
+
+ assertEquals(context, batchDictDeletedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/DictCreatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/DictCreatedEventTest.java
new file mode 100644
index 0000000000..55e36d5fae
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/DictCreatedEventTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.shenyu.admin.model.event.dict;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.ShenyuDictDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link DictCreatedEvent}.
+ */
+public class DictCreatedEventTest {
+
+ private ShenyuDictDO dictDO;
+
+ @BeforeEach
+ public void setUp() {
+ dictDO = ShenyuDictDO.builder()
+ .id("1")
+ .type("dictTest")
+ .dictCode("DICT_TEST")
+ .dictName("test")
+ .dictValue("test")
+ .desc("dict test desc")
+ .sort(0)
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void dictCreatedContextTest() {
+ DictCreatedEvent dictCreatedEvent = new DictCreatedEvent(dictDO,
"test-operator");
+
+ String context = String.format("the dict [%s] is %s",
dictDO.getDictName(),
StringUtils.lowerCase(EventTypeEnum.DICT_CREATE.getType().toString()));
+
+ assertEquals(context, dictCreatedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/DictUpdatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/DictUpdatedEventTest.java
new file mode 100644
index 0000000000..b8ca589528
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/dict/DictUpdatedEventTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.shenyu.admin.model.event.dict;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.ShenyuDictDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link DictUpdatedEvent}.
+ */
+public class DictUpdatedEventTest {
+
+ private ShenyuDictDO before;
+
+ private ShenyuDictDO after;
+
+ @BeforeEach
+ public void setUp() {
+ before = ShenyuDictDO.builder()
+ .id("1")
+ .type("dictTest")
+ .dictCode("DICT_TEST")
+ .dictName("test")
+ .dictValue("test")
+ .desc("dict test desc")
+ .sort(0)
+ .enabled(true)
+ .build();
+
+ after = ShenyuDictDO.builder()
+ .id("1")
+ .type("dictTestAfter")
+ .dictCode("DICT_TEST_AFTER")
+ .dictName("testAfter")
+ .dictValue("testAfter")
+ .desc("dict test desc after")
+ .sort(1)
+ .enabled(false)
+ .build();
+ }
+
+ @Test
+ public void dictUpdatedContextTest() {
+ String typeStr =
StringUtils.lowerCase(EventTypeEnum.DICT_UPDATE.getType().toString());
+
+ DictUpdatedEvent dictUpdatedNothingEvent = new
DictUpdatedEvent(before, before, "test-operator");
+ String baseContext = String.format("the dict [%s] is %s : %s",
before.getDictName(), typeStr, "it no change");
+ assertEquals(baseContext, dictUpdatedNothingEvent.buildContext());
+
+ final StringBuilder contrast = new StringBuilder();
+ contrast.append(String.format("name[%s => %s] ", before.getDictName(),
after.getDictName()));
+ contrast.append(String.format("value[%s => %s] ",
before.getDictValue(), after.getDictValue()));
+ contrast.append(String.format("desc[%s => %s] ", before.getDesc(),
after.getDesc()));
+ contrast.append(String.format("type[%s => %s] ", before.getType(),
after.getType()));
+ contrast.append(String.format("enable[%s => %s] ",
before.getEnabled(), after.getEnabled()));
+ contrast.append(String.format("sort[%s => %s] ", before.getSort(),
after.getSort()));
+
+ String context = String.format("the dict [%s] is %s : %s",
after.getDictName(), typeStr, contrast);
+ DictUpdatedEvent dictUpdatedEvent = new DictUpdatedEvent(after,
before, "test-operator");
+ assertEquals(context, dictUpdatedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEventTest.java
new file mode 100644
index 0000000000..435b4a87ae
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataChangedEventTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.shenyu.admin.model.event.metadata;
+
+import java.util.Arrays;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.MetaDataDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link BatchMetaDataChangedEvent}.
+ */
+public class BatchMetaDataChangedEventTest {
+
+ private MetaDataDO one;
+
+ private MetaDataDO two;
+
+ @BeforeEach
+ public void setUp() {
+ one = MetaDataDO.builder()
+ .id("1")
+ .appName("testAppNameOne")
+ .path("/testPathOne")
+ .pathDesc("testPathDescOne")
+ .rpcType("http")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestOneController")
+ .methodName("post")
+ .parameterTypes("java.lang.String")
+ .enabled(true)
+ .build();
+
+ two = MetaDataDO.builder()
+ .id("2")
+ .appName("testAppNameTwo")
+ .path("/testPathTwo")
+ .pathDesc("testPathDescTwo")
+ .rpcType("http")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestTwoController")
+ .methodName("post")
+ .parameterTypes("java.lang.String")
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void batchMetaDataChangedContextTest() {
+ BatchMetaDataChangedEvent batchMetaDataChangedEvent =
+ new BatchMetaDataChangedEvent(Arrays.asList(one, two), null,
EventTypeEnum.META_DATA_UPDATE, "test-operator");
+
+ String context = String.format("the meta data [%s] is %s",
+ "testAppNameOne,testAppNameTwo",
StringUtils.lowerCase(EventTypeEnum.META_DATA_UPDATE.getType().toString()));
+
+ assertEquals(context, batchMetaDataChangedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEventTest.java
new file mode 100644
index 0000000000..dc50b24d31
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/BatchMetaDataDeletedEventTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.shenyu.admin.model.event.metadata;
+
+import java.util.Arrays;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.MetaDataDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link BatchMetaDataDeletedEvent}.
+ */
+public class BatchMetaDataDeletedEventTest {
+
+ private MetaDataDO one;
+
+ private MetaDataDO two;
+
+ @BeforeEach
+ public void setUp() {
+ one = MetaDataDO.builder()
+ .id("1")
+ .appName("testAppNameOne")
+ .path("/testPathOne")
+ .pathDesc("testPathDescOne")
+ .rpcType("http")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestOneController")
+ .methodName("post")
+ .parameterTypes("java.lang.String")
+ .enabled(true)
+ .build();
+
+ two = MetaDataDO.builder()
+ .id("2")
+ .appName("testAppNameTwo")
+ .path("/testPathTwo")
+ .pathDesc("testPathDescTwo")
+ .rpcType("http")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestTwoController")
+ .methodName("post")
+ .parameterTypes("java.lang.String")
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void batchMetaDataDeletedContextTest() {
+ BatchMetaDataDeletedEvent batchMetaDataChangedEvent =
+ new BatchMetaDataDeletedEvent(Arrays.asList(one, two),
"test-operator");
+
+ String context = String.format("the meta data [%s] is %s",
+ "testAppNameOne,testAppNameTwo",
StringUtils.lowerCase(EventTypeEnum.META_DATA_DELETE.getType().toString()));
+
+ assertEquals(context, batchMetaDataChangedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEventTest.java
new file mode 100644
index 0000000000..d3da8f26dc
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataChangedEventTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.shenyu.admin.model.event.metadata;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.MetaDataDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link MetaDataChangedEvent}.
+ */
+public class MetaDataChangedEventTest {
+ private MetaDataDO createDO;
+
+ @BeforeEach
+ public void setUp() {
+ createDO = MetaDataDO.builder()
+ .id("1")
+ .appName("test-app")
+ .path("/test")
+ .pathDesc("test")
+ .rpcType("http")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestController")
+ .methodName("post")
+ .parameterTypes("java.lang.String")
+ .rpcExt("test")
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void metaDataDeleteContextTest() {
+ MetaDataChangedEvent deleteEvent =
+ new MetaDataChangedEvent(createDO, null,
EventTypeEnum.META_DATA_DELETE, "test-operator");
+
+ String context = String.format("the metadata [%s %s] is %s",
+ createDO.getAppName(), createDO.getPath(),
StringUtils.lowerCase(EventTypeEnum.META_DATA_DELETE.getType().toString()));
+
+ assertEquals(context, deleteEvent.buildContext());
+ }
+
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataCreatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataCreatedEventTest.java
new file mode 100644
index 0000000000..dc7ba7edc1
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetaDataCreatedEventTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.shenyu.admin.model.event.metadata;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.MetaDataDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+
+/**
+ * test case for {@link MetaDataCreatedEvent}.
+ */
+public class MetaDataCreatedEventTest {
+
+ private MetaDataDO createDO;
+
+ @BeforeEach
+ public void setUp() {
+ createDO = MetaDataDO.builder()
+ .id("1")
+ .appName("test-app")
+ .path("/test")
+ .pathDesc("test")
+ .rpcType("http")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestController")
+ .methodName("post")
+ .parameterTypes("java.lang.String")
+ .rpcExt("test")
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void metaDataCreateContextTest() {
+ MetaDataChangedEvent createdEvent =
+ new MetaDataChangedEvent(createDO, null,
EventTypeEnum.META_DATA_CREATE, "test-operator");
+
+ String context = String.format("the metadata [%s %s] is %s",
+ createDO.getAppName(), createDO.getPath(),
StringUtils.lowerCase(EventTypeEnum.META_DATA_CREATE.getType().toString()));
+
+ assertEquals(context, createdEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetadataUpdatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetadataUpdatedEventTest.java
new file mode 100644
index 0000000000..e76706d84b
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/metadata/MetadataUpdatedEventTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.shenyu.admin.model.event.metadata;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.MetaDataDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link MetadataUpdatedEvent}.
+ */
+public class MetadataUpdatedEventTest {
+ private MetaDataDO updateBeforeDO;
+
+ private MetaDataDO updateAfterDO;
+
+ @BeforeEach
+ public void setUp() {
+ updateBeforeDO = MetaDataDO.builder()
+ .id("1")
+ .appName("testUpdateBefore")
+ .path("/testUpdateBefore")
+ .pathDesc("testUpdateBefore")
+ .rpcType("http")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestBeforeController")
+ .methodName("before")
+ .parameterTypes("java.lang.String")
+ .enabled(true)
+ .rpcExt("rpcExtBefore")
+ .build();
+ updateAfterDO = MetaDataDO.builder()
+ .id("1")
+ .appName("testUpdateAfter")
+ .path("/testUpdateAfter")
+ .pathDesc("testUpdateAfter")
+ .rpcType("dubbo")
+
.serviceName("org.apache.shenyu.examples.http.controller.TestAfterController")
+ .methodName("after")
+ .parameterTypes("java.lang.Integer")
+ .enabled(false)
+ .rpcExt("rpcExtAfter")
+ .build();
+ }
+
+ @Test
+ public void metaDataUpdateContextTest() {
+ String eventTypeStr =
StringUtils.lowerCase(EventTypeEnum.META_DATA_UPDATE.getType().toString());
+
+ MetaDataChangedEvent updateNothingEvent =
+ new MetaDataChangedEvent(updateBeforeDO, updateBeforeDO,
EventTypeEnum.META_DATA_UPDATE, "test-operator");
+ String baseContext = String.format("the metadata [%s %s] is %s : %s",
+ updateBeforeDO.getAppName(), updateBeforeDO.getPath(),
eventTypeStr, "it no change");
+ assertEquals(baseContext, updateNothingEvent.buildContext());
+
+ final StringBuilder contrast = new StringBuilder();
+ contrast.append(String.format("appName[%s => %s] ",
updateBeforeDO.getAppName(), updateAfterDO.getAppName()));
+ contrast.append(String.format("path[%s => %s] ",
updateBeforeDO.getPath(), updateAfterDO.getPath()));
+ contrast.append(String.format("path desc[%s => %s] ",
updateBeforeDO.getPathDesc(), updateAfterDO.getPathDesc()));
+ contrast.append(String.format("service[%s => %s] ",
updateBeforeDO.getServiceName(), updateAfterDO.getServiceName()));
+ contrast.append(String.format("method[%s => %s] ",
updateBeforeDO.getMethodName(), updateAfterDO.getMethodName()));
+ contrast.append(String.format("parameter type[%s => %s] ",
updateBeforeDO.getParameterTypes(), updateAfterDO.getParameterTypes()));
+ contrast.append(String.format("enable[%s => %s] ",
updateBeforeDO.getEnabled(), updateAfterDO.getEnabled()));
+ contrast.append(String.format("rpc type[%s => %s] ",
updateBeforeDO.getRpcType(), updateAfterDO.getRpcType()));
+ contrast.append(String.format("rpc ext[%s => %s] ",
updateBeforeDO.getRpcExt(), updateAfterDO.getRpcExt()));
+
+ String context = String.format("the metadata [%s %s] is %s : %s",
+ updateAfterDO.getAppName(), updateAfterDO.getPath(),
eventTypeStr, contrast);
+
+ MetaDataChangedEvent updateEvent =
+ new MetaDataChangedEvent(updateAfterDO, updateBeforeDO,
EventTypeEnum.META_DATA_UPDATE, "test-operator");
+ assertEquals(context, updateEvent.buildContext());
+ }
+
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/BatchResourceCreatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/BatchResourceCreatedEventTest.java
new file mode 100644
index 0000000000..d3e92bdee7
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/BatchResourceCreatedEventTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.shenyu.admin.model.event.resource;
+
+import java.util.Arrays;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.ResourceDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link BatchResourceCreatedEvent}.
+ */
+public class BatchResourceCreatedEventTest {
+
+ private ResourceDO one;
+
+ private ResourceDO two;
+
+ @BeforeEach
+ public void setUp() {
+ one = ResourceDO.builder()
+ .name("plug")
+ .component("PluginList")
+ .icon("dashboard")
+ .title("SHENYU.MENU.PLUGIN.LIST")
+ .sort(1)
+ .perms("system:plugin:list")
+ .build();
+
+ two = ResourceDO.builder()
+ .name("system")
+ .component("system")
+ .icon("setting")
+ .title("SHENYU.MENU.SYSTEM.MANAGMENT")
+ .sort(2)
+ .perms("system:manager:list")
+ .build();
+ }
+
+ @Test
+ public void resourceCreateBuildContextTest() {
+ BatchResourceCreatedEvent createdEvent = new
BatchResourceCreatedEvent(Arrays.asList(one, two), "test-operator");
+
+ String context = String.format("the resource [%s] is %s",
+ one.getTitle() + "," + two.getTitle(),
StringUtils.lowerCase(EventTypeEnum.RESOURCE_CREATE.getType().toString()));
+
+ assertEquals(context, createdEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/BatchResourceDeletedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/BatchResourceDeletedEventTest.java
new file mode 100644
index 0000000000..18d3210454
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/BatchResourceDeletedEventTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.shenyu.admin.model.event.resource;
+
+import java.util.Arrays;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.ResourceDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link BatchResourceDeletedEvent}.
+ */
+public class BatchResourceDeletedEventTest {
+
+ private ResourceDO one;
+
+ private ResourceDO two;
+
+ @BeforeEach
+ public void setUp() {
+ one = ResourceDO.builder()
+ .name("plug")
+ .component("PluginList")
+ .icon("dashboard")
+ .title("SHENYU.MENU.PLUGIN.LIST")
+ .sort(1)
+ .perms("system:plugin:list")
+ .build();
+
+ two = ResourceDO.builder()
+ .name("system")
+ .component("system")
+ .icon("setting")
+ .title("SHENYU.MENU.SYSTEM.MANAGMENT")
+ .sort(2)
+ .perms("system:manager:list")
+ .build();
+ }
+
+ @Test
+ public void resourceChangeBuildContextTest() {
+ BatchResourceDeletedEvent batchResourceDeletedEvent = new
BatchResourceDeletedEvent(Arrays.asList(one, two), "test-operator");
+
+ String context = String.format("the resource[%s] is %s",
+ one.getTitle() + "," + two.getTitle(),
StringUtils.lowerCase(EventTypeEnum.RESOURCE_DELETE.getType().toString()));
+
+ assertEquals(context, batchResourceDeletedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/ResourceChangedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/ResourceChangedEventTest.java
new file mode 100644
index 0000000000..57a1529100
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/ResourceChangedEventTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.shenyu.admin.model.event.resource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.ResourceDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link ResourceChangedEvent}.
+ */
+public class ResourceChangedEventTest {
+
+ private ResourceDO before;
+
+ private ResourceDO after;
+
+ @BeforeEach
+ public void setUp() {
+ before = ResourceDO.builder()
+ .name("plug")
+ .component("PluginList")
+ .icon("dashboard")
+ .title("SHENYU.MENU.PLUGIN.LIST")
+ .sort(1)
+ .perms("system:plugin:list")
+ .build();
+
+ after = ResourceDO.builder()
+ .name("system")
+ .component("system")
+ .icon("setting")
+ .title("SHENYU.MENU.SYSTEM.MANAGMENT")
+ .sort(2)
+ .perms("system:manager:list")
+ .build();
+ }
+
+ @Test
+ public void resourceChangeBuildContextTest() {
+
+ final StringBuilder contrast = new StringBuilder();
+ contrast.append(String.format("name[%s => %s] ", before.getName(),
after.getName()));
+ contrast.append(String.format("component[%s => %s] ",
before.getComponent(), after.getComponent()));
+ contrast.append(String.format("match icon[%s => %s] ",
before.getIcon(), after.getIcon()));
+ contrast.append(String.format("title[%s => %s] ", before.getTitle(),
after.getTitle()));
+ contrast.append(String.format("sort[%s => %s] ", before.getSort(),
after.getSort()));
+ contrast.append(String.format("perms[%s => %s] ", before.getPerms(),
after.getPerms()));
+
+ String typeStr =
StringUtils.lowerCase(EventTypeEnum.RESOURCE_UPDATE.getType().toString());
+ String context = String.format("the resource [%s] is %s : %s",
after.getTitle(), typeStr, contrast);
+
+ ResourceChangedEvent resourceChangedEvent = new
ResourceChangedEvent(after, before, EventTypeEnum.RESOURCE_UPDATE,
"test-operator");
+ assertEquals(context, resourceChangedEvent.buildContext());
+ }
+
+ @Test
+ public void resourceDeleteBuildContextTest() {
+ ResourceChangedEvent resourceDeleteEvent = new
ResourceChangedEvent(after, after, EventTypeEnum.RESOURCE_DELETE,
"test-operator");
+
+ String typeStr =
StringUtils.lowerCase(EventTypeEnum.RESOURCE_DELETE.getType().toString());
+ String context = String.format("the resource [%s] is %s : %s",
after.getTitle(), typeStr, "it no change");
+
+ assertEquals(context, resourceDeleteEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/ResourceCreatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/ResourceCreatedEventTest.java
new file mode 100644
index 0000000000..14479fa3b7
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/resource/ResourceCreatedEventTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shenyu.admin.model.event.resource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.ResourceDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link ResourceCreatedEvent}.
+ */
+public class ResourceCreatedEventTest {
+
+ private ResourceDO resourceDO;
+
+ @BeforeEach
+ public void setUp() {
+ resourceDO = ResourceDO.builder()
+ .title("SHENYU.MENU.PLUGIN.LIST")
+ .name("plug")
+ .component("PluginList")
+ .sort(0)
+ .icon("dashboard")
+ .perms("system:plugin:list")
+ .build();
+ }
+
+ @Test
+ public void resourceCreatedBuildContextTest() {
+ ResourceCreatedEvent resourceCreatedEvent = new
ResourceCreatedEvent(resourceDO, "test-operator");
+
+ String context = String.format("the resource [%s] is %s",
+ resourceDO.getTitle(),
StringUtils.lowerCase(EventTypeEnum.RESOURCE_CREATE.getType().toString()));
+
+ assertEquals(context, resourceCreatedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/BatchUserDeletedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/BatchUserDeletedEventTest.java
new file mode 100644
index 0000000000..a148d70e52
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/BatchUserDeletedEventTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.shenyu.admin.model.event.user;
+
+import java.util.Arrays;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.DashboardUserDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.apache.shenyu.common.utils.DigestUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link BatchUserDeletedEvent}.
+ */
+public class BatchUserDeletedEventTest {
+
+ private DashboardUserDO one;
+
+ private DashboardUserDO two;
+
+ @BeforeEach
+ public void setUp() {
+ one = DashboardUserDO.builder()
+ .id("1")
+ .userName("adminOneTest")
+ .password(DigestUtils.sha512Hex("123456"))
+ .role(1)
+ .enabled(true)
+ .build();
+
+ two = DashboardUserDO.builder()
+ .id("2")
+ .userName("adminTwoTest")
+ .password(DigestUtils.sha512Hex("123457"))
+ .role(2)
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void batchUserDeletedContextTest() {
+ BatchUserDeletedEvent batchUserDeletedEvent = new
BatchUserDeletedEvent(Arrays.asList(one, two), "test-operator");
+
+ String context = String.format("the user[%s] is %s",
+ one.getUserName() + "," + two.getUserName(),
StringUtils.lowerCase(EventTypeEnum.USER_DELETE.getType().toString()));
+
+ assertEquals(context, batchUserDeletedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/UserCreatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/UserCreatedEventTest.java
new file mode 100644
index 0000000000..c7c0b9418c
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/UserCreatedEventTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shenyu.admin.model.event.user;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.DashboardUserDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.apache.shenyu.common.utils.DigestUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link UserCreatedEvent}.
+ */
+public class UserCreatedEventTest {
+
+ private DashboardUserDO dashboardUserDO;
+
+ @BeforeEach
+ public void setUp() {
+ dashboardUserDO = DashboardUserDO.builder()
+ .id("1")
+ .userName("adminTest")
+ .password(DigestUtils.sha512Hex("123456"))
+ .role(1)
+ .enabled(true)
+ .build();
+ }
+
+ @Test
+ public void userCreatedBuildCTest() {
+ UserCreatedEvent userCreatedEvent = new
UserCreatedEvent(dashboardUserDO, "admin");
+
+ String context = String.format("the selector [%s] is %s",
+ dashboardUserDO.getUserName(),
StringUtils.lowerCase(EventTypeEnum.USER_CREATE.getType().toString()));
+
+ assertEquals(context, userCreatedEvent.buildContext());
+ }
+}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/UserUpdatedEventTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/UserUpdatedEventTest.java
new file mode 100644
index 0000000000..ad27d4062e
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/model/event/user/UserUpdatedEventTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.shenyu.admin.model.event.user;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.admin.model.entity.DashboardUserDO;
+import org.apache.shenyu.admin.model.enums.EventTypeEnum;
+import org.apache.shenyu.common.utils.DigestUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * test case for {@link UserUpdatedEvent}.
+ */
+public class UserUpdatedEventTest {
+
+ private DashboardUserDO before;
+
+ private DashboardUserDO after;
+
+ @BeforeEach
+ public void setUp() {
+ before = DashboardUserDO.builder()
+ .id("1")
+ .userName("adminBeforeTest")
+ .password(DigestUtils.sha512Hex("123456"))
+ .role(1)
+ .enabled(true)
+ .build();
+
+ after = DashboardUserDO.builder()
+ .id("1")
+ .userName("adminAfterTest")
+ .password(DigestUtils.sha512Hex("123457"))
+ .role(2)
+ .enabled(false)
+ .build();
+ }
+
+ @Test
+ public void userUpdatedContextTest() {
+ String typeStr =
StringUtils.lowerCase(EventTypeEnum.USER_UPDATE.getType().toString());
+
+ UserUpdatedEvent userUpdatedNothingEvent = new UserUpdatedEvent(after,
after, "test-operator");
+ String contextNothing = String.format("the selector [%s] is %s : %s",
+ after.getUserName(), typeStr, "it no change");
+ assertEquals(contextNothing, userUpdatedNothingEvent.buildContext());
+
+ StringBuilder contrast = new StringBuilder();
+ contrast.append(String.format("name[%s => %s] ", before.getUserName(),
after.getUserName()));
+ contrast.append("password is changed...");
+ contrast.append(String.format("role[%s => %s] ", before.getRole(),
after.getRole()));
+ contrast.append(String.format("enable[%s => %s] ",
before.getEnabled(), after.getEnabled()));
+
+ String context = String.format("the selector [%s] is %s : %s",
+ after.getUserName(), typeStr, contrast);
+ UserUpdatedEvent userUpdatedEvent = new UserUpdatedEvent(after,
before, "test-operator");
+ assertEquals(context, userUpdatedEvent.buildContext());
+ }
+}