forked from apache/incubator-seata
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,000 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
common/src/test/java/org/apache/seata/common/code/CodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.common.code; | ||
|
||
import org.apache.seata.common.result.Code; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
public class CodeTest { | ||
|
||
@Test | ||
public void testGetErrorMsgWithValidCodeReturnsExpectedMsg() { | ||
// Test case for SUCCESS | ||
assertEquals("ok", Code.SUCCESS.getMsg()); | ||
// Test case for ERROR | ||
assertEquals("Server error", Code.ERROR.getMsg()); | ||
// Test case for LOGIN_FAILED | ||
assertEquals("Login failed", Code.LOGIN_FAILED.getMsg()); | ||
} | ||
|
||
@Test | ||
public void testGetErrorMsgWithInvalidCodeReturnsNull() { | ||
// Test case for non-existing code | ||
assertNull(Code.getErrorMsg("404")); | ||
} | ||
|
||
@Test | ||
public void testSetCodeAndMsgUpdatesValuesCorrectly() { | ||
// Test case to check if setCode and setMsg are working as expected | ||
Code.SUCCESS.setCode("201"); | ||
Code.SUCCESS.setMsg("Created"); | ||
assertEquals("201", Code.SUCCESS.getCode()); | ||
assertEquals("Created", Code.SUCCESS.getMsg()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
common/src/test/java/org/apache/seata/common/exception/SeataRuntimeExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.seata.common.exception; | ||
|
||
import java.sql.SQLException; | ||
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.assertNotNull; | ||
|
||
public class SeataRuntimeExceptionTest { | ||
|
||
private ErrorCode errorCode; | ||
private String[] params; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
errorCode = ErrorCode.ERR_CONFIG; | ||
params = new String[] {"param1", "param2"}; | ||
} | ||
|
||
@Test | ||
void testConstructorWithErrorCodeCauseAndParams() { | ||
SQLException cause = new SQLException("SQL Error", "S0001", 1000); | ||
SeataRuntimeException exception = new SeataRuntimeException(errorCode, cause, params); | ||
assertNotNull(exception); | ||
assertEquals(errorCode.getMessage(params), exception.getMessage()); | ||
assertEquals("S0001", exception.getSqlState()); | ||
assertEquals(1000, exception.getVendorCode()); | ||
} | ||
|
||
@Test | ||
void testToStringShouldReturnLocalizedMessage() { | ||
SeataRuntimeException exception = new SeataRuntimeException(errorCode, params); | ||
assertEquals(exception.getLocalizedMessage(), exception.toString()); | ||
} | ||
|
||
@Test | ||
void testGetVendorCodeWithSQLExceptionCause() { | ||
SQLException cause = new SQLException("SQL Error", "S0001", 1000); | ||
SeataRuntimeException exception = new SeataRuntimeException(errorCode, cause, params); | ||
assertEquals(1000, exception.getVendorCode()); | ||
} | ||
|
||
@Test | ||
void testGetSqlStateWithSQLExceptionCause() { | ||
SQLException cause = new SQLException("SQL Error", "S0001", 1000); | ||
SeataRuntimeException exception = new SeataRuntimeException(errorCode, cause, params); | ||
assertEquals("S0001", exception.getSqlState()); | ||
} | ||
|
||
@Test | ||
void testGetVendorCodeWithSeataRuntimeExceptionCause() { | ||
SQLException innerCause = new SQLException("SQL Error", "S0001", 1000); | ||
SeataRuntimeException cause = new SeataRuntimeException(errorCode, innerCause, params); | ||
SeataRuntimeException exception = new SeataRuntimeException(errorCode, cause, params); | ||
assertEquals(1000, exception.getVendorCode()); | ||
} | ||
|
||
@Test | ||
void testGetSqlStateWithSeataRuntimeExceptionCause() { | ||
SQLException innerCause = new SQLException("SQL Error", "S0001", 1000); | ||
SeataRuntimeException cause = new SeataRuntimeException(errorCode, innerCause, params); | ||
SeataRuntimeException exception = new SeataRuntimeException(errorCode, cause, params); | ||
assertEquals("S0001", exception.getSqlState()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.