mirror of https://github.com/apache/activemq.git
Merge pull request #642 from Charlie-chenchrl/brokerServiceTest
fix BrokerServiceTest by replacing powermock
This commit is contained in:
commit
fc2ad12e6b
|
@ -302,27 +302,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito-common</artifactId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -22,22 +22,19 @@ import org.apache.activemq.network.NetworkConnector;
|
|||
import org.apache.activemq.store.PersistenceAdapter;
|
||||
import org.apache.activemq.util.LargeFile;
|
||||
import org.apache.activemq.util.StoreUtil;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.powermock.api.mockito.PowerMockito.mockStatic;
|
||||
import static org.powermock.api.mockito.PowerMockito.verifyStatic;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import junit.framework.TestCase;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
/**
|
||||
* Tests for the BrokerService class
|
||||
*
|
||||
* @author chirino
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(StoreUtil.class)
|
||||
public class BrokerServiceTest extends TestCase {
|
||||
public void testAddRemoveTransportsWithJMX() throws Exception {
|
||||
BrokerService service = new BrokerService();
|
||||
|
@ -94,6 +91,7 @@ public class BrokerServiceTest extends TestCase {
|
|||
assertEquals( 1024L * 1024 * 1024 * 100, service.getSystemUsage().getStoreUsage().getLimit() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLargeFileSystem() throws Exception {
|
||||
BrokerService service = new BrokerService();
|
||||
|
||||
|
@ -105,29 +103,30 @@ public class BrokerServiceTest extends TestCase {
|
|||
service.setPersistenceAdapter(persistenceAdapter);
|
||||
service.setUseJmx(false);
|
||||
|
||||
mockStatic(StoreUtil.class);
|
||||
try(MockedStatic<StoreUtil> mocked = Mockito.mockStatic(StoreUtil.class)) {
|
||||
// Return a simulated handle to a very large file system that will return a negative totalSpace.
|
||||
mocked.when(() -> StoreUtil.findParentDirectory(dataDirectory)).thenReturn(new LargeFile(dataDirectory.getParentFile(), "KahaDB"));
|
||||
mocked.when(() -> StoreUtil.findParentDirectory(tmpDataDirectory)).thenReturn(tmpDataDirectory.getParentFile());
|
||||
|
||||
// Return a simulated handle to a very large file system that will return a negative totalSpace.
|
||||
when(StoreUtil.findParentDirectory(dataDirectory)).thenReturn(new LargeFile(dataDirectory.getParentFile(), "KahaDB"));
|
||||
when(StoreUtil.findParentDirectory(tmpDataDirectory)).thenReturn(tmpDataDirectory.getParentFile());
|
||||
try {
|
||||
service.start();
|
||||
fail("Expect error on negative totalspace");
|
||||
} catch (Exception expected) {
|
||||
// verify message
|
||||
assertTrue(expected.getLocalizedMessage().contains("negative"));
|
||||
}
|
||||
finally {
|
||||
service.stop();
|
||||
}
|
||||
|
||||
try {
|
||||
service.start();
|
||||
fail("Expect error on negative totalspace");
|
||||
} catch (Exception expected) {
|
||||
// verify message
|
||||
assertTrue(expected.getLocalizedMessage().contains("negative"));
|
||||
}
|
||||
finally {
|
||||
// configure a 2x value for the fs limit so it can start
|
||||
service.getSystemUsage().getStoreUsage().setTotal( service.getSystemUsage().getStoreUsage().getLimit() * 2);
|
||||
|
||||
service.start(true);
|
||||
service.stop();
|
||||
|
||||
mocked.verify(() -> StoreUtil.findParentDirectory(any()), times(3));
|
||||
}
|
||||
|
||||
// configure a 2x value for the fs limit so it can start
|
||||
service.getSystemUsage().getStoreUsage().setTotal( service.getSystemUsage().getStoreUsage().getLimit() * 2);
|
||||
|
||||
service.start(true);
|
||||
service.stop();
|
||||
|
||||
verifyStatic();
|
||||
}
|
||||
}
|
||||
|
|
25
pom.xml
25
pom.xml
|
@ -85,7 +85,6 @@
|
|||
<log4j-version>1.2.17</log4j-version>
|
||||
<mockito-version>3.8.0</mockito-version>
|
||||
<owasp-dependency-check-version>5.2.4</owasp-dependency-check-version>
|
||||
<powermock-version>1.7.4</powermock-version>
|
||||
<mqtt-client-version>1.16</mqtt-client-version>
|
||||
<org-apache-derby-version>10.14.2.0</org-apache-derby-version>
|
||||
<osgi-version>6.0.0</osgi-version>
|
||||
|
@ -943,27 +942,9 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-core</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito-common</artifactId>
|
||||
<version>${powermock-version}</version>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>${mockito-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
Loading…
Reference in New Issue