forked from sofastack/sofa-serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
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
ColdClear
committed
Sep 28, 2023
1 parent
3c8ec4b
commit c87cc57
Showing
6 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
.../alipay/sofa/serverless/arklet/core/command/builtin/handler/UninstallBizHandlerTests.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,84 @@ | ||
package com.alipay.sofa.serverless.arklet.core.command.builtin.handler; | ||
|
||
import com.alipay.sofa.ark.api.ClientResponse; | ||
import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; | ||
import com.alipay.sofa.serverless.arklet.core.command.handler.BaseHandlerTest; | ||
import com.alipay.sofa.serverless.arklet.core.command.meta.Output; | ||
import com.alipay.sofa.serverless.arklet.core.common.exception.CommandValidationException; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
public class UninstallBizHandlerTests extends BaseHandlerTest { | ||
|
||
private UninstallBizHandler handler; | ||
|
||
@Before | ||
public void setupInstallBizHandler() { | ||
handler = (UninstallBizHandler) commandService.getHandler(BuiltinCommand.UNINSTALL_BIZ); | ||
} | ||
|
||
@Test | ||
public void testHandle_Success() throws Throwable { | ||
UninstallBizHandler.Input input = new UninstallBizHandler.Input(); | ||
input.setBizName("testBizName"); | ||
input.setBizVersion("testBizVersion"); | ||
|
||
when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())).thenReturn(success); | ||
|
||
Output<ClientResponse> result = handler.handle(input); | ||
|
||
Assert.assertEquals(success, result.getData()); | ||
Assert.assertTrue(result.success()); | ||
} | ||
|
||
@Test | ||
public void testHandle_Failure() throws Throwable { | ||
UninstallBizHandler.Input input = new UninstallBizHandler.Input(); | ||
input.setBizName("testBizName"); | ||
input.setBizVersion("testBizVersion"); | ||
|
||
when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())).thenReturn(failed); | ||
|
||
Output<ClientResponse> result = handler.handle(input); | ||
|
||
Assert.assertSame(failed, result.getData()); | ||
Assert.assertTrue(result.failed()); | ||
} | ||
|
||
@Test(expected = CommandValidationException.class) | ||
public void testValidate_BlankBizName() throws CommandValidationException { | ||
// 准备测试数据 | ||
UninstallBizHandler.Input input = new UninstallBizHandler.Input(); | ||
input.setBizName(""); | ||
input.setBizVersion("testBizVersion"); | ||
|
||
// 执行测试 | ||
handler.validate(input); | ||
} | ||
|
||
@Test(expected = CommandValidationException.class) | ||
public void testValidate_BlankBizVersion() throws CommandValidationException { | ||
// 准备测试数据 | ||
UninstallBizHandler.Input input = new UninstallBizHandler.Input(); | ||
input.setBizName("testBizName"); | ||
input.setBizVersion(""); | ||
|
||
// 执行测试 | ||
handler.validate(input); | ||
} | ||
|
||
@Test(expected = CommandValidationException.class) | ||
public void testValidate_BlankRequestId() throws CommandValidationException { | ||
// 执行测试 | ||
UninstallBizHandler.Input input = new UninstallBizHandler.Input(); | ||
input.setAsync(true); | ||
input.setRequestId(""); | ||
|
||
// 执行测试 | ||
handler.validate(input); | ||
} | ||
|
||
} |
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
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
61 changes: 61 additions & 0 deletions
61
...klet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.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,61 @@ | ||
package com.alipay.sofa.serverless.arklet.core.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class AssertUtilsTests { | ||
|
||
@Test | ||
public void testTestAssertNotNull_Success() { | ||
Object instance = new Object(); | ||
final String message = "instance is not null"; | ||
AssertUtils.assertNotNull(instance, message); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testTestAssertNotNull_Failure() { | ||
final String message = "instance is null"; | ||
AssertUtils.assertNotNull(null, message); | ||
} | ||
|
||
@Test | ||
public void testTestAssertNull_Success() { | ||
final String message = "instance is null"; | ||
AssertUtils.assertNull(null, message); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testTestAssertNull_Failure() { | ||
Object instance = new Object(); | ||
final String message = "instance is not null"; | ||
AssertUtils.assertNull(instance, message); | ||
} | ||
|
||
@Test | ||
public void testIsTrue_Success() { | ||
final boolean expression = true; | ||
final String message = "expression is true"; | ||
AssertUtils.isTrue(expression, message); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testIsTrue_Failure() { | ||
final boolean expression = false; | ||
final String message = "expression is false"; | ||
AssertUtils.isTrue(expression, message); | ||
} | ||
|
||
@Test | ||
public void testIsFalse_Success() { | ||
final boolean expression = false; | ||
final String message = "expression is false"; | ||
AssertUtils.isFalse(expression, message); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testIsFalse_Failure() { | ||
final boolean expression = true; | ||
final String message = "expression is true"; | ||
AssertUtils.isFalse(expression, message); | ||
} | ||
} |
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