Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Increase [integration-tx-api] module test case coverage #6533

Merged
merged 24 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ea47fd3
test: add unit tests for ClassUtils class
azatyamanaev May 12, 2024
40a3aab
test: add unit tests for DubboUtil class
azatyamanaev May 12, 2024
b42e2ba
test: add unit tests for JsonParserWrap class
azatyamanaev May 12, 2024
d42e4b7
test: add unit tests for JsonParserFactory class
azatyamanaev May 12, 2024
bbf738a
test: add unit tests for TwoPhaseBusinessActionParam class
azatyamanaev May 12, 2024
6237e22
test: add unit tests for IfNeedEnhanceBean class
azatyamanaev May 12, 2024
c00c5e2
test: add unit tests for TwoPhaseResult class
azatyamanaev May 12, 2024
1846666
test: add unit tests for DefaultRemotingParser class
azatyamanaev May 12, 2024
6f7c04b
test: update unit tests for DefaultRemotingParser class
azatyamanaev May 13, 2024
dff2976
test: register changes in 2.x.md file
azatyamanaev May 15, 2024
d2a4bdf
test: resolve conflicts in 2.x.md file
azatyamanaev May 15, 2024
1a10843
resolve conflicts in 2.x.md file(2)
azatyamanaev May 15, 2024
09ca98f
resolve conflicts in 2.x.md file(3)
azatyamanaev May 15, 2024
b4903be
add license text for test classes
azatyamanaev May 15, 2024
9bcd49f
add changes in zh-cn/2.x.md
azatyamanaev Jun 5, 2024
9726f23
add changes in zh-cn/2.x.md(2)
azatyamanaev Jun 5, 2024
691b675
add spaces in zh-cn/2.x.md
azatyamanaev Jun 5, 2024
45c1769
resolve changes conflicts
azatyamanaev Jun 13, 2024
da05f70
resolve changes conflicts(2)
azatyamanaev Jun 13, 2024
a43f1e8
resolve changes conflicts(3)
azatyamanaev Jun 13, 2024
9e6e1b7
Merge branch '2.x' into integration-tx-api-tests
justinmclean Jun 25, 2024
63dfde3
Merge branch '2.x' of github.com:apache/incubator-seata into integrat…
funky-eyes Jul 5, 2024
c6906a2
update
funky-eyes Jul 5, 2024
3ebc46d
Merge branch '2.x' into integration-tx-api-tests
funky-eyes Jul 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6456](https://github.com/apache/incubator-seata/pull/6456)] adjust the test cases related to dynamic configuration
- [[#6466](https://github.com/apache/incubator-seata/pull/6466)] support redis integration testing
- [[#6484](https://github.com/apache/incubator-seata/pull/6484)] fix FileConfigurationTest and MockServerTest fail
- [[#6545](https://github.com/apache/incubator-seata/pull/6545)] fix TestConfigCustomSPI compatibility test fail
- [[#6533](https://github.com/apache/incubator-seata/pull/6533)] increase integration-tx-api module unit test coverage
funky-eyes marked this conversation as resolved.
Show resolved Hide resolved

### refactor:
- [[#6280](https://github.com/apache/incubator-seata/pull/6280)] refactor Saga designer using diagram-js
Expand Down
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
- [[#6456](https://github.com/apache/incubator-seata/pull/6456)] 调整动态配置监听测试用例
- [[#6466](https://github.com/apache/incubator-seata/pull/6466)] 支持redis的集成测试
- [[#6484](https://github.com/apache/incubator-seata/pull/6484)] 修复FileConfigurationTest和MockServerTest失败
- [[#6545](https://github.com/apache/incubator-seata/pull/6545)] 修复 TestConfigCustomSPI 兼容性测试失败
- [[#6533](https://github.com/apache/incubator-seata/pull/6533)] 增加 Integration-TX-API 模块单元测试覆盖范围

### refactor:
- [[#6280](https://github.com/apache/incubator-seata/pull/6280)] 使用diagram-js重构Saga设计器
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public String toString() {
sb.append("[");
sb.append("isSuccess:").append(isSuccess);
if (StringUtils.isNotBlank(message)) {
sb.append(", msg").append(message);
sb.append(", msg:").append(message);
}
sb.append("]");
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.seata.integration.tx.api.interceptor;

import java.util.HashMap;
import java.util.Map;

import org.apache.seata.common.Constants;
import org.apache.seata.core.model.BranchType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TwoPhaseBusinessActionParamTest {

private TwoPhaseBusinessActionParam actionParam;

@BeforeEach
public void setUp() {
actionParam = new TwoPhaseBusinessActionParam();
}

@Test
public void testGetActionName() {
actionParam.setActionName("business_action");
assertEquals("business_action", actionParam.getActionName());
}

@Test
public void testIsReportDelayed() {
actionParam.setDelayReport(true);
assertTrue(actionParam.getDelayReport());
}

@Test
public void testIsCommonFenceUsed() {
actionParam.setUseCommonFence(true);
assertTrue(actionParam.getUseCommonFence());
}

@Test
public void testFillBusinessActionContext() {
Map<String, Object> businessActionContextMap = new HashMap<>(2);
businessActionContextMap.put(Constants.COMMIT_METHOD, "commit");
businessActionContextMap.put(Constants.USE_COMMON_FENCE, false);

actionParam.setBusinessActionContext(businessActionContextMap);

assertEquals("commit", actionParam.getBusinessActionContext().get(Constants.COMMIT_METHOD));
assertFalse((Boolean) actionParam.getBusinessActionContext().get(Constants.USE_COMMON_FENCE));
}

@Test
public void testGetBranchType() {
actionParam.setBranchType(BranchType.TCC);
assertEquals(BranchType.TCC, actionParam.getBranchType());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.seata.integration.tx.api.interceptor.parser;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class IfNeedEnhanceBeanTest {

private IfNeedEnhanceBean enhanceBean;


@BeforeEach
public void setUp() {
enhanceBean = new IfNeedEnhanceBean();
}

@Test
public void testIsEnhanceNeeded() {
enhanceBean.setIfNeed(true);
assertTrue(enhanceBean.isIfNeed());
}

@Test
public void testGetNeedEnhanceEnum() {
enhanceBean.setNeedEnhanceEnum(NeedEnhanceEnum.SERVICE_BEAN);
assertEquals(NeedEnhanceEnum.SERVICE_BEAN, enhanceBean.getNeedEnhanceEnum());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.seata.integration.tx.api.json;

import java.io.IOException;

import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonParserImpl implements JsonParser {

private final ObjectMapper mapper = new ObjectMapper();

@Override
public String toJSONString(Object object) throws IOException {
return mapper.writeValueAsString(object);
}

@Override
public <T> T parseObject(String text, Class<T> clazz) throws IOException {
return mapper.readValue(text, clazz);
}

@Override
public String getName() {
return "customParser";
}
}
Original file line number Diff line number Diff line change
@@ -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.seata.integration.tx.api.json;

import org.apache.seata.common.exception.JsonParseException;
import org.apache.seata.core.model.BranchType;
import org.apache.seata.integration.tx.api.interceptor.TwoPhaseBusinessActionParam;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class JsonParserWrapTest {

private JsonParserWrap parserWrap;
private final String jsonString = "{\"actionName\":\"business_action\",\"useCommonFence\":null,\"businessActionContext\":null," +
"\"branchType\":\"TCC\",\"delayReport\":null}";


@BeforeEach
public void setUp() {
parserWrap = new JsonParserWrap(new JsonParserImpl());
}

@Test
public void testToJSONString() {
TwoPhaseBusinessActionParam actionParam = new TwoPhaseBusinessActionParam();
actionParam.setActionName("business_action");
actionParam.setBranchType(BranchType.TCC);

String resultString = parserWrap.toJSONString(actionParam);

assertEquals(jsonString, resultString);
}

@Test
public void testToJSONStringThrowsException() {
Object mockItem = mock(Object.class);
when(mockItem.toString()).thenReturn(mockItem.getClass().getName());
assertThrows(JsonParseException.class, () -> parserWrap.toJSONString(mockItem));
}

@Test
public void testParseObject() {
TwoPhaseBusinessActionParam actionParam = parserWrap.parseObject(jsonString, TwoPhaseBusinessActionParam.class);

assertEquals("business_action", actionParam.getActionName());
assertEquals(BranchType.TCC, actionParam.getBranchType());
}

@Test
public void testParseObjectThrowsException() {
assertThrows(JsonParseException.class, () -> parserWrap.parseObject(jsonString, Integer.class));
}

@Test
public void testGetName() {
assertEquals("customParser", parserWrap.getName());
}
}
Original file line number Diff line number Diff line change
@@ -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.seata.integration.tx.api.remoting;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TwoPhaseResultTest {

private TwoPhaseResult result;

@BeforeEach
public void setUp() {
result = new TwoPhaseResult(false, "");
}

@Test
public void testGetMessage() {
result.setMessage("message");
assertEquals("message", result.getMessage());
}

@Test
public void testIsSuccess() {
result.setSuccess(true);
assertTrue(result.isSuccess());
}

@Test
public void testToStringEmptyMessage() {
assertEquals("[isSuccess:false]", result.toString());
}

@Test
public void testToStringNotEmptyMessage() {
result.setMessage("test");
assertEquals("[isSuccess:false, msg:test]", result.toString());
}
}
Loading