mirror of https://github.com/apache/cloudstack.git
Fix failing unit tests
This commit is contained in:
parent
24771d4e8c
commit
33f3d3dd75
|
|
@ -24,6 +24,8 @@ import org.apache.cloudstack.framework.kms.KeyPurpose;
|
|||
import org.apache.cloudstack.kms.dao.HSMProfileDao;
|
||||
import org.apache.cloudstack.kms.dao.KMSKekVersionDao;
|
||||
import org.apache.cloudstack.kms.dao.KMSKeyDao;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
|
@ -33,6 +35,10 @@ import org.mockito.MockedStatic;
|
|||
import org.mockito.Mockito;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -68,6 +74,28 @@ public class KMSManagerImplKeyCreationTest {
|
|||
@Mock
|
||||
private KMSProvider kmsProvider;
|
||||
|
||||
private ExecutorService executor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
executor = Executors.newSingleThreadExecutor(r -> {
|
||||
Thread t = new Thread(r, "kms-test");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
ReflectionTestUtils.setField(kmsManager, "kmsOperationExecutor", executor);
|
||||
doReturn(5).when(kmsManager).getOperationTimeoutSec();
|
||||
doReturn(0).when(kmsManager).getRetryCount();
|
||||
doReturn(0).when(kmsManager).getRetryDelayMs();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (executor != null) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test: createUserKMSKey uses explicit HSM profile when provided
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import org.apache.cloudstack.kms.dao.HSMProfileDao;
|
|||
import org.apache.cloudstack.kms.dao.KMSKekVersionDao;
|
||||
import org.apache.cloudstack.kms.dao.KMSKeyDao;
|
||||
import org.apache.cloudstack.kms.dao.KMSWrappedKeyDao;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -37,8 +38,11 @@ import org.mockito.Mockito;
|
|||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -82,13 +86,28 @@ public class KMSManagerImplKeyLifecycleTest {
|
|||
@Mock
|
||||
private KMSProvider kmsProvider;
|
||||
|
||||
private ExecutorService executor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
executor = Executors.newSingleThreadExecutor(r -> {
|
||||
Thread t = new Thread(r, "kms-test");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
ReflectionTestUtils.setField(kmsManager, "kmsOperationExecutor", executor);
|
||||
doReturn(5).when(kmsManager).getOperationTimeoutSec();
|
||||
doReturn(0).when(kmsManager).getRetryCount();
|
||||
doReturn(0).when(kmsManager).getRetryDelayMs();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (executor != null) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = KMSException.class)
|
||||
public void testUnwrapKey_ThrowsWhenWrappedKeyNotFound() throws KMSException {
|
||||
when(kmsWrappedKeyDao.findById(1L)).thenReturn(null);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.apache.cloudstack.kms.dao.KMSKekVersionDao;
|
|||
import org.apache.cloudstack.kms.dao.KMSKeyDao;
|
||||
import org.apache.cloudstack.kms.dao.KMSWrappedKeyDao;
|
||||
import com.cloud.event.ActionEventUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -36,8 +37,11 @@ import org.mockito.MockedStatic;
|
|||
import org.mockito.Mockito;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -80,8 +84,26 @@ public class KMSManagerImplKeyRotationTest {
|
|||
private final Long testZoneId = 1L;
|
||||
private final String testProviderName = "pkcs11";
|
||||
|
||||
private ExecutorService executor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
executor = Executors.newSingleThreadExecutor(r -> {
|
||||
Thread t = new Thread(r, "kms-test");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
ReflectionTestUtils.setField(kmsManager, "kmsOperationExecutor", executor);
|
||||
doReturn(5).when(kmsManager).getOperationTimeoutSec();
|
||||
doReturn(0).when(kmsManager).getRetryCount();
|
||||
doReturn(0).when(kmsManager).getRetryDelayMs();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (executor != null) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,12 +18,17 @@
|
|||
package org.apache.cloudstack.kms;
|
||||
|
||||
import org.apache.cloudstack.framework.kms.KMSException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
|
@ -46,6 +51,25 @@ public class KMSManagerImplRetryTest {
|
|||
@InjectMocks
|
||||
private KMSManagerImpl kmsManager;
|
||||
|
||||
private ExecutorService executor;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
executor = Executors.newSingleThreadExecutor(r -> {
|
||||
Thread t = new Thread(r, "kms-test");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
ReflectionTestUtils.setField(kmsManager, "kmsOperationExecutor", executor);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (executor != null) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the spy to use a 1-second timeout, the given retry count, and no delay.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue