Skip to content

Commit

Permalink
Upgrade to junit API 5
Browse files Browse the repository at this point in the history
  • Loading branch information
andmor- committed Jun 19, 2024
1 parent 02f8469 commit 493edc1
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 64 deletions.
6 changes: 3 additions & 3 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package eu.clarin.switchboard.app.config;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static eu.clarin.switchboard.app.config.DataStoreConfig.convertStringWithMultiplicatorToLong;

public class DataStoreConfigTest {
@Test
public void testConvertStringWithMultiplicatorToLong() {
Assert.assertEquals(0, convertStringWithMultiplicatorToLong("0"));
Assert.assertEquals(1, convertStringWithMultiplicatorToLong("1"));
Assert.assertEquals(1000, convertStringWithMultiplicatorToLong("1000"));
Assert.assertEquals(999999, convertStringWithMultiplicatorToLong("999999"));
Assert.assertEquals(999999999999L, convertStringWithMultiplicatorToLong("999999999999"));
Assert.assertEquals(1234 * 1024, convertStringWithMultiplicatorToLong("1234k"));
Assert.assertEquals(1234 * 1024, convertStringWithMultiplicatorToLong("1234K"));
Assert.assertEquals(1234 * 1024 * 1024, convertStringWithMultiplicatorToLong("1234m"));
Assert.assertEquals(1234 * 1024 * 1024, convertStringWithMultiplicatorToLong("1234M"));
Assert.assertEquals(1234 * 1024 * 1024 * 1024L, convertStringWithMultiplicatorToLong("1234g"));
Assert.assertEquals(1234 * 1024 * 1024 * 1024L, convertStringWithMultiplicatorToLong("1234G"));
Assertions.assertEquals(0, convertStringWithMultiplicatorToLong("0"));
Assertions.assertEquals(1, convertStringWithMultiplicatorToLong("1"));
Assertions.assertEquals(1000, convertStringWithMultiplicatorToLong("1000"));
Assertions.assertEquals(999999, convertStringWithMultiplicatorToLong("999999"));
Assertions.assertEquals(999999999999L, convertStringWithMultiplicatorToLong("999999999999"));
Assertions.assertEquals(1234 * 1024, convertStringWithMultiplicatorToLong("1234k"));
Assertions.assertEquals(1234 * 1024, convertStringWithMultiplicatorToLong("1234K"));
Assertions.assertEquals(1234 * 1024 * 1024, convertStringWithMultiplicatorToLong("1234m"));
Assertions.assertEquals(1234 * 1024 * 1024, convertStringWithMultiplicatorToLong("1234M"));
Assertions.assertEquals(1234 * 1024 * 1024 * 1024L, convertStringWithMultiplicatorToLong("1234g"));
Assertions.assertEquals(1234 * 1024 * 1024 * 1024L, convertStringWithMultiplicatorToLong("1234G"));
}

@Test(expected = NumberFormatException.class)
@Test
public void testBadNumber() {
convertStringWithMultiplicatorToLong("23asdf");
Assert.fail(); // will not get here
Assertions.assertThrows(NumberFormatException.class, () -> {
convertStringWithMultiplicatorToLong("23asdf");
});
}
}
20 changes: 10 additions & 10 deletions backend/src/test/java/eu/clarin/switchboard/core/DataStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import eu.clarin.switchboard.app.config.DataStoreConfig;
import eu.clarin.switchboard.core.xc.StoragePolicyException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -14,13 +14,13 @@
import java.util.List;
import java.util.UUID;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;


