Migrate AttachmentControllerTest to JUnit 5

This commit is contained in:
Chris Eager 2021-07-23 14:31:17 -05:00 committed by Chris Eager
parent f7af861b31
commit 2144d2a8d8
1 changed files with 16 additions and 15 deletions

View File

@ -11,7 +11,8 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider; import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
import io.dropwizard.testing.junit.ResourceTestRule; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import io.dropwizard.testing.junit5.ResourceExtension;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -30,8 +31,8 @@ import org.assertj.core.api.Assertions;
import org.assertj.core.api.Condition; import org.assertj.core.api.Condition;
import org.assertj.core.api.InstanceOfAssertFactories; import org.assertj.core.api.InstanceOfAssertFactories;
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory; import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
import org.junit.ClassRule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith;
import org.whispersystems.textsecuregcm.auth.DisabledPermittedAccount; import org.whispersystems.textsecuregcm.auth.DisabledPermittedAccount;
import org.whispersystems.textsecuregcm.controllers.AttachmentControllerV1; import org.whispersystems.textsecuregcm.controllers.AttachmentControllerV1;
import org.whispersystems.textsecuregcm.controllers.AttachmentControllerV2; import org.whispersystems.textsecuregcm.controllers.AttachmentControllerV2;
@ -46,7 +47,8 @@ import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper; import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import org.whispersystems.textsecuregcm.util.SystemMapper; import org.whispersystems.textsecuregcm.util.SystemMapper;
public class AttachmentControllerTest { @ExtendWith(DropwizardExtensionsSupport.class)
class AttachmentControllerTest {
private static RateLimiters rateLimiters = mock(RateLimiters.class ); private static RateLimiters rateLimiters = mock(RateLimiters.class );
private static RateLimiter rateLimiter = mock(RateLimiter.class ); private static RateLimiter rateLimiter = mock(RateLimiter.class );
@ -71,12 +73,11 @@ public class AttachmentControllerTest {
} }
} }
@ClassRule private static final ResourceExtension resources;
public static final ResourceTestRule resources;
static { static {
try { try {
resources = ResourceTestRule.builder() resources = ResourceExtension.builder()
.addProvider(AuthHelper.getAuthFilter()) .addProvider(AuthHelper.getAuthFilter())
.addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(Account.class, DisabledPermittedAccount.class))) .addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(Account.class, DisabledPermittedAccount.class)))
.setMapper(SystemMapper.getMapper()) .setMapper(SystemMapper.getMapper())
@ -91,7 +92,7 @@ public class AttachmentControllerTest {
} }
@Test @Test
public void testV3Form() { void testV3Form() {
AttachmentDescriptorV3 descriptor = resources.getJerseyTest() AttachmentDescriptorV3 descriptor = resources.getJerseyTest()
.target("/v3/attachments/form/upload") .target("/v3/attachments/form/upload")
.request() .request()
@ -147,7 +148,7 @@ public class AttachmentControllerTest {
} }
@Test @Test
public void testV3FormDisabled() { void testV3FormDisabled() {
Response response = resources.getJerseyTest() Response response = resources.getJerseyTest()
.target("/v3/attachments/form/upload") .target("/v3/attachments/form/upload")
.request() .request()
@ -158,7 +159,7 @@ public class AttachmentControllerTest {
} }
@Test @Test
public void testV2Form() throws IOException { void testV2Form() throws IOException {
AttachmentDescriptorV2 descriptor = resources.getJerseyTest() AttachmentDescriptorV2 descriptor = resources.getJerseyTest()
.target("/v2/attachments/form/upload") .target("/v2/attachments/form/upload")
.request() .request()
@ -186,7 +187,7 @@ public class AttachmentControllerTest {
} }
@Test @Test
public void testV2FormDisabled() { void testV2FormDisabled() {
Response response = resources.getJerseyTest() Response response = resources.getJerseyTest()
.target("/v2/attachments/form/upload") .target("/v2/attachments/form/upload")
.request() .request()
@ -198,7 +199,7 @@ public class AttachmentControllerTest {
@Test @Test
public void testAcceleratedPut() { void testAcceleratedPut() {
AttachmentDescriptorV1 descriptor = resources.getJerseyTest() AttachmentDescriptorV1 descriptor = resources.getJerseyTest()
.target("/v1/attachments/") .target("/v1/attachments/")
.request() .request()
@ -211,7 +212,7 @@ public class AttachmentControllerTest {
} }
@Test @Test
public void testUnacceleratedPut() { void testUnacceleratedPut() {
AttachmentDescriptorV1 descriptor = resources.getJerseyTest() AttachmentDescriptorV1 descriptor = resources.getJerseyTest()
.target("/v1/attachments/") .target("/v1/attachments/")
.request() .request()
@ -224,7 +225,7 @@ public class AttachmentControllerTest {
} }
@Test @Test
public void testAcceleratedGet() throws MalformedURLException { void testAcceleratedGet() throws MalformedURLException {
AttachmentUri uri = resources.getJerseyTest() AttachmentUri uri = resources.getJerseyTest()
.target("/v1/attachments/1234") .target("/v1/attachments/1234")
.request() .request()
@ -235,7 +236,7 @@ public class AttachmentControllerTest {
} }
@Test @Test
public void testUnacceleratedGet() throws MalformedURLException { void testUnacceleratedGet() throws MalformedURLException {
AttachmentUri uri = resources.getJerseyTest() AttachmentUri uri = resources.getJerseyTest()
.target("/v1/attachments/1234") .target("/v1/attachments/1234")
.request() .request()