Skip to content

Commit e846d08

Browse files
committed
test: add unit tests for cluster raft processor
Add tests for: - PutNodeMetadataRequest: constructor and getters/setters - PutNodeMetadataResponse: constructor, getters/setters, and toString - PutNodeInfoRequestProcessor: constructor and interest method Total: 3 new test files with 11 test methods
1 parent 440bb41 commit e846d08

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.server.cluster.raft.processor;
18+
19+
import org.apache.seata.server.cluster.raft.processor.request.PutNodeMetadataRequest;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.*;
23+
24+
public class PutNodeInfoRequestProcessorTest {
25+
26+
@Test
27+
public void testConstructor() {
28+
PutNodeInfoRequestProcessor processor = new PutNodeInfoRequestProcessor();
29+
assertNotNull(processor);
30+
}
31+
32+
@Test
33+
public void testInterest() {
34+
PutNodeInfoRequestProcessor processor = new PutNodeInfoRequestProcessor();
35+
String interest = processor.interest();
36+
37+
assertNotNull(interest);
38+
assertEquals(PutNodeMetadataRequest.class.getName(), interest);
39+
}
40+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.server.cluster.raft.processor.request;
18+
19+
import org.apache.seata.common.metadata.Node;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.*;
23+
24+
public class PutNodeMetadataRequestTest {
25+
26+
@Test
27+
public void testDefaultConstructor() {
28+
PutNodeMetadataRequest request = new PutNodeMetadataRequest();
29+
assertNotNull(request);
30+
assertNull(request.getNode());
31+
}
32+
33+
@Test
34+
public void testConstructorWithNode() {
35+
Node node = new Node();
36+
PutNodeMetadataRequest request = new PutNodeMetadataRequest(node);
37+
38+
assertNotNull(request);
39+
assertEquals(node, request.getNode());
40+
}
41+
42+
@Test
43+
public void testSetAndGetNode() {
44+
PutNodeMetadataRequest request = new PutNodeMetadataRequest();
45+
Node node = new Node();
46+
request.setNode(node);
47+
48+
assertEquals(node, request.getNode());
49+
}
50+
51+
@Test
52+
public void testSetNodeToNull() {
53+
Node node = new Node();
54+
PutNodeMetadataRequest request = new PutNodeMetadataRequest(node);
55+
assertNotNull(request.getNode());
56+
57+
request.setNode(null);
58+
assertNull(request.getNode());
59+
}
60+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.server.cluster.raft.processor.response;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.junit.jupiter.api.Assertions.*;
22+
23+
public class PutNodeMetadataResponseTest {
24+
25+
@Test
26+
public void testConstructorWithTrue() {
27+
PutNodeMetadataResponse response = new PutNodeMetadataResponse(true);
28+
assertTrue(response.isSuccess());
29+
}
30+
31+
@Test
32+
public void testConstructorWithFalse() {
33+
PutNodeMetadataResponse response = new PutNodeMetadataResponse(false);
34+
assertFalse(response.isSuccess());
35+
}
36+
37+
@Test
38+
public void testSetSuccess() {
39+
PutNodeMetadataResponse response = new PutNodeMetadataResponse(false);
40+
assertFalse(response.isSuccess());
41+
42+
response.setSuccess(true);
43+
assertTrue(response.isSuccess());
44+
}
45+
46+
@Test
47+
public void testToString() {
48+
PutNodeMetadataResponse response = new PutNodeMetadataResponse(true);
49+
String str = response.toString();
50+
51+
assertNotNull(str);
52+
assertTrue(str.contains("success"));
53+
assertTrue(str.contains("true"));
54+
}
55+
56+
@Test
57+
public void testToStringWithFalse() {
58+
PutNodeMetadataResponse response = new PutNodeMetadataResponse(false);
59+
String str = response.toString();
60+
61+
assertNotNull(str);
62+
assertTrue(str.contains("success"));
63+
assertTrue(str.contains("false"));
64+
}
65+
}

0 commit comments

Comments
 (0)