Updated tests.
Change-Id: I4e43978c5cf8bbc678da5231ed938b707e11c442
diff --git a/full/Changes b/full/Changes
index ae3175d..02f043e 100644
--- a/full/Changes
+++ b/full/Changes
@@ -17,6 +17,7 @@
2022-01-03
- [security] More log4j security updates
- Bumped unboundid-ldapsdk
+ - Updated tests.
# version 0.64.1
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
index a856d90..25a1b36 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
@@ -2,14 +2,13 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@@ -18,15 +17,16 @@
import de.ids_mannheim.korap.config.FullConfiguration;
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
-import de.ids_mannheim.korap.constant.QueryType;
-import de.ids_mannheim.korap.constant.UserGroupStatus;
import de.ids_mannheim.korap.constant.QueryAccessStatus;
+import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
+import de.ids_mannheim.korap.constant.UserGroupStatus;
+import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.entity.Role;
import de.ids_mannheim.korap.entity.UserGroup;
import de.ids_mannheim.korap.entity.UserGroupMember;
-import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.user.User.CorpusAccess;
import edu.emory.mathcs.backport.java.util.Collections;
@@ -43,10 +43,6 @@
@Autowired
private FullConfiguration config;
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
-
@Test
public void createDeleteNewUserGroup () throws KustvaktException {
String groupName = "test group";
@@ -93,8 +89,13 @@
// hard delete
userGroupDao.deleteGroup(groupId, createdBy, false);
- thrown.expect(KustvaktException.class);
- group = userGroupDao.retrieveGroupById(groupId);
+
+ KustvaktException exception = assertThrows(KustvaktException.class, () -> {
+ userGroupDao.retrieveGroupById(groupId);
+ });
+
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ exception.getStatusCode().intValue());
}
@Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java
index bfdb84c..57bcf81 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusAccessDaoTest.java
@@ -1,20 +1,18 @@
package de.ids_mannheim.korap.dao;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import java.util.List;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import de.ids_mannheim.korap.constant.QueryAccessStatus;
-import de.ids_mannheim.korap.entity.UserGroup;
import de.ids_mannheim.korap.entity.QueryAccess;
+import de.ids_mannheim.korap.entity.UserGroup;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -24,9 +22,6 @@
@Autowired
private QueryAccessDao dao;
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
@Test
public void getAccessByVC () throws KustvaktException {
List<QueryAccess> vcaList = dao.retrieveActiveAccessByQuery(2);
@@ -38,5 +33,4 @@
assertEquals(2, group.getId());
}
-
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
index 10b3eb2..002dbfc 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
@@ -1,15 +1,15 @@
package de.ids_mannheim.korap.dao;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
import java.util.Iterator;
import java.util.List;
import javax.persistence.PersistenceException;
-import org.junit.Rule;
+import org.hibernate.exception.GenericJDBCException;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.annotation.Autowired;
import de.ids_mannheim.korap.config.SpringJerseyTest;
@@ -17,6 +17,7 @@
import de.ids_mannheim.korap.constant.ResourceType;
import de.ids_mannheim.korap.entity.QueryDO;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.user.User;
public class VirtualCorpusDaoTest extends SpringJerseyTest {
@@ -24,9 +25,6 @@
@Autowired
private QueryDao dao;
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
@Test
public void testListVCByType () throws KustvaktException {
List<QueryDO> vcList =
@@ -57,19 +55,27 @@
dao.deleteQuery(vc);
// check if vc has been deleted
- thrown.expect(KustvaktException.class);
- dao.retrieveQueryById(id);
+ KustvaktException exception =
+ assertThrows(KustvaktException.class, () -> {
+ dao.retrieveQueryById(id);
+ });
+
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ exception.getStatusCode().intValue());
}
@Test
public void testNonUniqueVC () throws KustvaktException {
- thrown.expect(PersistenceException.class);
- thrown.expectMessage("could not execute statement");
- dao.createQuery("system-vc", ResourceType.SYSTEM,
- QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
- "corpusSigle=GOE", "definition", "description", "experimental",
- false, "system", null, null);
+ PersistenceException exception = assertThrows(PersistenceException.class, ()->{
+ dao.createQuery("system-vc", ResourceType.SYSTEM,
+ QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
+ "corpusSigle=GOE", "definition", "description", "experimental",
+ false, "system", null, null);
+ });
+ assertEquals(
+ "org.hibernate.exception.GenericJDBCException: could not execute statement",
+ exception.getMessage());
}
@Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/StringUtilsTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/StringUtilsTest.java
index b6859bb..a2c8ea6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/StringUtilsTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/StringUtilsTest.java
@@ -1,13 +1,10 @@
package de.ids_mannheim.korap.misc;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import org.apache.commons.codec.binary.Base64;
import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import de.ids_mannheim.korap.authentication.BasicAuthentication;
import de.ids_mannheim.korap.authentication.http.AuthorizationData;
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.authentication.http.TransferEncoding;
@@ -31,9 +28,8 @@
@Test
public void testBasicHttpSplit () throws KustvaktException {
- TransferEncoding transferEncoding = new TransferEncoding();
String s2 = new String(Base64.encodeBase64("test:testPass".getBytes()));
- String[] f2 = transferEncoding.decodeBase64(s2);
+ String[] f2 = TransferEncoding.decodeBase64(s2);
assertEquals("test", f2[0]);
assertEquals("testPass", f2[1]);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
index 829ed63..5b6cdb2 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
@@ -64,7 +64,7 @@
response.getStatus());
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
- response.getMetadata().getFirst("X-Index-Revision")
+ response.getHeaders().getFirst("X-Index-Revision")
);
String message = response.getEntity(String.class);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
index f7ad853..3ca0e68 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
@@ -37,7 +37,7 @@
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
- response.getMetadata().getFirst("X-Index-Revision")
+ response.getHeaders().getFirst("X-Index-Revision")
);
String ent = response.getEntity(String.class);
@@ -194,7 +194,7 @@
assertEquals(
"Wes8Bd4h1OypPqbWF5njeQ==",
- response.getMetadata().getFirst("X-Index-Revision")
+ response.getHeaders().getFirst("X-Index-Revision")
);
assertEquals(ClientResponse.Status.OK.getStatusCode(),