Handled unique constraints.
Change-Id: I0ee968b18b028ded76af04a0473c7997a13f2f11
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java b/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
index 959dce2..60fb14a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
@@ -23,7 +23,7 @@
@ContextConfiguration("classpath:test-config.xml")
public abstract class SpringJerseyTest extends JerseyTest {
- public final static String API_VERSION = "v1.0";
+ public final static String API_VERSION = "v1.1";
@Autowired
protected GenericApplicationContext applicationContext;
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 1cdd7a5..d1fda36 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
@@ -70,12 +70,15 @@
assertEquals(createdBy, m.getUserId());
// member roles
- List<Role> roles = roleDao.retrieveRoleByGroupMemberId(m.getId());
+ Set<Role> roles = roleDao.retrieveRoleByGroupMemberId(m.getId());
assertEquals(2, roles.size());
+ ArrayList<Role> roleList = new ArrayList<>(2);
+ roleList.addAll(roles);
+ Collections.sort(roleList);
assertEquals(PredefinedRole.USER_GROUP_ADMIN.getId(),
- roles.get(0).getId());
+ roleList.get(0).getId());
assertEquals(PredefinedRole.VC_ACCESS_ADMIN.getId(),
- roles.get(1).getId());
+ roleList.get(1).getId());
//retrieve VC by group
List<VirtualCorpus> vc = virtualCorpusDao.retrieveVCByGroup(groupId);
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
index ff86c80..8b38d7b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupMemberDaoTest.java
@@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import java.util.List;
+import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -11,6 +12,7 @@
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.entity.Role;
import de.ids_mannheim.korap.entity.UserGroupMember;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -21,13 +23,31 @@
@Autowired
private UserGroupMemberDao dao;
+ @Autowired
+ private RoleDao roleDao;
+
@Test
public void testRetrieveMemberByRole () throws KustvaktException {
// dory group
List<UserGroupMember> vcaAdmins = dao.retrieveMemberByRole(2,
PredefinedRole.VC_ACCESS_ADMIN.getId());
-// System.out.println(vcaAdmins);
+ // System.out.println(vcaAdmins);
assertEquals(1, vcaAdmins.size());
assertEquals("dory", vcaAdmins.get(0).getUserId());
}
+
+ @Test
+ public void testAddSameMemberRole () throws KustvaktException {
+ UserGroupMember member = dao.retrieveMemberById("dory", 1);
+ Set<Role> roles = member.getRoles();
+ Role adminRole = roleDao
+ .retrieveRoleById(PredefinedRole.USER_GROUP_ADMIN.getId());
+ roles.add(adminRole);
+ member.setRoles(roles);
+ dao.updateMember(member);
+
+ member = dao.retrieveMemberById("dory", 1);
+ member.getRoles();
+ assertEquals(2, roles.size());
+ }
}
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 e15a518..5b7c9d7 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
@@ -5,6 +5,8 @@
import java.util.Iterator;
import java.util.List;
+import javax.persistence.PersistenceException;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -61,21 +63,32 @@
dao.retrieveVCById(id);
}
+ @Test
+ public void testNonUniqueVC () throws KustvaktException {
+ thrown.expect(PersistenceException.class);
+ thrown.expectMessage("could not execute statement");
+
+ dao.createVirtualCorpus("system VC", VirtualCorpusType.SYSTEM,
+ User.CorpusAccess.FREE, "corpusSigle=GOE", "definition",
+ "description", "experimental", false, "system");
+ }
@Test
public void retrieveSystemVC () throws KustvaktException {
- List<VirtualCorpus> vc = dao.retrieveVCByType(VirtualCorpusType.SYSTEM, null);
+ List<VirtualCorpus> vc =
+ dao.retrieveVCByType(VirtualCorpusType.SYSTEM, null);
assertEquals(1, vc.size());
}
-
- /** retrieve private and group VC
+ /**
+ * retrieve private and group VC
+ *
* @throws KustvaktException
*/
@Test
public void retrieveVCByUserDory () throws KustvaktException {
List<VirtualCorpus> virtualCorpora = dao.retrieveVCByUser("dory");
- // System.out.println(virtualCorpora);
+ // System.out.println(virtualCorpora);
assertEquals(4, virtualCorpora.size());
// ordered by id
Iterator<VirtualCorpus> i = virtualCorpora.iterator();
@@ -85,9 +98,10 @@
assertEquals("published VC", i.next().getName());
}
-
- /** retrieves group VC and
- * excludes hidden published VC (user has never used it)
+ /**
+ * retrieves group VC and
+ * excludes hidden published VC (user has never used it)
+ *
* @throws KustvaktException
*/
@Test
@@ -100,9 +114,10 @@
assertEquals("nemo VC", i.next().getName());
}
-
- /** retrieves published VC by the owner and
- * excludes group vc when a user is a pending member
+ /**
+ * retrieves published VC by the owner and
+ * excludes group vc when a user is a pending member
+ *
* @throws KustvaktException
*/
@Test
@@ -115,10 +130,10 @@
assertEquals("marlin VC", i.next().getName());
}
-
-
- /** retrieves published VC from an auto-generated hidden group and
- * excludes group vc when a user is a deleted member
+ /**
+ * retrieves published VC from an auto-generated hidden group and
+ * excludes group vc when a user is a deleted member
+ *
* @throws KustvaktException
*/
@Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
index 6ae2e3d..3cca102 100644
--- a/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/service/VirtualCorpusServiceTest.java
@@ -4,7 +4,9 @@
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;
@@ -26,6 +28,23 @@
@Autowired
private VirtualCorpusService vcService;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testCreateNonUniqueVC () throws KustvaktException {
+ thrown.expect(KustvaktException.class);
+ thrown.expectMessage("A UNIQUE constraint failed "
+ + "(UNIQUE constraint failed: virtual_corpus.name, "
+ + "virtual_corpus.created_by)");
+
+ VirtualCorpusJson vc = new VirtualCorpusJson();
+ vc.setCorpusQuery("corpusSigle=GOE");
+ vc.setName("dory VC");
+ vc.setType(VirtualCorpusType.PRIVATE);
+ vcService.storeVC(vc, "dory");
+ }
+
@Test
public void createDeletePublishVC () throws KustvaktException {
String username = "VirtualCorpusServiceTest";
@@ -63,7 +82,8 @@
// check VC
VirtualCorpusDto vcDto = vcService.searchVCById("dory", vcId);
assertEquals("group VC published", vcDto.getName());
- assertEquals(VirtualCorpusType.PUBLISHED.displayName(), vcDto.getType());
+ assertEquals(VirtualCorpusType.PUBLISHED.displayName(),
+ vcDto.getType());
// check access
List<VirtualCorpusAccess> accesses =
@@ -72,7 +92,7 @@
VirtualCorpusAccess access = accesses.get(1);
assertEquals(VirtualCorpusAccessStatus.HIDDEN, access.getStatus());
-
+
// check auto hidden group
UserGroup autoHiddenGroup = access.getUserGroup();
assertEquals(UserGroupStatus.HIDDEN, autoHiddenGroup.getStatus());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java b/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
index b8ca799..92400e6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/ApiVersionTest.java
@@ -23,7 +23,7 @@
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
- assertEquals("/api/v1.0/search", location.getPath());
+ assertEquals("/api/"+API_VERSION+"/search", location.getPath());
}
@Test
@@ -34,6 +34,6 @@
.get(ClientResponse.class);
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
- assertEquals("/api/v1.0/search", location.getPath());
+ assertEquals("/api/"+API_VERSION+"/search", location.getPath());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
index 093d586..86d902e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerTest.java
@@ -2,10 +2,13 @@
import static org.junit.Assert.assertEquals;
+import java.util.Set;
+
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.net.HttpHeaders;
@@ -20,6 +23,9 @@
import de.ids_mannheim.korap.config.SpringJerseyTest;
import de.ids_mannheim.korap.constant.GroupMemberStatus;
import de.ids_mannheim.korap.constant.PredefinedRole;
+import de.ids_mannheim.korap.dao.UserGroupMemberDao;
+import de.ids_mannheim.korap.entity.Role;
+import de.ids_mannheim.korap.entity.UserGroupMember;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
@@ -31,13 +37,17 @@
*/
public class UserGroupControllerTest extends SpringJerseyTest {
+ @Autowired
+ private UserGroupMemberDao memberDao;
+
private String username = "UserGroupControllerTest";
private String admin = "admin";
private JsonNode retrieveUserGroups (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("list")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("list")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -52,7 +62,8 @@
// dory is a group admin in dory group
@Test
public void testListDoryGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("list")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("list")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -72,7 +83,8 @@
// nemo is a group member in dory group
@Test
public void testListNemoGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("list")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("list")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -92,8 +104,8 @@
// marlin has 2 groups
@Test
public void testListMarlinGroups () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("list")
- .queryParam("username", "marlin")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("list").queryParam("username", "marlin")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -104,11 +116,10 @@
assertEquals(2, node.size());
}
-
@Test
public void testListGroupGuest () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("list")
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("list").header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.get(ClientResponse.class);
String entity = response.getEntity(String.class);
// System.out.println(entity);
@@ -129,8 +140,8 @@
json.setName("new user group");
json.setMembers(new String[] { "marlin", "nemo" });
- ClientResponse response = resource().path(API_VERSION).path("group").path("create")
- .type(MediaType.APPLICATION_JSON)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("create").type(MediaType.APPLICATION_JSON)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(json)
@@ -178,13 +189,12 @@
testUnsubscribeToDeletedGroup(groupId);
}
-
private void testDeleteMember (String groupId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// delete marlin from group
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("delete").path(groupId).path("marlin")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("delete").path(groupId).path("marlin")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -206,8 +216,8 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// nemo is a group member
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("delete").path(groupId).path("marlin")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("delete").path(groupId).path("marlin")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -227,7 +237,8 @@
private void testDeletePendingMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
// dory delete pearl
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member")
// dory group
.path("delete").path("2").path("pearl")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -245,8 +256,8 @@
@Test
public void testDeleteDeletedMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("delete").path("2").path("pearl")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("delete").path("2").path("pearl")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -267,8 +278,8 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
// delete group
- ClientResponse response = resource().path(API_VERSION).path("group").path("delete")
- .path(groupId)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("delete").path(groupId)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -277,8 +288,8 @@
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// check group
- response = resource().path(API_VERSION).path("group").path("list").path("system-admin")
- .queryParam("username", username)
+ response = resource().path(API_VERSION).path("group").path("list")
+ .path("system-admin").queryParam("username", username)
.queryParam("status", "DELETED")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
@@ -301,8 +312,8 @@
public void testDeleteGroupUnauthorized () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
// dory is a group admin in marlin group
- ClientResponse response = resource().path(API_VERSION).path("group").path("delete")
- .path("1")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("delete").path("1")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -321,8 +332,8 @@
@Test
public void testDeleteDeletedGroup () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("delete")
- .path("4")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("delete").path("4")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -343,8 +354,8 @@
ClientHandlerException, KustvaktException {
// delete marlin from marlin group
// dory is a group admin in marlin group
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("delete").path("1").path("marlin")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("delete").path("1").path("marlin")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -368,8 +379,8 @@
userGroup.setMembers(members);
userGroup.setId(Integer.parseInt(groupId));
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("invite").type(MediaType.APPLICATION_JSON)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("invite").type(MediaType.APPLICATION_JSON)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
@@ -405,8 +416,8 @@
// dory group
userGroup.setId(2);
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("invite").type(MediaType.APPLICATION_JSON)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("invite").type(MediaType.APPLICATION_JSON)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
@@ -434,8 +445,8 @@
// dory group
userGroup.setId(2);
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("invite").type(MediaType.APPLICATION_JSON)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("invite").type(MediaType.APPLICATION_JSON)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
@@ -464,8 +475,8 @@
// dory group
userGroup.setId(2);
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("invite").type(MediaType.APPLICATION_JSON)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("invite").type(MediaType.APPLICATION_JSON)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
@@ -484,7 +495,6 @@
node.at("/errors/0/2").asText());
}
-
@Test
public void testInviteActiveMember () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
@@ -496,8 +506,8 @@
// dory group
userGroup.setId(2);
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("invite").type(MediaType.APPLICATION_JSON)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("invite").type(MediaType.APPLICATION_JSON)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
@@ -528,8 +538,8 @@
// dory's deleted group
userGroup.setId(4);
- ClientResponse response = resource().path(API_VERSION).path("group").path("member")
- .path("invite").type(MediaType.APPLICATION_JSON)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("invite").type(MediaType.APPLICATION_JSON)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
@@ -551,8 +561,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", "2");
- ClientResponse response = resource().path(API_VERSION).path("group").path("subscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("subscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
@@ -578,7 +588,6 @@
assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(),
group.at("/userRoles/1").asText());
-
// unsubscribe marlin from dory group
testUnsubscribeActiveMember(form);
checkGroupMemberRole("2", "marlin");
@@ -594,8 +603,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", "2");
- ClientResponse response = resource().path(API_VERSION).path("group").path("subscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("subscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
@@ -612,7 +621,8 @@
@Test
public void testSubscribeMissingGroupId () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("subscribe")
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("subscribe")
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("bruce", "pass"))
@@ -632,8 +642,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", "2");
- ClientResponse response = resource().path(API_VERSION).path("group").path("subscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("subscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("bruce", "pass"))
@@ -654,8 +664,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", "100");
- ClientResponse response = resource().path(API_VERSION).path("group").path("subscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("subscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
@@ -677,8 +687,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", groupId);
- ClientResponse response = resource().path(API_VERSION).path("group").path("subscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("subscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
@@ -697,8 +707,8 @@
MultivaluedMap<String, String> form)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path("unsubscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("unsubscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
@@ -712,7 +722,8 @@
private void checkGroupMemberRole (String groupId, String deletedMemberName)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path(groupId)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path(groupId)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -741,8 +752,8 @@
// dory group
form.add("groupId", "2");
- ClientResponse response = resource().path(API_VERSION).path("group").path("unsubscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("unsubscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
@@ -771,8 +782,8 @@
// dory group
form.add("groupId", "2");
- ClientResponse response = resource().path(API_VERSION).path("group").path("unsubscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("unsubscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
@@ -792,8 +803,8 @@
public void testUnsubscribeMissingGroupId () throws KustvaktException {
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- ClientResponse response = resource().path(API_VERSION).path("group").path("unsubscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("unsubscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
@@ -815,8 +826,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", "2");
- ClientResponse response = resource().path(API_VERSION).path("group").path("unsubscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("unsubscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("bruce", "pass"))
@@ -838,8 +849,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", "100");
- ClientResponse response = resource().path(API_VERSION).path("group").path("unsubscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("unsubscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
@@ -862,8 +873,8 @@
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("groupId", groupId);
- ClientResponse response = resource().path(API_VERSION).path("group").path("unsubscribe")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("unsubscribe").type(MediaType.APPLICATION_FORM_URLENCODED)
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
@@ -877,4 +888,94 @@
assertEquals("Group new user group has been deleted.",
node.at("/errors/0/1").asText());
}
+
+ @Test
+ public void testAddSameMemberRole () throws UniformInterfaceException,
+ ClientHandlerException, KustvaktException {
+ MultivaluedMap<String, String> form = new MultivaluedMapImpl();
+ form.add("groupId", "1");
+ form.add("memberUsername", "dory");
+ form.add("roleIds", "1");
+
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("role").path("add")
+ .type(MediaType.APPLICATION_FORM_URLENCODED)
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .entity(form).post(ClientResponse.class);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
+ Set<Role> roles = member.getRoles();
+ assertEquals(2, roles.size());
+ }
+
+ @Test
+ public void testDeleteAddMemberRole () throws UniformInterfaceException,
+ ClientHandlerException, KustvaktException {
+ MultivaluedMap<String, String> form = new MultivaluedMapImpl();
+ form.add("groupId", "1");
+ form.add("memberUsername", "dory");
+ form.add("roleIds", "1");
+
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("role").path("delete")
+ .type(MediaType.APPLICATION_FORM_URLENCODED)
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .entity(form).post(ClientResponse.class);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
+ Set<Role> roles = member.getRoles();
+ assertEquals(1, roles.size());
+
+ testAddSameMemberRole();
+ }
+
+ @Test
+ public void testEditMemberRoleEmpty () throws UniformInterfaceException,
+ ClientHandlerException, KustvaktException {
+ MultivaluedMap<String, String> form = new MultivaluedMapImpl();
+ form.add("groupId", "1");
+ form.add("memberUsername", "dory");
+
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("role").path("edit")
+ .type(MediaType.APPLICATION_FORM_URLENCODED)
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .entity(form).post(ClientResponse.class);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
+ Set<Role> roles = member.getRoles();
+ assertEquals(0, roles.size());
+
+ testEditMemberRole(form);
+ }
+
+ private void testEditMemberRole (MultivaluedMap<String, String> form)
+ throws UniformInterfaceException, ClientHandlerException,
+ KustvaktException {
+ form.add("roleIds", "1");
+ form.add("roleIds", "3");
+
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path("member").path("role").path("edit")
+ .type(MediaType.APPLICATION_FORM_URLENCODED)
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .entity(form).post(ClientResponse.class);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
+ Set<Role> roles = member.getRoles();
+ assertEquals(2, roles.size());
+ }
+
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 9cb2445..6530e7d 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -14,6 +14,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import org.apache.http.HttpStatus;
import org.apache.http.entity.ContentType;
import org.junit.Test;
@@ -63,7 +64,8 @@
private JsonNode testSearchVC (String username, String vcId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path(vcId)
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path(vcId)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -78,7 +80,8 @@
private JsonNode testListVC (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("list")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("list")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -91,12 +94,11 @@
return JsonUtils.readTree(entity);
}
-
private JsonNode testListOwnerVC (String username)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("list")
- .path("user")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("list").path("user")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -112,8 +114,8 @@
private void testDeleteVC (String vcId, String username)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("delete")
- .path(vcId)
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("delete").path(vcId)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -125,8 +127,8 @@
private JsonNode testlistAccessByVC (String username, String vcId)
throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("access")
- .path("list").queryParam("vcId", vcId)
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("access").path("list").queryParam("vcId", vcId)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -161,10 +163,12 @@
public void testSearchPrivateVCUnauthorized ()
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("1").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("1")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.get(ClientResponse.class);
String entity = response.getEntity(String.class);
@@ -194,7 +198,8 @@
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("2")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("2")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("marlin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -250,8 +255,8 @@
@Test
public void testListVCByOtherUser () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("list")
- .queryParam("createdBy", "dory")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("list").queryParam("createdBy", "dory")
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("pearl", "pass"))
@@ -271,8 +276,8 @@
@Test
public void testListVCByGuest () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("list")
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("list").header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.get(ClientResponse.class);
String entity = response.getEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -291,10 +296,12 @@
String json = "{\"name\": \"new vc\",\"type\": \"PRIVATE\","
+ "\"corpusQuery\": \"corpusSigle=GOE\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.post(ClientResponse.class, json);
@@ -321,10 +328,12 @@
public void testCreatePublishVC () throws KustvaktException {
String json = "{\"name\": \"new published vc\",\"type\": \"PUBLISHED\""
+ ",\"corpusQuery\": \"corpusSigle=GOE\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.post(ClientResponse.class, json);
@@ -365,7 +374,8 @@
private JsonNode testCheckHiddenGroup (String groupId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("group").path(groupId)
+ ClientResponse response = resource().path(API_VERSION).path("group")
+ .path(groupId)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("admin", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -390,7 +400,8 @@
authToken = reader.readLine();
}
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
.header(Attributes.AUTHORIZATION,
AuthenticationScheme.API.displayName() + " "
+ authToken)
@@ -421,7 +432,8 @@
+ "UiLCJleHAiOjE1MzA2MTgyOTR9.JUMvTQZ4tvdRXFBpQKzoNxrq7"
+ "CuYAfytr_LWqY8woJs";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
.header(Attributes.AUTHORIZATION,
AuthenticationScheme.API.displayName() + " "
+ authToken)
@@ -445,10 +457,12 @@
String json = "{\"name\": \"new vc\",\"type\": \"SYSTEM\","
+ "\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).post(ClientResponse.class);
@@ -464,16 +478,18 @@
checkWWWAuthenticateHeader(response);
}
-
+
@Test
public void testCreateVCInvalidName () throws KustvaktException {
String json = "{\"name\": \"new $vc\",\"type\": \"PRIVATE\","
+ "\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).post(ClientResponse.class);
String entity = response.getEntity(String.class);
@@ -489,7 +505,8 @@
String json = "{\"name\": \"new vc\",\"type\": \"PRIVATE\","
+ "\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).post(ClientResponse.class);
@@ -509,10 +526,12 @@
public void testCreateVCWithoutcorpusQuery () throws KustvaktException {
String json = "{\"name\": \"new vc\",\"type\": \"PRIVATE\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).post(ClientResponse.class);
String entity = response.getEntity(String.class);
@@ -531,10 +550,12 @@
String json = "{\"name\": \"new vc\",\"corpusQuery\": "
+ "\"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).post(ClientResponse.class);
String entity = response.getEntity(String.class);
@@ -553,10 +574,12 @@
String json = "{\"name\": \"new vc\",\"type\": \"PRIVAT\","
+ "\"corpusQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("create").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("create")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).post(ClientResponse.class);
String entity = response.getEntity(String.class);
@@ -574,7 +597,8 @@
@Test
public void testDeleteVCUnauthorized () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("delete").path("1")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("delete").path("1")
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(
@@ -602,7 +626,8 @@
// 1st edit
String json = "{\"id\": \"1\", \"name\": \"edited vc\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("edit")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("edit")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -636,10 +661,12 @@
public void testEditVCNotOwner () throws KustvaktException {
String json = "{\"id\": \"1\", \"name\": \"edited vc\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("edit").header(
- Attributes.AUTHORIZATION,
- HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(
- "VirtualCorpusControllerTest", "pass"))
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("edit")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ "VirtualCorpusControllerTest", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.post(ClientResponse.class, json);
@@ -656,7 +683,6 @@
checkWWWAuthenticateHeader(response);
}
-
/**
* @see VirtualCorpusServiceTest
* @throws KustvaktException
@@ -667,7 +693,8 @@
String vcId = "2";
String json = "{\"id\": \"" + vcId + "\", \"type\": \"PUBLISHED\"}";
- ClientResponse response = resource().path(API_VERSION).path("vc").path("edit")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("edit")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -715,8 +742,8 @@
@Test
public void testlistAccessMissingId () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("access")
- .path("list")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("access").path("list")
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(
@@ -733,8 +760,9 @@
@Test
public void testlistAccessByGroup () throws KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("access")
- .path("list").path("byGroup").queryParam("groupId", "2")
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("access").path("list").path("byGroup")
+ .queryParam("groupId", "2")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -749,28 +777,12 @@
assertEquals("dory group", node.at("/0/userGroupName").asText());
}
-
@Test
public void testCreateDeleteAccess () throws UniformInterfaceException,
ClientHandlerException, KustvaktException {
String vcId = "5";
-
- MultivaluedMap<String, String> form = new MultivaluedMapImpl();
- // marlin vc
- form.add("vcId", vcId);
- // marlin group
- form.add("groupId", "1");
-
- ClientResponse response;
- // share VC
- response = resource().path(API_VERSION).path("vc").path("access").path("share")
- .type(MediaType.APPLICATION_FORM_URLENCODED)
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue("marlin", "pass"))
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(form)
- .post(ClientResponse.class);
-
+ ClientResponse response = testShareVC(vcId);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list vc access by marlin
@@ -784,8 +796,7 @@
String accessId = node.at("/accessId").asText();
- // delete access
- // unauthorized
+ testCreateNonUniqueAccess(vcId);
testDeleteAccessUnauthorized(accessId);
// delete access
@@ -797,6 +808,37 @@
assertEquals(0, node.size());
}
+ private ClientResponse testShareVC (String vcId)
+ throws UniformInterfaceException, ClientHandlerException,
+ KustvaktException {
+
+ MultivaluedMap<String, String> form = new MultivaluedMapImpl();
+ // marlin vc
+ form.add("vcId", vcId);
+ // marlin group
+ form.add("groupId", "1");
+
+ return resource().path(API_VERSION).path("vc").path("access")
+ .path("share").type(MediaType.APPLICATION_FORM_URLENCODED)
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(form)
+ .post(ClientResponse.class);
+ }
+
+ private void testCreateNonUniqueAccess (String vcId)
+ throws UniformInterfaceException, ClientHandlerException,
+ KustvaktException {
+ ClientResponse response = testShareVC(vcId);
+ JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
+
+ assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
+ assertEquals(StatusCodes.DB_INSERT_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertTrue(node.at("/errors/0/1").asText()
+ .startsWith("[SQLITE_CONSTRAINT_UNIQUE]"));
+ }
+
@Test
public void testCreateAccessByVCAButNotVCOwner ()
throws UniformInterfaceException, ClientHandlerException,
@@ -810,8 +852,9 @@
// share VC
// dory is VCA in marlin group
- ClientResponse response = resource().path(API_VERSION).path("vc").path("access")
- .path("share").type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("access").path("share")
+ .type(MediaType.APPLICATION_FORM_URLENCODED)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(form)
@@ -838,8 +881,9 @@
// share VC
// nemo is not VCA in marlin group
- ClientResponse response = resource().path(API_VERSION).path("vc").path("access")
- .path("share").type(MediaType.APPLICATION_FORM_URLENCODED)
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("access").path("share")
+ .type(MediaType.APPLICATION_FORM_URLENCODED)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("nemo", "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").entity(form)
@@ -857,8 +901,8 @@
private void testDeleteAccess (String username, String accessId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("access")
- .path("delete").path(accessId)
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("access").path("delete").path(accessId)
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
@@ -870,8 +914,8 @@
private void testDeleteAccessUnauthorized (String accessId)
throws UniformInterfaceException, ClientHandlerException,
KustvaktException {
- ClientResponse response = resource().path(API_VERSION).path("vc").path("access")
- .path("delete").path(accessId)
+ ClientResponse response = resource().path(API_VERSION).path("vc")
+ .path("access").path("delete").path(accessId)
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(
diff --git a/full/src/test/resources/kustvakt-test.conf b/full/src/test/resources/kustvakt-test.conf
index 9a522ba..356d46e 100644
--- a/full/src/test/resources/kustvakt-test.conf
+++ b/full/src/test/resources/kustvakt-test.conf
@@ -13,7 +13,7 @@
# Kustvakt
-current.api.version = v1.0
+current.api.version = v1.1
# multiple versions separated by space
supported.api.version = v0.1 v1.0