Skip to content

Commit

Permalink
fix actuator pom, and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdClear committed Sep 28, 2023
1 parent 3c8ec4b commit c87cc57
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 4 deletions.
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.junit.Before;
import org.mockito.MockedStatic;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mockStatic;

/**
Expand All @@ -46,6 +47,7 @@ public void setupHandler() {
arkClient = mockStatic(ArkClient.class);
arkClient.when(() -> {
ArkClient.installOperation(new BizOperation());
ArkClient.uninstallBiz(anyString(), anyString());
}).thenReturn(success);
arkClient.when(ArkClient::getBizManagerService).thenReturn(new CustomBizManagerService());
arkClient.when(ArkClient::getPluginManagerService).thenReturn(new CustomPluginManagerService());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* @author lunarscave
*/
public class HealthHandlerTest extends BaseHandlerTest {
public class HealthHandlerTests extends BaseHandlerTest {

private HealthHandler handler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.List;

import com.alipay.sofa.serverless.arklet.core.BaseTest;
import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand;
import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HelpHandler;
import com.alipay.sofa.serverless.arklet.core.command.builtin.model.CommandModel;
Expand All @@ -29,7 +28,6 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

/**
* @author mingmen
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import java.util.Date;

public class ConvertUtilsTest extends TestCase {
public class ConvertUtilsTests extends TestCase {

@Test
public void testBytes2Megabyte() {
Expand Down

0 comments on commit c87cc57

Please sign in to comment.