aboutsummaryrefslogtreecommitdiffstats
path: root/configserver-flags
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahooinc.com>2022-07-28 10:54:36 +0200
committerBjørn Christian Seime <bjorncs@yahooinc.com>2022-07-28 14:51:34 +0200
commit6b16d75894e7a33566794b82b2bd48e113fdf2e9 (patch)
treefad22b98f83b4a06f61cd6abd295caa39c2f89f8 /configserver-flags
parente8fc8c075ceaa5abaa71d693c5b372b2041d0beb (diff)
Convert configserver-flags to junit5
Replace use of Hamcrest with junit5/assertj assertions
Diffstat (limited to 'configserver-flags')
-rw-r--r--configserver-flags/pom.xml33
-rw-r--r--configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/ConfigServerFlagSourceTest.java18
-rw-r--r--configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/db/FlagsDbImplTest.java20
-rw-r--r--configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/http/FlagsHandlerTest.java41
4 files changed, 66 insertions, 46 deletions
diff --git a/configserver-flags/pom.xml b/configserver-flags/pom.xml
index 61d03e41cd5..e9c0c68685c 100644
--- a/configserver-flags/pom.xml
+++ b/configserver-flags/pom.xml
@@ -59,6 +59,12 @@
<artifactId>guice</artifactId>
<scope>provided</scope>
<classifier>no_aop</classifier>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
@@ -78,15 +84,29 @@
<artifactId>testutil</artifactId>
<version>${project.version}</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.apache.curator</groupId>
+ <artifactId>curator-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -94,6 +114,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/ConfigServerFlagSourceTest.java b/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/ConfigServerFlagSourceTest.java
index 05802db6223..f0df08bfb6b 100644
--- a/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/ConfigServerFlagSourceTest.java
+++ b/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/ConfigServerFlagSourceTest.java
@@ -8,9 +8,9 @@ import com.yahoo.vespa.flags.FlagId;
import com.yahoo.vespa.flags.Flags;
import com.yahoo.vespa.flags.RawFlag;
import com.yahoo.vespa.test.file.TestFileSystem;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -20,8 +20,8 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -41,12 +41,12 @@ public class ConfigServerFlagSourceTest {
private ConfigServerFlagSource flagSource;
private BooleanFlag flag;
- @Before
+ @BeforeEach
public void setUp() {
flagsReplacer = Flags.clearFlagsForTesting();
}
- @After
+ @AfterEach
public void tearDown() {
flagsReplacer.close();
}
@@ -57,7 +57,7 @@ public class ConfigServerFlagSourceTest {
}
@Test
- public void testAbsentInFileSystemForwardsToFlagsDb() {
+ void testAbsentInFileSystemForwardsToFlagsDb() {
initialize();
when(flagsDb.getValue(flagId)).thenReturn(Optional.empty());
@@ -67,7 +67,7 @@ public class ConfigServerFlagSourceTest {
}
@Test
- public void testAvoidingZooKeeperWhenOverridingInFile() throws IOException {
+ void testAvoidingZooKeeperWhenOverridingInFile() throws IOException {
// Here is how to set the value of a flag, such that ZooKeeper will NOT be queried when getting that value:
// - Make a flag.db file with the override
Path flagPath = fileSystem.getPath(vespaHome + "/var/vespa/flag.db");
diff --git a/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/db/FlagsDbImplTest.java b/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/db/FlagsDbImplTest.java
index f3087aa0e3b..36451e759fa 100644
--- a/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/db/FlagsDbImplTest.java
+++ b/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/db/FlagsDbImplTest.java
@@ -9,24 +9,22 @@ import com.yahoo.vespa.flags.json.Condition;
import com.yahoo.vespa.flags.json.FlagData;
import com.yahoo.vespa.flags.json.Rule;
import com.yahoo.vespa.flags.json.WhitelistCondition;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Map;
import java.util.Optional;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author hakonhall
*/
public class FlagsDbImplTest {
@Test
- public void test() {
+ void test() {
MockCurator curator = new MockCurator();
FlagsDbImpl db = new FlagsDbImpl(curator);
@@ -48,9 +46,9 @@ public class FlagsDbImplTest {
FlagData data2 = new FlagData(flagId2, new FetchVector().with(FetchVector.Dimension.ZONE_ID, "zone-a"), rule1);
db.setValue(flagId2, data2);
Map<FlagId, FlagData> flags = db.getAllFlagData();
- assertThat(flags.size(), equalTo(2));
- assertThat(flags.get(flagId), notNullValue());
- assertThat(flags.get(flagId2), notNullValue());
+ assertEquals(flags.size(), 2);
+ assertNotNull(flags.get(flagId));
+ assertNotNull(flags.get(flagId2));
db.removeValue(flagId2);
assertFalse(db.getValue(flagId2).isPresent());
diff --git a/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/http/FlagsHandlerTest.java b/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/http/FlagsHandlerTest.java
index 3ca0567a1c5..2700ab114e9 100644
--- a/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/http/FlagsHandlerTest.java
+++ b/configserver-flags/src/test/java/com/yahoo/vespa/configserver/flags/http/FlagsHandlerTest.java
@@ -13,7 +13,7 @@ import com.yahoo.vespa.flags.FlagId;
import com.yahoo.vespa.flags.Flags;
import com.yahoo.vespa.flags.UnboundBooleanFlag;
import com.yahoo.yolean.Exceptions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -23,10 +23,8 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author hakonhall
@@ -44,7 +42,7 @@ public class FlagsHandlerTest {
private final FlagsHandler handler = new FlagsHandler(FlagsHandler.testContext(), flagsDb);
@Test
- public void testV1() {
+ void testV1() {
String expectedResponse = "{" +
Stream.of("data", "defined")
.map(name -> "\"" + name + "\":{\"url\":\"https://foo.com:4443/flags/v1/" + name + "\"}")
@@ -55,7 +53,7 @@ public class FlagsHandlerTest {
}
@Test
- public void testDefined() {
+ void testDefined() {
try (Flags.Replacer replacer = Flags.clearFlagsForTesting()) {
fixUnusedWarning(replacer);
Flags.defineFeatureFlag("id", false, List.of("joe"), "2010-01-01", "2030-01-01", "desc", "mod", FetchVector.Dimension.HOSTNAME);
@@ -70,7 +68,7 @@ public class FlagsHandlerTest {
private void fixUnusedWarning(Flags.Replacer replacer) { }
@Test
- public void testData() {
+ void testData() {
// PUT flag with ID id1
verifySuccessfulRequest(Method.PUT, "/data/" + FLAG1.id(),
"{\n" +
@@ -96,8 +94,8 @@ public class FlagsHandlerTest {
"", "{\"flags\":[{\"id\":\"id1\",\"url\":\"https://foo.com:4443/flags/v1/data/id1\"}]}");
// Verify absent port => absent in response
- assertThat(handleWithPort(Method.GET, -1, "/data", "", 200),
- is("{\"flags\":[{\"id\":\"id1\",\"url\":\"https://foo.com/flags/v1/data/id1\"}]}"));
+ assertEquals(handleWithPort(Method.GET, -1, "/data", "", 200),
+ "{\"flags\":[{\"id\":\"id1\",\"url\":\"https://foo.com/flags/v1/data/id1\"}]}");
// PUT id2
verifySuccessfulRequest(Method.PUT, "/data/" + FLAG2.id(),
@@ -163,25 +161,24 @@ public class FlagsHandlerTest {
}
@Test
- public void testForcing() {
- assertThat(handle(Method.PUT, "/data/" + new FlagId("undef"), "", 400),
- containsString("There is no flag 'undef'"));
+ void testForcing() {
+ assertThat(handle(Method.PUT, "/data/" + new FlagId("undef"), "", 400)).contains("There is no flag 'undef'");
- assertThat(handle(Method.PUT, "/data/" + new FlagId("undef") + "?force=true", "", 400),
- containsString("No content to map due to end-of-input"));
+ assertThat(handle(Method.PUT, "/data/" + new FlagId("undef") + "?force=true", "", 400)).
+ contains("No content to map due to end-of-input");
- assertThat(handle(Method.PUT, "/data/" + FLAG1.id(), "{}", 400),
- containsString("Flag ID missing"));
+ assertThat(handle(Method.PUT, "/data/" + FLAG1.id(), "{}", 400)).
+ contains("Flag ID missing");
- assertThat(handle(Method.PUT, "/data/" + FLAG1.id(), "{\"id\": \"id1\",\"rules\": [{\"value\":\"string\"}]}", 400),
- containsString("Wrong type of JsonNode: STRING"));
+ assertThat(handle(Method.PUT, "/data/" + FLAG1.id(), "{\"id\": \"id1\",\"rules\": [{\"value\":\"string\"}]}", 400)).
+ contains("Wrong type of JsonNode: STRING");
- assertThat(handle(Method.PUT, "/data/" + FLAG1.id() + "?force=true", "{\"id\": \"id1\",\"rules\": [{\"value\":\"string\"}]}", 200),
- is(""));
+ assertEquals(handle(Method.PUT, "/data/" + FLAG1.id() + "?force=true", "{\"id\": \"id1\",\"rules\": [{\"value\":\"string\"}]}", 200),
+ "");
}
private void verifySuccessfulRequest(Method method, String pathSuffix, String requestBody, String expectedResponseBody) {
- assertThat(handle(method, pathSuffix, requestBody, 200), is(expectedResponseBody));
+ assertEquals(handle(method, pathSuffix, requestBody, 200), expectedResponseBody);
}
private String handle(Method method, String pathSuffix, String requestBody, int expectedStatus) {