public class DataStoreTest {
DataStore dataStore;

@Before
@BeforeEach
public void setUp() throws Exception {
Path dataStoreRoot = Files.createTempDirectory("switchboard-test-");
String maxSize = "1k";
Expand Down Expand Up @@ -93,13 +93,13 @@ public void eraseAllStorage() throws IOException, StoragePolicyException {
assertEquals(storePath.toFile().listFiles().length, 0);
}

@Test(expected = StoragePolicyException.class)
@Test
public void uploadTooLarge() throws IOException, StoragePolicyException {
UUID id = UUID.randomUUID();
InputStream is = new ByteArrayInputStream(new byte[2 * 1024]);
Path path = dataStore.save(id, "test", is);

assert (false); // will not get here
assertThrows(StoragePolicyException.class, () -> {
UUID id = UUID.randomUUID();
InputStream is = new ByteArrayInputStream(new byte[2 * 1024]);
Path path = dataStore.save(id, "test", is);
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.cache.CacheConfig;
import org.apache.http.impl.client.cache.CachingHttpClients;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class LinkMetadataTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import eu.clarin.switchboard.core.xc.StoragePolicyException;
import eu.clarin.switchboard.profiler.DefaultProfiler;
import eu.clarin.switchboard.profiler.api.ProfilingException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -18,14 +18,16 @@
import java.nio.file.Path;
import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class MediaLibraryTest {
DataStoreConfig dataStoreConfig;
DefaultStoragePolicy storagePolicy;
DataStore dataStore;
DefaultProfiler profiler;
UrlResolverConfig urlResolver;

@Before
@BeforeEach
public void setUp() throws Exception {
Path dataStoreRoot = Files.createTempDirectory("switchboard-test-");
String maxSize = "1M";
Expand Down Expand Up @@ -57,31 +59,36 @@ public void allOk() throws IOException, StoragePolicyException, ProfilingExcepti
assert (true);
}

@Test(expected = StoragePolicyException.class)
@Test
public void tooManyFiles() throws IOException, StoragePolicyException, ProfilingException, StorageException {
MediaLibrary mediaLibrary = new MediaLibrary(
dataStore, profiler, profiler.getTextExtractor(),
storagePolicy, urlResolver, dataStoreConfig);
mediaLibrary.addFile("test", new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8)), null);
mediaLibrary.addFile("test", new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8)), null);
mediaLibrary.addFile("test", new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8)), null);
assert (false); // will not get here
assertThrows(StoragePolicyException.class, () -> {
MediaLibrary mediaLibrary = new MediaLibrary(
dataStore, profiler, profiler.getTextExtractor(),
storagePolicy, urlResolver, dataStoreConfig);
mediaLibrary.addFile("test", new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8)), null);
mediaLibrary.addFile("test", new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8)), null);
mediaLibrary.addFile("test", new ByteArrayInputStream("test".getBytes(StandardCharsets.UTF_8)), null);
});
}

@Test(expected = LinkException.class)
@Test
public void addMedia1() throws CommonException, ProfilingException {
MediaLibrary mediaLibrary = new MediaLibrary(
dataStore, profiler, profiler.getTextExtractor(),
storagePolicy, urlResolver, dataStoreConfig);
mediaLibrary.addByUrl("http://this^is&a)bad@url", null);
assertThrows(LinkException.class, () -> {
MediaLibrary mediaLibrary = new MediaLibrary(
dataStore, profiler, profiler.getTextExtractor(),
storagePolicy, urlResolver, dataStoreConfig);
mediaLibrary.addByUrl("http://this^is&a)bad@url", null);
});
}

@Test(expected = StoragePolicyException.class)
@Test
public void addMedia2() throws CommonException, ProfilingException {
MediaLibrary mediaLibrary = new MediaLibrary(
dataStore, profiler, profiler.getTextExtractor(),
storagePolicy, urlResolver, dataStoreConfig);
// a site that does a HTTP redirect
mediaLibrary.addByUrl("http://clarin.eu", null);
assertThrows(StoragePolicyException.class, () -> {
MediaLibrary mediaLibrary = new MediaLibrary(
dataStore, profiler, profiler.getTextExtractor(),
storagePolicy, urlResolver, dataStoreConfig);
// a site that does a HTTP redirect
mediaLibrary.addByUrl("http://clarin.eu", null);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import eu.clarin.switchboard.core.xc.LinkException;
import eu.clarin.switchboard.profiler.api.Profile;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.UUID;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class QuirksTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import eu.clarin.switchboard.profiler.api.Profile;
import eu.clarin.switchboard.tool.Tool;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static java.util.Arrays.asList;

public class ToolRegistryTest {
ToolRegistry toolRegistry;

@Before
@BeforeEach
public void setUp() throws Exception {
toolRegistry = new ToolRegistry("./src/test/resources/registry");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import eu.clarin.switchboard.core.MediaLibrary;
import eu.clarin.switchboard.profiler.DefaultProfiler;
import eu.clarin.switchboard.profiler.api.Profiler;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.StreamingOutput;
Expand All @@ -21,12 +21,12 @@
import java.util.Collections;
import java.util.Map;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class DataResourceTest {
DataResource dataResource;

@Before
@BeforeEach
public void setUp() throws Exception {
Path dataStoreRoot = Files.createTempDirectory("switchboard-test-");
String maxSize = "1M";
Expand Down

0 comments on commit 493edc1

Please sign in to comment.