Skip to content

Commit 9a6ece1

Browse files
authored
test: add some test case (#7030)
1 parent 556a734 commit 9a6ece1

File tree

7 files changed

+95
-8
lines changed

7 files changed

+95
-8
lines changed

changes/en-us/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Add changes here for all PR submitted to the 2.x branch.
6161
### test:
6262
- [[#6927](https://github.com/apache/incubator-seata/pull/6927)] Add unit tests for the `seata-rocketmq` module
6363
- [[#7018](https://github.com/apache/incubator-seata/pull/7018)] Add unit tests for the `seata-tm` module
64+
- [[#7030](https://github.com/apache/incubator-seata/pull/7030)] Add unit tests for the `seata-common` module
6465

6566
Thanks to these contributors for their code commits. Please report an unintended omission.
6667

changes/zh-cn/2.x.md

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
### test:
6565
- [[#6927](https://github.com/apache/incubator-seata/pull/6927)] 增加`seata-rocketmq`模块的测试用例
6666
- [[#7018](https://github.com/apache/incubator-seata/pull/7018)] 增加 `seata-tm` 模块的测试用例
67+
- [[#7030](https://github.com/apache/incubator-seata/pull/7030)] 增加 `seata-common` 模块的测试用例
68+
6769

6870

6971
非常感谢以下 contributors 的代码贡献。若有无意遗漏,请报告。

common/src/main/java/org/apache/seata/common/LockStrategyMode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.apache.seata.common;
1818

1919
/**
20-
* @funkye
20+
* Lock Strategy Mode
2121
*/
2222
public enum LockStrategyMode {
2323
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.common.exception;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.lang.reflect.InvocationTargetException;
23+
import java.lang.reflect.UndeclaredThrowableException;
24+
25+
/**
26+
*
27+
*/
28+
class ExceptionUtilTest {
29+
30+
@Test
31+
public void unwrap() {
32+
InvocationTargetException targetException = new InvocationTargetException(new RuntimeException("invocation"));
33+
Assertions.assertInstanceOf(RuntimeException.class, ExceptionUtil.unwrap(targetException));
34+
35+
UndeclaredThrowableException exception = new UndeclaredThrowableException(new RuntimeException("undeclared"));
36+
Assertions.assertInstanceOf(RuntimeException.class, ExceptionUtil.unwrap(exception));
37+
38+
RuntimeException runtimeException = new RuntimeException("runtime");
39+
Assertions.assertInstanceOf(RuntimeException.class, ExceptionUtil.unwrap(runtimeException));
40+
}
41+
}

common/src/test/java/org/apache/seata/common/metadata/namingserver/InstanceTest.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.core.JsonProcessingException;
2020
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import org.apache.seata.common.metadata.ClusterRole;
2122
import org.apache.seata.common.metadata.Node;
2223
import org.junit.jupiter.api.Test;
2324

@@ -33,13 +34,21 @@ class InstanceTest {
3334
void toJsonString() throws JsonProcessingException {
3435
ObjectMapper objectMapper = new ObjectMapper();
3536
Instance instance = Instance.getInstance();
36-
Map<String,Object> map = new HashMap<>();
37-
Map<String,Object> mmap = new HashMap<>();
38-
mmap.put("k","v");
39-
map.put("k",mmap);
37+
Map<String, Object> map = new HashMap<>();
38+
Map<String, Object> mmap = new HashMap<>();
39+
mmap.put("k", "v");
40+
map.put("k", mmap);
4041
instance.setMetadata(map);
41-
instance.setControl(new Node.Endpoint("1.1.1.1",888));
42-
instance.setTransaction(new Node.Endpoint("2.2.2.2",999));
43-
assertEquals(instance.toJsonString(objectMapper),objectMapper.writeValueAsString(instance));
42+
instance.setNamespace("namespace");
43+
instance.setClusterName("clustername");
44+
instance.setRole(ClusterRole.LEADER);
45+
instance.setUnit("unit");
46+
instance.setWeight(100d);
47+
instance.setHealthy(true);
48+
instance.setTerm(100L);
49+
instance.setTimestamp(System.currentTimeMillis());
50+
instance.setControl(new Node.Endpoint("1.1.1.1", 888));
51+
instance.setTransaction(new Node.Endpoint("2.2.2.2", 999));
52+
assertEquals(instance.toJsonString(objectMapper), objectMapper.writeValueAsString(instance));
4453
}
4554
}

common/src/test/java/org/apache/seata/common/metadata/namingserver/NamingServerNodeTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ void toJsonString() throws JsonProcessingException {
3838
map.put("k","v");
3939
node.setMetadata(map);
4040
node.setGroup("group");
41+
node.setUnit("unit");
42+
node.setHealthy(true);
43+
node.setTerm(111L);
4144
node.setControl(new Node.Endpoint("1.1.1.1",888));
4245
node.setTransaction(new Node.Endpoint("2.2.2.2",999));
4346
assertEquals(node.toJsonString(objectMapper),objectMapper.writeValueAsString(node));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.common.util;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
/**
23+
*
24+
*/
25+
class UUIDGeneratorTest {
26+
27+
@Test
28+
void generateUUID() {
29+
Assertions.assertTrue(UUIDGenerator.generateUUID() > 0);
30+
}
31+
}

0 commit comments

Comments
 (0)