Formatted project
Change-Id: I6993ddfab02e06541b4138040280a4777c719562
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/APIAuthenticationTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/APIAuthenticationTest.java
index 3c8f808..eeb3ea6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/APIAuthenticationTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/APIAuthenticationTest.java
@@ -34,9 +34,13 @@
private FullConfiguration config;
@Test
- public void testDeprecatedService() throws KustvaktException {
- String userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
- Response response = target().path(API_VERSION).path("auth").path("apiToken").request().header(Attributes.AUTHORIZATION, userAuthHeader).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testDeprecatedService () throws KustvaktException {
+ String userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
+ Response response = target().path(API_VERSION).path("auth")
+ .path("apiToken").request()
+ .header(Attributes.AUTHORIZATION, userAuthHeader)
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -44,7 +48,8 @@
}
@Test
- public void testCreateGetTokenContext() throws KustvaktException, IOException, InterruptedException, JOSEException {
+ public void testCreateGetTokenContext () throws KustvaktException,
+ IOException, InterruptedException, JOSEException {
User user = new KorAPUser();
user.setUsername("testUser");
Map<String, Object> attr = new HashMap<>();
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
index 892219b..9e6f120 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/AuthenticationFilterTest.java
@@ -14,12 +14,16 @@
public class AuthenticationFilterTest extends SpringJerseyTest {
@Test
- public void testAuthenticationWithUnknownScheme() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, "Blah blah").get();
+ public void testAuthenticationWithUnknownScheme ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .request().header(Attributes.AUTHORIZATION, "Blah blah").get();
String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
assertEquals(n.at("/errors/0/0").asText(), "2001");
- assertEquals(n.at("/errors/0/1").asText(), "Authentication scheme is not supported.");
+ assertEquals(n.at("/errors/0/1").asText(),
+ "Authentication scheme is not supported.");
assertEquals(n.at("/errors/0/2").asText(), "Blah");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/LdapAuth3Test.java b/full/src/test/java/de/ids_mannheim/korap/authentication/LdapAuth3Test.java
index f7c8a86..0580bba 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/LdapAuth3Test.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/LdapAuth3Test.java
@@ -19,7 +19,6 @@
import static de.ids_mannheim.korap.authentication.LdapAuth3.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
-
public class LdapAuth3Test {
public static final String TEST_LDAP_CONF = "src/test/resources/test-ldap.conf";
@@ -35,11 +34,17 @@
static InMemoryDirectoryServer server;
@BeforeAll
- static void startDirectoryServer() throws LDAPException, GeneralSecurityException {
- InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com");
- config.addAdditionalBindCredentials("cn=admin,dc=example,dc=com", "adminpassword");
+ static void startDirectoryServer ()
+ throws LDAPException, GeneralSecurityException {
+ InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(
+ "dc=example,dc=com");
+ config.addAdditionalBindCredentials("cn=admin,dc=example,dc=com",
+ "adminpassword");
config.setSchema(null);
- final SSLUtil serverSSLUtil = new SSLUtil(new KeyStoreKeyManager(keyStorePath, "password".toCharArray(), "PKCS12", "server-cert"), new TrustStoreTrustManager(keyStorePath));
+ final SSLUtil serverSSLUtil = new SSLUtil(
+ new KeyStoreKeyManager(keyStorePath, "password".toCharArray(),
+ "PKCS12", "server-cert"),
+ new TrustStoreTrustManager(keyStorePath));
final SSLUtil clientSslUtil = new SSLUtil(new TrustAllTrustManager());
config.setListenerConfigs(// Listener name
InMemoryListenerConfig.createLDAPConfig(// Listener name
@@ -50,7 +55,8 @@
InMemoryListenerConfig.createLDAPSConfig(// Listener name
"LDAPS", // Listen address. (null = listen on all interfaces)
null, // Listen port (0 = automatically choose an available port)
- 3269, serverSSLUtil.createSSLServerSocketFactory(), clientSslUtil.createSSLSocketFactory()));
+ 3269, serverSSLUtil.createSSLServerSocketFactory(),
+ clientSslUtil.createSSLSocketFactory()));
server = new InMemoryDirectoryServer(config);
String configPath = TEST_LDAP_USERS_LDIF;
server.importFromLDIF(true, configPath);
@@ -58,130 +64,167 @@
}
@AfterAll
- static void shutDownDirectoryServer() {
+ static void shutDownDirectoryServer () {
server.shutDown(true);
}
@Test
- public void loginWithExtraProfileNameWorks() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser123", "password", TEST_LDAP_CONF));
+ public void loginWithExtraProfileNameWorks () throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser123", "password", TEST_LDAP_CONF));
}
@Test
- public void loginWithUidWorks() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser", "password", TEST_LDAP_CONF));
+ public void loginWithUidWorks () throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser", "password", TEST_LDAP_CONF));
}
@Test
- public void loginWithUidAndBase64PasswordWorks() throws LDAPException {
+ public void loginWithUidAndBase64PasswordWorks () throws LDAPException {
final byte[] passwordBytes = StaticUtils.getBytes("password");
String pw = Base64.encode(passwordBytes);
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser", pw, TEST_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser", pw, TEST_LDAP_CONF));
}
@Test
- public void loginWithEmailWorks() throws LDAPException {
+ public void loginWithEmailWorks () throws LDAPException {
final byte[] passwordBytes = StaticUtils.getBytes("password");
String pw = Base64.encode(passwordBytes);
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser@example.com", pw, TEST_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser@example.com", pw, TEST_LDAP_CONF));
}
@Test
- public void allLoginPasswordCombinationsWork() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("uid", "userPassword", TEST_LDAP_CONF));
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("uid", "extraPassword", TEST_LDAP_CONF));
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("mail@example.org", "userPassword", TEST_LDAP_CONF));
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("mail@example.org", "extraPassword", TEST_LDAP_CONF));
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("extraProfile", "userPassword", TEST_LDAP_CONF));
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("extraProfile", "extraPassword", TEST_LDAP_CONF));
+ public void allLoginPasswordCombinationsWork () throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("uid", "userPassword", TEST_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("uid", "extraPassword", TEST_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("mail@example.org",
+ "userPassword", TEST_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("mail@example.org",
+ "extraPassword", TEST_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("extraProfile",
+ "userPassword", TEST_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("extraProfile",
+ "extraPassword", TEST_LDAP_CONF));
}
@Test
- public void loginWithWrongEmailFails() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("notestuser@example.com", "topsecret", TEST_LDAP_CONF));
+ public void loginWithWrongEmailFails () throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3
+ .login("notestuser@example.com", "topsecret", TEST_LDAP_CONF));
}
@Test
- public void loginWithEmailAndWrongPasswordFails() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("testuser@example.com", "wrongpw", TEST_LDAP_CONF));
+ public void loginWithEmailAndWrongPasswordFails () throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("testuser@example.com",
+ "wrongpw", TEST_LDAP_CONF));
}
@Test
- public void loginWithUsernameAndWrongPasswordFails() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("testuser", "wrongpw", TEST_LDAP_CONF));
+ public void loginWithUsernameAndWrongPasswordFails () throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN,
+ LdapAuth3.login("testuser", "wrongpw", TEST_LDAP_CONF));
}
@Test
- public void loginOfNotRegisteredUserFails() throws LDAPException {
- assertEquals(LDAP_AUTH_RNOTREG, LdapAuth3.login("not_registered_user", "topsecret", TEST_LDAP_CONF));
+ public void loginOfNotRegisteredUserFails () throws LDAPException {
+ assertEquals(LDAP_AUTH_RNOTREG, LdapAuth3.login("not_registered_user",
+ "topsecret", TEST_LDAP_CONF));
}
@Test
- public void blockedUserIsRefused() throws LDAPException {
- assertEquals(LDAP_AUTH_RLOCKED, LdapAuth3.login("nameOfBlockedUser", "topsecret", TEST_LDAP_CONF));
+ public void blockedUserIsRefused () throws LDAPException {
+ assertEquals(LDAP_AUTH_RLOCKED, LdapAuth3.login("nameOfBlockedUser",
+ "topsecret", TEST_LDAP_CONF));
}
@Test
- public void loginWithUsernameOverSSLWorks() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser", "password", TEST_LDAPS_CONF));
+ public void loginWithUsernameOverSSLWorks () throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser", "password", TEST_LDAPS_CONF));
}
@Test
- public void loginOnTrustedServerWorks() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser", "password", TEST_LDAPS_TS_CONF));
+ public void loginOnTrustedServerWorks () throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser", "password", TEST_LDAPS_TS_CONF));
}
@Test
- public void loginOnTrustedServerWithWrongPassswordFails() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("testuser", "topsecrets", TEST_LDAPS_TS_CONF));
+ public void loginOnTrustedServerWithWrongPassswordFails ()
+ throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN,
+ LdapAuth3.login("testuser", "topsecrets", TEST_LDAPS_TS_CONF));
}
@Test
- public void passwordWithAsteriskWorks() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("test", "top*ecret", TEST_LDAPS_CONF));
+ public void passwordWithAsteriskWorks () throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("test", "top*ecret", TEST_LDAPS_CONF));
}
@Test
- public void passwordWithGlobOperatorFails() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("testuser", "passw*", TEST_LDAPS_TS_CONF));
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser", "password", TEST_LDAPS_TS_CONF));
+ public void passwordWithGlobOperatorFails () throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN,
+ LdapAuth3.login("testuser", "passw*", TEST_LDAPS_TS_CONF));
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser", "password", TEST_LDAPS_TS_CONF));
}
@Test
- public void passwordWithExistenceOperatorFails() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("testuser", "*", TEST_LDAPS_TS_CONF));
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("testuser", "password", TEST_LDAPS_TS_CONF));
+ public void passwordWithExistenceOperatorFails () throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN,
+ LdapAuth3.login("testuser", "*", TEST_LDAPS_TS_CONF));
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("testuser", "password", TEST_LDAPS_TS_CONF));
}
@Test
- public void gettingMailAttributeForUid() throws LDAPException {
- assertEquals(LdapAuth3.getEmail("testuser", TEST_LDAP_CONF), "testuser@example.com");
- assertEquals(LdapAuth3.getEmail("testuser2", TEST_LDAPS_CONF), "peter@example.org");
+ public void gettingMailAttributeForUid () throws LDAPException {
+ assertEquals(LdapAuth3.getEmail("testuser", TEST_LDAP_CONF),
+ "testuser@example.com");
+ assertEquals(LdapAuth3.getEmail("testuser2", TEST_LDAPS_CONF),
+ "peter@example.org");
assertEquals(null, LdapAuth3.getEmail("non-exsting", TEST_LDAPS_CONF));
}
@Test
- public void gettingUsernameForEmail() throws LDAPException {
- assertEquals(LdapAuth3.getUsername("testuser@example.com", TEST_LDAP_CONF), "idsTestUser");
- assertEquals(LdapAuth3.getUsername("peter@example.org", TEST_LDAPS_CONF), "testuser2");
- assertEquals(null, LdapAuth3.getUsername("non-exsting", TEST_LDAPS_CONF));
- assertEquals(LdapAuth3.getUsername("testUser2", TEST_LDAPS_CONF), "testuser2");
+ public void gettingUsernameForEmail () throws LDAPException {
+ assertEquals(
+ LdapAuth3.getUsername("testuser@example.com", TEST_LDAP_CONF),
+ "idsTestUser");
+ assertEquals(
+ LdapAuth3.getUsername("peter@example.org", TEST_LDAPS_CONF),
+ "testuser2");
+ assertEquals(null,
+ LdapAuth3.getUsername("non-exsting", TEST_LDAPS_CONF));
+ assertEquals(LdapAuth3.getUsername("testUser2", TEST_LDAPS_CONF),
+ "testuser2");
// login with uid, get idsC2Profile username
- assertEquals(LdapAuth3.getUsername("testUser", TEST_LDAPS_CONF), "idsTestUser");
+ assertEquals(LdapAuth3.getUsername("testUser", TEST_LDAPS_CONF),
+ "idsTestUser");
}
@Test
- public void gettingMailAttributeForNotRegisteredUserWorks() throws LDAPException {
- assertEquals(LdapAuth3.getEmail("not_registered_user", TEST_LDAP_CONF), "not_registered_user@example.com");
+ public void gettingMailAttributeForNotRegisteredUserWorks ()
+ throws LDAPException {
+ assertEquals(LdapAuth3.getEmail("not_registered_user", TEST_LDAP_CONF),
+ "not_registered_user@example.com");
}
@Test
- public void gettingMailAttributeForBlockedUserWorks() throws LDAPException {
- assertEquals(LdapAuth3.getEmail("nameOfBlockedUser", TEST_LDAP_CONF), "nameOfBlockedUser@example.com");
+ public void gettingMailAttributeForBlockedUserWorks ()
+ throws LDAPException {
+ assertEquals(LdapAuth3.getEmail("nameOfBlockedUser", TEST_LDAP_CONF),
+ "nameOfBlockedUser@example.com");
}
@Test
- public void canLoadLdapConfig() {
+ public void canLoadLdapConfig () {
LDAPConfig ldapConfig = new LDAPConfig(TEST_LDAPS_CONF);
assertEquals(3269, ldapConfig.port);
assertEquals(ldapConfig.host, "localhost");
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java b/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java
index fd59d79..c45cc37 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/LdapOAuth2Test.java
@@ -56,38 +56,43 @@
private String redirectUri = "https://client.com/redirect";
@BeforeAll
- static void startTestLDAPServer() throws LDAPException, GeneralSecurityException {
+ static void startTestLDAPServer ()
+ throws LDAPException, GeneralSecurityException {
LdapAuth3Test.startDirectoryServer();
}
@AfterAll
- static void stopTestLDAPServer() {
+ static void stopTestLDAPServer () {
LdapAuth3Test.shutDownDirectoryServer();
}
@BeforeEach
- public void setLDAPAuthentication() {
+ public void setLDAPAuthentication () {
config.setOAuth2passwordAuthentication(AuthenticationMethod.LDAP);
}
@AfterEach
- public void resetAuthenticationMethod() {
+ public void resetAuthenticationMethod () {
config.setOAuth2passwordAuthentication(AuthenticationMethod.TEST);
}
@Test
- public void testRequestTokenPasswordUnknownUser() throws KustvaktException {
- Response response = requestTokenWithPassword(superClientId, clientSecret, "unknown", "password");
+ public void testRequestTokenPasswordUnknownUser ()
+ throws KustvaktException {
+ Response response = requestTokenWithPassword(superClientId,
+ clientSecret, "unknown", "password");
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2023, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "LDAP Authentication failed due to unknown user or password!");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "LDAP Authentication failed due to unknown user or password!");
}
@Test
- public void testMapEmailToUsername() throws KustvaktException {
- Response response = requestTokenWithPassword(superClientId, clientSecret, testUserEmail, "password");
+ public void testMapEmailToUsername () throws KustvaktException {
+ Response response = requestTokenWithPassword(superClientId,
+ clientSecret, testUserEmail, "password");
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String accessToken = node.at("/access_token").asText();
@@ -102,29 +107,39 @@
String clientSecret = node.at("/client_secret").asText();
testRequestTokenWithAuthorization(clientId, clientSecret, accessToken);
}
-
+
private void testRegisterPublicClient (String accessToken)
throws KustvaktException {
OAuth2ClientJson json = new OAuth2ClientJson();
json.setName("LDAP test client");
json.setType(OAuth2ClientType.PUBLIC);
- json.setDescription("Test registering a public client with LDAP authentication");
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("register").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).post(Entity.json(json));
+ json.setDescription(
+ "Test registering a public client with LDAP authentication");
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("register").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .post(Entity.json(json));
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String clientId = node.at("/client_id").asText();
OAuth2Client client = clientDao.retrieveClientById(clientId);
assertEquals(testUsername, client.getRegisteredBy());
}
-
+
private JsonNode testRegisterConfidentialClient (String accessToken)
throws KustvaktException {
OAuth2ClientJson json = new OAuth2ClientJson();
json.setName("LDAP test client");
json.setType(OAuth2ClientType.CONFIDENTIAL);
json.setRedirectURI(redirectUri);
- json.setDescription("Test registering a confidential client with LDAP authentication");
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("register").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).post(Entity.json(json));
+ json.setDescription(
+ "Test registering a confidential client with LDAP authentication");
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("register").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .post(Entity.json(json));
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String clientId = node.at("/client_id").asText();
@@ -133,14 +148,23 @@
return node;
}
- private void testRequestTokenWithAuthorization(String clientId, String clientSecret, String accessToken) throws KustvaktException {
+ private void testRequestTokenWithAuthorization (String clientId,
+ String clientSecret, String accessToken) throws KustvaktException {
String authHeader = "Bearer " + accessToken;
- Response response = target().path(API_VERSION).path("oauth2").path("authorize").queryParam("response_type", "code").queryParam("client_id", clientId).queryParam("client_secret", clientSecret).queryParam("scope", "search match_info").request().header(Attributes.AUTHORIZATION, authHeader).get();
- assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(), response.getStatus());
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("authorize").queryParam("response_type", "code")
+ .queryParam("client_id", clientId)
+ .queryParam("client_secret", clientSecret)
+ .queryParam("scope", "search match_info").request()
+ .header(Attributes.AUTHORIZATION, authHeader).get();
+ assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
+ response.getStatus());
URI redirectUri = response.getLocation();
- MultiValueMap<String, String> params = UriComponentsBuilder.fromUri(redirectUri).build().getQueryParams();
+ MultiValueMap<String, String> params = UriComponentsBuilder
+ .fromUri(redirectUri).build().getQueryParams();
String code = params.getFirst("code");
- response = requestTokenWithAuthorizationCodeAndForm(clientId, clientSecret, code);
+ response = requestTokenWithAuthorizationCodeAndForm(clientId,
+ clientSecret, code);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String at = node.at("/access_token").asText();
AccessToken accessTokenObj = accessDao.retrieveAccessToken(at);
diff --git a/full/src/test/java/de/ids_mannheim/korap/authentication/RandomCodeGeneratorTest.java b/full/src/test/java/de/ids_mannheim/korap/authentication/RandomCodeGeneratorTest.java
index a3694f0..9ffe776 100644
--- a/full/src/test/java/de/ids_mannheim/korap/authentication/RandomCodeGeneratorTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/authentication/RandomCodeGeneratorTest.java
@@ -17,14 +17,16 @@
private RandomCodeGenerator random;
@Test
- public void testRandomGenerator() throws NoSuchAlgorithmException, KustvaktException {
+ public void testRandomGenerator ()
+ throws NoSuchAlgorithmException, KustvaktException {
String value = random.createRandomCode();
assertEquals(22, value.length());
// System.out.println(value);
}
@Disabled
- public void testRandomGeneratorPerformance() throws NoSuchAlgorithmException, KustvaktException {
+ public void testRandomGeneratorPerformance ()
+ throws NoSuchAlgorithmException, KustvaktException {
long min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
String code;
while (true) {
@@ -39,7 +41,8 @@
min = duration;
else if (duration > max)
max = duration;
- System.out.println("d : " + duration + " min :" + min + ", max: " + max);
+ System.out.println(
+ "d : " + duration + " min :" + min + ", max: " + max);
}
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java b/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
index 8d3d275..7b7db2f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
@@ -27,7 +27,8 @@
private QueryDao dao;
@Test
- public void testNamedVCLoader() throws IOException, QueryException, KustvaktException {
+ public void testNamedVCLoader ()
+ throws IOException, QueryException, KustvaktException {
String vcId = "named-vc1";
vcLoader.loadVCToCache(vcId, "/vc/named-vc1.jsonld");
assertTrue(VirtualCorpusCache.contains(vcId));
diff --git a/full/src/test/java/de/ids_mannheim/korap/cache/TotalResultTest.java b/full/src/test/java/de/ids_mannheim/korap/cache/TotalResultTest.java
index 5beb40b..819f7a3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/cache/TotalResultTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/cache/TotalResultTest.java
@@ -3,7 +3,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.JsonNode;
@@ -18,15 +17,15 @@
@Autowired
private SearchService searchService;
-
+
@Test
public void testClearCache () {
for (int i = 1; i < 10; i++) {
searchService.getTotalResultCache().storeInCache(i, "10");
}
-
+
searchService.getTotalResultCache().clearCache();
-
+
assertEquals(0, searchService.getTotalResultCache()
.getAllCacheElements().size());
}
@@ -34,48 +33,77 @@
@Test
public void testSearchWithPaging () throws KustvaktException {
searchService.getTotalResultCache().clearCache();
-
+
assertEquals(0, searchService.getTotalResultCache()
.getAllCacheElements().size());
-
+
Response response = target().path(API_VERSION).path("search")
.queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
.queryParam("page", "1").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertTrue(node.at("/meta/totalResults").isNumber(), "totalResults should be a number");
+ assertTrue(node.at("/meta/totalResults").isNumber(),
+ "totalResults should be a number");
int totalResults = node.at("/meta/totalResults").asInt();
- assertEquals(1, searchService.getTotalResultCache().getAllCacheElements().size());
- response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("page", "2").request().get();
+ assertEquals(1, searchService.getTotalResultCache()
+ .getAllCacheElements().size());
+ response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("page", "2").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
- assertTrue(node.at("/meta/totalResults").isNumber(), "totalResults should be a number");
+ assertTrue(node.at("/meta/totalResults").isNumber(),
+ "totalResults should be a number");
assertEquals(totalResults, node.at("/meta/totalResults").asInt());
- assertEquals(1, searchService.getTotalResultCache().getAllCacheElements().size());
+ assertEquals(1, searchService.getTotalResultCache()
+ .getAllCacheElements().size());
assertTrue(node.at("/meta/cutOff").isMissingNode());
testSearchWithCutOff();
}
@Test
- public void testSearchWithCutOffTrue() throws KustvaktException {
- int cacheSize = searchService.getTotalResultCache().getAllCacheElements().size();
- Response response = target().path(API_VERSION).path("search").queryParam("q", "ich").queryParam("ql", "poliqarp").queryParam("page", "2").queryParam("cutoff", "true").request().get();
+ public void testSearchWithCutOffTrue () throws KustvaktException {
+ int cacheSize = searchService.getTotalResultCache()
+ .getAllCacheElements().size();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "ich").queryParam("ql", "poliqarp")
+ .queryParam("page", "2").queryParam("cutoff", "true").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- String query = "{\"meta\":{\"startPage\":2,\"tokens\":false,\"cutOff\":" + "true,\"snippets\":true,\"timeout\":10000},\"query\":{\"@type\":" + "\"koral:token\",\"wrap\":{\"@type\":\"koral:term\",\"match\":" + "\"match:eq\",\"layer\":\"orth\",\"key\":\"ich\",\"foundry\":" + "\"opennlp\",\"rewrites\":[{\"@type\":\"koral:rewrite\",\"src\":" + "\"Kustvakt\",\"operation\":\"operation:injection\",\"scope\":" + "\"foundry\"}]}},\"@context\":\"http://korap.ids-mannheim.de/ns" + "/koral/0.3/context.jsonld\",\"collection\":{\"@type\":\"koral:" + "doc\",\"match\":\"match:eq\",\"type\":\"type:regex\",\"value\":" + "\"CC-BY.*\",\"key\":\"availability\",\"rewrites\":[{\"@type\":" + "\"koral:rewrite\",\"src\":\"Kustvakt\",\"operation\":\"operation:" + "insertion\",\"scope\":\"availability(FREE)\"}]}}";
+ String query = "{\"meta\":{\"startPage\":2,\"tokens\":false,\"cutOff\":"
+ + "true,\"snippets\":true,\"timeout\":10000},\"query\":{\"@type\":"
+ + "\"koral:token\",\"wrap\":{\"@type\":\"koral:term\",\"match\":"
+ + "\"match:eq\",\"layer\":\"orth\",\"key\":\"ich\",\"foundry\":"
+ + "\"opennlp\",\"rewrites\":[{\"@type\":\"koral:rewrite\",\"src\":"
+ + "\"Kustvakt\",\"operation\":\"operation:injection\",\"scope\":"
+ + "\"foundry\"}]}},\"@context\":\"http://korap.ids-mannheim.de/ns"
+ + "/koral/0.3/context.jsonld\",\"collection\":{\"@type\":\"koral:"
+ + "doc\",\"match\":\"match:eq\",\"type\":\"type:regex\",\"value\":"
+ + "\"CC-BY.*\",\"key\":\"availability\",\"rewrites\":[{\"@type\":"
+ + "\"koral:rewrite\",\"src\":\"Kustvakt\",\"operation\":\"operation:"
+ + "insertion\",\"scope\":\"availability(FREE)\"}]}}";
int cacheKey = searchService.createTotalResultCacheKey(query);
- assertEquals(null, searchService.getTotalResultCache().getCacheValue(cacheKey));
- assertEquals(cacheSize, searchService.getTotalResultCache().getAllCacheElements().size());
+ assertEquals(null,
+ searchService.getTotalResultCache().getCacheValue(cacheKey));
+ assertEquals(cacheSize, searchService.getTotalResultCache()
+ .getAllCacheElements().size());
}
- private void testSearchWithCutOff() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("page", "3").queryParam("cutoff", "false").request().get();
+ private void testSearchWithCutOff () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("page", "3").queryParam("cutoff", "false").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertTrue(node.at("/meta/cutOff").isMissingNode());
- response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("page", "4").queryParam("cutoff", "true").request().get();
+ response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("page", "4").queryParam("cutoff", "true").request()
+ .get();
entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
assertTrue(node.at("/meta/cutOff").asBoolean());
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/LiteJerseyTest.java b/full/src/test/java/de/ids_mannheim/korap/config/LiteJerseyTest.java
index 98fa24b..80b00a5 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/LiteJerseyTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/LiteJerseyTest.java
@@ -25,16 +25,21 @@
@Autowired
protected GenericApplicationContext applicationContext;
- public static String[] classPackages = new String[]{"de.ids_mannheim.korap.core.web", "de.ids_mannheim.korap.web.filter", "de.ids_mannheim.korap.web.utils", "de.ids_mannheim.korap.test", "com.fasterxml.jackson.jaxrs.json"};
+ public static String[] classPackages = new String[] {
+ "de.ids_mannheim.korap.core.web",
+ "de.ids_mannheim.korap.web.filter",
+ "de.ids_mannheim.korap.web.utils", "de.ids_mannheim.korap.test",
+ "com.fasterxml.jackson.jaxrs.json" };
@Override
- protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ protected TestContainerFactory getTestContainerFactory ()
+ throws TestContainerException {
return new GrizzlyWebTestContainerFactory();
}
@BeforeEach
@Override
- public void setUp() throws Exception {
+ public void setUp () throws Exception {
GenericWebApplicationContext genericContext = new GenericWebApplicationContext();
genericContext.setParent(this.applicationContext);
genericContext.setClassLoader(this.applicationContext.getClassLoader());
@@ -43,7 +48,11 @@
}
@Override
- protected DeploymentContext configureDeployment() {
- return ServletDeploymentContext.forServlet(new ServletContainer(new ResourceConfig().packages(classPackages))).addListener(StaticContextLoaderListener.class).contextParam("adminToken", "secret").build();
+ protected DeploymentContext configureDeployment () {
+ return ServletDeploymentContext
+ .forServlet(new ServletContainer(
+ new ResourceConfig().packages(classPackages)))
+ .addListener(StaticContextLoaderListener.class)
+ .contextParam("adminToken", "secret").build();
}
}
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 1fca983..a1baccb 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
@@ -28,16 +28,19 @@
@Autowired
protected GenericApplicationContext applicationContext;
- public static String[] classPackages = new String[]{"de.ids_mannheim.korap.web", "de.ids_mannheim.korap.core.web", "de.ids_mannheim.korap.test", "com.fasterxml.jackson.jaxrs.json"};
+ public static String[] classPackages = new String[] {
+ "de.ids_mannheim.korap.web", "de.ids_mannheim.korap.core.web",
+ "de.ids_mannheim.korap.test", "com.fasterxml.jackson.jaxrs.json" };
@Override
- protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+ protected TestContainerFactory getTestContainerFactory ()
+ throws TestContainerException {
return new GrizzlyWebTestContainerFactory();
}
@BeforeEach
@Override
- public void setUp() throws Exception {
+ public void setUp () throws Exception {
GenericWebApplicationContext genericContext = new GenericWebApplicationContext();
genericContext.setParent(this.applicationContext);
genericContext.setClassLoader(this.applicationContext.getClassLoader());
@@ -46,7 +49,11 @@
}
@Override
- protected DeploymentContext configureDeployment() {
- return ServletDeploymentContext.forServlet(new ServletContainer(new ResourceConfig().packages(classPackages))).addListener(StaticContextLoaderListener.class).contextParam("adminToken", "secret").build();
+ protected DeploymentContext configureDeployment () {
+ return ServletDeploymentContext
+ .forServlet(new ServletContainer(
+ new ResourceConfig().packages(classPackages)))
+ .addListener(StaticContextLoaderListener.class)
+ .contextParam("adminToken", "secret").build();
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/StaticContextLoaderListener.java b/full/src/test/java/de/ids_mannheim/korap/config/StaticContextLoaderListener.java
index d4cf8d9..018bd6e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/StaticContextLoaderListener.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/StaticContextLoaderListener.java
@@ -1,6 +1,5 @@
package de.ids_mannheim.korap.config;
-
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
@@ -23,14 +22,14 @@
super(applicationContext);
}
- @Override
- public void contextInitialized(ServletContextEvent event) {
+ @Override
+ public void contextInitialized (ServletContextEvent event) {
contextClassLoader = Thread.currentThread().getContextClassLoader();
super.contextInitialized(event);
- }
+ }
- @Override
- public void contextDestroyed(ServletContextEvent event) {
+ @Override
+ public void contextDestroyed (ServletContextEvent event) {
// Perform the destruction with the same contextual ClassLoader that was present
// during initialization.
// This a workaround for a bug in org.glassfish.grizzly.servlet.WebappContext
@@ -43,5 +42,5 @@
super.contextDestroyed(event);
Thread.currentThread().setContextClassLoader(loader);
- }
+ }
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/TestVariables.java b/full/src/test/java/de/ids_mannheim/korap/config/TestVariables.java
index 1e157a5..e4658ce 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/TestVariables.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/TestVariables.java
@@ -9,67 +9,44 @@
public static final String RESULT = "{\n"
+ "\t\"@context\": \"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld\",\n"
- + "\t\"meta\": {\n"
- + "\t\t\"count\": 25,\n"
- + "\t\t\"startIndex\": 0,\n"
- + "\t\t\"timeout\": 120000,\n"
- + "\t\t\"context\": {\n"
- + "\t\t\t\"left\": [\"token\", 6],\n"
- + "\t\t\t\"right\": [\"token\", 6]\n"
- + "\t\t},\n"
+ + "\t\"meta\": {\n" + "\t\t\"count\": 25,\n"
+ + "\t\t\"startIndex\": 0,\n" + "\t\t\"timeout\": 120000,\n"
+ + "\t\t\"context\": {\n" + "\t\t\t\"left\": [\"token\", 6],\n"
+ + "\t\t\t\"right\": [\"token\", 6]\n" + "\t\t},\n"
+ "\t\t\"fields\": [\"pubDate\", \"subTitle\", \"author\", \"pubPlace\", \"title\", \"textSigle\", \"UID\", \"ID\", \"layerInfos\", \"corpusSigle\", \"docSigle\", \"corpusID\", \"textClass\"],\n"
+ "\t\t\"version\": \"0.55.5\",\n"
+ "\t\t\"benchmark\": \"0.117436617 s\",\n"
+ "\t\t\"totalResults\": 31,\n"
+ "\t\t\"serialQuery\": \"tokens:s:das\",\n"
- + "\t\t\"itemsPerPage\": 25\n"
- + "\t},\n"
- + "\t\"query\": {\n"
- + "\t\t\"@type\": \"koral:token\",\n"
- + "\t\t\"wrap\": {\n"
- + "\t\t\t\"@type\": \"koral:term\",\n"
- + "\t\t\t\"key\": \"das\",\n"
+ + "\t\t\"itemsPerPage\": 25\n" + "\t},\n" + "\t\"query\": {\n"
+ + "\t\t\"@type\": \"koral:token\",\n" + "\t\t\"wrap\": {\n"
+ + "\t\t\t\"@type\": \"koral:term\",\n" + "\t\t\t\"key\": \"das\",\n"
+ "\t\t\t\"layer\": \"orth\",\n"
+ "\t\t\t\"match\": \"match:eq\",\n"
- + "\t\t\t\"foundry\": \"opennlp\",\n"
- + "\t\t\t\"rewrites\": [{\n"
+ + "\t\t\t\"foundry\": \"opennlp\",\n" + "\t\t\t\"rewrites\": [{\n"
+ "\t\t\t\t\"@type\": \"koral:rewrite\",\n"
+ "\t\t\t\t\"src\": \"Kustvakt\",\n"
+ "\t\t\t\t\"operation\": \"operation:injection\",\n"
- + "\t\t\t\t\"scope\": \"foundry\"\n"
- + "\t\t\t}]\n"
- + "\t\t},\n"
- + "\t\t\"idn\": \"das_0\",\n"
- + "\t\t\"rewrites\": [{\n"
+ + "\t\t\t\t\"scope\": \"foundry\"\n" + "\t\t\t}]\n" + "\t\t},\n"
+ + "\t\t\"idn\": \"das_0\",\n" + "\t\t\"rewrites\": [{\n"
+ "\t\t\t\"@type\": \"koral:rewrite\",\n"
+ "\t\t\t\"src\": \"Kustvakt\",\n"
+ "\t\t\t\"operation\": \"operation:injection\",\n"
- + "\t\t\t\"scope\": \"idn\"\n"
- + "\t\t}]\n"
- + "\t},\n"
- + "\t\"collection\": {\n"
- + "\t\t\"@type\": \"koral:docGroup\",\n"
+ + "\t\t\t\"scope\": \"idn\"\n" + "\t\t}]\n" + "\t},\n"
+ + "\t\"collection\": {\n" + "\t\t\"@type\": \"koral:docGroup\",\n"
+ "\t\t\"operation\": \"operation:or\",\n"
- + "\t\t\"operands\": [{\n"
- + "\t\t\t\"@type\": \"koral:doc\",\n"
+ + "\t\t\"operands\": [{\n" + "\t\t\t\"@type\": \"koral:doc\",\n"
+ "\t\t\t\"key\": \"corpusSigle\",\n"
- + "\t\t\t\"value\": \"GOE\",\n"
- + "\t\t\t\"match\": \"match:eq\"\n"
- + "\t\t}, {\n"
- + "\t\t\t\"@type\": \"koral:doc\",\n"
+ + "\t\t\t\"value\": \"GOE\",\n" + "\t\t\t\"match\": \"match:eq\"\n"
+ + "\t\t}, {\n" + "\t\t\t\"@type\": \"koral:doc\",\n"
+ "\t\t\t\"key\": \"corpusSigle\",\n"
- + "\t\t\t\"value\": \"WPD\",\n"
- + "\t\t\t\"match\": \"match:eq\"\n"
- + "\t\t}],\n"
- + "\t\t\"rewrites\": [{\n"
+ + "\t\t\t\"value\": \"WPD\",\n" + "\t\t\t\"match\": \"match:eq\"\n"
+ + "\t\t}],\n" + "\t\t\"rewrites\": [{\n"
+ "\t\t\t\"@type\": \"koral:rewrite\",\n"
+ "\t\t\t\"src\": \"Kustvakt\",\n"
+ "\t\t\t\"operation\": \"operation:insertion\",\n"
- + "\t\t\t\"scope\": \"corpusSigle\"\n"
- + "\t\t}]\n"
- + "\t},\n"
- + "\t\"matches\": [{\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\t\"scope\": \"corpusSigle\"\n" + "\t\t}]\n" + "\t},\n"
+ + "\t\"matches\": [{\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00004\",\n"
@@ -78,14 +55,11 @@
+ "\t\t\"title\": \"A (Logik)\",\n"
+ "\t\t\"author\": \"Zenogantner; ElRaki; 1\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>z.B. mit dem Wort Barbara" bezeichnet, </span><mark>das</mark><span class=\\\"context-right\\\"> dreimal den Buchstaben a enthält, aber<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00004-p195-196\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"kultur musik freizeit-unterhaltung reisen\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.02439\",\n"
@@ -94,14 +68,11 @@
+ "\t\t\"title\": \"Aegukka\",\n"
+ "\t\t\"author\": \"ThorstenS; 2\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>wörtlich "Das Lied der Liebe für </span><mark>das</mark><span class=\\\"context-right\\\"> Land", oder "Das patriotische Lied". Es<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.02439-p22-23\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"kultur musik freizeit-unterhaltung reisen\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.02439\",\n"
@@ -110,14 +81,11 @@
+ "\t\t\"title\": \"Aegukka\",\n"
+ "\t\t\"author\": \"ThorstenS; 2\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Besatzungszeit von 1910 bis 1945 wurde </span><mark>das</mark><span class=\\\"context-right\\\"> Lied verboten. Im Ausland lebende Koreaner<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.02439-p74-75\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"kultur musik freizeit-unterhaltung reisen\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.02439\",\n"
@@ -126,348 +94,262 @@
+ "\t\t\"title\": \"Aegukka\",\n"
+ "\t\t\"author\": \"ThorstenS; 2\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>3. Deutsche Übersetzung 1. Strophe Bis </span><mark>das</mark><span class=\\\"context-right\\\"> Meer des Ostens ausdörrt und der<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.02439-p298-299\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Ausnahme von Fremdwörtern und Namen ist </span><mark>das</mark><span class=\\\"context-right\\\"> A der einzige Buchstabe im Deutschen<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p41-42\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>flache Stellung niedergedrückt wird. Stellt man </span><mark>das</mark><span class=\\\"context-right\\\"> Verhältnis der drei Hauptvokale a, i<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p107-108\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>kommt i als der hellste an </span><mark>das</mark><span class=\\\"context-right\\\"> obere, u als der dumpfeste an<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p127-128\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>obere, u als der dumpfeste an </span><mark>das</mark><span class=\\\"context-right\\\"> untere Ende, a als der mittlere<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p134-135\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>im 9. Jahrhundert v. Chr. war </span><mark>das</mark><span class=\\\"context-right\\\"> Schriftzeichen bereits stark stilisiert, die Hörner<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p271-272\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>im Alphabet inne. Als die Griechen </span><mark>das</mark><span class=\\\"context-right\\\"> Phönizische Alphabet übernamen, drehten sie das<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p313-314\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>das Phönizische Alphabet übernamen, drehten sie </span><mark>das</mark><span class=\\\"context-right\\\"> Zeichen um 90 Grad und machten<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p319-320\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>um 90 Grad und machten daraus </span><mark>das</mark><span class=\\\"context-right\\\"> Alpha. Da das Griechische reich an<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p327-328\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>und machten daraus das Alpha. Da </span><mark>das</mark><span class=\\\"context-right\\\"> Griechische reich an Vokalen war, verwendeten<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p330-331\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>reich an Vokalen war, verwendeten sie </span><mark>das</mark><span class=\\\"context-right\\\"> Zeichen für den Lautwert a. Die<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p338-339\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>den Lautwert a. Die Etrusker übernahmen </span><mark>das</mark><span class=\\\"context-right\\\"> frühgriechische Alpha und ließen es größtenteils<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p347-348\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>von rechts nach links) versahen sie </span><mark>das</mark><span class=\\\"context-right\\\"> Zeichen mit einem Abschwung nach links<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p365-366\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Abschwung nach links. Als die Römer </span><mark>das</mark><span class=\\\"context-right\\\"> lateinische Alphabet schufen, verwendeten sie das<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p375-376\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>das lateinische Alphabet schufen, verwendeten sie </span><mark>das</mark><span class=\\\"context-right\\\"> A aus dem etruskischen Alphabet, der<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p381-382\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>in der Biologie steht A für </span><mark>das</mark><span class=\\\"context-right\\\"> Nukleosid Adenosin steht A die Base<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p404-405\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Wert 10, siehe auch Hexadezimalsystem. steht </span><mark>das</mark><span class=\\\"context-right\\\"> Symbol ∀ (ein auf den Kopf gestelltes<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p526-527\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>für die Vorsilbe Atto ist A </span><mark>das</mark><span class=\\\"context-right\\\"> Einheitensymbol der elektrischen Stromstärke Ampere in<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p624-625\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Anordnung (Rechtswesen), Agent (Börse), Aufzeichung (Rechtsw.), </span><mark>das</mark><span class=\\\"context-right\\\"> Flächenmaß Acre und Ausgabe A ist<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p757-758\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Band). in Redewendungen für den Anfang (</span><mark>das</mark><span class=\\\"context-right\\\"> A und O, von A bis<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p777-778\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>Z). a ist die Abkürzung für </span><mark>das</mark><span class=\\\"context-right\\\"> Flächenmaß Ar in der Kaufmannssprache bedeutet<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p790-791\",\n"
- + "\t\t\"UID\": 0,\n"
- + "\t\t\"pubDate\": \"2005-03-28\"\n"
- + "\t}, {\n"
- + "\t\t\"field\": \"tokens\",\n"
+ + "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ + "\t}, {\n" + "\t\t\"field\": \"tokens\",\n"
+ "\t\t\"textClass\": \"freizeit-unterhaltung reisen wissenschaft populaerwissenschaft\",\n"
+ "\t\t\"pubPlace\": \"URL:http://de.wikipedia.org\",\n"
+ "\t\t\"textSigle\": \"WPD_AAA.00001\",\n"
+ "\t\t\"docSigle\": \"WPD_AAA\",\n"
- + "\t\t\"corpusSigle\": \"WPD\",\n"
- + "\t\t\"title\": \"A\",\n"
+ + "\t\t\"corpusSigle\": \"WPD\",\n" + "\t\t\"title\": \"A\",\n"
+ "\t\t\"author\": \"Ruru; Jens.Ol; Aglarech; u.a.\",\n"
+ "\t\t\"layerInfos\": \"base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/l=tokens xip/p=tokens xip/s=spans\",\n"
- + "\t\t\"startMore\": true,\n"
- + "\t\t\"endMore\": true,\n"
+ + "\t\t\"startMore\": true,\n" + "\t\t\"endMore\": true,\n"
+ "\t\t\"snippet\": \"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>ad zu) ‚[das Stück] zu...‘ für </span><mark>das</mark><span class=\\\"context-right\\\"> Französische à „nach“, z. B. in<span class=\\\"more\\\"></span></span>\",\n"
+ "\t\t\"matchID\": \"match-WPD_AAA.00001-p805-806\",\n"
+ "\t\t\"UID\": 0,\n" + "\t\t\"pubDate\": \"2005-03-28\"\n"
+ "\t}]\n" + "}";
-
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java
index 59ca413..13b2c91 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/RolePrivilegeDaoTest.java
@@ -27,13 +27,14 @@
private PrivilegeDao privilegeDao;
@Test
- public void retrievePredefinedRole() {
- Role r = roleDao.retrieveRoleById(PredefinedRole.USER_GROUP_ADMIN.getId());
+ public void retrievePredefinedRole () {
+ Role r = roleDao
+ .retrieveRoleById(PredefinedRole.USER_GROUP_ADMIN.getId());
assertEquals(1, r.getId());
}
@Test
- public void createDeleteRole() {
+ public void createDeleteRole () {
String roleName = "vc editor";
List<PrivilegeType> privileges = new ArrayList<PrivilegeType>();
privileges.add(PrivilegeType.READ);
@@ -46,7 +47,7 @@
}
@Test
- public void updateRole() {
+ public void updateRole () {
Role role = roleDao.retrieveRoleByName("USER_GROUP_MEMBER");
roleDao.editRoleName(role.getId(), "USER_GROUP_MEMBER role");
role = roleDao.retrieveRoleById(role.getId());
@@ -57,7 +58,7 @@
}
@Test
- public void addDeletePrivilegeOfExistingRole() {
+ public void addDeletePrivilegeOfExistingRole () {
Role role = roleDao.retrieveRoleByName("USER_GROUP_MEMBER");
List<Privilege> privileges = role.getPrivileges();
assertEquals(1, role.getPrivileges().size());
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 dd5fcf5..1ee65bf 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
@@ -47,11 +47,12 @@
private FullConfiguration config;
@Test
- public void createDeleteNewUserGroup() throws KustvaktException {
+ public void createDeleteNewUserGroup () throws KustvaktException {
String groupName = "test group";
String createdBy = "test class";
// create group
- int groupId = userGroupDao.createGroup(groupName, null, createdBy, UserGroupStatus.ACTIVE);
+ int groupId = userGroupDao.createGroup(groupName, null, createdBy,
+ UserGroupStatus.ACTIVE);
// retrieve group
UserGroup group = userGroupDao.retrieveGroupById(groupId, true);
assertEquals(groupName, group.getName());
@@ -71,39 +72,47 @@
ArrayList<Role> roleList = new ArrayList<>(2);
roleList.addAll(roles);
Collections.sort(roleList);
- assertEquals(PredefinedRole.USER_GROUP_ADMIN.getId(), roleList.get(0).getId());
- assertEquals(PredefinedRole.VC_ACCESS_ADMIN.getId(), roleList.get(1).getId());
+ assertEquals(PredefinedRole.USER_GROUP_ADMIN.getId(),
+ roleList.get(0).getId());
+ assertEquals(PredefinedRole.VC_ACCESS_ADMIN.getId(),
+ roleList.get(1).getId());
// retrieve VC by group
List<QueryDO> vc = virtualCorpusDao.retrieveQueryByGroup(groupId);
assertEquals(0, vc.size());
// soft delete group
- userGroupDao.deleteGroup(groupId, createdBy, config.isSoftDeleteGroup());
+ userGroupDao.deleteGroup(groupId, createdBy,
+ config.isSoftDeleteGroup());
group = userGroupDao.retrieveGroupById(groupId);
assertEquals(UserGroupStatus.DELETED, group.getStatus());
// hard delete
userGroupDao.deleteGroup(groupId, createdBy, false);
- KustvaktException exception = assertThrows(KustvaktException.class, () -> {
- userGroupDao.retrieveGroupById(groupId);
- });
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, exception.getStatusCode().intValue());
+ KustvaktException exception = assertThrows(KustvaktException.class,
+ () -> {
+ userGroupDao.retrieveGroupById(groupId);
+ });
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ exception.getStatusCode().intValue());
}
@Test
- public void retrieveGroupWithMembers() throws KustvaktException {
+ public void retrieveGroupWithMembers () throws KustvaktException {
// dory group
- List<UserGroupMember> members = userGroupDao.retrieveGroupById(2, true).getMembers();
+ List<UserGroupMember> members = userGroupDao.retrieveGroupById(2, true)
+ .getMembers();
assertEquals(4, members.size());
UserGroupMember m = members.get(1);
Set<Role> roles = m.getRoles();
assertEquals(2, roles.size());
List<Role> sortedRoles = new ArrayList<>(roles);
Collections.sort(sortedRoles);
- assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(), sortedRoles.get(0).getName());
- assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(), sortedRoles.get(1).getName());
+ assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(),
+ sortedRoles.get(0).getName());
+ assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(),
+ sortedRoles.get(1).getName());
}
@Test
- public void retrieveGroupByUserId() throws KustvaktException {
+ public void retrieveGroupByUserId () throws KustvaktException {
List<UserGroup> group = userGroupDao.retrieveGroupByUserId("dory");
assertEquals(2, group.size());
group = userGroupDao.retrieveGroupByUserId("pearl");
@@ -111,15 +120,18 @@
}
@Test
- public void addVCToGroup() throws KustvaktException {
+ public void addVCToGroup () throws KustvaktException {
// dory group
int groupId = 2;
UserGroup group = userGroupDao.retrieveGroupById(groupId);
String createdBy = "dory";
String name = "dory new vc";
- int id = virtualCorpusDao.createQuery(name, ResourceType.PROJECT, QueryType.VIRTUAL_CORPUS, CorpusAccess.PUB, "corpusSigle=WPD15", "", "", "", false, createdBy, null, null);
+ int id = virtualCorpusDao.createQuery(name, ResourceType.PROJECT,
+ QueryType.VIRTUAL_CORPUS, CorpusAccess.PUB, "corpusSigle=WPD15",
+ "", "", "", false, createdBy, null, null);
QueryDO virtualCorpus = virtualCorpusDao.retrieveQueryById(id);
- userGroupDao.addQueryToGroup(virtualCorpus, createdBy, QueryAccessStatus.ACTIVE, group);
+ userGroupDao.addQueryToGroup(virtualCorpus, createdBy,
+ QueryAccessStatus.ACTIVE, group);
List<QueryDO> vc = virtualCorpusDao.retrieveQueryByGroup(groupId);
assertEquals(2, vc.size());
assertEquals(name, vc.get(1).getName());
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 93e3b78..e3fdc87 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
@@ -27,19 +27,21 @@
private RoleDao roleDao;
@Test
- public void testRetrieveMemberByRole() throws KustvaktException {
+ public void testRetrieveMemberByRole () throws KustvaktException {
// dory group
- List<UserGroupMember> vcaAdmins = dao.retrieveMemberByRole(2, PredefinedRole.VC_ACCESS_ADMIN.getId());
+ List<UserGroupMember> vcaAdmins = dao.retrieveMemberByRole(2,
+ PredefinedRole.VC_ACCESS_ADMIN.getId());
// System.out.println(vcaAdmins);
assertEquals(1, vcaAdmins.size());
assertEquals(vcaAdmins.get(0).getUserId(), "dory");
}
@Test
- public void testAddSameMemberRole() throws KustvaktException {
+ 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());
+ Role adminRole = roleDao
+ .retrieveRoleById(PredefinedRole.USER_GROUP_ADMIN.getId());
roles.add(adminRole);
member.setRoles(roles);
dao.updateMember(member);
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 6be38cf..72f1e0f 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
@@ -23,7 +23,7 @@
private QueryAccessDao dao;
@Test
- public void getAccessByVC() throws KustvaktException {
+ public void getAccessByVC () throws KustvaktException {
List<QueryAccess> vcaList = dao.retrieveActiveAccessByQuery(2);
QueryAccess access = vcaList.get(0);
assertEquals(QueryAccessStatus.ACTIVE, access.getStatus());
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 95af5dc..cfd226b 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
@@ -25,8 +25,9 @@
private QueryDao dao;
@Test
- public void testListVCByType() throws KustvaktException {
- List<QueryDO> vcList = dao.retrieveQueryByType(ResourceType.PUBLISHED, null, QueryType.VIRTUAL_CORPUS);
+ public void testListVCByType () throws KustvaktException {
+ List<QueryDO> vcList = dao.retrieveQueryByType(ResourceType.PUBLISHED,
+ null, QueryType.VIRTUAL_CORPUS);
assertEquals(1, vcList.size());
QueryDO vc = vcList.get(0);
assertEquals(4, vc.getId());
@@ -35,40 +36,48 @@
}
@Test
- public void testSystemVC() throws KustvaktException {
+ public void testSystemVC () throws KustvaktException {
// insert vc
- int id = dao.createQuery("system-vc", ResourceType.SYSTEM, QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE, "corpusSigle=GOE", "definition", "description", "experimental", false, "test class", null, null);
+ int id = dao.createQuery("system-vc", ResourceType.SYSTEM,
+ QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
+ "corpusSigle=GOE", "definition", "description", "experimental",
+ false, "test class", null, null);
// select vc
- List<QueryDO> vcList = dao.retrieveQueryByType(ResourceType.SYSTEM, null, QueryType.VIRTUAL_CORPUS);
+ List<QueryDO> vcList = dao.retrieveQueryByType(ResourceType.SYSTEM,
+ null, QueryType.VIRTUAL_CORPUS);
assertEquals(2, vcList.size());
QueryDO vc = dao.retrieveQueryById(id);
// delete vc
dao.deleteQuery(vc);
// check if vc has been deleted
- KustvaktException exception = assertThrows(KustvaktException.class, () -> {
- dao.retrieveQueryById(id);
- });
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, exception.getStatusCode().intValue());
+ KustvaktException exception = assertThrows(KustvaktException.class,
+ () -> {
+ dao.retrieveQueryById(id);
+ });
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ exception.getStatusCode().intValue());
}
@Test
public void testNonUniqueVC () throws KustvaktException {
-
- 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);
- });
-
+
+ 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(exception.getMessage(),
"Converting `org.hibernate.exception.GenericJDBCException` "
- + "to JPA `PersistenceException` : could not execute statement");
+ + "to JPA `PersistenceException` : could not execute statement");
}
@Test
- public void retrieveSystemVC() throws KustvaktException {
- List<QueryDO> vc = dao.retrieveQueryByType(ResourceType.SYSTEM, null, QueryType.VIRTUAL_CORPUS);
+ public void retrieveSystemVC () throws KustvaktException {
+ List<QueryDO> vc = dao.retrieveQueryByType(ResourceType.SYSTEM, null,
+ QueryType.VIRTUAL_CORPUS);
assertEquals(1, vc.size());
}
@@ -78,8 +87,9 @@
* @throws KustvaktException
*/
@Test
- public void retrieveVCByUserDory() throws KustvaktException {
- List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("dory", QueryType.VIRTUAL_CORPUS);
+ public void retrieveVCByUserDory () throws KustvaktException {
+ List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("dory",
+ QueryType.VIRTUAL_CORPUS);
// System.out.println(virtualCorpora);
assertEquals(4, virtualCorpora.size());
// ordered by id
@@ -97,8 +107,9 @@
* @throws KustvaktException
*/
@Test
- public void retrieveVCByUserNemo() throws KustvaktException {
- List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("nemo", QueryType.VIRTUAL_CORPUS);
+ public void retrieveVCByUserNemo () throws KustvaktException {
+ List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("nemo",
+ QueryType.VIRTUAL_CORPUS);
assertEquals(3, virtualCorpora.size());
Iterator<QueryDO> i = virtualCorpora.iterator();
assertEquals(i.next().getName(), "group-vc");
@@ -113,8 +124,9 @@
* @throws KustvaktException
*/
@Test
- public void retrieveVCByUserMarlin() throws KustvaktException {
- List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("marlin", QueryType.VIRTUAL_CORPUS);
+ public void retrieveVCByUserMarlin () throws KustvaktException {
+ List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("marlin",
+ QueryType.VIRTUAL_CORPUS);
assertEquals(3, virtualCorpora.size());
Iterator<QueryDO> i = virtualCorpora.iterator();
assertEquals(i.next().getName(), "system-vc");
@@ -129,8 +141,9 @@
* @throws KustvaktException
*/
@Test
- public void retrieveVCByUserPearl() throws KustvaktException {
- List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("pearl", QueryType.VIRTUAL_CORPUS);
+ public void retrieveVCByUserPearl () throws KustvaktException {
+ List<QueryDO> virtualCorpora = dao.retrieveQueryByUser("pearl",
+ QueryType.VIRTUAL_CORPUS);
assertEquals(2, virtualCorpora.size());
Iterator<QueryDO> i = virtualCorpora.iterator();
assertEquals(i.next().getName(), "system-vc");
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/BCryptTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/BCryptTest.java
index a679a12..ce1abb3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/BCryptTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/BCryptTest.java
@@ -8,7 +8,7 @@
public class BCryptTest {
@Test
- public void testSalt() {
+ public void testSalt () {
String salt = BCrypt.gensalt(8);
// System.out.println(salt);
String plain = "secret";
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java
index 980d749..0935f6c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/CollectionQueryBuilderTest.java
@@ -17,7 +17,7 @@
public class CollectionQueryBuilderTest {
@Test
- public void testsimpleAdd() throws KustvaktException {
+ public void testsimpleAdd () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("corpusSigle=WPD");
JsonNode node = JsonUtils.readTree(b.toJSON());
@@ -27,41 +27,48 @@
}
@Test
- public void testSimpleConjunction() throws KustvaktException {
+ public void testSimpleConjunction () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("corpusSigle=WPD & textClass=freizeit");
JsonNode node = JsonUtils.readTree(b.toJSON());
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
- assertEquals(node.at("/collection/operands/0/key").asText(), "corpusSigle");
- assertEquals(node.at("/collection/operands/1/key").asText(), "textClass");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "corpusSigle");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "textClass");
}
@Test
- public void testSimpleDisjunction() throws KustvaktException {
+ public void testSimpleDisjunction () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("corpusSigle=WPD | textClass=freizeit");
JsonNode node = JsonUtils.readTree(b.toJSON());
assertNotNull(node);
assert node.at("/collection/operation").asText().equals("operation:or");
- assert node.at("/collection/operands/0/key").asText().equals("corpusSigle");
- assert node.at("/collection/operands/1/key").asText().equals("textClass");
+ assert node.at("/collection/operands/0/key").asText()
+ .equals("corpusSigle");
+ assert node.at("/collection/operands/1/key").asText()
+ .equals("textClass");
}
@Test
- public void testComplexSubQuery() throws KustvaktException {
+ public void testComplexSubQuery () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(corpusSigle=WPD) | (textClass=freizeit & corpusSigle=BRZ13)");
JsonNode node = JsonUtils.readTree(b.toJSON());
assertNotNull(node);
assert node.at("/collection/operation").asText().equals("operation:or");
- assert node.at("/collection/operands/0/key").asText().equals("corpusSigle");
- assert node.at("/collection/operands/1/@type").asText().equals("koral:docGroup");
+ assert node.at("/collection/operands/0/key").asText()
+ .equals("corpusSigle");
+ assert node.at("/collection/operands/1/@type").asText()
+ .equals("koral:docGroup");
}
@Test
- public void testAddResourceQueryAfter() throws KustvaktException {
+ public void testAddResourceQueryAfter () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(textClass=politik & title=\"random title\") | textClass=wissenschaft");
KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder();
@@ -69,19 +76,26 @@
c.with("corpusSigle=WPD");
JsonNode node = JsonUtils.readTree(c.toJSON());
assertNotNull(node);
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:docGroup");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:docGroup");
assertEquals(2, node.at("/collection/operands").size());
assertEquals(2, node.at("/collection/operands/0/operands").size());
- assertEquals(2, node.at("/collection/operands/0/operands/0/operands").size());
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
- assertEquals(node.at("/collection/operands/0/operation").asText(), "operation:or");
- assertEquals(node.at("/collection/operands/0/operands/0/operation").asText(), "operation:and");
+ assertEquals(2,
+ node.at("/collection/operands/0/operands/0/operands").size());
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
+ assertEquals(node.at("/collection/operands/0/operation").asText(),
+ "operation:or");
+ assertEquals(
+ node.at("/collection/operands/0/operands/0/operation").asText(),
+ "operation:and");
assertEquals(node.at("/collection/operands/1/value").asText(), "WPD");
}
@Test
- public void testAddComplexResourceQueryAfter() throws KustvaktException {
+ public void testAddComplexResourceQueryAfter () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(title=\"random title\") | (textClass=wissenschaft)");
KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder();
@@ -89,16 +103,26 @@
c.with("(corpusSigle=BRZ13 | corpusSigle=AZPS)");
JsonNode node = JsonUtils.readTree(c.toJSON());
assertNotNull(node);
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/1/operands/0/value").asText(), "BRZ13");
- assertEquals(node.at("/collection/operands/1/operands/1/value").asText(), "AZPS");
- assertEquals(node.at("/collection/operands/0/operands/0/value").asText(), "random title");
- assertEquals(node.at("/collection/operands/0/operands/1/value").asText(), "wissenschaft");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:docGroup");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:docGroup");
+ assertEquals(
+ node.at("/collection/operands/1/operands/0/value").asText(),
+ "BRZ13");
+ assertEquals(
+ node.at("/collection/operands/1/operands/1/value").asText(),
+ "AZPS");
+ assertEquals(
+ node.at("/collection/operands/0/operands/0/value").asText(),
+ "random title");
+ assertEquals(
+ node.at("/collection/operands/0/operands/1/value").asText(),
+ "wissenschaft");
}
@Test
- public void testBuildQuery() throws KustvaktException {
+ public void testBuildQuery () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -111,12 +135,17 @@
assertNotNull(res);
assertEquals(res.at("/collection/@type").asText(), "koral:docGroup");
assertEquals(res.at("/collection/operation").asText(), "operation:and");
- assertEquals(res.at("/collection/operands/0/@type").asText(), "koral:doc");
- assertEquals(res.at("/collection/operands/1/value").asText(), "freizeit");
- assertEquals(res.at("/collection/operands/1/key").asText(), "textClass");
- assertEquals(res.at("/collection/operands/1/@type").asText(), "koral:doc");
+ assertEquals(res.at("/collection/operands/0/@type").asText(),
+ "koral:doc");
+ assertEquals(res.at("/collection/operands/1/value").asText(),
+ "freizeit");
+ assertEquals(res.at("/collection/operands/1/key").asText(),
+ "textClass");
+ assertEquals(res.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
assertEquals(res.at("/collection/operands/0/value").asText(), "WPD");
- assertEquals(res.at("/collection/operands/0/key").asText(), "corpusSigle");
+ assertEquals(res.at("/collection/operands/0/key").asText(),
+ "corpusSigle");
// check also that query is still there
assertEquals(res.at("/query/@type").asText(), "koral:token");
assertEquals(res.at("/query/wrap/@type").asText(), "koral:term");
@@ -125,7 +154,7 @@
}
@Test
- public void testBaseQueryBuild() throws KustvaktException {
+ public void testBaseQueryBuild () throws KustvaktException {
KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder();
b.with("(corpusSigle=ADF) | (textClass=freizeit & corpusSigle=WPD)");
KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder();
@@ -134,14 +163,16 @@
JsonNode base = (JsonNode) c.rebaseCollection();
assertNotNull(base);
assertEquals(base.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(base.at("/collection/operands/1/@type").asText(), "koral:doc");
+ assertEquals(base.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
assertEquals(base.at("/collection/operands/1/value").asText(), "BRZ13");
- assertEquals(base.at("/collection/operands/0/@type").asText(), "koral:docGroup");
+ assertEquals(base.at("/collection/operands/0/@type").asText(),
+ "koral:docGroup");
assertEquals(base.at("/collection/operands/0/operands").size(), 2);
}
@Test
- public void testNodeMergeWithBase() throws KustvaktException {
+ public void testNodeMergeWithBase () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -155,12 +186,13 @@
node = b.mergeWith(node);
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
assertEquals(2, node.at("/collection/operands").size());
}
@Test
- public void testNodeMergeWithoutBase() throws KustvaktException {
+ public void testNodeMergeWithoutBase () throws KustvaktException {
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
check.setQuery(query, "poliqarp");
@@ -178,7 +210,8 @@
}
@Test
- public void testNodeMergeWithoutBaseWrongOperator() throws KustvaktException {
+ public void testNodeMergeWithoutBaseWrongOperator ()
+ throws KustvaktException {
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
check.setQuery(query, "poliqarp");
@@ -197,11 +230,10 @@
}
@Test
- public void testStoredCollectionBaseQueryBuild() {
- }
+ public void testStoredCollectionBaseQueryBuild () {}
@Test
- public void testAddOROperator() throws KustvaktException {
+ public void testAddOROperator () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -218,7 +250,7 @@
}
@Test
- public void testAddANDOperator() throws KustvaktException {
+ public void testAddANDOperator () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -230,12 +262,13 @@
JsonNode node = (JsonNode) test.rebaseCollection();
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
assertEquals(2, node.at("/collection/operands/1/operands").size());
}
@Test
- public void testAddDefaultOperator() throws KustvaktException {
+ public void testAddDefaultOperator () throws KustvaktException {
String coll = "corpusSigle=WPD";
String query = "[base=Haus]";
QuerySerializer check = new QuerySerializer();
@@ -247,12 +280,13 @@
JsonNode node = (JsonNode) test.rebaseCollection();
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
assertEquals(2, node.at("/collection/operands/1/operands").size());
}
@Test
- public void testBaseCollectionNull() throws KustvaktException {
+ public void testBaseCollectionNull () throws KustvaktException {
// base is missing collection segment
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Haus]", "poliqarp");
@@ -260,18 +294,24 @@
total.setBaseQuery(s.toJSON());
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
builder.with("textClass=politik & corpusSigle=WPD");
- JsonNode node = total.and().mergeWith((JsonNode) builder.rebaseCollection());
+ JsonNode node = total.and()
+ .mergeWith((JsonNode) builder.rebaseCollection());
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/0/key").asText(), "textClass");
- assertEquals(node.at("/collection/operands/1/key").asText(), "corpusSigle");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "corpusSigle");
}
@Test
- public void testMergeCollectionNull() throws KustvaktException {
+ public void testMergeCollectionNull () throws KustvaktException {
// merge json is missing collection segment
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Haus]", "poliqarp");
@@ -279,7 +319,8 @@
KoralCollectionQueryBuilder total = new KoralCollectionQueryBuilder();
total.setBaseQuery(s.toJSON());
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
- JsonNode node = total.and().mergeWith((JsonNode) builder.rebaseCollection());
+ JsonNode node = total.and()
+ .mergeWith((JsonNode) builder.rebaseCollection());
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:doc");
assertEquals(node.at("/collection/key").asText(), "textClass");
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/ConfigTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/ConfigTest.java
index 7fa7e33..f683230 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/ConfigTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/ConfigTest.java
@@ -26,19 +26,19 @@
KustvaktConfiguration config;
@Test
- public void testConfigLoader() {
+ public void testConfigLoader () {
InputStream stream = ConfigLoader.loadConfigStream("kustvakt.conf");
assertNotNull(stream);
}
@Test
- public void testPropertyLoader() throws IOException {
+ public void testPropertyLoader () throws IOException {
Properties p = ConfigLoader.loadProperties("kustvakt.conf");
assertNotNull(p);
}
@Test
- public void testServiceInfo() {
+ public void testServiceInfo () {
String version = ServiceInfo.getInfo().getVersion();
String name = ServiceInfo.getInfo().getName();
assertNotEquals("UNKNOWN", version, "wrong version");
@@ -46,8 +46,10 @@
}
@Test
- public void testProperties() {
- assertEquals("opennlp", config.getDefault_orthography(), "token layer does not match");
- assertEquals(TimeUtils.convertTimeToSeconds("1D"), config.getLongTokenTTL(), "token expiration does not match");
+ public void testProperties () {
+ assertEquals("opennlp", config.getDefault_orthography(),
+ "token layer does not match");
+ assertEquals(TimeUtils.convertTimeToSeconds("1D"),
+ config.getLongTokenTTL(), "token expiration does not match");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/KoralNodeTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/KoralNodeTest.java
index 7e974f3..eb9051b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/KoralNodeTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/KoralNodeTest.java
@@ -16,7 +16,7 @@
// todo: 21.10.15 --> e.g. injection does not tell you if an entire node was injected, or just a value!
@Test
- public void addToNode() {
+ public void addToNode () {
ObjectNode node = JsonUtils.createObjectNode();
KoralNode knode = KoralNode.wrapNode(node);
knode.put("value_1", "setting_1");
@@ -24,7 +24,7 @@
}
@Test
- public void removeFromNode() {
+ public void removeFromNode () {
ObjectNode node = JsonUtils.createObjectNode();
node.put("value_1", "setting_1");
KoralNode knode = KoralNode.wrapNode(node);
@@ -33,16 +33,16 @@
}
@Test
- public void replaceObject() {
+ public void replaceObject () {
ObjectNode node = JsonUtils.createObjectNode();
node.put("value_1", "setting_1");
KoralNode knode = KoralNode.wrapNode(node);
knode.replace("value_1", "settings_2", null);
- assertEquals(knode.rawNode().toString(), "{\"value_1\":\"settings_2\"}");
+ assertEquals(knode.rawNode().toString(),
+ "{\"value_1\":\"settings_2\"}");
}
// todo: 21.10.15 --> if a node is injected, that node must contain a "rewrites" reference?!
@Test
- public void addNodeToKoral() {
- }
+ public void addNodeToKoral () {}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java
index a7b5c01..9591a0e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/LocalQueryTest.java
@@ -29,12 +29,12 @@
KustvaktConfiguration config;
@PostConstruct
- public void setup() throws Exception {
+ public void setup () throws Exception {
index = config.getIndexDir();
}
@Test
- public void testQuery() throws KustvaktException {
+ public void testQuery () throws KustvaktException {
String qstring = "creationDate since 1786 & creationDate until 1788";
// qstring = "creationDate since 1765 & creationDate until 1768";
// qstring = "textType = Aphorismus";
@@ -47,7 +47,7 @@
}
@Test
- public void testCollQuery() throws IOException, KustvaktException {
+ public void testCollQuery () throws IOException, KustvaktException {
String qstring = "creationDate since 1800 & creationDate until 1820";
CollectionQueryProcessor processor = new CollectionQueryProcessor();
processor.process(qstring);
@@ -59,7 +59,7 @@
}
@Test
- public void testCollQuery2() throws IOException {
+ public void testCollQuery2 () throws IOException {
String query = "{\"@context\":\"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld\",\"errors\":[],\"warnings\":[],\"messages\":[],\"collection\":{\"@type\":\"koral:docGroup\",\"operation\":\"operation:and\",\"operands\":[{\"@type\":\"koral:doc\",\"key\":\"creationDate\",\"type\":\"type:date\",\"value\":\"1786\",\"match\":\"match:geq\"},{\"@type\":\"koral:doc\",\"key\":\"creationDate\",\"type\":\"type:date\",\"value\":\"1788\",\"match\":\"match:leq\"}]},\"query\":{},\"meta\":{}}";
KrillCollection c = new KrillCollection(query);
c.setIndex(new SearchKrill(index).getIndex());
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java
index 35e995e..4d59790 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java
@@ -14,23 +14,23 @@
@SuppressWarnings("unchecked")
@Test
- public void testConvertToMap() {
+ public void testConvertToMap () {
MultivaluedMap<String, String> mm = new MultivaluedHashMap<String, String>();
- mm.put("k1", Arrays.asList(new String[]{"a", "b", "c"}));
- mm.put("k2", Arrays.asList(new String[]{"d", "e", "f"}));
+ mm.put("k1", Arrays.asList(new String[] { "a", "b", "c" }));
+ mm.put("k2", Arrays.asList(new String[] { "d", "e", "f" }));
Map<String, String> map = MapUtils.toMap(mm);
assertEquals(map.get("k1"), "a b c");
assertEquals(map.get("k2"), "d e f");
}
@Test
- public void testConvertNullMap() {
+ public void testConvertNullMap () {
Map<String, String> map = MapUtils.toMap(null);
assertEquals(0, map.size());
}
@Test
- public void testConvertEmptyMap() {
+ public void testConvertEmptyMap () {
MultivaluedMap<String, String> mm = new MultivaluedHashMap<String, String>();
Map<String, String> map = MapUtils.toMap(mm);
assertEquals(0, map.size());
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/MetaQueryBuilderTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/MetaQueryBuilderTest.java
index c6328c3..7eda84d 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/MetaQueryBuilderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/MetaQueryBuilderTest.java
@@ -8,15 +8,15 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
-
/**
* Created by hanl on 17.04.16.
*/
public class MetaQueryBuilderTest {
@Test
- public void testSpanContext() {
- MetaQueryBuilder m = QueryBuilderUtil.defaultMetaBuilder(0, 1, 5, "sentence", false);
+ public void testSpanContext () {
+ MetaQueryBuilder m = QueryBuilderUtil.defaultMetaBuilder(0, 1, 5,
+ "sentence", false);
Map<?, ?> map = m.raw();
assertEquals(map.get("context"), "sentence");
assertEquals(1, map.get("startPage"));
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/RegexTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/RegexTest.java
index 518ae39..634530b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/RegexTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/RegexTest.java
@@ -10,7 +10,7 @@
public class RegexTest {
@Test
- public void testQuote() {
+ public void testQuote () {
String s = "ah[\"-\"]";
Matcher m = AnnotationParser.quotePattern.matcher(s);
if (m.find()) {
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/ScopesTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/ScopesTest.java
index 4d82706..ad92c36 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/ScopesTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/ScopesTest.java
@@ -9,10 +9,8 @@
public class ScopesTest {
@Test
- public void testScopes() {
- }
+ public void testScopes () {}
@Test
- public void testOpenIDScopes() {
- }
+ public void testOpenIDScopes () {}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/SerializationTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/SerializationTest.java
index 7471e12..dd4ca5b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/SerializationTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/SerializationTest.java
@@ -11,7 +11,7 @@
public class SerializationTest {
@Test
- public void testSettingsObject() {
+ public void testSettingsObject () {
// String t = "poliqarp_test";
// UserSettings s = new UserSettings();
// Map map = s.toObjectMap();
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 657ba0b..f7dfb3a 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
@@ -16,7 +16,7 @@
public class StringUtilsTest {
@Test
- public void testTextIToDoc() {
+ public void testTextIToDoc () {
String textSigle = "WPD_AAA.02439";
String docSigle = "WPD_AAA";
assertEquals(docSigle, StringUtils.getDocSigle(textSigle));
@@ -24,13 +24,14 @@
}
@Test
- public void testBasicHttpSplit() throws KustvaktException {
+ public void testBasicHttpSplit () throws KustvaktException {
String s2 = new String(Base64.encodeBase64("test:testPass".getBytes()));
String[] f2 = TransferEncoding.decodeBase64(s2);
assertEquals(f2[0], "test");
assertEquals(f2[1], "testPass");
HttpAuthorizationHandler handler = new HttpAuthorizationHandler();
- String s1 = "basic " + new String(Base64.encodeBase64("test:testPass".getBytes()));
+ String s1 = "basic "
+ + new String(Base64.encodeBase64("test:testPass".getBytes()));
AuthorizationData f1 = handler.parseAuthorizationHeaderValue(s1);
assertEquals(s2, f1.getToken());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/TestNullableSqls.java b/full/src/test/java/de/ids_mannheim/korap/misc/TestNullableSqls.java
index 86a2a79..8fcb1d0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/TestNullableSqls.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/TestNullableSqls.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.misc;
+
/**
* @author hanl
* @date 30/01/2016
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/CollectionRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/CollectionRewriteTest.java
index ae8e39b..e205ce3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/CollectionRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/CollectionRewriteTest.java
@@ -24,72 +24,89 @@
public KustvaktConfiguration config;
@Test
- public void testCollectionNodeRemoveCorpusIdNoErrors() throws KustvaktException {
+ public void testCollectionNodeRemoveCorpusIdNoErrors ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
s.setCollection("textClass=politik & corpusSigle=WPD");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(result, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(result,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(1, node.at("/collection/operands").size());
}
@Test
- public void testCollectionNodeDeletionNotification() {
- }
+ public void testCollectionNodeDeletionNotification () {}
@Test
- public void testCollectionNodeRemoveAllCorpusIdNoErrors() throws KustvaktException {
+ public void testCollectionNodeRemoveAllCorpusIdNoErrors ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
s.setCollection("corpusSigle=BRZ13 & corpusSigle=WPD");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(result, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(result,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(0, node.at("/collection/operands").size());
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testCollectionNodeRemoveGroupedCorpusIdNoErrors() throws KustvaktException {
+ public void testCollectionNodeRemoveGroupedCorpusIdNoErrors ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
- s.setCollection("(corpusSigle=BRZ13 & textClass=Wissenschaft) & corpusSigle=WPD");
+ s.setCollection(
+ "(corpusSigle=BRZ13 & textClass=Wissenschaft) & corpusSigle=WPD");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(result, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(result,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/0/operands/0/key").asText(), "textClass");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:docGroup");
+ assertEquals(node.at("/collection/operands/0/operands/0/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
// fixme: will probably fail when one doc groups are being refactored
@Test
- public void testCollectionCleanEmptyDocGroupNoErrors() throws KustvaktException {
+ public void testCollectionCleanEmptyDocGroupNoErrors ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
handler.add(CollectionCleanRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
- s.setCollection("(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft & textClass=Sport");
+ s.setCollection(
+ "(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft & textClass=Sport");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(result, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(result,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
assertEquals(2, node.at("/collection/operands").size());
- assertEquals(node.at("/collection/operands/0/key").asText(), "textClass");
- assertEquals(node.at("/collection/operands/1/key").asText(), "textClass");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testCollectionCleanMoveOneDocFromGroupUpNoErrors() throws KustvaktException {
+ public void testCollectionCleanMoveOneDocFromGroupUpNoErrors ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
handler.add(CollectionCleanRewrite.class);
@@ -97,123 +114,164 @@
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
s.setCollection("(corpusSigle=BRZ13 & textClass=wissenschaft)");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(result, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(result,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:doc");
assertEquals(node.at("/collection/key").asText(), "textClass");
assertEquals(node.at("/collection/value").asText(), "wissenschaft");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testCollectionCleanEmptyGroupAndMoveOneFromGroupUpNoErrors() throws KustvaktException {
+ public void testCollectionCleanEmptyGroupAndMoveOneFromGroupUpNoErrors ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
handler.add(CollectionCleanRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
- s.setCollection("(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft");
+ s.setCollection(
+ "(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft");
String result = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(result, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(result,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:doc");
assertEquals(node.at("/collection/key").asText(), "textClass");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testCollectionRemoveAndMoveOneFromGroupUpNoErrors() throws KustvaktException {
+ public void testCollectionRemoveAndMoveOneFromGroupUpNoErrors ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
handler.add(CollectionCleanRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
- s.setCollection("(docID=random & textClass=Wissenschaft) & corpusSigle=WPD");
+ s.setCollection(
+ "(docID=random & textClass=Wissenschaft) & corpusSigle=WPD");
String org = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(org, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(org,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
assertEquals(2, node.at("/collection/operands").size());
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testPublicCollectionRewriteEmptyAdd() throws KustvaktException {
+ public void testPublicCollectionRewriteEmptyAdd ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
String org = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(org, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(org,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(node.at("/collection/key").asText(), "availability");
assertEquals(node.at("/collection/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
// todo:
}
@Test
- public void testPublicCollectionRewriteNonEmptyAdd() throws KustvaktException {
+ public void testPublicCollectionRewriteNonEmptyAdd ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
s.setCollection("(docSigle=WPD_AAA & textClass=wissenschaft)");
String org = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(org, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(org,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(2, node.at("/collection/operands").size());
- assertEquals(node.at("/collection/operands/0/key").asText(), "availability");
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/1/operands/0/key").asText(), "docSigle");
- assertEquals(node.at("/collection/operands/1/operands/1/key").asText(), "textClass");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "availability");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(node.at("/collection/operands/1/operands/0/key").asText(),
+ "docSigle");
+ assertEquals(node.at("/collection/operands/1/operands/1/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
}
@Test
- public void testRemoveCorpusFromDifferentGroups() throws KustvaktException {
+ public void testRemoveCorpusFromDifferentGroups ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
- s.setCollection("(corpusSigle=BRZ14 & textClass=wissenschaft) | (corpusSigle=AZPR | textClass=freizeit)");
+ s.setCollection(
+ "(corpusSigle=BRZ14 & textClass=wissenschaft) | (corpusSigle=AZPR | textClass=freizeit)");
String org = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(org, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(org,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
assertEquals(2, node.at("/collection/operands").size());
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:docGroup");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:docGroup");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:docGroup");
assertEquals(1, node.at("/collection/operands/0/operands").size());
assertEquals(1, node.at("/collection/operands/1/operands").size());
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testRemoveOneCorpusAndMoveDocFromTwoGroups() throws KustvaktException {
+ public void testRemoveOneCorpusAndMoveDocFromTwoGroups ()
+ throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
handler.add(CollectionConstraint.class);
// todo: use this collection query also to test clean up filter! after reduction of corpusSigle (wiss | freizeit)!
handler.add(CollectionCleanRewrite.class);
QuerySerializer s = new QuerySerializer();
s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp");
- s.setCollection("(corpusSigle=BRZ14 & textClass=wissenschaft) | (corpusSigle=AZPR | textClass=freizeit)");
+ s.setCollection(
+ "(corpusSigle=BRZ14 & textClass=wissenschaft) | (corpusSigle=AZPR | textClass=freizeit)");
String org = s.toJSON();
- JsonNode node = JsonUtils.readTree(handler.processQuery(org, User.UserFactory.getUser("test_user")));
+ JsonNode node = JsonUtils.readTree(handler.processQuery(org,
+ User.UserFactory.getUser("test_user")));
assertNotNull(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
assertEquals(2, node.at("/collection/operands").size());
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/0/key").asText(), "textClass");
- assertEquals(node.at("/collection/operands/0/value").asText(), "wissenschaft");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/1/key").asText(), "textClass");
- assertEquals(node.at("/collection/operands/1/value").asText(), "freizeit");
- assertEquals(node.at("/collection/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "wissenschaft");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/operands/1/value").asText(),
+ "freizeit");
+ assertEquals(node.at("/collection/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java
index 65d3752..51e7fc5 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/FoundryRewriteTest.java
@@ -44,50 +44,67 @@
private LayerMapper m;
@Test
- public void testSearchRewriteFoundryWithUserSetting() throws KustvaktException {
+ public void testSearchRewriteFoundryWithUserSetting ()
+ throws KustvaktException {
// create user setting
String json = "{\"pos-foundry\":\"opennlp\"}";
String username = "foundryRewriteTest";
String pathUsername = "~" + username;
- Response response = target().path(API_VERSION).path(pathUsername).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path(pathUsername)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
// search
- response = target().path(API_VERSION).path("search").queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).accept(MediaType.APPLICATION_JSON).get();
+ response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp")
+ .request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .accept(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/query/wrap/foundry").asText(), "opennlp");
- assertEquals(node.at("/query/wrap/rewrites/0/scope").asText(), "foundry");
+ assertEquals(node.at("/query/wrap/rewrites/0/scope").asText(),
+ "foundry");
}
@Test
- public void testRewritePosFoundryWithUserSetting() throws KustvaktException {
+ public void testRewritePosFoundryWithUserSetting ()
+ throws KustvaktException {
// EM: see
// full/src/main/resources/db/insert/V3.6__insert_default_settings.sql
String username = "bubbles";
QuerySerializer s = new QuerySerializer();
s.setQuery("[pos=ADJA]", "poliqarp");
- String result = handler.processQuery(s.toJSON(), new KorAPUser(username));
+ String result = handler.processQuery(s.toJSON(),
+ new KorAPUser(username));
JsonNode node = JsonUtils.readTree(result);
assertEquals(node.at("/query/wrap/foundry").asText(), "corenlp");
- assertEquals(node.at("/query/wrap/rewrites/0/scope").asText(), "foundry");
+ assertEquals(node.at("/query/wrap/rewrites/0/scope").asText(),
+ "foundry");
}
@Test
- public void testRewriteLemmaFoundryWithUserSetting() throws KustvaktException {
+ public void testRewriteLemmaFoundryWithUserSetting ()
+ throws KustvaktException {
String username = "bubbles";
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Haus]", "poliqarp");
- String result = handler.processQuery(s.toJSON(), new KorAPUser(username));
+ String result = handler.processQuery(s.toJSON(),
+ new KorAPUser(username));
JsonNode node = JsonUtils.readTree(result);
// EM: only for testing, in fact, opennlp lemma does not
// exist!
assertEquals(node.at("/query/wrap/foundry").asText(), "opennlp");
- assertEquals(node.at("/query/wrap/rewrites/0/scope").asText(), "foundry");
+ assertEquals(node.at("/query/wrap/rewrites/0/scope").asText(),
+ "foundry");
}
@Test
- public void testDefaultLayerMapperThrowsNoException() {
+ public void testDefaultLayerMapperThrowsNoException () {
assertEquals(config.getDefault_lemma(), m.findFoundry("lemma"));
assertEquals(config.getDefault_pos(), m.findFoundry("pos"));
assertEquals(config.getDefault_orthography(), m.findFoundry("surface"));
@@ -96,35 +113,42 @@
}
@Test
- public void testDefaultFoundryInjectLemmaThrowsNoError() throws KustvaktException {
+ public void testDefaultFoundryInjectLemmaThrowsNoError ()
+ throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[base=Haus]", "poliqarp");
String result = handler.processQuery(s.toJSON(), new KorAPUser("test"));
JsonNode node = JsonUtils.readTree(result);
assertNotNull(node);
assertFalse(node.at("/query/wrap/foundry").isMissingNode());
- assertEquals(config.getDefault_lemma(), node.at("/query/wrap/foundry").asText());
+ assertEquals(config.getDefault_lemma(),
+ node.at("/query/wrap/foundry").asText());
assertEquals(node.at("/query/wrap/layer").asText(), "lemma");
assertFalse(node.at("/query/wrap/rewrites").isMissingNode());
- assertEquals(node.at("/query/wrap/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/query/wrap/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testDefaultFoundryInjectPOSNoErrors() throws KustvaktException {
+ public void testDefaultFoundryInjectPOSNoErrors ()
+ throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[pos=ADJA]", "poliqarp");
String result = handler.processQuery(s.toJSON(), new KorAPUser("test"));
JsonNode node = JsonUtils.readTree(result);
assertNotNull(node);
assertFalse(node.at("/query/wrap/foundry").isMissingNode());
- assertEquals(config.getDefault_pos(), node.at("/query/wrap/foundry").asText());
+ assertEquals(config.getDefault_pos(),
+ node.at("/query/wrap/foundry").asText());
assertEquals(node.at("/query/wrap/layer").asText(), "pos");
assertFalse(node.at("/query/wrap/rewrites").isMissingNode());
- assertEquals(node.at("/query/wrap/rewrites/0/@type").asText(), "koral:rewrite");
+ assertEquals(node.at("/query/wrap/rewrites/0/@type").asText(),
+ "koral:rewrite");
}
@Test
- public void testFoundryInjectJoinedQueryNoErrors() throws KustvaktException {
+ public void testFoundryInjectJoinedQueryNoErrors ()
+ throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=laufe/i & base!=Lauf]", "poliqarp");
String result = handler.processQuery(s.toJSON(), new KorAPUser("test"));
@@ -138,7 +162,8 @@
}
@Test
- public void testFoundryInjectGroupedQueryNoErrors() throws KustvaktException {
+ public void testFoundryInjectGroupedQueryNoErrors ()
+ throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[(base=laufen | tt/pos=VVFIN)]", "poliqarp");
String result = handler.processQuery(s.toJSON(), new KorAPUser("test"));
@@ -152,7 +177,7 @@
}
@Test
- public void testFoundryBaseRewrite() throws KustvaktException {
+ public void testFoundryBaseRewrite () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=laufen]", "poliqarp");
String result = handler.processQuery(s.toJSON(), new KorAPUser("test"));
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/IdRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/IdRewriteTest.java
index b0fc1ea..ef33982 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/IdRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/IdRewriteTest.java
@@ -26,7 +26,7 @@
private KustvaktConfiguration config;
@Test
- public void insertTokenId() throws KustvaktException {
+ public void insertTokenId () throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
assertTrue(handler.add(IdWriter.class));
String query = "[surface=Wort]";
@@ -39,7 +39,7 @@
}
@Test
- public void testIdWriterTest() throws KustvaktException {
+ public void testIdWriterTest () throws KustvaktException {
RewriteHandler handler = new RewriteHandler(config);
assertTrue(handler.add(IdWriter.class));
QuerySerializer s = new QuerySerializer();
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
index 8862def..524dad5 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
@@ -18,28 +18,42 @@
public class QueryRewriteTest extends SpringJerseyTest {
@Test
- public void testRewriteRefNotFound() throws KustvaktException, Exception {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "{q}").queryParam("ql", "poliqarp").resolveTemplate("q", "[orth=der]{#examplequery} Baum").request().get();
+ public void testRewriteRefNotFound () throws KustvaktException, Exception {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "{q}").queryParam("ql", "poliqarp")
+ .resolveTemplate("q", "[orth=der]{#examplequery} Baum")
+ .request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(node.at("/errors/0/1").asText(), "Query system/examplequery is not found.");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Query system/examplequery is not found.");
}
@Test
- public void testRewriteSystemQuery() throws KustvaktException, Exception {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "{q}").queryParam("ql", "poliqarp").resolveTemplate("q", "[orth=der]{#system-q} Baum").request().get();
+ public void testRewriteSystemQuery () throws KustvaktException, Exception {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "{q}").queryParam("ql", "poliqarp")
+ .resolveTemplate("q", "[orth=der]{#system-q} Baum").request()
+ .get();
String ent = response.readEntity(String.class);
// System.out.println(ent);
JsonNode node = JsonUtils.readTree(ent);
}
@Test
- public void testRewriteRefRewrite() throws KustvaktException, Exception {
+ public void testRewriteRefRewrite () throws KustvaktException, Exception {
// Added in the database migration sql for tests
- Response response = target().path(API_VERSION).path("search").queryParam("q", "{q}").queryParam("ql", "poliqarp").resolveTemplate("q", "[orth=der]{#dory/dory-q} Baum").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "{q}").queryParam("ql", "poliqarp")
+ .resolveTemplate("q", "[orth=der]{#dory/dory-q} Baum").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(node.at("/query/operands/1/@type").asText(), "koral:token");
- assertEquals(node.at("/query/operands/1/rewrites/0/scope").asText(), "@type(koral:queryRef)");
+ assertEquals(node.at("/query/operands/1/@type").asText(),
+ "koral:token");
+ assertEquals(node.at("/query/operands/1/rewrites/0/scope").asText(),
+ "@type(koral:queryRef)");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/ResultRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/ResultRewriteTest.java
index 6642514..77767a0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/ResultRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/ResultRewriteTest.java
@@ -21,9 +21,11 @@
public RewriteHandler ha;
@Test
- public void testPostRewriteNothingToDo() throws KustvaktException {
- assertEquals(true, ha.add(CollectionRewrite.class), "Handler could not be added to rewrite handler instance!");
+ public void testPostRewriteNothingToDo () throws KustvaktException {
+ assertEquals(true, ha.add(CollectionRewrite.class),
+ "Handler could not be added to rewrite handler instance!");
String v = ha.processResult(TestVariables.RESULT, null);
- assertEquals(JsonUtils.readTree(TestVariables.RESULT), JsonUtils.readTree(v), "results do not match");
+ assertEquals(JsonUtils.readTree(TestVariables.RESULT),
+ JsonUtils.readTree(v), "results do not match");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/RewriteHandlerTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/RewriteHandlerTest.java
index 60b934c..35df9d3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/RewriteHandlerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/RewriteHandlerTest.java
@@ -79,7 +79,7 @@
private KustvaktConfiguration config;
@Test
- public void testRewriteTaskAdd() {
+ public void testRewriteTaskAdd () {
RewriteHandler handler = new RewriteHandler(config);
assertTrue(handler.add(FoundryInject.class));
assertTrue(handler.add(CollectionCleanRewrite.class));
@@ -88,11 +88,12 @@
// throws exception cause of missing configuration
@Test
- public void testRewriteConfigThrowsException() {
+ public void testRewriteConfigThrowsException () {
assertThrows(RuntimeException.class, () -> {
RewriteHandler handler = new RewriteHandler();
QuerySerializer s = new QuerySerializer();
- s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]", "poliqarp");
+ s.setQuery("[(base=laufen | base=gehen) & tt/pos=VVFIN]",
+ "poliqarp");
assertTrue(handler.add(FoundryInject.class));
handler.processQuery(s.toJSON(), null);
});
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
index 170ffd0..f0ea66c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewriteTest.java
@@ -36,10 +36,13 @@
private QueryDao dao;
@Test
- public void testRefCachedVC() throws KustvaktException, IOException, QueryException {
+ public void testRefCachedVC ()
+ throws KustvaktException, IOException, QueryException {
vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld");
assertTrue(VirtualCorpusCache.contains("named-vc1"));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo named-vc1").request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo named-vc1").request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
@@ -54,8 +57,12 @@
assertFalse(VirtualCorpusCache.contains("named-vc1"));
}
- private void testRefCachedVCWithUsername() throws KustvaktException, IOException, QueryException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"system/named-vc1\"").request().get();
+ private void testRefCachedVCWithUsername ()
+ throws KustvaktException, IOException, QueryException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"system/named-vc1\"").request()
+ .get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
@@ -67,8 +74,11 @@
}
@Test
- public void testRewriteFreeAndSystemVCRef() throws KustvaktException, Exception {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"system-vc\"").request().get();
+ public void testRewriteFreeAndSystemVCRef ()
+ throws KustvaktException, Exception {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"system-vc\"").request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
@@ -85,8 +95,13 @@
}
@Test
- public void testRewritePubAndSystemVCRef() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"system/system-vc\"").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("user", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testRewritePubAndSystemVCRef () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"system/system-vc\"").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("user", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
@@ -100,8 +115,14 @@
}
@Test
- public void testRewriteWithDoryVCRef() throws KustvaktException, IOException, QueryException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Fisch").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"dory/dory-vc\"").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).get();
+ public void testRewriteWithDoryVCRef ()
+ throws KustvaktException, IOException, QueryException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Fisch").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"dory/dory-vc\"").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
node = node.at("/collection");
diff --git a/full/src/test/java/de/ids_mannheim/korap/scenario/ICCTest.java b/full/src/test/java/de/ids_mannheim/korap/scenario/ICCTest.java
index 0119a21..fcc655f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/scenario/ICCTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/scenario/ICCTest.java
@@ -28,12 +28,15 @@
* this instance:<em>kustvakt-icc.conf</em>.
*
* <p>
- * To run a Kustvakt jar with ICC setup, the following files are needed:
+ * To run a Kustvakt jar with ICC setup, the following files are
+ * needed:
* </p>
* <ul>
* <li>a Spring configuration file</li>
- * <li>a Kustvakt configuration file that must be placed at the jar folder</li>
- * <li>a JDBC properties file that must be placed at the jar folder</li>
+ * <li>a Kustvakt configuration file that must be placed at the jar
+ * folder</li>
+ * <li>a JDBC properties file that must be placed at the jar
+ * folder</li>
* </ul>
* <p>
* Example:
@@ -67,12 +70,14 @@
* </code>
* </pre>
*
- * <p>For production, the init-method of Initializator should be changed to init.</p>
+ * <p>For production, the init-method of Initializator should be
+ * changed to init.</p>
*
* <pre>
* <code>
- * <bean id="initializator" class="de.ids_mannheim.de.init.Initializator"
- * init-method="init"></bean>
+ * <bean id="initializator"
+ * class="de.ids_mannheim.de.init.Initializator"
+ * init-method="init"></bean>
* </code>
* </pre>
*
@@ -129,22 +134,28 @@
public String basicAuth;
- public ICCTest() throws KustvaktException {
- basicAuth = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("user", "password");
+ public ICCTest () throws KustvaktException {
+ basicAuth = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("user", "password");
}
@Test
- public void searchWithoutLogin() throws KustvaktException {
- Response r = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").request().get();
+ public void searchWithoutLogin () throws KustvaktException {
+ Response r = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .request().get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), r.getStatus());
String entity = r.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void searchWithLogin() throws KustvaktException {
- Response r = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, basicAuth).get();
+ public void searchWithLogin () throws KustvaktException {
+ Response r = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .request().header(Attributes.AUTHORIZATION, basicAuth).get();
assertEquals(Status.OK.getStatusCode(), r.getStatus());
String entity = r.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -152,17 +163,23 @@
}
@Test
- public void matchInfoWithoutLogin() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("WDD17").path("982").path("72848").path("p2815-2816").queryParam("foundry", "*").request().get();
+ public void matchInfoWithoutLogin () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("WDD17").path("982").path("72848").path("p2815-2816")
+ .queryParam("foundry", "*").request().get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void matchInfoWithLogin() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("WDD17").path("982").path("72848").path("p2815-2816").queryParam("foundry", "*").request().header(Attributes.AUTHORIZATION, basicAuth).get();
+ public void matchInfoWithLogin () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("WDD17").path("982").path("72848").path("p2815-2816")
+ .queryParam("foundry", "*").request()
+ .header(Attributes.AUTHORIZATION, basicAuth).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/server/EmbeddedLdapServerTest.java b/full/src/test/java/de/ids_mannheim/korap/server/EmbeddedLdapServerTest.java
index 79f640f..98b35cf 100644
--- a/full/src/test/java/de/ids_mannheim/korap/server/EmbeddedLdapServerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/server/EmbeddedLdapServerTest.java
@@ -18,71 +18,90 @@
import static de.ids_mannheim.korap.authentication.LdapAuth3.LDAP_AUTH_RUNKNOWN;
import static org.junit.jupiter.api.Assertions.assertEquals;
-
public class EmbeddedLdapServerTest {
public static final String TEST_EMBEDDED_LDAP_CONF = "src/test/resources/test-embedded-ldap.conf";
@AfterAll
- static void shutdownEmbeddedLdapServer() {
+ static void shutdownEmbeddedLdapServer () {
EmbeddedLdapServer.stop();
}
@Test
- public void embeddedServerStartsAutomaticallyAndUsersCanLogin() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("user", "password", TEST_EMBEDDED_LDAP_CONF));
+ public void embeddedServerStartsAutomaticallyAndUsersCanLogin ()
+ throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("user", "password", TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void usersWithClearPasswordCanLogin() throws LDAPException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("user1", "password1", TEST_EMBEDDED_LDAP_CONF));
+ public void usersWithClearPasswordCanLogin () throws LDAPException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("user1", "password1", TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void usersWithSHA1PasswordCanLogin() throws LDAPException, NoSuchAlgorithmException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("user3", "password3", TEST_EMBEDDED_LDAP_CONF));
+ public void usersWithSHA1PasswordCanLogin ()
+ throws LDAPException, NoSuchAlgorithmException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("user3", "password3", TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void usersWithSHA256PasswordCanLogin() throws LDAPException, NoSuchAlgorithmException, InvalidKeySpecException {
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("user4", "password4", TEST_EMBEDDED_LDAP_CONF));
+ public void usersWithSHA256PasswordCanLogin () throws LDAPException,
+ NoSuchAlgorithmException, InvalidKeySpecException {
+ assertEquals(LDAP_AUTH_ROK,
+ LdapAuth3.login("user4", "password4", TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void asteriskPasswordsFail() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("user1", "*", TEST_EMBEDDED_LDAP_CONF));
+ public void asteriskPasswordsFail () throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN,
+ LdapAuth3.login("user1", "*", TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void loginWithPreencodedPBKDF2Password() throws LDAPException, NoSuchAlgorithmException, InvalidKeySpecException {
+ public void loginWithPreencodedPBKDF2Password () throws LDAPException,
+ NoSuchAlgorithmException, InvalidKeySpecException {
byte[] salt = new byte[32];
- KeySpec spec = new PBEKeySpec("password5".toCharArray(), salt, 65536, 256);
- SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2withHmacSHA256");
+ KeySpec spec = new PBEKeySpec("password5".toCharArray(), salt, 65536,
+ 256);
+ SecretKeyFactory f = SecretKeyFactory
+ .getInstance("PBKDF2withHmacSHA256");
byte[] hash = f.generateSecret(spec).getEncoded();
- final String pbkdf2sha256Password = "{PBKDF2-SHA256}" + Base64.encode(hash);
+ final String pbkdf2sha256Password = "{PBKDF2-SHA256}"
+ + Base64.encode(hash);
// System.out.println(pbkdf2sha256Password);
- assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("user5", pbkdf2sha256Password, TEST_EMBEDDED_LDAP_CONF));
+ assertEquals(LDAP_AUTH_ROK, LdapAuth3.login("user5",
+ pbkdf2sha256Password, TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void loginWithUnencodedPBKDF2PasswordFails() throws LDAPException, NoSuchAlgorithmException, InvalidKeySpecException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("user5", "password5", TEST_EMBEDDED_LDAP_CONF));
+ public void loginWithUnencodedPBKDF2PasswordFails () throws LDAPException,
+ NoSuchAlgorithmException, InvalidKeySpecException {
+ assertEquals(LDAP_AUTH_RUNKNOWN,
+ LdapAuth3.login("user5", "password5", TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void unauthorizedUsersAreNotAllowed() throws LDAPException {
- assertEquals(LDAP_AUTH_RUNKNOWN, LdapAuth3.login("yuser", "password", TEST_EMBEDDED_LDAP_CONF));
+ public void unauthorizedUsersAreNotAllowed () throws LDAPException {
+ assertEquals(LDAP_AUTH_RUNKNOWN,
+ LdapAuth3.login("yuser", "password", TEST_EMBEDDED_LDAP_CONF));
}
@Test
- public void gettingMailForUser() throws LDAPException, UnknownHostException, GeneralSecurityException {
+ public void gettingMailForUser () throws LDAPException,
+ UnknownHostException, GeneralSecurityException {
EmbeddedLdapServer.startIfNotRunning(TEST_EMBEDDED_LDAP_CONF);
- assertEquals(LdapAuth3.getEmail("user2", TEST_EMBEDDED_LDAP_CONF), "user2@example.com");
+ assertEquals(LdapAuth3.getEmail("user2", TEST_EMBEDDED_LDAP_CONF),
+ "user2@example.com");
}
@Test
- public void gettingMailForNAUTHUserIsNull() throws LDAPException, UnknownHostException, GeneralSecurityException {
+ public void gettingMailForNAUTHUserIsNull () throws LDAPException,
+ UnknownHostException, GeneralSecurityException {
EmbeddedLdapServer.startIfNotRunning(TEST_EMBEDDED_LDAP_CONF);
- assertEquals(null, LdapAuth3.getEmail("user1000", TEST_EMBEDDED_LDAP_CONF));
+ assertEquals(null,
+ LdapAuth3.getEmail("user1000", TEST_EMBEDDED_LDAP_CONF));
}
}
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 60a661f..8799ad7 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
@@ -33,7 +33,7 @@
private UserGroupService groupService;
@Test
- public void testCreateNonUniqueVC() throws KustvaktException {
+ public void testCreateNonUniqueVC () throws KustvaktException {
// EM: message differs depending on the database used
// for testing. The message below is from sqlite.
// thrown.expectMessage("A UNIQUE constraint failed "
@@ -43,11 +43,12 @@
vc.setCorpusQuery("corpusSigle=GOE");
vc.setType(ResourceType.PRIVATE);
vc.setQueryType(QueryType.VIRTUAL_CORPUS);
- assertThrows(KustvaktException.class, () -> vcService.storeQuery(vc, "dory-vc", "dory", "dory"));
+ assertThrows(KustvaktException.class,
+ () -> vcService.storeQuery(vc, "dory-vc", "dory", "dory"));
}
@Test
- public void createDeletePublishVC() throws KustvaktException {
+ public void createDeletePublishVC () throws KustvaktException {
String vcName = "new-published-vc";
QueryJson vc = new QueryJson();
vc.setCorpusQuery("corpusSigle=GOE");
@@ -55,7 +56,8 @@
vc.setQueryType(QueryType.VIRTUAL_CORPUS);
String username = "VirtualCorpusServiceTest";
vcService.storeQuery(vc, vcName, username, username);
- List<QueryAccessDto> accesses = vcService.listQueryAccessByUsername("admin");
+ List<QueryAccessDto> accesses = vcService
+ .listQueryAccessByUsername("admin");
int size = accesses.size();
QueryAccessDto dto = accesses.get(accesses.size() - 1);
assertEquals(vcName, dto.getQueryName());
@@ -66,21 +68,25 @@
UserGroup group = groupService.retrieveUserGroupById(groupId);
assertEquals(UserGroupStatus.HIDDEN, group.getStatus());
// delete vc
- vcService.deleteQueryByName(username, vcName, username, QueryType.VIRTUAL_CORPUS);
+ vcService.deleteQueryByName(username, vcName, username,
+ QueryType.VIRTUAL_CORPUS);
// check hidden access
accesses = vcService.listQueryAccessByUsername("admin");
assertEquals(size - 1, accesses.size());
// check hidden group
- KustvaktException e = assertThrows(KustvaktException.class, () -> groupService.retrieveUserGroupById(groupId));
- assertEquals("Group with id " + groupId + " is not found", e.getMessage());
+ KustvaktException e = assertThrows(KustvaktException.class,
+ () -> groupService.retrieveUserGroupById(groupId));
+ assertEquals("Group with id " + groupId + " is not found",
+ e.getMessage());
}
@Test
- public void testEditPublishVC() throws KustvaktException {
+ public void testEditPublishVC () throws KustvaktException {
String username = "dory";
int vcId = 2;
String vcName = "group-vc";
- QueryDO existingVC = vcService.searchQueryByName(username, vcName, username, QueryType.VIRTUAL_CORPUS);
+ QueryDO existingVC = vcService.searchQueryByName(username, vcName,
+ username, QueryType.VIRTUAL_CORPUS);
QueryJson vcJson = new QueryJson();
vcJson.setType(ResourceType.PUBLISHED);
vcService.editQuery(existingVC, vcJson, vcName, username);
@@ -89,7 +95,8 @@
assertEquals(vcName, vcDto.getName());
assertEquals(ResourceType.PUBLISHED.displayName(), vcDto.getType());
// check access
- List<QueryAccessDto> accesses = vcService.listQueryAccessByUsername("admin");
+ List<QueryAccessDto> accesses = vcService
+ .listQueryAccessByUsername("admin");
int size = accesses.size();
QueryAccessDto dto = accesses.get(accesses.size() - 1);
assertEquals(vcName, dto.getQueryName());
@@ -110,7 +117,9 @@
// check access
accesses = vcService.listQueryAccessByUsername("admin");
assertEquals(size - 1, accesses.size());
- KustvaktException e = assertThrows(KustvaktException.class, () -> groupService.retrieveUserGroupById(groupId));
- assertEquals("Group with id " + groupId + " is not found", e.getMessage());
+ KustvaktException e = assertThrows(KustvaktException.class,
+ () -> groupService.retrieveUserGroupById(groupId));
+ assertEquals("Group with id " + groupId + " is not found",
+ e.getMessage());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/user/DataFactoryTest.java b/full/src/test/java/de/ids_mannheim/korap/user/DataFactoryTest.java
index 513020e..5584fb7 100644
--- a/full/src/test/java/de/ids_mannheim/korap/user/DataFactoryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/user/DataFactoryTest.java
@@ -20,7 +20,7 @@
public class DataFactoryTest {
@Test
- public void testDataFactoryAdd() throws KustvaktException {
+ public void testDataFactoryAdd () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
DataFactory factory = DataFactory.getFactory();
@@ -36,7 +36,7 @@
}
@Test
- public void testDataFactoryGet() throws KustvaktException {
+ public void testDataFactoryGet () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
DataFactory factory = DataFactory.getFactory();
@@ -63,7 +63,7 @@
}
@Test
- public void testDataFactoryMerge() throws KustvaktException {
+ public void testDataFactoryMerge () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
DataFactory factory = DataFactory.getFactory();
@@ -85,7 +85,7 @@
}
@Test
- public void testDataFactoryKeys() throws KustvaktException {
+ public void testDataFactoryKeys () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
DataFactory factory = DataFactory.getFactory();
@@ -98,7 +98,7 @@
@Test
@Disabled
- public void testDataFactoryRemove() throws KustvaktException {
+ public void testDataFactoryRemove () throws KustvaktException {
String data = "{}";
Object node = JsonUtils.readTree(data);
DataFactory factory = DataFactory.getFactory();
@@ -136,7 +136,7 @@
}
@Test
- public void testDataFactoryEmbeddedProperty() throws KustvaktException {
+ public void testDataFactoryEmbeddedProperty () throws KustvaktException {
String data = "{}";
JsonNode node = JsonUtils.readTree(data);
DataFactory factory = DataFactory.getFactory();
diff --git a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
index 75f3e6b..0e99a7f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/user/UserdataTest.java
@@ -27,7 +27,7 @@
// EM: added
@Test
- public void testReadEmptyMap() throws KustvaktException {
+ public void testReadEmptyMap () throws KustvaktException {
Userdata userData = new UserSettingProcessor();
userData.read(new HashMap<>(), false);
String jsonSettings = userData.serialize();
@@ -35,7 +35,7 @@
}
@Test
- public void testReadNullMap() throws KustvaktException {
+ public void testReadNullMap () throws KustvaktException {
Userdata userData = new UserSettingProcessor();
userData.read(null, false);
String jsonSettings = userData.serialize();
@@ -53,10 +53,10 @@
//
// At the moment, validation is not needed for default settings.
@Test
- public void testValidateMap() throws IOException, KustvaktException {
+ public void testValidateMap () throws IOException, KustvaktException {
Map<String, Object> map = new HashMap<>();
- map.put("k1", Arrays.asList(new String[]{"a", "b", "c"}));
- map.put("k2", Arrays.asList(new Integer[]{1, 2, 3}));
+ map.put("k1", Arrays.asList(new String[] { "a", "b", "c" }));
+ map.put("k2", Arrays.asList(new Integer[] { 1, 2, 3 }));
Userdata data = new UserSettingProcessor();
data.read(map, false);
data.validate(new ApacheValidator());
@@ -64,7 +64,7 @@
// EM: below are tests from MH
@Test
- public void testDataValidation() {
+ public void testDataValidation () {
Userdata data = new UserDetails(1);
data.setField(Attributes.COUNTRY, "Germany");
String[] req = data.requiredFields();
@@ -75,7 +75,7 @@
}
@Test
- public void testSettingsValidation() {
+ public void testSettingsValidation () {
Userdata data = new UserSettingProcessor();
data.setField(Attributes.FILE_FORMAT_FOR_EXPORT, "export");
String[] req = data.requiredFields();
@@ -86,7 +86,7 @@
}
@Test
- public void testUserdataRequiredFields() throws KustvaktException {
+ public void testUserdataRequiredFields () throws KustvaktException {
UserDetails details = new UserDetails(-1);
Map<String, Object> m = new HashMap<>();
m.put(Attributes.FIRSTNAME, "first");
@@ -100,7 +100,7 @@
}
@Test
- public void testUserdataDefaultFields() throws KustvaktException {
+ public void testUserdataDefaultFields () throws KustvaktException {
UserSettingProcessor settings = new UserSettingProcessor();
Map<String, Object> m = new HashMap<>();
m.put(Attributes.DEFAULT_FOUNDRY_RELATION, "rel_1");
@@ -113,15 +113,17 @@
settings.read(m, true);
assertNotEquals(m.size(), settings.size());
assertEquals(settings.defaultFields().length, settings.size());
- assertEquals(settings.get(Attributes.DEFAULT_FOUNDRY_RELATION), "rel_1");
+ assertEquals(settings.get(Attributes.DEFAULT_FOUNDRY_RELATION),
+ "rel_1");
assertEquals(settings.get(Attributes.DEFAULT_FOUNDRY_POS), "pos_1");
assertEquals(settings.get(Attributes.DEFAULT_FOUNDRY_LEMMA), "lemma_1");
- assertEquals(settings.get(Attributes.DEFAULT_FOUNDRY_CONSTITUENT), "const_1");
+ assertEquals(settings.get(Attributes.DEFAULT_FOUNDRY_CONSTITUENT),
+ "const_1");
assertEquals(10, settings.get(Attributes.PAGE_LENGTH));
}
@Test
- public void testUserDataRequiredFieldsException() {
+ public void testUserDataRequiredFieldsException () {
assertThrows(KustvaktException.class, () -> {
UserDetails details = new UserDetails(-1);
Map<String, Object> m = new HashMap<>();
@@ -137,7 +139,7 @@
}
@Test
- public void testUserDataPointerFunction() throws KustvaktException {
+ public void testUserDataPointerFunction () throws KustvaktException {
UserDetails details = new UserDetails(-1);
Map<String, Object> m = new HashMap<>();
m.put(Attributes.FIRSTNAME, "first");
@@ -154,7 +156,7 @@
}
@Test
- public void testUserDataUpdate() {
+ public void testUserDataUpdate () {
UserDetails details = new UserDetails(-1);
details.setField(Attributes.FIRSTNAME, "first");
details.setField(Attributes.LASTNAME, "last");
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 e06fe0d..9e138fa 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
@@ -18,16 +18,20 @@
public class ApiVersionTest extends SpringJerseyTest {
@Test
- public void testSearchWithoutVersion() throws KustvaktException {
- Response response = target().path("api").path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchWithoutVersion () throws KustvaktException {
+ Response response = target().path("api").path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .request().accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals("/api/" + API_VERSION + "/search", location.getPath());
}
@Test
- public void testSearchWrongVersion() throws KustvaktException {
- Response response = target().path("api").path("v0.2").path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchWrongVersion () throws KustvaktException {
+ Response response = target().path("api").path("v0.2").path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .request().accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals("/api/" + API_VERSION + "/search", location.getPath());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java b/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java
index a936e6b..e8c8eef 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/InitialSuperClientTest.java
@@ -29,10 +29,12 @@
@Autowired
private OAuth2ClientDao clientDao;
- private String path = KustvaktConfiguration.DATA_FOLDER + "/" + OAuth2InitClientService.TEST_OUTPUT_FILENAME;
+ private String path = KustvaktConfiguration.DATA_FOLDER + "/"
+ + OAuth2InitClientService.TEST_OUTPUT_FILENAME;
@Test
- public void testCreatingInitialSuperClient() throws IOException, KustvaktException {
+ public void testCreatingInitialSuperClient ()
+ throws IOException, KustvaktException {
assertTrue(config.createInitialSuperClient());
File f = new File(path);
assertTrue(f.exists());
@@ -45,8 +47,10 @@
removeSuperClientFile();
}
- private void testLogin(String superClientId, String superClientSecret) throws KustvaktException {
- Response response = requestTokenWithPassword(superClientId, superClientSecret, "username", "password");
+ private void testLogin (String superClientId, String superClientSecret)
+ throws KustvaktException {
+ Response response = requestTokenWithPassword(superClientId,
+ superClientSecret, "username", "password");
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertTrue(!node.at("/access_token").isMissingNode());
@@ -56,7 +60,7 @@
assertEquals(node.at("/token_type").asText(), "Bearer");
}
- private void removeSuperClientFile() {
+ private void removeSuperClientFile () {
File f = new File(path);
if (f.exists()) {
f.delete();
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java
index 571c15c..4730f2c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java
@@ -18,29 +18,30 @@
public class JettyServerTest {
static int selectedPort = 0;
-
+
@BeforeAll
- static void testServerStarts() throws Exception {
-
-
+ static void testServerStarts () throws Exception {
+
for (int port = 1000; port <= 2000; port++) {
try (ServerSocket ignored = new ServerSocket(port)) {
selectedPort = port;
break;
- } catch (IOException ignored) {
+ }
+ catch (IOException ignored) {
// Port is already in use, try the next one
}
}
-
+
Server server = new Server(selectedPort);
- ShutdownHandler shutdownHandler = new ShutdownHandler("secret");
+ ShutdownHandler shutdownHandler = new ShutdownHandler("secret");
server.setHandler(shutdownHandler);
server.start();
}
-
+
@Test
- public void testShutdown() throws IOException {
- URL url = new URL("http://localhost:"+selectedPort+"/shutdown?token=secret");
+ public void testShutdown () throws IOException {
+ URL url = new URL(
+ "http://localhost:" + selectedPort + "/shutdown?token=secret");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
assertEquals(200, connection.getResponseCode());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/SearchKrillTest.java b/full/src/test/java/de/ids_mannheim/korap/web/SearchKrillTest.java
index c4476c2..2034592 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/SearchKrillTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/SearchKrillTest.java
@@ -30,31 +30,33 @@
SearchKrill krill = null;
@PostConstruct
- private void createKrill() {
+ private void createKrill () {
krill = new SearchKrill(config.getIndexDir());
assertNotNull(krill);
}
@Test
- public void testIndex() throws KustvaktException {
+ public void testIndex () throws KustvaktException {
KrillIndex index = krill.getIndex();
assertNotNull(index);
}
@Test
- public void testDocSize() {
+ public void testDocSize () {
assertNotEquals(0, krill.getIndex().numberOf("documents"));
}
@Test
- public void testMatchInfo() throws KustvaktException {
- String matchinfo = krill.getMatch("WPD/AAA.00002/p169-197", config.getFreeLicensePattern());
+ public void testMatchInfo () throws KustvaktException {
+ String matchinfo = krill.getMatch("WPD/AAA.00002/p169-197",
+ config.getFreeLicensePattern());
JsonNode node = JsonUtils.readTree(matchinfo);
- assertEquals(node.at("/errors/0/1").asText(), "Invalid match identifier");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Invalid match identifier");
}
@Test
- public void testSearch() throws KustvaktException {
+ public void testSearch () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=der]", "poliqarp");
String result = krill.search(s.toJSON());
@@ -64,7 +66,7 @@
}
@Test
- public void testTimeOut() throws KustvaktException {
+ public void testTimeOut () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=der]", "poliqarp");
// s.setQuery("node ->malt/d[func=/.*/] node", "annis");
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/AdminLoadVCTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/AdminLoadVCTest.java
index c7bc757..2c359a0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/AdminLoadVCTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/AdminLoadVCTest.java
@@ -20,11 +20,16 @@
public class AdminLoadVCTest extends SpringJerseyTest {
@Test
- public void testLoadCacheVC() throws KustvaktException, InterruptedException {
+ public void testLoadCacheVC ()
+ throws KustvaktException, InterruptedException {
assertFalse(VirtualCorpusCache.contains("named-vc1"));
Form f = new Form();
f.param("token", "secret");
- Response response = target().path(API_VERSION).path("admin").path("vc").path("load-cache").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin").path("vc")
+ .path("load-cache").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
Thread.sleep(100);
assertTrue(VirtualCorpusCache.contains("named-vc1"));
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java
index 9626114..e6737bb 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/AnnotationControllerTest.java
@@ -19,8 +19,9 @@
public class AnnotationControllerTest extends SpringJerseyTest {
@Test
- public void testAnnotationLayers() throws KustvaktException {
- Response response = target().path(API_VERSION).path("annotation").path("layers").request().get();
+ public void testAnnotationLayers () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("annotation")
+ .path("layers").request().get();
String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
assertEquals(31, n.size());
@@ -33,9 +34,10 @@
}
@Test
- public void testAnnotationFoundry() throws KustvaktException {
+ public void testAnnotationFoundry () throws KustvaktException {
String json = "{\"codes\":[\"opennlp/*\"], \"language\":\"en\"}";
- Response response = target().path(API_VERSION).path("annotation").path("description").request().post(Entity.json(json));
+ Response response = target().path(API_VERSION).path("annotation")
+ .path("description").request().post(Entity.json(json));
String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
n = n.get(0);
@@ -53,9 +55,10 @@
}
@Test
- public void testAnnotationValues() throws KustvaktException {
+ public void testAnnotationValues () throws KustvaktException {
String json = "{\"codes\":[\"mate/m\"], \"language\":\"en\"}";
- Response response = target().path(API_VERSION).path("annotation").path("description").request().post(Entity.json(json));
+ Response response = target().path(API_VERSION).path("annotation")
+ .path("description").request().post(Entity.json(json));
String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity);
n = n.get(0);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
index ca4c915..42d7a68 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/AvailabilityTest.java
@@ -19,125 +19,193 @@
public class AvailabilityTest extends SpringJerseyTest {
- private void checkAndFree(String json) throws KustvaktException {
+ private void checkAndFree (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
- assertEquals(node.at("/collection/operands/0/key").asText(), "availability");
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "availability");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
}
- private void checkAndPublic(String json) throws KustvaktException {
+ private void checkAndPublic (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
- assertEquals(node.at("/collection/operands/0/operands/0/match").asText(), "match:eq");
- assertEquals(node.at("/collection/operands/0/operands/0/type").asText(), "type:regex");
- assertEquals(node.at("/collection/operands/0/operands/0/key").asText(), "availability");
- assertEquals(node.at("/collection/operands/0/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/0/operands/1/operands/0/match").asText(), "match:eq");
- assertEquals(node.at("/collection/operands/0/operands/1/operands/0/value").asText(), "ACA.*");
- assertEquals(node.at("/collection/operands/0/operands/1/operands/1/match").asText(), "match:eq");
- assertEquals(node.at("/collection/operands/0/operands/1/operands/1/value").asText(), "QAO-NC");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(PUB)");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
+ assertEquals(
+ node.at("/collection/operands/0/operands/0/match").asText(),
+ "match:eq");
+ assertEquals(node.at("/collection/operands/0/operands/0/type").asText(),
+ "type:regex");
+ assertEquals(node.at("/collection/operands/0/operands/0/key").asText(),
+ "availability");
+ assertEquals(
+ node.at("/collection/operands/0/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(
+ node.at("/collection/operands/0/operands/1/operands/0/match")
+ .asText(),
+ "match:eq");
+ assertEquals(
+ node.at("/collection/operands/0/operands/1/operands/0/value")
+ .asText(),
+ "ACA.*");
+ assertEquals(
+ node.at("/collection/operands/0/operands/1/operands/1/match")
+ .asText(),
+ "match:eq");
+ assertEquals(
+ node.at("/collection/operands/0/operands/1/operands/1/value")
+ .asText(),
+ "QAO-NC");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(PUB)");
}
- private void checkAndPublicWithACA(String json) throws KustvaktException {
+ private void checkAndPublicWithACA (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(PUB)");
- assertEquals(node.at("/collection/operands/1/match").asText(), "match:eq");
- assertEquals(node.at("/collection/operands/1/type").asText(), "type:regex");
- assertEquals(node.at("/collection/operands/1/key").asText(), "availability");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(PUB)");
+ assertEquals(node.at("/collection/operands/1/match").asText(),
+ "match:eq");
+ assertEquals(node.at("/collection/operands/1/type").asText(),
+ "type:regex");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "availability");
assertEquals(node.at("/collection/operands/1/value").asText(), "ACA.*");
node = node.at("/collection/operands/0");
assertEquals(node.at("/operands/0/match").asText(), "match:eq");
assertEquals(node.at("/operands/0/type").asText(), "type:regex");
assertEquals(node.at("/operands/0/key").asText(), "availability");
assertEquals(node.at("/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/operands/1/operands/0/match").asText(), "match:eq");
- assertEquals(node.at("/operands/1/operands/0/type").asText(), "type:regex");
- assertEquals(node.at("/operands/1/operands/0/key").asText(), "availability");
+ assertEquals(node.at("/operands/1/operands/0/match").asText(),
+ "match:eq");
+ assertEquals(node.at("/operands/1/operands/0/type").asText(),
+ "type:regex");
+ assertEquals(node.at("/operands/1/operands/0/key").asText(),
+ "availability");
assertEquals(node.at("/operands/1/operands/0/value").asText(), "ACA.*");
}
- private void checkAndAllWithACA(String json) throws KustvaktException {
+ private void checkAndAllWithACA (String json) throws KustvaktException {
JsonNode node = JsonUtils.readTree(json);
assertNotNull(node);
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(ALL)");
- assertEquals(node.at("/collection/operands/1/match").asText(), "match:eq");
- assertEquals(node.at("/collection/operands/1/type").asText(), "type:regex");
- assertEquals(node.at("/collection/operands/1/key").asText(), "availability");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(ALL)");
+ assertEquals(node.at("/collection/operands/1/match").asText(),
+ "match:eq");
+ assertEquals(node.at("/collection/operands/1/type").asText(),
+ "type:regex");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "availability");
assertEquals(node.at("/collection/operands/1/value").asText(), "ACA.*");
node = node.at("/collection/operands/0");
assertEquals(node.at("/operands/0/match").asText(), "match:eq");
assertEquals(node.at("/operands/0/type").asText(), "type:regex");
assertEquals(node.at("/operands/0/key").asText(), "availability");
assertEquals(node.at("/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/operands/1/operands/1/operands/0/match").asText(), "match:eq");
- assertEquals(node.at("/operands/1/operands/1/operands/0/value").asText(), "QAO-NC");
- assertEquals(node.at("/operands/1/operands/1/operands/1/match").asText(), "match:eq");
- assertEquals(node.at("/operands/1/operands/1/operands/1/value").asText(), "QAO.*");
+ assertEquals(
+ node.at("/operands/1/operands/1/operands/0/match").asText(),
+ "match:eq");
+ assertEquals(
+ node.at("/operands/1/operands/1/operands/0/value").asText(),
+ "QAO-NC");
+ assertEquals(
+ node.at("/operands/1/operands/1/operands/1/match").asText(),
+ "match:eq");
+ assertEquals(
+ node.at("/operands/1/operands/1/operands/1/value").asText(),
+ "QAO.*");
}
- private Response searchQuery(String collectionQuery) {
- return target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("cq", collectionQuery).request().get();
+ private Response searchQuery (String collectionQuery) {
+ return target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("cq", collectionQuery).request().get();
}
- private Response searchQueryWithIP(String collectionQuery, String ip) throws ProcessingException, KustvaktException {
- return target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("cq", collectionQuery).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, ip).get();
+ private Response searchQueryWithIP (String collectionQuery, String ip)
+ throws ProcessingException, KustvaktException {
+ return target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("cq", collectionQuery).request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, ip).get();
}
@Test
- public void testAvailabilityFreeAuthorized() throws KustvaktException {
+ public void testAvailabilityFreeAuthorized () throws KustvaktException {
Response response = searchQuery("availability = CC-BY-SA");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testAvailabilityRegexFreeAuthorized() throws KustvaktException {
+ public void testAvailabilityRegexFreeAuthorized ()
+ throws KustvaktException {
Response response = searchQuery("availability = /.*BY.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testAvailabilityFreeUnauthorized() throws KustvaktException {
+ public void testAvailabilityFreeUnauthorized () throws KustvaktException {
Response response = searchQuery("availability = ACA-NC");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testAvailabilityRegexFreeUnauthorized() throws KustvaktException {
+ public void testAvailabilityRegexFreeUnauthorized ()
+ throws KustvaktException {
Response response = searchQuery("availability = /ACA.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testAvailabilityRegexNoRewrite() throws KustvaktException {
- Response response = searchQuery("availability = /CC-BY.*/ & availability = /ACA.*/");
+ public void testAvailabilityRegexNoRewrite () throws KustvaktException {
+ Response response = searchQuery(
+ "availability = /CC-BY.*/ & availability = /ACA.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String json = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(json);
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
- assertEquals(node.at("/collection/operands/0/match").asText(), "match:eq");
- assertEquals(node.at("/collection/operands/0/type").asText(), "type:regex");
- assertEquals(node.at("/collection/operands/0/key").asText(), "availability");
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/1/match").asText(), "match:eq");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
+ assertEquals(node.at("/collection/operands/0/match").asText(),
+ "match:eq");
+ assertEquals(node.at("/collection/operands/0/type").asText(),
+ "type:regex");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "availability");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(node.at("/collection/operands/1/match").asText(),
+ "match:eq");
assertEquals(node.at("/collection/operands/1/value").asText(), "ACA.*");
}
@Test
- public void testAvailabilityRegexFreeUnauthorized3() throws KustvaktException {
+ public void testAvailabilityRegexFreeUnauthorized3 ()
+ throws KustvaktException {
Response response = searchQuery("availability = /.*NC.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// System.out.println(response.readEntity(String.class));
@@ -145,113 +213,141 @@
}
@Test
- public void testNegationAvailabilityFreeUnauthorized() throws KustvaktException {
+ public void testNegationAvailabilityFreeUnauthorized ()
+ throws KustvaktException {
Response response = searchQuery("availability != /CC-BY.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testNegationAvailabilityFreeUnauthorized2() throws KustvaktException {
+ public void testNegationAvailabilityFreeUnauthorized2 ()
+ throws KustvaktException {
Response response = searchQuery("availability != /.*BY.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testNegationAvailabilityWithOperationOrUnauthorized() throws KustvaktException {
- Response response = searchQuery("availability = /CC-BY.*/ | availability != /CC-BY.*/");
+ public void testNegationAvailabilityWithOperationOrUnauthorized ()
+ throws KustvaktException {
+ Response response = searchQuery(
+ "availability = /CC-BY.*/ | availability != /CC-BY.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testComplexNegationAvailabilityFreeUnauthorized() throws KustvaktException {
- Response response = searchQuery("textClass=politik & availability != /CC-BY.*/");
+ public void testComplexNegationAvailabilityFreeUnauthorized ()
+ throws KustvaktException {
+ Response response = searchQuery(
+ "textClass=politik & availability != /CC-BY.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testComplexAvailabilityFreeUnauthorized() throws KustvaktException {
- Response response = searchQuery("textClass=politik & availability=ACA-NC");
+ public void testComplexAvailabilityFreeUnauthorized ()
+ throws KustvaktException {
+ Response response = searchQuery(
+ "textClass=politik & availability=ACA-NC");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testComplexAvailabilityFreeUnauthorized3() throws KustvaktException {
- Response response = searchQuery("textClass=politik & availability=/.*NC.*/");
+ public void testComplexAvailabilityFreeUnauthorized3 ()
+ throws KustvaktException {
+ Response response = searchQuery(
+ "textClass=politik & availability=/.*NC.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testAvailabilityPublicAuthorized() throws KustvaktException {
- Response response = searchQueryWithIP("availability=ACA-NC", "149.27.0.32");
+ public void testAvailabilityPublicAuthorized () throws KustvaktException {
+ Response response = searchQueryWithIP("availability=ACA-NC",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndPublic(response.readEntity(String.class));
}
@Test
- public void testAvailabilityPublicUnauthorized() throws KustvaktException {
- Response response = searchQueryWithIP("availability=QAO-NC-LOC:ids", "149.27.0.32");
+ public void testAvailabilityPublicUnauthorized () throws KustvaktException {
+ Response response = searchQueryWithIP("availability=QAO-NC-LOC:ids",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndPublic(response.readEntity(String.class));
}
@Test
- public void testAvailabilityRegexPublicAuthorized() throws KustvaktException {
- Response response = searchQueryWithIP("availability= /ACA.*/", "149.27.0.32");
+ public void testAvailabilityRegexPublicAuthorized ()
+ throws KustvaktException {
+ Response response = searchQueryWithIP("availability= /ACA.*/",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndPublicWithACA(response.readEntity(String.class));
}
@Test
- public void testNegationAvailabilityPublicUnauthorized() throws KustvaktException {
- Response response = searchQueryWithIP("availability != ACA-NC", "149.27.0.32");
+ public void testNegationAvailabilityPublicUnauthorized ()
+ throws KustvaktException {
+ Response response = searchQueryWithIP("availability != ACA-NC",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndPublic(response.readEntity(String.class));
}
@Test
- public void testNegationAvailabilityRegexPublicUnauthorized() throws KustvaktException {
- Response response = searchQueryWithIP("availability != /ACA.*/", "149.27.0.32");
+ public void testNegationAvailabilityRegexPublicUnauthorized ()
+ throws KustvaktException {
+ Response response = searchQueryWithIP("availability != /ACA.*/",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndPublic(response.readEntity(String.class));
}
@Test
- public void testComplexAvailabilityPublicUnauthorized() throws KustvaktException {
- Response response = searchQueryWithIP("textClass=politik & availability=QAO-NC-LOC:ids", "149.27.0.32");
+ public void testComplexAvailabilityPublicUnauthorized ()
+ throws KustvaktException {
+ Response response = searchQueryWithIP(
+ "textClass=politik & availability=QAO-NC-LOC:ids",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndPublic(response.readEntity(String.class));
}
@Test
- public void testNegationComplexAvailabilityPublicUnauthorized() throws KustvaktException {
- Response response = searchQueryWithIP("textClass=politik & availability!=QAO-NC-LOC:ids", "149.27.0.32");
+ public void testNegationComplexAvailabilityPublicUnauthorized ()
+ throws KustvaktException {
+ Response response = searchQueryWithIP(
+ "textClass=politik & availability!=QAO-NC-LOC:ids",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndPublic(response.readEntity(String.class));
}
@Test
- public void testAvailabilityRegexAllAuthorized() throws KustvaktException {
- Response response = searchQueryWithIP("availability= /ACA.*/", "10.27.0.32");
+ public void testAvailabilityRegexAllAuthorized () throws KustvaktException {
+ Response response = searchQueryWithIP("availability= /ACA.*/",
+ "10.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndAllWithACA(response.readEntity(String.class));
}
@Test
- public void testAvailabilityOr() throws KustvaktException {
- Response response = searchQuery("availability=/CC-BY.*/ | availability=/ACA.*/");
+ public void testAvailabilityOr () throws KustvaktException {
+ Response response = searchQuery(
+ "availability=/CC-BY.*/ | availability=/ACA.*/");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testRedundancyOrPub() throws KustvaktException {
- Response response = searchQueryWithIP("availability=/CC-BY.*/ | availability=/ACA.*/ | availability=/QAO-NC/", "149.27.0.32");
+ public void testRedundancyOrPub () throws KustvaktException {
+ Response response = searchQueryWithIP(
+ "availability=/CC-BY.*/ | availability=/ACA.*/ | availability=/QAO-NC/",
+ "149.27.0.32");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String json = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(json);
@@ -260,21 +356,22 @@
}
@Test
- public void testAvailabilityOrCorpusSigle() throws KustvaktException {
- Response response = searchQuery("availability=/CC-BY.*/ | corpusSigle=GOE");
+ public void testAvailabilityOrCorpusSigle () throws KustvaktException {
+ Response response = searchQuery(
+ "availability=/CC-BY.*/ | corpusSigle=GOE");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testOrWithoutAvailability() throws KustvaktException {
+ public void testOrWithoutAvailability () throws KustvaktException {
Response response = searchQuery("corpusSigle=GOE | textClass=politik");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
}
@Test
- public void testWithoutAvailability() throws KustvaktException {
+ public void testWithoutAvailability () throws KustvaktException {
Response response = searchQuery("corpusSigle=GOE");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
checkAndFree(response.readEntity(String.class));
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
index e8a5d79..cf74436 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
@@ -15,13 +15,16 @@
public class FreeResourceControllerTest extends SpringJerseyTest {
@Test
- public void testResource() throws KustvaktException {
- Response response = target().path(API_VERSION).path("resource").request().get();
+ public void testResource () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("resource")
+ .request().get();
String entity = response.readEntity(String.class);
JsonNode n = JsonUtils.readTree(entity).get(0);
assertEquals(n.at("/resourceId").asText(), "WPD17");
- assertEquals(n.at("/titles/de").asText(), "Deutsche Wikipedia Artikel 2017");
- assertEquals(n.at("/titles/en").asText(), "German Wikipedia Articles 2017");
+ assertEquals(n.at("/titles/de").asText(),
+ "Deutsche Wikipedia Artikel 2017");
+ assertEquals(n.at("/titles/en").asText(),
+ "German Wikipedia Articles 2017");
assertEquals(1, n.at("/languages").size());
assertEquals(6, n.at("/layers").size());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
index ef70ac5..3b9dfbc 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/IndexControllerTest.java
@@ -37,8 +37,10 @@
private SearchKrill searchKrill;
@Test
- public void testCloseIndex() throws IOException, KustvaktException, URISyntaxException, InterruptedException {
- URI uri = IndexControllerTest.class.getClassLoader().getResource("vc/named-vc1.jsonld").toURI();
+ public void testCloseIndex () throws IOException, KustvaktException,
+ URISyntaxException, InterruptedException {
+ URI uri = IndexControllerTest.class.getClassLoader()
+ .getResource("vc/named-vc1.jsonld").toURI();
Path toLink = Paths.get(uri);
Path symLink = Paths.get("vc/named-vc1.jsonld");
Path vcPath = Paths.get("vc");
@@ -53,15 +55,22 @@
assertEquals(true, searchKrill.getIndex().isReaderOpen());
Form form = new Form();
form.param("token", "secret");
- Response response = target().path(API_VERSION).path("index").path("close").request().post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("index")
+ .path("close").request().post(Entity.form(form));
assertEquals(HttpStatus.SC_OK, response.getStatus());
assertEquals(false, searchKrill.getIndex().isReaderOpen());
// Cleaning database and cache
Thread.sleep(200);
- response = target().path(API_VERSION).path("vc").path("~system").path("named-vc1").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).delete();
- response = target().path(API_VERSION).path("vc").path("~system").path("named-vc1").request().get();
+ response = target().path(API_VERSION).path("vc").path("~system")
+ .path("named-vc1").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .delete();
+ response = target().path(API_VERSION).path("vc").path("~system")
+ .path("named-vc1").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
index fd12bdb..ab60ba3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
@@ -25,15 +25,20 @@
private SearchKrill krill;
@Test
- public void testInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("info").request().get();
+ public void testInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("info").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(config.getCurrentVersion(), node.at("/latest_api_version").asText());
- assertEquals(config.getSupportedVersions().size(), node.at("/supported_api_versions").size());
- assertEquals(ServiceInfo.getInfo().getVersion(), node.at("/kustvakt_version").asText());
- assertEquals(krill.getIndex().getVersion(), node.at("/krill_version").asText());
+ assertEquals(config.getCurrentVersion(),
+ node.at("/latest_api_version").asText());
+ assertEquals(config.getSupportedVersions().size(),
+ node.at("/supported_api_versions").size());
+ assertEquals(ServiceInfo.getInfo().getVersion(),
+ node.at("/kustvakt_version").asText());
+ assertEquals(krill.getIndex().getVersion(),
+ node.at("/krill_version").asText());
QuerySerializer s = new QuerySerializer();
assertEquals(s.getVersion(), node.at("/koral_version").asText());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
index 09a72be..ec282c9 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
@@ -20,55 +20,94 @@
public class MatchInfoControllerTest extends SpringJerseyTest {
@Test
- public void testGetMatchInfoPublicCorpus() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGA").path("01784").path("p36-100").path("matchInfo").queryParam("foundry", "*").request().get();
+ public void testGetMatchInfoPublicCorpus () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGA").path("01784").path("p36-100")
+ .path("matchInfo").queryParam("foundry", "*").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
- assertEquals(node.at("/author").asText(), "Goethe, Johann Wolfgang von");
- assertTrue(node.at("/snippet").asText().startsWith("<span class=\"context-left\"></span>" + "<span class=\"match\">"));
+ assertEquals(node.at("/author").asText(),
+ "Goethe, Johann Wolfgang von");
+ assertTrue(node.at("/snippet").asText()
+ .startsWith("<span class=\"context-left\"></span>"
+ + "<span class=\"match\">"));
}
@Test
- public void testGetMatchInfoNotAllowed() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGI").path("04846").path("p36875-36876").path("matchInfo").queryParam("foundry", "*").request().get();
+ public void testGetMatchInfoNotAllowed () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGI").path("04846").path("p36875-36876")
+ .path("matchInfo").queryParam("foundry", "*").request().get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Retrieving resource with ID " + "match-GOE/AGI/04846-p36875-36876 is not allowed.", node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "Retrieving resource with ID "
+ + "match-GOE/AGI/04846-p36875-36876 is not allowed.",
+ node.at("/errors/0/1").asText());
assertTrue(node.at("/snippet").isMissingNode());
}
@Test
- public void testGetMatchInfoWithAuthentication() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGI").path("04846").path("p36875-36876").path("matchInfo").queryParam("foundry", "*").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32").get();
+ public void testGetMatchInfoWithAuthentication () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGI").path("04846").path("p36875-36876")
+ .path("matchInfo").queryParam("foundry", "*").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32").get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGI/04846");
- assertEquals(node.at("/title").asText(), "Zweiter römischer Aufenthalt");
- assertEquals(node.at("/subTitle").asText(), "vom Juni 1787 bis April 1788");
- assertEquals(node.at("/author").asText(), "Goethe, Johann Wolfgang von");
- assertTrue(node.at("/snippet").asText().startsWith("<span class=\"context-left\"></span>" + "<span class=\"match\">"));
+ assertEquals(node.at("/title").asText(),
+ "Zweiter römischer Aufenthalt");
+ assertEquals(node.at("/subTitle").asText(),
+ "vom Juni 1787 bis April 1788");
+ assertEquals(node.at("/author").asText(),
+ "Goethe, Johann Wolfgang von");
+ assertTrue(node.at("/snippet").asText()
+ .startsWith("<span class=\"context-left\"></span>"
+ + "<span class=\"match\">"));
assertEquals(node.at("/availability").asText(), "QAO-NC-LOC:ids");
}
@Test
- public void testAvailabilityAll() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGD").path("00000").path("p75-76").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32").get();
+ public void testAvailabilityAll () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGD").path("00000").path("p75-76").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
- public void testAvailabilityAllUnauthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGD").path("00000").path("p75-76").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32").get();
+ public void testAvailabilityAllUnauthorized () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGD").path("00000").path("p75-76").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32").get();
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Retrieving resource with ID " + "match-GOE/AGD/00000-p75-76 is not allowed.", node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "Retrieving resource with ID "
+ + "match-GOE/AGD/00000-p75-76 is not allowed.",
+ node.at("/errors/0/1").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
index 147d893..dcc63d7 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
@@ -20,8 +20,10 @@
public class MetadataControllerTest extends SpringJerseyTest {
@Test
- public void testRetrieveMetadataWithField() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGA").path("01784").queryParam("fields", "author").request().get();
+ public void testRetrieveMetadataWithField () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGA").path("01784")
+ .queryParam("fields", "author").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -29,8 +31,11 @@
}
@Test
- public void testRetrieveMetadataWithMultipleFields() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGA").path("01784").queryParam("fields", "author,title").request().get();
+ public void testRetrieveMetadataWithMultipleFields ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGA").path("01784")
+ .queryParam("fields", "author,title").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -39,8 +44,9 @@
}
@Test
- public void testFreeMetadata() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGA").path("01784").request().get();
+ public void testFreeMetadata () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGA").path("01784").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -50,34 +56,62 @@
// EM: currently all metadata are allowed
@Test
@Disabled
- public void testMetadataUnauthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGI").path("04846").request().get();
+ public void testMetadataUnauthorized () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGI").path("04846").request().get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Retrieving resource with ID " + "GOE/AGI/04846 is not allowed.", node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "Retrieving resource with ID "
+ + "GOE/AGI/04846 is not allowed.",
+ node.at("/errors/0/1").asText());
}
@Test
- public void testMetadataWithAuthentication() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGI").path("04846").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32").get();
+ public void testMetadataWithAuthentication () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGI").path("04846").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
- public void testMetadataAvailabilityAll() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGI").path("00000").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32").get();
+ public void testMetadataAvailabilityAll () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGI").path("00000").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
// EM: currently all metadata are allowed
@Test
@Disabled
- public void testMetadataAvailabilityAllUnauthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").path("AGD").path("00000").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32").get();
+ public void testMetadataAvailabilityAllUnauthorized ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").path("AGD").path("00000").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32").get();
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Retrieving resource with ID " + "GOE/AGD/00000 is not allowed.", node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "Retrieving resource with ID "
+ + "GOE/AGD/00000 is not allowed.",
+ node.at("/errors/0/1").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java
index 26a121f..775afd8 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MultipleCorpusQueryTest.java
@@ -17,8 +17,12 @@
public class MultipleCorpusQueryTest extends SpringJerseyTest {
@Test
- public void testSearchGet() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "das").queryParam("ql", "poliqarp").queryParam("cq", "pubPlace=München").queryParam("cq", "textSigle=\"GOE/AGA/01784\"").request().get();
+ public void testSearchGet () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "das").queryParam("ql", "poliqarp")
+ .queryParam("cq", "pubPlace=München")
+ .queryParam("cq", "textSigle=\"GOE/AGA/01784\"").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -35,8 +39,11 @@
}
@Test
- public void testStatisticsWithMultipleCq() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung").queryParam("cq", "corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithMultipleCq ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung")
+ .queryParam("cq", "corpusSigle=GOE").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -48,8 +55,12 @@
}
@Test
- public void testStatisticsWithMultipleCorpusQuery() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "textType=Autobiographie").queryParam("corpusQuery", "corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithMultipleCorpusQuery ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "textType=Autobiographie")
+ .queryParam("corpusQuery", "corpusSigle=GOE").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -58,6 +69,7 @@
assertEquals(19387, node.at("/sentences").asInt());
assertEquals(514, node.at("/paragraphs").asInt());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "Parameter corpusQuery is deprecated in favor of cq.");
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "Parameter corpusQuery is deprecated in favor of cq.");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
index 315728a..6b5627d 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AccessTokenTest.java
@@ -31,43 +31,56 @@
private String clientAuthHeader;
- public OAuth2AccessTokenTest() throws KustvaktException {
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
- clientAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(confidentialClientId, clientSecret);
+ public OAuth2AccessTokenTest () throws KustvaktException {
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
+ clientAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(confidentialClientId,
+ clientSecret);
}
@Test
- public void testScopeWithSuperClient() throws KustvaktException {
- Response response = requestTokenWithDoryPassword(superClientId, clientSecret);
+ public void testScopeWithSuperClient () throws KustvaktException {
+ Response response = requestTokenWithDoryPassword(superClientId,
+ clientSecret);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(node.at("/scope").asText(), "all");
String accessToken = node.at("/access_token").asText();
// test list user group
- response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).get();
+ response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(2, node.size());
}
@Test
- public void testCustomScope() throws KustvaktException {
- Response response = requestAuthorizationCode("code", confidentialClientId, "", OAuth2Scope.VC_INFO.toString(), "", userAuthHeader);
+ public void testCustomScope () throws KustvaktException {
+ Response response = requestAuthorizationCode("code",
+ confidentialClientId, "", OAuth2Scope.VC_INFO.toString(), "",
+ userAuthHeader);
String code = parseAuthorizationCode(response);
- response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String token = node.at("/access_token").asText();
- assertTrue(node.at("/scope").asText().contains(OAuth2Scope.VC_INFO.toString()));
+ assertTrue(node.at("/scope").asText()
+ .contains(OAuth2Scope.VC_INFO.toString()));
// test list vc using the token
- response = target().path(API_VERSION).path("vc").request().header(Attributes.AUTHORIZATION, "Bearer " + token).get();
+ response = target().path(API_VERSION).path("vc").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + token).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(4, node.size());
}
@Test
- public void testDefaultScope() throws KustvaktException, IOException {
- String code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ public void testDefaultScope () throws KustvaktException, IOException {
+ String code = requestAuthorizationCode(confidentialClientId,
+ userAuthHeader);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
@@ -76,52 +89,76 @@
testSearchWithOAuth2Token(accessToken);
}
- private void testScopeNotAuthorized(String accessToken) throws KustvaktException {
- Response response = target().path(API_VERSION).path("vc").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).get();
+ private void testScopeNotAuthorized (String accessToken)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Scope vc_info is not authorized");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Scope vc_info is not authorized");
}
- private void testScopeNotAuthorize2(String accessToken) throws KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("access").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).get();
+ private void testScopeNotAuthorize2 (String accessToken)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("access")
+ .request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .get();
String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Scope vc_access_info is not authorized");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Scope vc_access_info is not authorized");
}
@Test
- public void testSearchWithUnknownToken() throws KustvaktException, IOException {
- Response response = searchWithAccessToken("ljsa8tKNRSczJhk20öhq92zG8z350");
+ public void testSearchWithUnknownToken ()
+ throws KustvaktException, IOException {
+ Response response = searchWithAccessToken(
+ "ljsa8tKNRSczJhk20öhq92zG8z350");
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(StatusCodes.INVALID_ACCESS_TOKEN, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Access token is invalid");
+ assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Access token is invalid");
}
@Test
- public void testRevokeAccessTokenConfidentialClient() throws KustvaktException {
- String code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- JsonNode node = requestTokenWithAuthorizationCodeAndHeader(confidentialClientId, code, clientAuthHeader);
+ public void testRevokeAccessTokenConfidentialClient ()
+ throws KustvaktException {
+ String code = requestAuthorizationCode(confidentialClientId,
+ userAuthHeader);
+ JsonNode node = requestTokenWithAuthorizationCodeAndHeader(
+ confidentialClientId, code, clientAuthHeader);
String accessToken = node.at("/access_token").asText();
Form form = new Form();
form.param("token", accessToken);
form.param("client_id", confidentialClientId);
form.param("client_secret", "secret");
- Response response = target().path(API_VERSION).path("oauth2").path("revoke").request().header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("revoke").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
testSearchWithRevokedAccessToken(accessToken);
}
@Test
- public void testRevokeAccessTokenPublicClientViaSuperClient() throws KustvaktException {
+ public void testRevokeAccessTokenPublicClientViaSuperClient ()
+ throws KustvaktException {
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "", code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ publicClientId, "", code);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
testRevokeTokenViaSuperClient(accessToken, userAuthHeader);
@@ -129,9 +166,12 @@
}
@Test
- public void testAccessTokenAfterRequestRefreshToken() throws KustvaktException, IOException {
- String code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- JsonNode node = requestTokenWithAuthorizationCodeAndHeader(confidentialClientId, code, clientAuthHeader);
+ public void testAccessTokenAfterRequestRefreshToken ()
+ throws KustvaktException, IOException {
+ String code = requestAuthorizationCode(confidentialClientId,
+ userAuthHeader);
+ JsonNode node = requestTokenWithAuthorizationCodeAndHeader(
+ confidentialClientId, code, clientAuthHeader);
String accessToken = node.at("/access_token").asText();
String refreshToken = node.at("/refresh_token").asText();
Form form = new Form();
@@ -139,7 +179,12 @@
form.param("client_id", confidentialClientId);
form.param("client_secret", "secret");
form.param("refresh_token", refreshToken);
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(entity);
@@ -149,27 +194,38 @@
}
@Test
- public void testRequestAuthorizationWithBearerTokenUnauthorized() throws KustvaktException {
- String code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- JsonNode node = requestTokenWithAuthorizationCodeAndHeader(confidentialClientId, code, clientAuthHeader);
+ public void testRequestAuthorizationWithBearerTokenUnauthorized ()
+ throws KustvaktException {
+ String code = requestAuthorizationCode(confidentialClientId,
+ userAuthHeader);
+ JsonNode node = requestTokenWithAuthorizationCodeAndHeader(
+ confidentialClientId, code, clientAuthHeader);
String userAuthToken = node.at("/access_token").asText();
- Response response = requestAuthorizationCode("code", confidentialClientId, "", "search", "", "Bearer " + userAuthToken);
+ Response response = requestAuthorizationCode("code",
+ confidentialClientId, "", "search", "",
+ "Bearer " + userAuthToken);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Scope authorize is not authorized");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Scope authorize is not authorized");
}
@Test
- public void testRequestAuthorizationWithBearerToken() throws KustvaktException {
- Response response = requestTokenWithDoryPassword(superClientId, clientSecret);
+ public void testRequestAuthorizationWithBearerToken ()
+ throws KustvaktException {
+ Response response = requestTokenWithDoryPassword(superClientId,
+ clientSecret);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String userAuthToken = node.at("/access_token").asText();
assertNotNull(userAuthToken);
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
- String code = requestAuthorizationCode(superClientId, "Bearer " + userAuthToken);
+ String code = requestAuthorizationCode(superClientId,
+ "Bearer " + userAuthToken);
assertNotNull(code);
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java
index 2a143cb..fabc267 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AdminControllerTest.java
@@ -40,47 +40,65 @@
@Autowired
private AccessTokenDao accessDao;
- public OAuth2AdminControllerTest() throws KustvaktException {
- adminAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "password");
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
+ public OAuth2AdminControllerTest () throws KustvaktException {
+ adminAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "password");
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
}
- private Response updateClientPrivilege(String username, Form form) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("admin").path("oauth2").path("client").path("privilege").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ private Response updateClientPrivilege (String username, Form form)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("admin")
+ .path("oauth2").path("client").path("privilege").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
return response;
}
- private Response updateClientPrivilegeWithAdminToken(String clientId) throws ProcessingException, KustvaktException {
+ private Response updateClientPrivilegeWithAdminToken (String clientId)
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("client_id", clientId);
form.param("super", Boolean.toString(false));
// adminToken
form.param("token", "secret");
- Response response = target().path(API_VERSION).path("admin").path("oauth2").path("client").path("privilege").request().header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("admin")
+ .path("oauth2").path("client").path("privilege").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
return response;
}
- private void testUpdateClientPriviledgeUnauthorized(Form form) throws ProcessingException, KustvaktException {
+ private void testUpdateClientPriviledgeUnauthorized (Form form)
+ throws ProcessingException, KustvaktException {
Response response = updateClientPrivilege(username, form);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
@Order(1)
- public void testCleanExpiredTokensUsingAdminToken() throws KustvaktException {
+ public void testCleanExpiredTokensUsingAdminToken ()
+ throws KustvaktException {
createExpiredAccessToken();
-
- int refreshTokensBefore =
- refreshDao.retrieveInvalidRefreshTokens().size();
+
+ int refreshTokensBefore = refreshDao.retrieveInvalidRefreshTokens()
+ .size();
assertTrue(refreshTokensBefore > 0);
int accessTokensBefore = accessDao.retrieveInvalidAccessTokens().size();
assertTrue(accessTokensBefore > 0);
Form form = new Form();
form.param("token", "secret");
- target().path(API_VERSION).path("admin").path("oauth2").path("token").path("clean").request().post(Entity.form(form));
+ target().path(API_VERSION).path("admin").path("oauth2").path("token")
+ .path("clean").request().post(Entity.form(form));
assertEquals(0, refreshDao.retrieveInvalidRefreshTokens().size());
assertEquals(0, accessDao.retrieveInvalidAccessTokens().size());
}
@@ -91,28 +109,33 @@
int accessTokensBefore = accessDao.retrieveInvalidAccessTokens().size();
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(publicClientId, clientSecret, code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ publicClientId, clientSecret, code);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String accessToken = node.at("/access_token").asText();
testRevokeToken(accessToken, publicClientId, null, ACCESS_TOKEN_TYPE);
int accessTokensAfter = accessDao.retrieveInvalidAccessTokens().size();
assertEquals(accessTokensAfter, accessTokensBefore + 1);
- target().path(API_VERSION).path("admin").path("oauth2").path("token").path("clean").request().header(Attributes.AUTHORIZATION, adminAuthHeader).post(null);
+ target().path(API_VERSION).path("admin").path("oauth2").path("token")
+ .path("clean").request()
+ .header(Attributes.AUTHORIZATION, adminAuthHeader).post(null);
assertEquals(0, accessDao.retrieveInvalidAccessTokens().size());
}
@Test
- public void testUpdateClientPrivilege() throws KustvaktException {
+ public void testUpdateClientPrivilege () throws KustvaktException {
// register a client
Response response = registerConfidentialClient(username);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String clientId = node.at("/client_id").asText();
String clientSecret = node.at("/client_secret").asText();
// request an access token
- String clientAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(clientId, clientSecret);
+ String clientAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(clientId, clientSecret);
String code = requestAuthorizationCode(clientId, userAuthHeader);
- node = requestTokenWithAuthorizationCodeAndHeader(clientId, code, clientAuthHeader);
+ node = requestTokenWithAuthorizationCodeAndHeader(clientId, code,
+ clientAuthHeader);
String accessToken = node.at("/access_token").asText();
// update client priviledge to super client
Form form = new Form();
@@ -129,29 +152,37 @@
}
// old access tokens retain their scopes
- private void testAccessTokenAfterUpgradingClient(String clientId, String accessToken) throws KustvaktException {
+ private void testAccessTokenAfterUpgradingClient (String clientId,
+ String accessToken) throws KustvaktException {
JsonNode node = retrieveClientInfo(clientId, "admin");
assertTrue(node.at("/super").asBoolean());
// list vc
- Response response = target().path(API_VERSION).path("vc").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).get();
+ Response response = target().path(API_VERSION).path("vc").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Scope vc_info is not authorized");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Scope vc_info is not authorized");
// search
response = searchWithAccessToken(accessToken);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
- private void testAccessTokenAfterDegradingSuperClient(String clientId, String accessToken) throws KustvaktException {
+ private void testAccessTokenAfterDegradingSuperClient (String clientId,
+ String accessToken) throws KustvaktException {
JsonNode node = retrieveClientInfo(clientId, username);
assertTrue(node.at("/isSuper").isMissingNode());
Response response = searchWithAccessToken(accessToken);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ACCESS_TOKEN, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Access token is invalid");
+ assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Access token is invalid");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java
index a2e7090..8372acc 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationPostTest.java
@@ -28,31 +28,41 @@
public String userAuthHeader;
- public OAuth2AuthorizationPostTest() throws KustvaktException {
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
+ public OAuth2AuthorizationPostTest () throws KustvaktException {
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
}
- private Response requestAuthorizationCode(Form form, String authHeader) throws KustvaktException {
- return target().path(API_VERSION).path("oauth2").path("authorize").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ private Response requestAuthorizationCode (Form form, String authHeader)
+ throws KustvaktException {
+ return target().path(API_VERSION).path("oauth2").path("authorize")
+ .request().header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
}
@Test
- public void testAuthorizeConfidentialClient() throws KustvaktException {
+ public void testAuthorizeConfidentialClient () throws KustvaktException {
Form form = new Form();
form.param("response_type", "code");
form.param("client_id", confidentialClientId);
form.param("state", "thisIsMyState");
form.param("scope", "search");
Response response = requestAuthorizationCode(form, userAuthHeader);
- assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(), response.getStatus());
+ assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
+ response.getStatus());
URI redirectUri = response.getLocation();
- MultiValueMap<String, String> params = UriComponentsBuilder.fromUri(redirectUri).build().getQueryParams();
+ MultiValueMap<String, String> params = UriComponentsBuilder
+ .fromUri(redirectUri).build().getQueryParams();
assertNotNull(params.getFirst("code"));
assertEquals(params.getFirst("state"), "thisIsMyState");
}
@Test
- public void testRequestTokenAuthorizationConfidential() throws KustvaktException {
+ public void testRequestTokenAuthorizationConfidential ()
+ throws KustvaktException {
Form authForm = new Form();
authForm.param("response_type", "code");
authForm.param("client_id", confidentialClientId);
@@ -60,11 +70,10 @@
Response response = requestAuthorizationCode(authForm, userAuthHeader);
URI redirectUri = response.getLocation();
- MultivaluedMap<String, String> params =
- UriComponent.decodeQuery(redirectUri, true);
+ MultivaluedMap<String, String> params = UriComponent
+ .decodeQuery(redirectUri, true);
String code = params.get("code").get(0);
-
response = requestTokenWithAuthorizationCodeAndForm(
confidentialClientId, clientSecret, code);
String entity = response.readEntity(String.class);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationTest.java
index a91b119..27903e7 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2AuthorizationTest.java
@@ -19,14 +19,14 @@
import jakarta.ws.rs.core.Response.Status;
public class OAuth2AuthorizationTest extends OAuth2TestBase {
-
+
private String userAuthHeader;
public OAuth2AuthorizationTest () throws KustvaktException {
userAuthHeader = HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("dory", "password");
}
-
+
@Test
public void testAuthorizeUnauthenticated () throws KustvaktException {
@@ -40,18 +40,19 @@
assertEquals("Unauthorized operation for user: guest",
node.at("/errors/0/1").asText());
}
+
@Test
public void testAuthorizeConfidentialClient () throws KustvaktException {
// with registered redirect URI
- Response response =
- requestAuthorizationCode("code", confidentialClientId, "",
- "match_info search client_info", state, userAuthHeader);
+ Response response = requestAuthorizationCode("code",
+ confidentialClientId, "", "match_info search client_info",
+ state, userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
URI redirectUri = response.getLocation();
- MultivaluedMap<String, String> params =
- getQueryParamsFromURI(redirectUri);
+ MultivaluedMap<String, String> params = getQueryParamsFromURI(
+ redirectUri);
assertNotNull(params.getFirst("code"));
assertEquals(state, params.getFirst("state"));
}
@@ -65,10 +66,9 @@
@Test
public void testAuthorizeWithRedirectUri () throws KustvaktException {
- Response response =
- requestAuthorizationCode("code", publicClientId2,
- "https://public.com/redirect", "search match_info",
- "", userAuthHeader);
+ Response response = requestAuthorizationCode("code", publicClientId2,
+ "https://public.com/redirect", "search match_info", "",
+ userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -93,8 +93,7 @@
assertEquals(redirectUri.getPath(), "/confidential/redirect");
String[] queryParts = redirectUri.getQuery().split("&");
- assertEquals("error_description=scope+is+required",
- queryParts[1]);
+ assertEquals("error_description=scope+is+required", queryParts[1]);
assertEquals("error=invalid_scope", queryParts[0]);
}
@@ -111,44 +110,43 @@
@Test
public void testAuthorizeMissingRedirectUri () throws KustvaktException {
- Response response = requestAuthorizationCode("code",
- publicClientId2, "", "search", state, userAuthHeader);
+ Response response = requestAuthorizationCode("code", publicClientId2,
+ "", "search", state, userAuthHeader);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Missing parameter: redirect URI",
node.at("/error_description").asText());
assertEquals(state, node.at("/state").asText());
}
@Test
- public void testAuthorizeMissingResponseType() throws KustvaktException {
- Response response = requestAuthorizationCode("",
- confidentialClientId, "", "search", "", userAuthHeader);
+ public void testAuthorizeMissingResponseType () throws KustvaktException {
+ Response response = requestAuthorizationCode("", confidentialClientId,
+ "", "search", "", userAuthHeader);
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
- assertEquals("https://third.party.com/confidential/redirect?"
- + "error=invalid_request_uri&"
- + "error_description=Missing+response_type+parameter"
- , response.getLocation().toString());
+ assertEquals(
+ "https://third.party.com/confidential/redirect?"
+ + "error=invalid_request_uri&"
+ + "error_description=Missing+response_type+parameter",
+ response.getLocation().toString());
}
-
+
@Test
- public void testAuthorizeMissingResponseTypeWithoutClientId () throws KustvaktException {
- Response response = requestAuthorizationCode("",
- "", "", "search", "", userAuthHeader);
-
- assertEquals(Status.BAD_REQUEST.getStatusCode(),
- response.getStatus());
+ public void testAuthorizeMissingResponseTypeWithoutClientId ()
+ throws KustvaktException {
+ Response response = requestAuthorizationCode("", "", "", "search", "",
+ userAuthHeader);
+
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
-
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Missing parameter: client_id",
node.at("/error_description").asText());
}
@@ -170,9 +168,9 @@
String redirectUri = "https://different.uri/redirect";
Response response = requestAuthorizationCode("code",
confidentialClientId, redirectUri, "", state, userAuthHeader);
-
- testInvalidRedirectUri(response.readEntity(String.class),
- response.getHeaderString("Content-Type"),true,
+
+ testInvalidRedirectUri(response.readEntity(String.class),
+ response.getHeaderString("Content-Type"), true,
response.getStatus());
}
@@ -185,8 +183,8 @@
response.getStatus());
URI redirectUri = response.getLocation();
- MultivaluedMap<String, String> params =
- getQueryParamsFromURI(redirectUri);
+ MultivaluedMap<String, String> params = getQueryParamsFromURI(
+ redirectUri);
assertNotNull(params.getFirst("code"));
assertEquals(state, params.getFirst("state"));
}
@@ -194,11 +192,11 @@
@Test
public void testAuthorizeWithRedirectUriFragment ()
throws KustvaktException {
- Response response = requestAuthorizationCode("code",
- publicClientId2, "http://public.com/index.html#redirect", "search",
- state, userAuthHeader);
- testInvalidRedirectUri(response.readEntity(String.class),
- response.getHeaderString("Content-Type"),true,
+ Response response = requestAuthorizationCode("code", publicClientId2,
+ "http://public.com/index.html#redirect", "search", state,
+ userAuthHeader);
+ testInvalidRedirectUri(response.readEntity(String.class),
+ response.getHeaderString("Content-Type"), true,
response.getStatus());
}
@@ -206,10 +204,10 @@
public void testAuthorizeInvalidRedirectUri () throws KustvaktException {
// host not allowed by Apache URI Validator
String redirectUri = "https://public.uri/redirect";
- Response response = requestAuthorizationCode("code",
- publicClientId2, redirectUri, "", state, userAuthHeader);
- testInvalidRedirectUri(response.readEntity(String.class),
- response.getHeaderString("Content-Type"),true,
+ Response response = requestAuthorizationCode("code", publicClientId2,
+ redirectUri, "", state, userAuthHeader);
+ testInvalidRedirectUri(response.readEntity(String.class),
+ response.getHeaderString("Content-Type"), true,
response.getStatus());
}
@@ -224,8 +222,7 @@
assertEquals("https://third.party.com/confidential/redirect?"
+ "error=unsupported_response_type"
+ "&error_description=Unsupported+response+type.+Only+code+is+supported."
- + "&state=thisIsMyState" ,
- response.getLocation().toString());
+ + "&state=thisIsMyState", response.getLocation().toString());
// with redirect URI, and no registered redirect URI
response = requestAuthorizationCode("string", publicClientId2,
@@ -237,8 +234,7 @@
assertEquals("https://public.client.com/redirect?"
+ "error=unsupported_response_type"
+ "&error_description=Unsupported+response+type.+Only+code+is+supported."
- + "&state=thisIsMyState",
- response.getLocation().toString());
+ + "&state=thisIsMyState", response.getLocation().toString());
// with different redirect URI
String redirectUri = "https://different.uri/redirect";
@@ -247,8 +243,7 @@
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Invalid redirect URI",
node.at("/error_description").asText());
assertEquals(state, node.at("/state").asText());
@@ -260,8 +255,7 @@
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals("Missing parameter: redirect URI",
node.at("/error_description").asText());
assertEquals(state, node.at("/state").asText());
@@ -277,8 +271,8 @@
assertEquals(
"https://third.party.com/confidential/redirect?"
- + "error=invalid_scope&error_description=Invalid+"
- +"scope&state=thisIsMyState",
+ + "error=invalid_scope&error_description=Invalid+"
+ + "scope&state=thisIsMyState",
response.getLocation().toString());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
index 25127d5..5f24cd6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ClientControllerTest.java
@@ -43,11 +43,13 @@
private String userAuthHeader;
- public OAuth2ClientControllerTest() throws KustvaktException {
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
+ public OAuth2ClientControllerTest () throws KustvaktException {
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
}
- private OAuth2ClientJson createOAuth2ClientJson(String name, OAuth2ClientType type, String description) {
+ private OAuth2ClientJson createOAuth2ClientJson (String name,
+ OAuth2ClientType type, String description) {
OAuth2ClientJson client = new OAuth2ClientJson();
if (name != null) {
client.setName(name);
@@ -60,19 +62,22 @@
}
@Test
- public void testRetrieveClientInfo() throws KustvaktException {
+ public void testRetrieveClientInfo () throws KustvaktException {
// public client
JsonNode clientInfo = retrieveClientInfo(publicClientId, "system");
assertEquals(publicClientId, clientInfo.at("/client_id").asText());
- assertEquals(clientInfo.at("/client_name").asText(), "public client plugin with redirect uri");
+ assertEquals(clientInfo.at("/client_name").asText(),
+ "public client plugin with redirect uri");
assertNotNull(clientInfo.at("/client_description"));
assertNotNull(clientInfo.at("/client_url"));
assertEquals(clientInfo.at("/client_type").asText(), "PUBLIC");
assertEquals(clientInfo.at("/registered_by").asText(), "system");
// confidential client
clientInfo = retrieveClientInfo(confidentialClientId, "system");
- assertEquals(confidentialClientId, clientInfo.at("/client_id").asText());
- assertEquals(clientInfo.at("/client_name").asText(), "non super confidential client");
+ assertEquals(confidentialClientId,
+ clientInfo.at("/client_id").asText());
+ assertEquals(clientInfo.at("/client_name").asText(),
+ "non super confidential client");
assertNotNull(clientInfo.at("/client_url"));
assertNotNull(clientInfo.at("/redirect_uri"));
assertEquals(false, clientInfo.at("/super").asBoolean());
@@ -80,7 +85,8 @@
// super client
clientInfo = retrieveClientInfo(superClientId, "system");
assertEquals(superClientId, clientInfo.at("/client_id").asText());
- assertEquals(clientInfo.at("/client_name").asText(), "super confidential client");
+ assertEquals(clientInfo.at("/client_name").asText(),
+ "super confidential client");
assertNotNull(clientInfo.at("/client_url"));
assertNotNull(clientInfo.at("/redirect_uri"));
assertEquals(clientInfo.at("/client_type").asText(), "CONFIDENTIAL");
@@ -88,7 +94,7 @@
}
@Test
- public void testRegisterConfidentialClient() throws KustvaktException {
+ public void testRegisterConfidentialClient () throws KustvaktException {
Response response = registerConfidentialClient(username);
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -105,68 +111,88 @@
}
@Test
- public void testRegisterClientNameTooShort() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson("R", OAuth2ClientType.PUBLIC, null);
+ public void testRegisterClientNameTooShort ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson("R",
+ OAuth2ClientType.PUBLIC, null);
Response response = registerClient(username, clientJson);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "client_name must contain at least 3 characters");
+ assertEquals(node.at("/error_description").asText(),
+ "client_name must contain at least 3 characters");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testRegisterClientEmptyName() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson("", OAuth2ClientType.PUBLIC, null);
+ public void testRegisterClientEmptyName ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson("",
+ OAuth2ClientType.PUBLIC, null);
Response response = registerClient(username, clientJson);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "client_name must contain at least 3 characters");
+ assertEquals(node.at("/error_description").asText(),
+ "client_name must contain at least 3 characters");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testRegisterClientMissingName() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson(null, OAuth2ClientType.PUBLIC, null);
+ public void testRegisterClientMissingName ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(null,
+ OAuth2ClientType.PUBLIC, null);
Response response = registerClient(username, clientJson);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "client_name is null");
+ assertEquals(node.at("/error_description").asText(),
+ "client_name is null");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testRegisterClientMissingDescription() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson("R client", OAuth2ClientType.PUBLIC, null);
+ public void testRegisterClientMissingDescription ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson("R client",
+ OAuth2ClientType.PUBLIC, null);
Response response = registerClient(username, clientJson);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "client_description is null");
+ assertEquals(node.at("/error_description").asText(),
+ "client_description is null");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testRegisterClientMissingType() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson("R client", null, null);
+ public void testRegisterClientMissingType ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson("R client", null,
+ null);
Response response = registerClient(username, clientJson);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "client_type is null");
+ assertEquals(node.at("/error_description").asText(),
+ "client_type is null");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testRegisterClientInvalidRedirectURI() throws ProcessingException, KustvaktException {
+ public void testRegisterClientInvalidRedirectURI ()
+ throws ProcessingException, KustvaktException {
// invalid hostname
String redirectUri = "https://test.public.client/redirect";
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2PublicClient", OAuth2ClientType.PUBLIC, "A public test client.");
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2PublicClient", OAuth2ClientType.PUBLIC,
+ "A public test client.");
clientJson.setRedirectURI(redirectUri);
Response response = registerClient(username, clientJson);
- testInvalidRedirectUri(response.readEntity(String.class), response.getHeaderString("Content-Type"), false, response.getStatus());
+ testInvalidRedirectUri(response.readEntity(String.class),
+ response.getHeaderString("Content-Type"), false,
+ response.getStatus());
// localhost is not allowed
// redirectUri = "http://localhost:1410";
// clientJson.setRedirectURI(redirectUri);
@@ -177,12 +203,17 @@
redirectUri = "https://public.client.com/redirect.html#bar";
clientJson.setRedirectURI(redirectUri);
response = registerClient(username, clientJson);
- testInvalidRedirectUri(response.readEntity(String.class), response.getHeaderString("Content-Type"), false, response.getStatus());
+ testInvalidRedirectUri(response.readEntity(String.class),
+ response.getHeaderString("Content-Type"), false,
+ response.getStatus());
}
@Test
- public void testRegisterPublicClientWithRefreshTokenExpiry() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2PublicClient", OAuth2ClientType.PUBLIC, "A public test client.");
+ public void testRegisterPublicClientWithRefreshTokenExpiry ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2PublicClient", OAuth2ClientType.PUBLIC,
+ "A public test client.");
clientJson.setRefreshTokenExpiry(31535000);
Response response = registerClient(username, clientJson);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
@@ -191,9 +222,12 @@
}
@Test
- public void testRegisterConfidentialClientWithRefreshTokenExpiry() throws ProcessingException, KustvaktException {
+ public void testRegisterConfidentialClientWithRefreshTokenExpiry ()
+ throws ProcessingException, KustvaktException {
int expiry = 31535000;
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2 Confidential Client", OAuth2ClientType.CONFIDENTIAL, "A confidential client.");
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2 Confidential Client", OAuth2ClientType.CONFIDENTIAL,
+ "A confidential client.");
clientJson.setRefreshTokenExpiry(expiry);
Response response = registerClient(username, clientJson);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
@@ -204,21 +238,28 @@
}
@Test
- public void testRegisterConfidentialClientWithInvalidRefreshTokenExpiry() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2 Confidential Client", OAuth2ClientType.CONFIDENTIAL, "A confidential client.");
+ public void testRegisterConfidentialClientWithInvalidRefreshTokenExpiry ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2 Confidential Client", OAuth2ClientType.CONFIDENTIAL,
+ "A confidential client.");
clientJson.setRefreshTokenExpiry(31537000);
Response response = registerClient(username, clientJson);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(node.at("/error_description").asText(), "Maximum refresh token expiry is 31536000 seconds (1 year)");
+ assertEquals(node.at("/error_description").asText(),
+ "Maximum refresh token expiry is 31536000 seconds (1 year)");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testRegisterClientInvalidURL() throws ProcessingException, KustvaktException {
+ public void testRegisterClientInvalidURL ()
+ throws ProcessingException, KustvaktException {
// invalid hostname
String url = "https://test.public.client";
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2PublicClient", OAuth2ClientType.PUBLIC, "A public test client.");
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2PublicClient", OAuth2ClientType.PUBLIC,
+ "A public test client.");
clientJson.setUrl(url);
Response response = registerClient(username, clientJson);
testInvalidUrl(response.readEntity(String.class), response.getStatus());
@@ -229,7 +270,8 @@
testInvalidUrl(response.readEntity(String.class), response.getStatus());
}
- private void testInvalidUrl(String entity, int status) throws KustvaktException {
+ private void testInvalidUrl (String entity, int status)
+ throws KustvaktException {
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertEquals(node.at("/error_description").asText(), "Invalid URL");
@@ -237,9 +279,12 @@
}
@Test
- public void testRegisterPublicClient() throws ProcessingException, KustvaktException {
+ public void testRegisterPublicClient ()
+ throws ProcessingException, KustvaktException {
String redirectUri = "https://public.client.com/redirect";
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2PublicClient", OAuth2ClientType.PUBLIC, "A public test client.");
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2PublicClient", OAuth2ClientType.PUBLIC,
+ "A public test client.");
// http and fragment are allowed
clientJson.setUrl("http://public.client.com/index.html#bar");
clientJson.setRedirectURI(redirectUri);
@@ -255,27 +300,46 @@
testAccessTokenAfterDeregistration(clientId, null, "");
}
- private void testRegisterClientUnauthorizedScope(String clientId) throws ProcessingException, KustvaktException {
- String userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
+ private void testRegisterClientUnauthorizedScope (String clientId)
+ throws ProcessingException, KustvaktException {
+ String userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
String code = requestAuthorizationCode(clientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(clientId, clientSecret, code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(clientId,
+ clientSecret, code);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(node.at("/scope").asText(), "match_info search");
String accessToken = node.at("/access_token").asText();
- OAuth2ClientJson clientJson = createOAuth2ClientJson("R client", OAuth2ClientType.PUBLIC, null);
- response = target().path(API_VERSION).path("oauth2").path("client").path("register").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).post(Entity.json(clientJson));
+ OAuth2ClientJson clientJson = createOAuth2ClientJson("R client",
+ OAuth2ClientType.PUBLIC, null);
+ response = target().path(API_VERSION).path("oauth2").path("client")
+ .path("register").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .post(Entity.json(clientJson));
String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Scope register_client is not authorized");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Scope register_client is not authorized");
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
@Test
- public void testRegisterClientUsingPlainJson() throws ProcessingException, KustvaktException, IOException {
- InputStream is = getClass().getClassLoader().getResourceAsStream("json/oauth2_public_client.json");
+ public void testRegisterClientUsingPlainJson ()
+ throws ProcessingException, KustvaktException, IOException {
+ InputStream is = getClass().getClassLoader()
+ .getResourceAsStream("json/oauth2_public_client.json");
String json = IOUtils.toString(is, Charset.defaultCharset());
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("register").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "password")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).post(Entity.json(json));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("register").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username,
+ "password"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .post(Entity.json(json));
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -287,8 +351,11 @@
}
@Test
- public void testRegisterDesktopApp() throws ProcessingException, KustvaktException {
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2DesktopClient", OAuth2ClientType.PUBLIC, "This is a desktop test client.");
+ public void testRegisterDesktopApp ()
+ throws ProcessingException, KustvaktException {
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2DesktopClient", OAuth2ClientType.PUBLIC,
+ "This is a desktop test client.");
Response response = registerClient(username, clientJson);
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -302,9 +369,12 @@
}
@Test
- public void testRegisterMultipleDesktopApps() throws ProcessingException, KustvaktException {
+ public void testRegisterMultipleDesktopApps ()
+ throws ProcessingException, KustvaktException {
// First client
- OAuth2ClientJson clientJson = createOAuth2ClientJson("OAuth2DesktopClient1", OAuth2ClientType.PUBLIC, "A desktop test client.");
+ OAuth2ClientJson clientJson = createOAuth2ClientJson(
+ "OAuth2DesktopClient1", OAuth2ClientType.PUBLIC,
+ "A desktop test client.");
Response response = registerClient(username, clientJson);
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -313,7 +383,8 @@
assertNotNull(clientId1);
assertTrue(node.at("/client_secret").isMissingNode());
// Second client
- clientJson = createOAuth2ClientJson("OAuth2DesktopClient2", OAuth2ClientType.PUBLIC, "Another desktop test client.");
+ clientJson = createOAuth2ClientJson("OAuth2DesktopClient2",
+ OAuth2ClientType.PUBLIC, "Another desktop test client.");
response = registerClient(username, clientJson);
entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -322,66 +393,106 @@
assertNotNull(clientId2);
assertTrue(node.at("/client_secret").isMissingNode());
testResetPublicClientSecret(clientId1);
- testAccessTokenAfterDeregistration(clientId1, null, "https://OAuth2DesktopClient1.com");
+ testAccessTokenAfterDeregistration(clientId1, null,
+ "https://OAuth2DesktopClient1.com");
testResetPublicClientSecret(clientId2);
- testAccessTokenAfterDeregistration(clientId2, null, "https://OAuth2DesktopClient2.com");
+ testAccessTokenAfterDeregistration(clientId2, null,
+ "https://OAuth2DesktopClient2.com");
}
- private void testAccessTokenAfterDeregistration(String clientId, String clientSecret, String redirectUri) throws KustvaktException {
- String userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
- String code = requestAuthorizationCode(clientId, redirectUri, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(clientId, clientSecret, code, redirectUri);
+ private void testAccessTokenAfterDeregistration (String clientId,
+ String clientSecret, String redirectUri) throws KustvaktException {
+ String userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
+ String code = requestAuthorizationCode(clientId, redirectUri,
+ userAuthHeader);
+ Response response = requestTokenWithAuthorizationCodeAndForm(clientId,
+ clientSecret, code, redirectUri);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
response = searchWithAccessToken(accessToken);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
code = requestAuthorizationCode(clientId, redirectUri, userAuthHeader);
testDeregisterPublicClient(clientId, username);
- response = requestTokenWithAuthorizationCodeAndForm(clientId, clientSecret, code, redirectUri);
+ response = requestTokenWithAuthorizationCodeAndForm(clientId,
+ clientSecret, code, redirectUri);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(OAuth2Error.INVALID_CLIENT.toString(), node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_CLIENT.toString(),
+ node.at("/error").asText());
response = searchWithAccessToken(accessToken);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.INVALID_ACCESS_TOKEN, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Access token is invalid");
+ assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Access token is invalid");
}
- private void testDeregisterPublicClientMissingUserAuthentication(String clientId) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("deregister").path(clientId).request().delete();
+ private void testDeregisterPublicClientMissingUserAuthentication (
+ String clientId) throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("deregister").path(clientId).request()
+ .delete();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
- private void testDeregisterPublicClientMissingId() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("deregister").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
- assertEquals(Status.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatus());
+ private void testDeregisterPublicClientMissingId ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("deregister").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
+ assertEquals(Status.METHOD_NOT_ALLOWED.getStatusCode(),
+ response.getStatus());
}
- private void testDeregisterPublicClient(String clientId, String username) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("deregister").path(clientId).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
+ private void testDeregisterPublicClient (String clientId, String username)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("deregister").path(clientId).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
- private void testResetPublicClientSecret(String clientId) throws ProcessingException, KustvaktException {
+ private void testResetPublicClientSecret (String clientId)
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("client_id", clientId);
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("reset").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("reset").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
- assertEquals(node.at("/error_description").asText(), "Operation is not allowed for public clients");
+ assertEquals(node.at("/error_description").asText(),
+ "Operation is not allowed for public clients");
}
- private String testResetConfidentialClientSecret(String clientId, String clientSecret) throws ProcessingException, KustvaktException {
+ private String testResetConfidentialClientSecret (String clientId,
+ String clientSecret) throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("client_id", clientId);
form.param("client_secret", clientSecret);
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("reset").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("reset").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -391,10 +502,16 @@
return newClientSecret;
}
- private void requestAuthorizedClientList(String userAuthHeader) throws KustvaktException {
+ private void requestAuthorizedClientList (String userAuthHeader)
+ throws KustvaktException {
Form form = getSuperClientForm();
form.param("authorized_only", "true");
- Response response = target().path(API_VERSION).path("oauth2").path("client").path("list").request().header(Attributes.AUTHORIZATION, userAuthHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("client").path("list").request()
+ .header(Attributes.AUTHORIZATION, userAuthHeader)
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
// System.out.println(entity);
@@ -402,21 +519,24 @@
assertEquals(2, node.size());
assertEquals(confidentialClientId, node.at("/0/client_id").asText());
assertEquals(publicClientId, node.at("/1/client_id").asText());
- assertEquals(node.at("/0/client_name").asText(), "non super confidential client");
+ assertEquals(node.at("/0/client_name").asText(),
+ "non super confidential client");
assertEquals(node.at("/0/client_type").asText(), "CONFIDENTIAL");
assertFalse(node.at("/0/client_url").isMissingNode());
assertFalse(node.at("/0/client_description").isMissingNode());
}
@Test
- public void testListPublicClient() throws KustvaktException {
+ public void testListPublicClient () throws KustvaktException {
String clientName = "OAuth2DoryClient";
- OAuth2ClientJson json = createOAuth2ClientJson(clientName, OAuth2ClientType.PUBLIC, "Dory's client.");
+ OAuth2ClientJson json = createOAuth2ClientJson(clientName,
+ OAuth2ClientType.PUBLIC, "Dory's client.");
registerClient("dory", json);
JsonNode node = listUserRegisteredClients("dory");
assertEquals(1, node.size());
assertEquals(clientName, node.at("/0/client_name").asText());
- assertEquals(OAuth2ClientType.PUBLIC.name(), node.at("/0/client_type").asText());
+ assertEquals(OAuth2ClientType.PUBLIC.name(),
+ node.at("/0/client_type").asText());
assertTrue(node.at("/0/permitted").asBoolean());
assertFalse(node.at("/0/registration_date").isMissingNode());
assertTrue(node.at("/refresh_token_expiry").isMissingNode());
@@ -424,38 +544,46 @@
testDeregisterPublicClient(clientId, "dory");
}
- private void testListConfidentialClient(String username, String clientId) throws ProcessingException, KustvaktException {
+ private void testListConfidentialClient (String username, String clientId)
+ throws ProcessingException, KustvaktException {
JsonNode node = listUserRegisteredClients(username);
assertEquals(1, node.size());
assertEquals(clientId, node.at("/0/client_id").asText());
assertEquals(node.at("/0/client_name").asText(), "OAuth2ClientTest");
- assertEquals(OAuth2ClientType.CONFIDENTIAL.name(), node.at("/0/client_type").asText());
+ assertEquals(OAuth2ClientType.CONFIDENTIAL.name(),
+ node.at("/0/client_type").asText());
assertNotNull(node.at("/0/client_description"));
assertEquals(clientURL, node.at("/0/client_url").asText());
- assertEquals(clientRedirectUri, node.at("/0/client_redirect_uri").asText());
+ assertEquals(clientRedirectUri,
+ node.at("/0/client_redirect_uri").asText());
assertNotNull(node.at("/0/registration_date"));
- assertEquals(defaultRefreshTokenExpiry, node.at("/0/refresh_token_expiry").asInt());
+ assertEquals(defaultRefreshTokenExpiry,
+ node.at("/0/refresh_token_expiry").asInt());
assertTrue(node.at("/0/permitted").asBoolean());
assertTrue(node.at("/0/source").isMissingNode());
}
@Test
- public void testListUserClients() throws KustvaktException {
+ public void testListUserClients () throws KustvaktException {
String username = "pearl";
String password = "pwd";
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, password);
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, password);
// super client
- Response response = requestTokenWithPassword(superClientId, clientSecret, username, password);
+ Response response = requestTokenWithPassword(superClientId,
+ clientSecret, username, password);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// client 1
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "", code);
+ response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "",
+ code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
// client 2
code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
String refreshToken = node.at("/refresh_token").asText();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
requestAuthorizedClientList(userAuthHeader);
@@ -463,64 +591,88 @@
testListAuthorizedClientWithMultipleAccessTokens(userAuthHeader);
testListWithClientsFromAnotherUser(userAuthHeader);
// revoke client 1
- testRevokeAllTokenViaSuperClient(publicClientId, userAuthHeader, accessToken);
+ testRevokeAllTokenViaSuperClient(publicClientId, userAuthHeader,
+ accessToken);
// revoke client 2
node = JsonUtils.readTree(response.readEntity(String.class));
accessToken = node.at("/access_token").asText();
refreshToken = node.at("/refresh_token").asText();
- testRevokeAllTokenViaSuperClient(confidentialClientId, userAuthHeader, accessToken);
- testRequestTokenWithRevokedRefreshToken(confidentialClientId, clientSecret, refreshToken);
+ testRevokeAllTokenViaSuperClient(confidentialClientId, userAuthHeader,
+ accessToken);
+ testRequestTokenWithRevokedRefreshToken(confidentialClientId,
+ clientSecret, refreshToken);
}
- private void testListAuthorizedClientWithMultipleRefreshTokens(String userAuthHeader) throws KustvaktException {
+ private void testListAuthorizedClientWithMultipleRefreshTokens (
+ String userAuthHeader) throws KustvaktException {
// client 2
- String code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ String code = requestAuthorizationCode(confidentialClientId,
+ userAuthHeader);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
requestAuthorizedClientList(userAuthHeader);
}
- private void testListAuthorizedClientWithMultipleAccessTokens(String userAuthHeader) throws KustvaktException {
+ private void testListAuthorizedClientWithMultipleAccessTokens (
+ String userAuthHeader) throws KustvaktException {
// client 1
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "", code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ publicClientId, "", code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
requestAuthorizedClientList(userAuthHeader);
}
- private void testListWithClientsFromAnotherUser(String userAuthHeader) throws KustvaktException {
- String aaaAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("aaa", "pwd");
+ private void testListWithClientsFromAnotherUser (String userAuthHeader)
+ throws KustvaktException {
+ String aaaAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("aaa", "pwd");
// client 1
String code = requestAuthorizationCode(publicClientId, aaaAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "", code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ publicClientId, "", code);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken1 = node.at("/access_token").asText();
// client 2
code = requestAuthorizationCode(confidentialClientId, aaaAuthHeader);
- response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken2 = node.at("/access_token").asText();
String refreshToken = node.at("/refresh_token").asText();
requestAuthorizedClientList(aaaAuthHeader);
requestAuthorizedClientList(userAuthHeader);
- testRevokeAllTokenViaSuperClient(publicClientId, aaaAuthHeader, accessToken1);
- testRevokeAllTokenViaSuperClient(confidentialClientId, aaaAuthHeader, accessToken2);
- testRequestTokenWithRevokedRefreshToken(confidentialClientId, clientSecret, refreshToken);
+ testRevokeAllTokenViaSuperClient(publicClientId, aaaAuthHeader,
+ accessToken1);
+ testRevokeAllTokenViaSuperClient(confidentialClientId, aaaAuthHeader,
+ accessToken2);
+ testRequestTokenWithRevokedRefreshToken(confidentialClientId,
+ clientSecret, refreshToken);
}
- private void testRevokeAllTokenViaSuperClient(String clientId, String userAuthHeader, String accessToken) throws KustvaktException {
+ private void testRevokeAllTokenViaSuperClient (String clientId,
+ String userAuthHeader, String accessToken)
+ throws KustvaktException {
// check token before revoking
Response response = searchWithAccessToken(accessToken);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertTrue(node.at("/matches").size() > 0);
Form form = getSuperClientForm();
form.param("client_id", clientId);
- response = target().path(API_VERSION).path("oauth2").path("revoke").path("super").path("all").request().header(Attributes.AUTHORIZATION, userAuthHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ response = target().path(API_VERSION).path("oauth2").path("revoke")
+ .path("super").path("all").request()
+ .header(Attributes.AUTHORIZATION, userAuthHeader)
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertEquals(response.readEntity(String.class), "SUCCESS");
response = searchWithAccessToken(accessToken);
node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.INVALID_ACCESS_TOKEN, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Access token is invalid");
+ assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Access token is invalid");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
index af00355..ab2eb27 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2ControllerTest.java
@@ -40,29 +40,35 @@
public String userAuthHeader;
- public OAuth2ControllerTest() throws KustvaktException {
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "password");
+ public OAuth2ControllerTest () throws KustvaktException {
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "password");
}
@Test
public void testRequestTokenAuthorizationPublic ()
throws KustvaktException {
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(publicClientId, clientSecret, code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ publicClientId, clientSecret, code);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String accessToken = node.at("/access_token").asText();
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertEquals(31536000, node.at("/expires_in").asInt());
testRevokeToken(accessToken, publicClientId, null, ACCESS_TOKEN_TYPE);
assertTrue(node.at("/refresh_token").isMissingNode());
}
@Test
- public void testRequestTokenAuthorizationConfidential() throws KustvaktException {
+ public void testRequestTokenAuthorizationConfidential ()
+ throws KustvaktException {
String scope = "search";
- Response response = requestAuthorizationCode("code", confidentialClientId, "", scope, state, userAuthHeader);
- MultivaluedMap<String, String> params = getQueryParamsFromURI(response.getLocation());
+ Response response = requestAuthorizationCode("code",
+ confidentialClientId, "", scope, state, userAuthHeader);
+ MultivaluedMap<String, String> params = getQueryParamsFromURI(
+ response.getLocation());
String code = params.get("code").get(0);
response = requestTokenWithAuthorizationCodeAndForm(
@@ -71,7 +77,8 @@
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
testRequestTokenWithUsedAuthorization(code);
String refreshToken = node.at("/refresh_token").asText();
@@ -79,21 +86,27 @@
testRequestRefreshTokenInvalidScope(confidentialClientId, refreshToken);
testRequestRefreshTokenInvalidClient(refreshToken);
testRequestRefreshTokenInvalidRefreshToken(confidentialClientId);
- testRequestRefreshToken(confidentialClientId, clientSecret, refreshToken);
+ testRequestRefreshToken(confidentialClientId, clientSecret,
+ refreshToken);
}
- private void testRequestTokenWithUsedAuthorization(String code) throws KustvaktException {
- Response response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ private void testRequestTokenWithUsedAuthorization (String code)
+ throws KustvaktException {
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
- assertEquals(node.at("/error_description").asText(), "Invalid authorization");
+ assertEquals(node.at("/error_description").asText(),
+ "Invalid authorization");
}
@Test
- public void testRequestTokenInvalidAuthorizationCode() throws KustvaktException {
- Response response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, "blahblah");
+ public void testRequestTokenInvalidAuthorizationCode ()
+ throws KustvaktException {
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, "blahblah");
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -101,10 +114,13 @@
}
@Test
- public void testRequestTokenAuthorizationReplyAttack() throws KustvaktException {
+ public void testRequestTokenAuthorizationReplyAttack ()
+ throws KustvaktException {
String redirect_uri = "https://third.party.com/confidential/redirect";
String scope = "search";
- Response response = requestAuthorizationCode("code", confidentialClientId, redirect_uri, scope, state, userAuthHeader);
+ Response response = requestAuthorizationCode("code",
+ confidentialClientId, redirect_uri, scope, state,
+ userAuthHeader);
String code = parseAuthorizationCode(response);
testRequestTokenAuthorizationInvalidClient(code);
testRequestTokenAuthorizationMissingRedirectUri(code);
@@ -112,22 +128,28 @@
testRequestTokenAuthorizationRevoked(code, redirect_uri);
}
- private void testRequestTokenAuthorizationInvalidClient(String code) throws KustvaktException {
- Response response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, "wrong_secret", code);
+ private void testRequestTokenAuthorizationInvalidClient (String code)
+ throws KustvaktException {
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, "wrong_secret", code);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_CLIENT, node.at("/error").asText());
}
- private void testRequestTokenAuthorizationMissingRedirectUri(String code) throws KustvaktException {
- Response response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, "secret", code);
+ private void testRequestTokenAuthorizationMissingRedirectUri (String code)
+ throws KustvaktException {
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, "secret", code);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
- assertEquals(node.at("/error_description").asText(), "Missing redirect URI");
+ assertEquals(node.at("/error_description").asText(),
+ "Missing redirect URI");
}
- private void testRequestTokenAuthorizationInvalidRedirectUri(String code) throws KustvaktException {
+ private void testRequestTokenAuthorizationInvalidRedirectUri (String code)
+ throws KustvaktException {
Form tokenForm = new Form();
tokenForm.param("grant_type", "authorization_code");
tokenForm.param("client_id", confidentialClientId);
@@ -140,7 +162,8 @@
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
}
- private void testRequestTokenAuthorizationRevoked(String code, String uri) throws KustvaktException {
+ private void testRequestTokenAuthorizationRevoked (String code, String uri)
+ throws KustvaktException {
Form tokenForm = new Form();
tokenForm.param("grant_type", "authorization_code");
tokenForm.param("client_id", confidentialClientId);
@@ -151,21 +174,26 @@
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
- assertEquals(node.at("/error_description").asText(), "Invalid authorization");
+ assertEquals(node.at("/error_description").asText(),
+ "Invalid authorization");
}
@Test
- public void testRequestTokenPasswordGrantConfidentialSuper() throws KustvaktException {
- Response response = requestTokenWithDoryPassword(superClientId, clientSecret);
+ public void testRequestTokenPasswordGrantConfidentialSuper ()
+ throws KustvaktException {
+ Response response = requestTokenWithDoryPassword(superClientId,
+ clientSecret);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
assertEquals(node.at("/scope").asText(), "all");
String refresh = node.at("/refresh_token").asText();
- RefreshToken refreshToken = refreshTokenDao.retrieveRefreshToken(refresh);
+ RefreshToken refreshToken = refreshTokenDao
+ .retrieveRefreshToken(refresh);
Set<AccessScope> scopes = refreshToken.getScopes();
assertEquals(1, scopes.size());
assertEquals(scopes.toString(), "[all]");
@@ -173,7 +201,8 @@
}
@Test
- public void testRequestTokenPasswordGrantWithScope() throws KustvaktException {
+ public void testRequestTokenPasswordGrantWithScope ()
+ throws KustvaktException {
String scope = "match_info search";
Form form = new Form();
form.param("grant_type", "password");
@@ -187,47 +216,65 @@
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
assertEquals(scope, node.at("/scope").asText());
String refreshToken = node.at("/refresh_token").asText();
- testRequestRefreshTokenWithUnauthorizedScope(superClientId, clientSecret, refreshToken, "all");
- testRequestRefreshTokenWithScope(superClientId, clientSecret, refreshToken, "search");
+ testRequestRefreshTokenWithUnauthorizedScope(superClientId,
+ clientSecret, refreshToken, "all");
+ testRequestRefreshTokenWithScope(superClientId, clientSecret,
+ refreshToken, "search");
}
@Test
- public void testRequestTokenPasswordGrantConfidentialNonSuper() throws KustvaktException {
- Response response = requestTokenWithDoryPassword(confidentialClientId, clientSecret);
+ public void testRequestTokenPasswordGrantConfidentialNonSuper ()
+ throws KustvaktException {
+ Response response = requestTokenWithDoryPassword(confidentialClientId,
+ clientSecret);
String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.UNAUTHORIZED_CLIENT, node.at("/error").asText());
- assertEquals(node.at("/error_description").asText(), "Password grant is not allowed for third party clients");
+ assertEquals(OAuth2Error.UNAUTHORIZED_CLIENT,
+ node.at("/error").asText());
+ assertEquals(node.at("/error_description").asText(),
+ "Password grant is not allowed for third party clients");
}
@Test
- public void testRequestTokenPasswordGrantPublic() throws KustvaktException {
+ public void testRequestTokenPasswordGrantPublic ()
+ throws KustvaktException {
Response response = requestTokenWithDoryPassword(publicClientId, "");
String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.UNAUTHORIZED_CLIENT, node.at("/error").asText());
- assertEquals(node.at("/error_description").asText(), "Password grant is not allowed for third party clients");
+ assertEquals(OAuth2Error.UNAUTHORIZED_CLIENT,
+ node.at("/error").asText());
+ assertEquals(node.at("/error_description").asText(),
+ "Password grant is not allowed for third party clients");
}
@Test
- public void testRequestTokenPasswordGrantAuthorizationHeader() throws KustvaktException {
+ public void testRequestTokenPasswordGrantAuthorizationHeader ()
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", "password");
form.param("client_id", superClientId);
form.param("username", "dory");
form.param("password", "password");
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.AUTHORIZATION, "Basic ZkNCYlFrQXlZekk0TnpVeE1nOnNlY3JldA==").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.AUTHORIZATION,
+ "Basic ZkNCYlFrQXlZekk0TnpVeE1nOnNlY3JldA==")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
}
@@ -238,74 +285,81 @@
* @throws KustvaktException
*/
@Test
- public void testRequestTokenPasswordGrantDifferentClientIds() throws KustvaktException {
+ public void testRequestTokenPasswordGrantDifferentClientIds ()
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", "password");
form.param("client_id", "9aHsGW6QflV13ixNpez");
form.param("username", "dory");
form.param("password", "password");
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.AUTHORIZATION, "Basic ZkNCYlFrQXlZekk0TnpVeE1nOnNlY3JldA==").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.AUTHORIZATION,
+ "Basic ZkNCYlFrQXlZekk0TnpVeE1nOnNlY3JldA==")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
}
@Test
public void testRequestTokenPasswordGrantMissingClientSecret ()
throws KustvaktException {
- Response response =
- requestTokenWithDoryPassword(confidentialClientId, "");
+ Response response = requestTokenWithDoryPassword(confidentialClientId,
+ "");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertNotNull(node.at("/error_description").asText());
}
-
+
@Test
public void testRequestTokenPasswordGrantEmptyClientSecret ()
throws KustvaktException {
- Response response =
- requestTokenWithDoryPassword(confidentialClientId, "");
+ Response response = requestTokenWithDoryPassword(confidentialClientId,
+ "");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
- assertEquals(node.at("/error_description").asText(), "Missing parameter: client_secret");
+ assertEquals(node.at("/error_description").asText(),
+ "Missing parameter: client_secret");
}
@Test
- public void testRequestTokenPasswordGrantMissingClientId() throws KustvaktException {
+ public void testRequestTokenPasswordGrantMissingClientId ()
+ throws KustvaktException {
Response response = requestTokenWithDoryPassword(null, clientSecret);
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertNotNull(node.at("/error_description").asText());
}
-
+
@Test
public void testRequestTokenPasswordGrantEmptyClientId ()
throws KustvaktException {
- Response response =
- requestTokenWithDoryPassword("", clientSecret);
+ Response response = requestTokenWithDoryPassword("", clientSecret);
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertNotNull(node.at("/error_description").asText());
}
@Test
- public void testRequestTokenClientCredentialsGrant() throws KustvaktException {
+ public void testRequestTokenClientCredentialsGrant ()
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", "client_credentials");
form.param("client_id", confidentialClientId);
@@ -317,7 +371,8 @@
// length?
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
}
@@ -326,7 +381,8 @@
* clients.
*/
@Test
- public void testRequestTokenClientCredentialsGrantPublic() throws KustvaktException {
+ public void testRequestTokenClientCredentialsGrantPublic ()
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", "client_credentials");
form.param("client_id", publicClientId);
@@ -335,13 +391,13 @@
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.at("/error").asText());
assertNotNull(node.at("/error_description").asText());
}
@Test
- public void testRequestTokenClientCredentialsGrantReducedScope() throws KustvaktException {
+ public void testRequestTokenClientCredentialsGrantReducedScope ()
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", "client_credentials");
form.param("client_id", confidentialClientId);
@@ -354,13 +410,14 @@
// length?
assertNotNull(node.at("/access_token").asText());
assertNotNull(node.at("/refresh_token").asText());
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
assertEquals(node.at("/scope").asText(), "client_info");
}
@Test
- public void testRequestTokenMissingGrantType() throws KustvaktException {
+ public void testRequestTokenMissingGrantType () throws KustvaktException {
Form form = new Form();
Response response = requestToken(form);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -370,109 +427,155 @@
}
@Test
- public void testRequestTokenUnsupportedGrant() throws KustvaktException {
+ public void testRequestTokenUnsupportedGrant () throws KustvaktException {
Form form = new Form();
form.param("grant_type", "blahblah");
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.get("error_description").asText());
- assertEquals(OAuth2Error.INVALID_REQUEST,
- node.get("error").asText());
+ assertEquals(OAuth2Error.INVALID_REQUEST, node.get("error").asText());
}
- private void testRequestRefreshTokenInvalidScope(String clientId, String refreshToken) throws KustvaktException {
+ private void testRequestRefreshTokenInvalidScope (String clientId,
+ String refreshToken) throws KustvaktException {
Form form = new Form();
form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
form.param("client_id", clientId);
form.param("client_secret", clientSecret);
form.param("refresh_token", refreshToken);
form.param("scope", "search serialize_query");
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_SCOPE, node.at("/error").asText());
}
- private void testRequestRefreshToken(String clientId, String clientSecret, String refreshToken) throws KustvaktException {
+ private void testRequestRefreshToken (String clientId, String clientSecret,
+ String refreshToken) throws KustvaktException {
Form form = new Form();
form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
form.param("client_id", clientId);
form.param("client_secret", clientSecret);
form.param("refresh_token", refreshToken);
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
String newRefreshToken = node.at("/refresh_token").asText();
assertNotNull(newRefreshToken);
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
assertTrue(!newRefreshToken.equals(refreshToken));
- testRequestTokenWithRevokedRefreshToken(clientId, clientSecret, refreshToken);
- testRevokeToken(newRefreshToken, clientId, clientSecret, REFRESH_TOKEN_TYPE);
- testRequestTokenWithRevokedRefreshToken(clientId, clientSecret, newRefreshToken);
+ testRequestTokenWithRevokedRefreshToken(clientId, clientSecret,
+ refreshToken);
+ testRevokeToken(newRefreshToken, clientId, clientSecret,
+ REFRESH_TOKEN_TYPE);
+ testRequestTokenWithRevokedRefreshToken(clientId, clientSecret,
+ newRefreshToken);
}
- private void testRequestRefreshTokenWithUnauthorizedScope(String clientId, String clientSecret, String refreshToken, String scope) throws KustvaktException {
+ private void testRequestRefreshTokenWithUnauthorizedScope (String clientId,
+ String clientSecret, String refreshToken, String scope)
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
form.param("client_id", clientId);
form.param("client_secret", clientSecret);
form.param("refresh_token", refreshToken);
form.param("scope", scope);
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_SCOPE, node.at("/error").asText());
}
- private void testRequestRefreshTokenWithScope(String clientId, String clientSecret, String refreshToken, String scope) throws KustvaktException {
+ private void testRequestRefreshTokenWithScope (String clientId,
+ String clientSecret, String refreshToken, String scope)
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
form.param("client_id", clientId);
form.param("client_secret", clientSecret);
form.param("refresh_token", refreshToken);
form.param("scope", scope);
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node.at("/access_token").asText());
String newRefreshToken = node.at("/refresh_token").asText();
assertNotNull(newRefreshToken);
- assertEquals(TokenType.BEARER.displayName(), node.at("/token_type").asText());
+ assertEquals(TokenType.BEARER.displayName(),
+ node.at("/token_type").asText());
assertNotNull(node.at("/expires_in").asText());
assertTrue(!newRefreshToken.equals(refreshToken));
assertEquals(scope, node.at("/scope").asText());
}
- private void testRequestRefreshTokenInvalidClient(String refreshToken) throws KustvaktException {
+ private void testRequestRefreshTokenInvalidClient (String refreshToken)
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
form.param("client_id", "iBr3LsTCxOj7D2o0A5m");
form.param("refresh_token", refreshToken);
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_CLIENT, node.at("/error").asText());
}
- private void testRequestRefreshTokenInvalidRefreshToken(String clientId) throws KustvaktException {
+ private void testRequestRefreshTokenInvalidRefreshToken (String clientId)
+ throws KustvaktException {
Form form = new Form();
form.param("grant_type", GrantType.REFRESH_TOKEN.toString());
form.param("client_id", clientId);
form.param("client_secret", clientSecret);
form.param("refresh_token", "Lia8s8w8tJeZSBlaQDrYV8ion3l");
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(OAuth2Error.INVALID_GRANT, node.at("/error").asText());
}
- private JsonNode requestTokenList(String userAuthHeader, String tokenType, String clientId) throws KustvaktException {
+ private JsonNode requestTokenList (String userAuthHeader, String tokenType,
+ String clientId) throws KustvaktException {
Form form = new Form();
form.param("super_client_id", superClientId);
form.param("super_client_secret", clientSecret);
@@ -480,33 +583,46 @@
if (clientId != null && !clientId.isEmpty()) {
form.param("client_id", clientId);
}
- Response response = target().path(API_VERSION).path("oauth2").path("token").path("list").request().header(Attributes.AUTHORIZATION, userAuthHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").path("list").request()
+ .header(Attributes.AUTHORIZATION, userAuthHeader)
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
- private JsonNode requestTokenList(String userAuthHeader, String tokenType) throws KustvaktException {
+ private JsonNode requestTokenList (String userAuthHeader, String tokenType)
+ throws KustvaktException {
return requestTokenList(userAuthHeader, tokenType, null);
}
@Test
- public void testListRefreshTokenConfidentialClient() throws KustvaktException {
+ public void testListRefreshTokenConfidentialClient ()
+ throws KustvaktException {
String username = "gurgle";
String password = "pwd";
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, password);
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, password);
// super client
- Response response = requestTokenWithPassword(superClientId, clientSecret, username, password);
+ Response response = requestTokenWithPassword(superClientId,
+ clientSecret, username, password);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String refreshToken1 = node.at("/refresh_token").asText();
// client 1
- String code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ String code = requestAuthorizationCode(confidentialClientId,
+ userAuthHeader);
+ response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// client 2
- code = requestAuthorizationCode(confidentialClientId2, clientRedirectUri, userAuthHeader);
- response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId2, clientSecret, code, clientRedirectUri);
+ code = requestAuthorizationCode(confidentialClientId2,
+ clientRedirectUri, userAuthHeader);
+ response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId2, clientSecret, code, clientRedirectUri);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list
node = requestTokenList(userAuthHeader, REFRESH_TOKEN_TYPE);
@@ -515,31 +631,39 @@
assertEquals(confidentialClientId2, node.at("/1/client_id").asText());
// client 1
code = requestAuthorizationCode(confidentialClientId, userAuthHeader);
- response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// another user
- String darlaAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("darla", "pwd");
+ String darlaAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("darla", "pwd");
// test listing clients
node = requestTokenList(darlaAuthHeader, REFRESH_TOKEN_TYPE);
assertEquals(0, node.size());
// client 1
code = requestAuthorizationCode(confidentialClientId, darlaAuthHeader);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = requestTokenWithAuthorizationCodeAndForm(confidentialClientId, clientSecret, code);
+ response = requestTokenWithAuthorizationCodeAndForm(
+ confidentialClientId, clientSecret, code);
node = JsonUtils.readTree(response.readEntity(String.class));
String refreshToken5 = node.at("/refresh_token").asText();
// list all refresh tokens
node = requestTokenList(userAuthHeader, REFRESH_TOKEN_TYPE);
assertEquals(3, node.size());
// list refresh tokens from client 1
- node = requestTokenList(userAuthHeader, REFRESH_TOKEN_TYPE, confidentialClientId);
+ node = requestTokenList(userAuthHeader, REFRESH_TOKEN_TYPE,
+ confidentialClientId);
assertEquals(2, node.size());
- testRevokeToken(refreshToken1, superClientId, clientSecret, REFRESH_TOKEN_TYPE);
- testRevokeToken(node.at("/0/token").asText(), confidentialClientId, clientSecret, REFRESH_TOKEN_TYPE);
- testRevokeToken(node.at("/1/token").asText(), confidentialClientId2, clientSecret, REFRESH_TOKEN_TYPE);
+ testRevokeToken(refreshToken1, superClientId, clientSecret,
+ REFRESH_TOKEN_TYPE);
+ testRevokeToken(node.at("/0/token").asText(), confidentialClientId,
+ clientSecret, REFRESH_TOKEN_TYPE);
+ testRevokeToken(node.at("/1/token").asText(), confidentialClientId2,
+ clientSecret, REFRESH_TOKEN_TYPE);
node = requestTokenList(userAuthHeader, REFRESH_TOKEN_TYPE);
assertEquals(1, node.size());
- testRevokeTokenViaSuperClient(node.at("/0/token").asText(), userAuthHeader);
+ testRevokeTokenViaSuperClient(node.at("/0/token").asText(),
+ userAuthHeader);
node = requestTokenList(userAuthHeader, REFRESH_TOKEN_TYPE);
assertEquals(0, node.size());
// try revoking a token belonging to another user
@@ -553,19 +677,22 @@
}
@Test
- public void testListTokenPublicClient() throws KustvaktException {
+ public void testListTokenPublicClient () throws KustvaktException {
String username = "nemo";
String password = "pwd";
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, password);
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, password);
// access token 1
String code = requestAuthorizationCode(publicClientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "", code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(
+ publicClientId, "", code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken1 = node.at("/access_token").asText();
// access token 2
code = requestAuthorizationCode(publicClientId, userAuthHeader);
- response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "", code);
+ response = requestTokenWithAuthorizationCodeAndForm(publicClientId, "",
+ code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken2 = node.at("/access_token").asText();
@@ -593,9 +720,11 @@
assertEquals(0, node.size());
}
- private void testRefreshTokenExpiry(String refreshToken) throws KustvaktException {
+ private void testRefreshTokenExpiry (String refreshToken)
+ throws KustvaktException {
RefreshToken token = refreshTokenDao.retrieveRefreshToken(refreshToken);
- ZonedDateTime expiry = token.getCreatedDate().plusSeconds(config.getRefreshTokenLongExpiry());
+ ZonedDateTime expiry = token.getCreatedDate()
+ .plusSeconds(config.getRefreshTokenLongExpiry());
assertTrue(expiry.equals(token.getExpiryDate()));
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java
index 62b96f7..90597e2 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2PluginTest.java
@@ -45,9 +45,10 @@
@Autowired
private InstalledPluginDao pluginDao;
-
+
@Test
- public void testRegisterPlugin() throws ProcessingException, KustvaktException {
+ public void testRegisterPlugin ()
+ throws ProcessingException, KustvaktException {
JsonNode source = JsonUtils.readTree("{ \"plugin\" : \"source\"}");
int refreshTokenExpiry = TimeUtils.convertTimeToSeconds("90D");
String clientName = "Plugin";
@@ -71,12 +72,13 @@
// permitted only
node = listPlugins(true);
assertEquals(2, node.size());
- testListUserRegisteredPlugins(username, clientId, clientName, refreshTokenExpiry);
+ testListUserRegisteredPlugins(username, clientId, clientName,
+ refreshTokenExpiry);
deregisterClient(username, clientId);
}
@Test
- public void testRegisterPublicPlugin() throws KustvaktException {
+ public void testRegisterPublicPlugin () throws KustvaktException {
JsonNode source = JsonUtils.readTree("{ \"plugin\" : \"source\"}");
String clientName = "Public Plugin";
OAuth2ClientJson json = new OAuth2ClientJson();
@@ -96,40 +98,50 @@
// deregisterClient(username, clientId);
}
- private void testRetrievePluginInfo(String clientId, int refreshTokenExpiry) throws ProcessingException, KustvaktException {
+ private void testRetrievePluginInfo (String clientId,
+ int refreshTokenExpiry)
+ throws ProcessingException, KustvaktException {
JsonNode clientInfo = retrieveClientInfo(clientId, username);
assertEquals(clientId, clientInfo.at("/client_id").asText());
assertEquals(clientInfo.at("/client_name").asText(), "Plugin");
- assertEquals(OAuth2ClientType.CONFIDENTIAL.name(), clientInfo.at("/client_type").asText());
+ assertEquals(OAuth2ClientType.CONFIDENTIAL.name(),
+ clientInfo.at("/client_type").asText());
assertNotNull(clientInfo.at("/client_description").asText());
assertNotNull(clientInfo.at("/source").asText());
assertFalse(clientInfo.at("/permitted").asBoolean());
assertEquals(username, clientInfo.at("/registered_by").asText());
assertNotNull(clientInfo.at("/registration_date"));
- assertEquals(refreshTokenExpiry, clientInfo.at("/refresh_token_expiry").asInt());
+ assertEquals(refreshTokenExpiry,
+ clientInfo.at("/refresh_token_expiry").asInt());
}
- private void testListUserRegisteredPlugins(String username, String clientId, String clientName, int refreshTokenExpiry) throws ProcessingException, KustvaktException {
+ private void testListUserRegisteredPlugins (String username,
+ String clientId, String clientName, int refreshTokenExpiry)
+ throws ProcessingException, KustvaktException {
JsonNode node = listUserRegisteredClients(username);
assertEquals(1, node.size());
assertEquals(clientId, node.at("/0/client_id").asText());
assertEquals(clientName, node.at("/0/client_name").asText());
- assertEquals(OAuth2ClientType.CONFIDENTIAL.name(), node.at("/0/client_type").asText());
+ assertEquals(OAuth2ClientType.CONFIDENTIAL.name(),
+ node.at("/0/client_type").asText());
assertFalse(node.at("/0/permitted").asBoolean());
assertFalse(node.at("/0/registration_date").isMissingNode());
assertFalse(node.at("/0/source").isMissingNode());
- assertEquals(refreshTokenExpiry, node.at("/0/refresh_token_expiry").asInt());
+ assertEquals(refreshTokenExpiry,
+ node.at("/0/refresh_token_expiry").asInt());
}
@Test
- public void testListPluginsUnauthorizedPublic() throws ProcessingException, KustvaktException {
+ public void testListPluginsUnauthorizedPublic ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("super_client_id", publicClientId);
testListPluginsClientUnauthorized(form);
}
@Test
- public void testListPluginsUnauthorizedConfidential() throws ProcessingException, KustvaktException {
+ public void testListPluginsUnauthorizedConfidential ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("super_client_id", confidentialClientId2);
form.param("super_client_secret", clientSecret);
@@ -137,10 +149,16 @@
}
@Test
- public void testListPluginsMissingClientSecret() throws ProcessingException, KustvaktException {
+ public void testListPluginsMissingClientSecret ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("super_client_id", confidentialClientId);
- Response response = target().path(API_VERSION).path("plugins").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("plugins").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
@@ -148,31 +166,45 @@
assertFalse(node.at("/error_description").isMissingNode());
}
- private void testListPluginsClientUnauthorized(Form form) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("plugins").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ private void testListPluginsClientUnauthorized (Form form)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("plugins").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(OAuth2Error.UNAUTHORIZED_CLIENT, node.at("/error").asText());
+ assertEquals(OAuth2Error.UNAUTHORIZED_CLIENT,
+ node.at("/error").asText());
assertFalse(node.at("/error_description").isMissingNode());
}
@Test
- public void testListPluginsUserUnauthorized() throws ProcessingException, KustvaktException {
+ public void testListPluginsUserUnauthorized ()
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
- Response response = target().path(API_VERSION).path("plugins").request().header(Attributes.AUTHORIZATION, "Bearer blahblah").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("plugins").request()
+ .header(Attributes.AUTHORIZATION, "Bearer blahblah")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.INVALID_ACCESS_TOKEN, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testListPluginsConcurrent() throws InterruptedException {
+ public void testListPluginsConcurrent () throws InterruptedException {
ExecutorService executorService = Executors.newFixedThreadPool(3);
List<Future<Void>> futures = new ArrayList<>();
for (int i = 0; i < 3; i++) {
- futures.add(executorService.submit(new PluginListCallable("Thread " + (i + 1))));
+ futures.add(executorService
+ .submit(new PluginListCallable("Thread " + (i + 1))));
}
executorService.shutdown();
executorService.awaitTermination(2, TimeUnit.SECONDS);
@@ -181,7 +213,8 @@
// This will re-throw any exceptions
future.get();
// that occurred in threads
- } catch (ExecutionException e) {
+ }
+ catch (ExecutionException e) {
fail("Test failed: " + e.getCause().getMessage());
}
}
@@ -191,20 +224,29 @@
private final String name;
- public PluginListCallable(String name) {
+ public PluginListCallable (String name) {
this.name = name;
}
@Override
- public Void call() {
+ public Void call () {
Form form = getSuperClientForm();
try {
- Response response = target().path(API_VERSION).path("plugins").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("plugins")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.size());
- } catch (KustvaktException e) {
+ }
+ catch (KustvaktException e) {
e.printStackTrace();
throw new RuntimeException(name, e);
}
@@ -213,7 +255,8 @@
}
@Test
- public void testListAllPlugins() throws ProcessingException, KustvaktException {
+ public void testListAllPlugins ()
+ throws ProcessingException, KustvaktException {
JsonNode node = listPlugins(false);
assertEquals(2, node.size());
assertFalse(node.at("/0/client_id").isMissingNode());
@@ -227,18 +270,26 @@
// assertTrue(node.at("/1/refresh_token_expiry").isMissingNode());
}
- private JsonNode listPlugins(boolean permitted_only) throws ProcessingException, KustvaktException {
+ private JsonNode listPlugins (boolean permitted_only)
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
if (permitted_only) {
form.param("permitted_only", Boolean.toString(permitted_only));
}
- Response response = target().path(API_VERSION).path("plugins").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("plugins").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
- private void testInstallConfidentialPlugin(String superClientId, String clientId, String username) throws ProcessingException, KustvaktException {
+ private void testInstallConfidentialPlugin (String superClientId,
+ String clientId, String username)
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
form.param("client_id", clientId);
Response response = installPlugin(form);
@@ -255,7 +306,8 @@
}
@Test
- public void testInstallPublicPlugin() throws ProcessingException, KustvaktException {
+ public void testInstallPublicPlugin ()
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
form.param("client_id", publicClientId2);
Response response = installPlugin(form);
@@ -276,71 +328,84 @@
assertTrue(node.isEmpty());
}
- private void testInstallPluginRedundant(Form form) throws ProcessingException, KustvaktException {
+ private void testInstallPluginRedundant (Form form)
+ throws ProcessingException, KustvaktException {
Response response = installPlugin(form);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.PLUGIN_HAS_BEEN_INSTALLED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.PLUGIN_HAS_BEEN_INSTALLED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
- private void testInstallPluginNotPermitted(String clientId) throws ProcessingException, KustvaktException {
+ private void testInstallPluginNotPermitted (String clientId)
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
form.param("client_id", clientId);
Response response = installPlugin(form);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.PLUGIN_NOT_PERMITTED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.PLUGIN_NOT_PERMITTED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testInstallPluginMissingClientId() throws ProcessingException, KustvaktException {
+ public void testInstallPluginMissingClientId ()
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
Response response = installPlugin(form);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testInstallPluginInvalidClientId() throws ProcessingException, KustvaktException {
+ public void testInstallPluginInvalidClientId ()
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
form.param("client_id", "unknown");
Response response = installPlugin(form);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "Unknown client: unknown");
+ assertEquals(node.at("/error_description").asText(),
+ "Unknown client: unknown");
assertEquals(node.at("/error").asText(), "invalid_client");
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
@Test
- public void testInstallPluginMissingSuperClientSecret() throws ProcessingException, KustvaktException {
+ public void testInstallPluginMissingSuperClientSecret ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("super_client_id", superClientId);
Response response = installPlugin(form);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "Missing parameter: super_client_secret");
+ assertEquals(node.at("/error_description").asText(),
+ "Missing parameter: super_client_secret");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testInstallPluginMissingSuperClientId() throws ProcessingException, KustvaktException {
+ public void testInstallPluginMissingSuperClientId ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
Response response = installPlugin(form);
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/error_description").asText(), "Missing parameter: super_client_id");
+ assertEquals(node.at("/error_description").asText(),
+ "Missing parameter: super_client_id");
assertEquals(node.at("/error").asText(), "invalid_request");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testInstallPluginUnauthorizedClient() throws ProcessingException, KustvaktException {
+ public void testInstallPluginUnauthorizedClient ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("super_client_id", confidentialClientId);
form.param("super_client_secret", clientSecret);
@@ -351,18 +416,34 @@
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
- private Response installPlugin(Form form) throws ProcessingException, KustvaktException {
- return target().path(API_VERSION).path("plugins").path("install").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ private Response installPlugin (Form form)
+ throws ProcessingException, KustvaktException {
+ return target().path(API_VERSION).path("plugins").path("install")
+ .request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
}
- private Response uninstallPlugin(String clientId, String username) throws ProcessingException, KustvaktException {
+ private Response uninstallPlugin (String clientId, String username)
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
form.param("client_id", clientId);
- return target().path(API_VERSION).path("plugins").path("uninstall").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ return target().path(API_VERSION).path("plugins").path("uninstall")
+ .request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
}
- private void testRetrieveInstalledPlugin(String superClientId, String clientId, String installedBy) throws KustvaktException {
- InstalledPlugin plugin = pluginDao.retrieveInstalledPlugin(superClientId, clientId, installedBy);
+ private void testRetrieveInstalledPlugin (String superClientId,
+ String clientId, String installedBy) throws KustvaktException {
+ InstalledPlugin plugin = pluginDao
+ .retrieveInstalledPlugin(superClientId, clientId, installedBy);
assertEquals(clientId, plugin.getClient().getId());
assertEquals(superClientId, plugin.getSuperClient().getId());
assertEquals(installedBy, plugin.getInstalledBy());
@@ -371,20 +452,24 @@
}
@Test
- public void testListUserInstalledPlugins() throws ProcessingException, KustvaktException, IOException {
- testInstallConfidentialPlugin(superClientId, confidentialClientId, username);
+ public void testListUserInstalledPlugins ()
+ throws ProcessingException, KustvaktException, IOException {
+ testInstallConfidentialPlugin(superClientId, confidentialClientId,
+ username);
JsonNode node = testRequestAccessToken(confidentialClientId);
String accessToken = node.at("/access_token").asText();
String refreshToken = node.at("/refresh_token").asText();
testSearchWithOAuth2Token(accessToken);
- testInstallConfidentialPlugin(superClientId, confidentialClientId2, username);
+ testInstallConfidentialPlugin(superClientId, confidentialClientId2,
+ username);
node = retrieveUserInstalledPlugin(getSuperClientForm());
assertEquals(2, node.size());
Response response = uninstallPlugin(confidentialClientId, username);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = retrieveUserInstalledPlugin(getSuperClientForm());
assertEquals(1, node.size());
- testRequestTokenWithRevokedRefreshToken(confidentialClientId, clientSecret, refreshToken);
+ testRequestTokenWithRevokedRefreshToken(confidentialClientId,
+ clientSecret, refreshToken);
testSearchWithRevokedAccessToken(accessToken);
response = uninstallPlugin(confidentialClientId2, username);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -394,8 +479,10 @@
testUninstallNotInstalledPlugin();
}
- private void testReinstallUninstalledPlugin() throws ProcessingException, KustvaktException {
- testInstallConfidentialPlugin(superClientId, confidentialClientId2, username);
+ private void testReinstallUninstalledPlugin ()
+ throws ProcessingException, KustvaktException {
+ testInstallConfidentialPlugin(superClientId, confidentialClientId2,
+ username);
JsonNode node = retrieveUserInstalledPlugin(getSuperClientForm());
assertEquals(1, node.size());
Response response = uninstallPlugin(confidentialClientId2, username);
@@ -404,24 +491,36 @@
assertEquals(0, node.size());
}
- private JsonNode testRequestAccessToken(String clientId) throws KustvaktException {
- String userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "password");
+ private JsonNode testRequestAccessToken (String clientId)
+ throws KustvaktException {
+ String userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "password");
String code = requestAuthorizationCode(clientId, userAuthHeader);
- Response response = requestTokenWithAuthorizationCodeAndForm(clientId, clientSecret, code);
+ Response response = requestTokenWithAuthorizationCodeAndForm(clientId,
+ clientSecret, code);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
return node;
}
- private void testUninstallNotInstalledPlugin() throws ProcessingException, KustvaktException {
+ private void testUninstallNotInstalledPlugin ()
+ throws ProcessingException, KustvaktException {
Response response = uninstallPlugin(confidentialClientId2, username);
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
}
- private JsonNode retrieveUserInstalledPlugin(Form form) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("plugins").path("installed").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ private JsonNode retrieveUserInstalledPlugin (Form form)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("plugins")
+ .path("installed").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2RClientTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2RClientTest.java
index 30bb832..d0eab61 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2RClientTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2RClientTest.java
@@ -26,11 +26,12 @@
private String userAuthHeader;
- public OAuth2RClientTest() throws KustvaktException {
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("R-user", "password");
+ public OAuth2RClientTest () throws KustvaktException {
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("R-user", "password");
}
- public OAuth2ClientJson createOAuth2RClient() {
+ public OAuth2ClientJson createOAuth2RClient () {
OAuth2ClientJson client = new OAuth2ClientJson();
client.setName("R client");
client.setType(OAuth2ClientType.PUBLIC);
@@ -40,7 +41,8 @@
}
@Test
- public void testRClientWithLocalhost() throws ProcessingException, KustvaktException, IOException {
+ public void testRClientWithLocalhost ()
+ throws ProcessingException, KustvaktException, IOException {
// Register client
OAuth2ClientJson clientJson = createOAuth2RClient();
Response response = registerClient(username, clientJson);
@@ -50,7 +52,8 @@
// send authorization
String code = testAuthorize(clientId);
// send token request
- response = requestTokenWithAuthorizationCodeAndForm(clientId, null, code);
+ response = requestTokenWithAuthorizationCodeAndForm(clientId, null,
+ code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
@@ -62,14 +65,17 @@
testSearchWithRevokedAccessToken(accessToken);
}
- private String testAuthorize(String clientId) throws KustvaktException {
- Response response = requestAuthorizationCode("code", clientId, "", "search", "", userAuthHeader);
- assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(), response.getStatus());
+ private String testAuthorize (String clientId) throws KustvaktException {
+ Response response = requestAuthorizationCode("code", clientId, "",
+ "search", "", userAuthHeader);
+ assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
+ response.getStatus());
URI redirectUri = response.getLocation();
assertEquals(redirectUri.getScheme(), "http");
assertEquals(redirectUri.getHost(), "localhost");
assertEquals(1410, redirectUri.getPort());
- MultiValueMap<String, String> params = UriComponentsBuilder.fromUri(redirectUri).build().getQueryParams();
+ MultiValueMap<String, String> params = UriComponentsBuilder
+ .fromUri(redirectUri).build().getQueryParams();
String code = params.getFirst("code");
assertNotNull(code);
return code;
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java
index 0b94e02..b27fd0f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/OAuth2TestBase.java
@@ -80,8 +80,9 @@
public static String ACCESS_TOKEN_TYPE = "access_token";
public static String REFRESH_TOKEN_TYPE = "refresh_token";
- protected int defaultRefreshTokenExpiry = TimeUtils.convertTimeToSeconds("365D");
-
+ protected int defaultRefreshTokenExpiry = TimeUtils
+ .convertTimeToSeconds("365D");
+
protected String clientURL = "http://example.client.com";
protected String clientRedirectUri = "https://example.client.com/redirect";
@@ -97,7 +98,7 @@
}
protected String parseAuthorizationCode (Response response) {
-
+
assertEquals(Status.TEMPORARY_REDIRECT.getStatusCode(),
response.getStatus());
@@ -106,7 +107,7 @@
.fromUri(redirectUri).build().getQueryParams();
return params.getFirst("code");
}
-
+
protected Response requestAuthorizationCode (String responseType,
String clientId, String redirectUri, String scope, String state,
String authHeader) throws KustvaktException {
@@ -114,7 +115,7 @@
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.FOLLOW_REDIRECTS, false);
Client client = ClientBuilder.newClient(clientConfig);
-
+
WebTarget request = client.target(getBaseUri()).path(API_VERSION)
.path("oauth2").path("authorize");
@@ -133,9 +134,10 @@
if (!state.isEmpty()) {
request = request.queryParam("state", state);
}
-
- Builder builder = request.request().header(Attributes.AUTHORIZATION, authHeader);
-
+
+ Builder builder = request.request().header(Attributes.AUTHORIZATION,
+ authHeader);
+
return builder.get();
}
@@ -166,14 +168,12 @@
return params.getFirst("code");
}
- protected Response requestToken (Form form)
- throws KustvaktException {
- return target().path(API_VERSION).path("oauth2").path("token")
- .request()
+ protected Response requestToken (Form form) throws KustvaktException {
+ return target().path(API_VERSION).path("oauth2").path("token").request()
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
- .post(Entity.form(form));
+ .post(Entity.form(form));
}
// client credentials as form params
@@ -187,8 +187,7 @@
form.param("client_secret", clientSecret);
form.param("code", code);
- return target().path(API_VERSION).path("oauth2").path("token")
- .request()
+ return target().path(API_VERSION).path("oauth2").path("token").request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
.post(Entity.form(form));
@@ -207,8 +206,7 @@
form.param("redirect_uri", redirectUri);
}
- return target().path(API_VERSION).path("oauth2").path("token")
- .request()
+ return target().path(API_VERSION).path("oauth2").path("token").request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
.post(Entity.form(form));
@@ -224,15 +222,14 @@
form.param("code", code);
Response response = target().path(API_VERSION).path("oauth2")
- .path("token")
- .request()
+ .path("token").request()
.header(Attributes.AUTHORIZATION, authHeader)
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
.post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
-
+
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
@@ -249,7 +246,7 @@
Form form = new Form();
form.param("grant_type", "password");
form.param("client_id", clientId);
- if (clientSecret !=null && !clientSecret.isEmpty()) {
+ if (clientSecret != null && !clientSecret.isEmpty()) {
form.param("client_secret", clientSecret);
}
form.param("username", username);
@@ -269,27 +266,25 @@
form.param("client_secret", clientSecret);
}
- Response response =
- target().path(API_VERSION).path("oauth2").path("token")
- .request()
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .header(HttpHeaders.CONTENT_TYPE,
- ContentType.APPLICATION_FORM_URLENCODED)
- .post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(OAuth2Error.INVALID_GRANT.getCode(), node.at("/error").asText());
+ assertEquals(OAuth2Error.INVALID_GRANT.getCode(),
+ node.at("/error").asText());
assertEquals("Refresh token has been revoked",
node.at("/error_description").asText());
}
- protected Response registerClient (String username,
- OAuth2ClientJson json) throws
- ProcessingException, KustvaktException {
+ protected Response registerClient (String username, OAuth2ClientJson json)
+ throws ProcessingException, KustvaktException {
return target().path(API_VERSION).path("oauth2").path("client")
- .path("register")
- .request()
+ .path("register").request()
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username,
@@ -313,11 +308,11 @@
}
protected void testConfidentialClientInfo (String clientId, String username)
- throws ProcessingException,
- KustvaktException {
+ throws ProcessingException, KustvaktException {
JsonNode clientInfo = retrieveClientInfo(clientId, username);
assertEquals(clientId, clientInfo.at("/client_id").asText());
- assertEquals("OAuth2ClientTest", clientInfo.at("/client_name").asText());
+ assertEquals("OAuth2ClientTest",
+ clientInfo.at("/client_name").asText());
assertEquals(OAuth2ClientType.CONFIDENTIAL.name(),
clientInfo.at("/client_type").asText());
assertEquals(username, clientInfo.at("/registered_by").asText());
@@ -334,13 +329,11 @@
}
- protected void deregisterClient (String username,
- String clientId) throws
- ProcessingException, KustvaktException {
+ protected void deregisterClient (String username, String clientId)
+ throws ProcessingException, KustvaktException {
Response response = target().path(API_VERSION).path("oauth2")
- .path("client").path("deregister").path(clientId)
- .request()
+ .path("client").path("deregister").path(clientId).request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pass"))
.delete();
@@ -349,17 +342,15 @@
}
protected JsonNode retrieveClientInfo (String clientId, String username)
- throws ProcessingException,
- KustvaktException {
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("super_client_id", superClientId);
form.param("super_client_secret", clientSecret);
-
+
Response response = target().path(API_VERSION).path("oauth2")
- .path("client").path(clientId)
- .request()
-// .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
-// .createBasicAuthorizationHeaderValue(username, "pass"))
+ .path("client").path(clientId).request()
+ // .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ // .createBasicAuthorizationHeaderValue(username, "pass"))
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
.post(Entity.form(form));
@@ -375,27 +366,24 @@
.queryParam("q", "Wasser").queryParam("ql", "poliqarp")
.request()
.header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .get();
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
}
-
+
protected void testSearchWithOAuth2Token (String accessToken)
throws KustvaktException, IOException {
Response response = searchWithAccessToken(accessToken);
String entity = response.readEntity(String.class);
- assertEquals(Status.OK.getStatusCode(),
- response.getStatus());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertEquals(25, node.at("/matches").size());
}
-
+
protected void testSearchWithRevokedAccessToken (String accessToken)
throws KustvaktException {
Response response = searchWithAccessToken(accessToken);
String entity = response.readEntity(String.class);
- assertEquals(Status.UNAUTHORIZED.getStatusCode(),
- response.getStatus());
+ assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
@@ -404,7 +392,6 @@
node.at("/errors/0/1").asText());
}
-
protected void testRevokeTokenViaSuperClient (String token,
String userAuthHeader) {
Form form = new Form();
@@ -413,8 +400,7 @@
form.param("super_client_secret", clientSecret);
Response response = target().path(API_VERSION).path("oauth2")
- .path("revoke").path("super")
- .request()
+ .path("revoke").path("super").request()
.header(HttpHeaders.CONTENT_TYPE,
ContentType.APPLICATION_FORM_URLENCODED)
.header(Attributes.AUTHORIZATION, userAuthHeader)
@@ -434,24 +420,21 @@
form.param("client_secret", clientSecret);
}
- Response response =
- target().path(API_VERSION).path("oauth2").path("revoke")
- .request()
- .header(HttpHeaders.CONTENT_TYPE,
- ContentType.APPLICATION_FORM_URLENCODED)
- .post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("revoke").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertEquals("SUCCESS", response.readEntity(String.class));
}
protected JsonNode listUserRegisteredClients (String username)
- throws ProcessingException,
- KustvaktException {
+ throws ProcessingException, KustvaktException {
Form form = getSuperClientForm();
Response response = target().path(API_VERSION).path("oauth2")
- .path("client").path("list")
- .request()
+ .path("client").path("list").request()
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue(username, "pwd"))
.header(HttpHeaders.CONTENT_TYPE,
@@ -463,7 +446,7 @@
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
-
+
protected void testInvalidRedirectUri (String entity, String contentType,
boolean includeState, int status) throws KustvaktException {
JsonNode node = JsonUtils.readTree(entity);
@@ -478,18 +461,18 @@
assertEquals("application/json;charset=utf-8", contentType);
assertEquals(Status.BAD_REQUEST.getStatusCode(), status);
}
-
+
protected String createExpiredAccessToken () throws KustvaktException {
String authToken = codeGenerator.createRandomCode();
-
+
// create new access token
OAuth2Client client = clientDao.retrieveClientById(publicClientId);
- ZonedDateTime now =
- ZonedDateTime.now(ZoneId.of(Attributes.DEFAULT_TIME_ZONE));
+ ZonedDateTime now = ZonedDateTime
+ .now(ZoneId.of(Attributes.DEFAULT_TIME_ZONE));
Set<AccessScope> scopes = new HashSet<>();
scopes.add(new AccessScope(OAuth2Scope.EDIT_VC));
-
+
AccessToken accessToken = new AccessToken();
accessToken.setCreatedDate(now.minusSeconds(5));
accessToken.setExpiryDate(now.minusSeconds(3));
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
index 89e2cb5..57dc847 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
@@ -28,8 +28,14 @@
private String system = "system";
- private void testRetrieveQueryByName(String qName, String query, String queryCreator, String username, ResourceType resourceType, CorpusAccess access) throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").path("~" + queryCreator).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).get();
+ private void testRetrieveQueryByName (String qName, String query,
+ String queryCreator, String username, ResourceType resourceType,
+ CorpusAccess access) throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + queryCreator).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .get();
String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -42,173 +48,283 @@
assertEquals(access.name(), node.at("/requiredAccess").asText());
}
- private void testUpdateQuery(String qName, String qCreator, String username, ResourceType type) throws ProcessingException, KustvaktException {
- String json = "{\"query\": \"Sonne\"" + ",\"queryLanguage\": \"poliqarp\"}";
- Response response = target().path(API_VERSION).path("query").path("~" + qCreator).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ private void testUpdateQuery (String qName, String qCreator,
+ String username, ResourceType type)
+ throws ProcessingException, KustvaktException {
+ String json = "{\"query\": \"Sonne\""
+ + ",\"queryLanguage\": \"poliqarp\"}";
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + qCreator).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
- testRetrieveQueryByName(qName, "Sonne", qCreator, username, type, CorpusAccess.PUB);
+ testRetrieveQueryByName(qName, "Sonne", qCreator, username, type,
+ CorpusAccess.PUB);
}
@Test
- public void testCreatePrivateQuery() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\"" + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"der\"}";
+ public void testCreatePrivateQuery () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
+ + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"der\"}";
String qName = "new_query";
- Response response = target().path(API_VERSION).path("query").path("~" + testUser).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + testUser).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- testRetrieveQueryByName(qName, "der", testUser, testUser, ResourceType.PRIVATE, CorpusAccess.PUB);
+ testRetrieveQueryByName(qName, "der", testUser, testUser,
+ ResourceType.PRIVATE, CorpusAccess.PUB);
testUpdateQuery(qName, testUser, testUser, ResourceType.PRIVATE);
testDeleteQueryByName(qName, testUser, testUser);
}
@Test
- public void testCreatePublishQuery() throws KustvaktException {
- String json = "{\"type\": \"PUBLISHED\"" + ",\"queryType\": \"QUERY\"" + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Regen\"}";
+ public void testCreatePublishQuery () throws KustvaktException {
+ String json = "{\"type\": \"PUBLISHED\"" + ",\"queryType\": \"QUERY\""
+ + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Regen\"}";
String qName = "publish_query";
- Response response = target().path(API_VERSION).path("query").path("~" + testUser).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + testUser).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- testRetrieveQueryByName(qName, "Regen", testUser, testUser, ResourceType.PUBLISHED, CorpusAccess.PUB);
+ testRetrieveQueryByName(qName, "Regen", testUser, testUser,
+ ResourceType.PUBLISHED, CorpusAccess.PUB);
testDeleteQueryByName(qName, testUser, testUser);
// check if hidden group has been created
}
@Test
- public void testCreateUserQueryByAdmin() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\"" + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Sommer\"}";
+ public void testCreateUserQueryByAdmin () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
+ + ",\"queryLanguage\": \"poliqarp\""
+ + ",\"query\": \"Sommer\"}";
String qName = "marlin-query";
- Response response = target().path(API_VERSION).path("query").path("~marlin").path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(adminUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~marlin").path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(adminUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- testRetrieveQueryByName(qName, "Sommer", "marlin", adminUser, ResourceType.PRIVATE, CorpusAccess.PUB);
+ testRetrieveQueryByName(qName, "Sommer", "marlin", adminUser,
+ ResourceType.PRIVATE, CorpusAccess.PUB);
testUpdateQuery(qName, "marlin", adminUser, ResourceType.PRIVATE);
testDeleteQueryByName(qName, "marlin", adminUser);
}
@Test
- public void testCreateSystemQuery() throws KustvaktException {
- String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"QUERY\"" + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Sommer\"}";
+ public void testCreateSystemQuery () throws KustvaktException {
+ String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"QUERY\""
+ + ",\"queryLanguage\": \"poliqarp\""
+ + ",\"query\": \"Sommer\"}";
String qName = "system-query";
- Response response = target().path(API_VERSION).path("query").path("~system").path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(adminUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~system").path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(adminUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- testRetrieveQueryByName(qName, "Sommer", system, adminUser, ResourceType.SYSTEM, CorpusAccess.PUB);
+ testRetrieveQueryByName(qName, "Sommer", system, adminUser,
+ ResourceType.SYSTEM, CorpusAccess.PUB);
testUpdateQuery(qName, system, adminUser, ResourceType.SYSTEM);
testDeleteSystemQueryUnauthorized(qName);
testDeleteQueryByName(qName, system, adminUser);
}
@Test
- public void testCreateSystemQueryUnauthorized() throws KustvaktException {
- String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"QUERY\"" + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Sommer\"}";
- Response response = target().path(API_VERSION).path("query").path("~" + testUser).path("system-query").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateSystemQueryUnauthorized () throws KustvaktException {
+ String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"QUERY\""
+ + ",\"queryLanguage\": \"poliqarp\""
+ + ",\"query\": \"Sommer\"}";
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + testUser).path("system-query").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Unauthorized operation for user: " + testUser, node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Unauthorized operation for user: " + testUser,
+ node.at("/errors/0/1").asText());
}
@Test
- public void testCreateQueryMissingQueryType() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Sohn\"}";
+ public void testCreateQueryMissingQueryType () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\""
+ + ",\"queryLanguage\": \"poliqarp\"" + ",\"query\": \"Sohn\"}";
String qName = "new_query";
- Response response = target().path(API_VERSION).path("query").path("~" + testUser).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + testUser).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- testRetrieveQueryByName(qName, "Sohn", testUser, testUser, ResourceType.PRIVATE, CorpusAccess.PUB);
+ testRetrieveQueryByName(qName, "Sohn", testUser, testUser,
+ ResourceType.PRIVATE, CorpusAccess.PUB);
testDeleteQueryByName(qName, testUser, testUser);
}
@Test
- public void testCreateQueryMissingQueryLanguage() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\"" + ",\"query\": \"Sohn\"}";
+ public void testCreateQueryMissingQueryLanguage ()
+ throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
+ + ",\"query\": \"Sohn\"}";
String qName = "new_query";
- Response response = target().path(API_VERSION).path("query").path("~" + testUser).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + testUser).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "queryLanguage is null");
assertEquals(node.at("/errors/0/2").asText(), "queryLanguage");
}
@Test
- public void testCreateQueryMissingQuery() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\"" + ",\"queryLanguage\": \"poliqarp\"}";
+ public void testCreateQueryMissingQuery () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"QUERY\""
+ + ",\"queryLanguage\": \"poliqarp\"}";
String qName = "new_query";
- Response response = target().path(API_VERSION).path("query").path("~" + testUser).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + testUser).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "query is null");
assertEquals(node.at("/errors/0/2").asText(), "query");
}
@Test
- public void testCreateQueryMissingResourceType() throws KustvaktException {
- String json = "{\"query\": \"Wind\"" + ",\"queryLanguage\": \"poliqarp\"}";
+ public void testCreateQueryMissingResourceType () throws KustvaktException {
+ String json = "{\"query\": \"Wind\""
+ + ",\"queryLanguage\": \"poliqarp\"}";
String qName = "new_query";
- Response response = target().path(API_VERSION).path("query").path("~" + testUser).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + testUser).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "type is null");
assertEquals(node.at("/errors/0/2").asText(), "type");
}
- private void testDeleteQueryByName(String qName, String qCreator, String username) throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").path("~" + qCreator).path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
+ private void testDeleteQueryByName (String qName, String qCreator,
+ String username) throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .path("~" + qCreator).path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
- public void testDeleteQueryUnauthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").path("~dory").path("dory-q").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).delete();
+ public void testDeleteQueryUnauthorized () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .path("~dory").path("dory-q").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .delete();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Unauthorized operation for user: " + testUser, node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Unauthorized operation for user: " + testUser,
+ node.at("/errors/0/1").asText());
}
- private void testDeleteSystemQueryUnauthorized(String qName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").path("~system").path(qName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).delete();
+ private void testDeleteSystemQueryUnauthorized (String qName)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .path("~system").path(qName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .delete();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Unauthorized operation for user: " + testUser, node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Unauthorized operation for user: " + testUser,
+ node.at("/errors/0/1").asText());
}
@Test
- public void testDeleteNonExistingQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").path("~dory").path("non-existing-query").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).delete();
+ public void testDeleteNonExistingQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .path("~dory").path("non-existing-query").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .delete();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Query dory/non-existing-query is not found.");
- assertEquals(node.at("/errors/0/2").asText(), "dory/non-existing-query");
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Query dory/non-existing-query is not found.");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "dory/non-existing-query");
}
@Test
- public void testListAvailableQueryForDory() throws ProcessingException, KustvaktException {
+ public void testListAvailableQueryForDory ()
+ throws ProcessingException, KustvaktException {
JsonNode node = testListAvailableQuery("dory");
assertEquals(2, node.size());
}
@Test
- public void testListAvailableQueryForPearl() throws ProcessingException, KustvaktException {
+ public void testListAvailableQueryForPearl ()
+ throws ProcessingException, KustvaktException {
JsonNode node = testListAvailableQuery("pearl");
assertEquals(1, node.size());
assertEquals(node.at("/0/name").asText(), "system-q");
- assertEquals(ResourceType.SYSTEM.displayName(), node.at("/0/type").asText());
+ assertEquals(ResourceType.SYSTEM.displayName(),
+ node.at("/0/type").asText());
assertEquals(node.at("/0/description").asText(), "\"system\" query");
assertEquals(node.at("/0/query").asText(), "[]");
- assertEquals(CorpusAccess.FREE.name(), node.at("/0/requiredAccess").asText());
+ assertEquals(CorpusAccess.FREE.name(),
+ node.at("/0/requiredAccess").asText());
// assertEquals("koral:token", node.at("/0/koralQuery/@type").asText());
}
- private JsonNode testListAvailableQuery(String username) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("query").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ private JsonNode testListAvailableQuery (String username)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("query").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
// System.out.println(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java
index e709d1b..27f3567 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceSearchTest.java
@@ -28,10 +28,10 @@
.queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
.queryParam("cq", "referTo \"dory/dory-q\"")
.get();
-
+
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches").size() > 0);
}
-*/
+ */
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
index b1d8add..5c70f57 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QuerySerializationControllerTest.java
@@ -25,8 +25,12 @@
public class QuerySerializationControllerTest extends SpringJerseyTest {
@Test
- public void testQuerySerializationFilteredPublic() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/WPD13/query").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("context", "base/s:s").request().method("GET");
+ public void testQuerySerializationFilteredPublic ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/WPD13/query").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -36,28 +40,46 @@
}
@Test
- public void testQuerySerializationUnexistingResource() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/ZUW19/query").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("context", "base/s:s").request().method("GET");
+ public void testQuerySerializationUnexistingResource ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/ZUW19/query").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
+ .request().method("GET");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(101, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/2").asText(), "[Cannot found public Corpus with ids: [ZUW19]]");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "[Cannot found public Corpus with ids: [ZUW19]]");
}
@Test
- public void testQuerySerializationWithNonPublicCorpus() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/BRZ10/query").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("context", "base/s:s").request().method("GET");
+ public void testQuerySerializationWithNonPublicCorpus ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/BRZ10/query").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
+ .request().method("GET");
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(101, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/2").asText(), "[Cannot found public Corpus with ids: [BRZ10]]");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "[Cannot found public Corpus with ids: [BRZ10]]");
}
@Test
- public void testQuerySerializationWithAuthentication() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/BRZ10/query").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).method("GET");
+ public void testQuerySerializationWithAuthentication ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/BRZ10/query").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -68,9 +90,21 @@
}
@Test
- public void testQuerySerializationWithNewCollection() throws KustvaktException {
+ public void testQuerySerializationWithNewCollection ()
+ throws KustvaktException {
// Add Virtual Collection
- Response response = target().path(API_VERSION).path("virtualcollection").queryParam("filter", "false").queryParam("query", "creationDate since 1775 & corpusSigle=GOE").queryParam("name", "Weimarer Werke").queryParam("description", "Goethe-Werke in Weimar (seit 1775)").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).post(Entity.json(""));
+ Response response = target().path(API_VERSION).path("virtualcollection")
+ .queryParam("filter", "false")
+ .queryParam("query",
+ "creationDate since 1775 & corpusSigle=GOE")
+ .queryParam("name", "Weimarer Werke")
+ .queryParam("description", "Goethe-Werke in Weimar (seit 1775)")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .post(Entity.json(""));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -78,7 +112,12 @@
assertTrue(node.isObject());
assertEquals(node.path("name").asText(), "Weimarer Werke");
// Get virtual collections
- response = target().path(API_VERSION).path("collection").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).get();
+ response = target().path(API_VERSION).path("collection").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ent = response.readEntity(String.class);
node = JsonUtils.readTree(ent);
@@ -93,42 +132,70 @@
assertNotNull(id);
assertFalse(id.isEmpty());
// query serialization service
- response = target().path(API_VERSION).path("collection").path(id).path("query").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("context", "base/s:s").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).method("GET");
+ response = target().path(API_VERSION).path("collection").path(id)
+ .path("query").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ent = response.readEntity(String.class);
node = JsonUtils.readTree(ent);
assertNotNull(node);
// System.out.println("NODE " + ent);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/0/key").asText(), "creationDate");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "creationDate");
assertEquals(node.at("/collection/operands/0/value").asText(), "1775");
- assertEquals(node.at("/collection/operands/0/type").asText(), "type:date");
- assertEquals(node.at("/collection/operands/0/match").asText(), "match:geq");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/1/key").asText(), "corpusSigle");
+ assertEquals(node.at("/collection/operands/0/type").asText(),
+ "type:date");
+ assertEquals(node.at("/collection/operands/0/match").asText(),
+ "match:geq");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "corpusSigle");
assertEquals(node.at("/collection/operands/1/value").asText(), "GOE");
- assertEquals(node.at("/collection/operands/1/match").asText(), "match:eq");
+ assertEquals(node.at("/collection/operands/1/match").asText(),
+ "match:eq");
}
@Test
- public void testQuerySerializationOfVirtualCollection() throws KustvaktException {
- Response response = target().path(API_VERSION).path("collection/GOE-VC/query").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("context", "base/s:s").request().method("GET");
+ public void testQuerySerializationOfVirtualCollection ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("collection/GOE-VC/query").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").queryParam("context", "base/s:s")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
- assertEquals(node.at("/collection/operands/0/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/0/key").asText(), "corpusSigle");
+ assertEquals(node.at("/collection/operands/0/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "corpusSigle");
assertEquals(node.at("/collection/operands/0/value").asText(), "GOE");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:doc");
- assertEquals(node.at("/collection/operands/1/key").asText(), "creationDate");
- assertEquals(node.at("/collection/operands/1/value").asText(), "1810-01-01");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "creationDate");
+ assertEquals(node.at("/collection/operands/1/value").asText(),
+ "1810-01-01");
}
@Test
- public void testMetaQuerySerialization() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("context", "sentence").queryParam("count", "20").queryParam("page", "5").queryParam("cutoff", "true").queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp").request().method("GET");
+ public void testMetaQuerySerialization () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("context", "sentence").queryParam("count", "20")
+ .queryParam("page", "5").queryParam("cutoff", "true")
+ .queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp")
+ .request().method("GET");
assertEquals(response.getStatus(), Status.OK.getStatusCode());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -143,8 +210,13 @@
}
@Test
- public void testMetaQuerySerializationWithOffset() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("context", "sentence").queryParam("count", "20").queryParam("page", "5").queryParam("offset", "2").queryParam("cutoff", "true").queryParam("q", "[pos=ADJA]").queryParam("ql", "poliqarp").request().method("GET");
+ public void testMetaQuerySerializationWithOffset ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("context", "sentence").queryParam("count", "20")
+ .queryParam("page", "5").queryParam("offset", "2")
+ .queryParam("cutoff", "true").queryParam("q", "[pos=ADJA]")
+ .queryParam("ql", "poliqarp").request().method("GET");
assertEquals(response.getStatus(), Status.OK.getStatusCode());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
index 8f30d17..d2d4fed 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/ResourceInfoControllerTest.java
@@ -20,14 +20,15 @@
/**
* @author hanl, margaretha
* @lastUpdate 19/04/2017
- * EM: FIX ME: Database restructure
+ * EM: FIX ME: Database restructure
*/
@Disabled
public class ResourceInfoControllerTest extends SpringJerseyTest {
@Test
- public void testGetPublicVirtualCollectionInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("collection").request().get();
+ public void testGetPublicVirtualCollectionInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("collection")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -36,8 +37,15 @@
}
@Test
- public void testGetVirtualCollectionInfoWithAuthentication() throws KustvaktException {
- Response response = target().path(API_VERSION).path("collection").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).get();
+ public void testGetVirtualCollectionInfoWithAuthentication ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("collection")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(node);
@@ -46,32 +54,38 @@
}
@Test
- public void testGetVirtualCollectionInfoById() throws KustvaktException {
- Response response = target().path(API_VERSION).path("collection").path("GOE-VC").request().get();
+ public void testGetVirtualCollectionInfoById () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("collection")
+ .path("GOE-VC").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
assertEquals(node.path("name").asText(), "Goethe Virtual Collection");
- assertEquals(node.path("description").asText(), "Goethe works from 1810");
+ assertEquals(node.path("description").asText(),
+ "Goethe works from 1810");
}
@Test
- public void testGetVirtualCollectionInfoByIdUnauthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("collection").path("WPD15-VC").request().get();
+ public void testGetVirtualCollectionInfoByIdUnauthorized ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("collection")
+ .path("WPD15-VC").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
assertEquals(101, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/2").asText(), "[Cannot found public VirtualCollection with ids: [WPD15-VC]]");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "[Cannot found public VirtualCollection with ids: [WPD15-VC]]");
}
@Test
- public void testGetPublicCorporaInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").request().get();
+ public void testGetPublicCorporaInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -81,8 +95,9 @@
}
@Test
- public void testGetCorpusInfoById() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("WPD13").request().get();
+ public void testGetCorpusInfoById () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("WPD13").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
// System.out.println(ent);
@@ -93,8 +108,9 @@
}
@Test
- public void testGetCorpusInfoById2() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("GOE").request().get();
+ public void testGetCorpusInfoById2 () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("GOE").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -104,8 +120,9 @@
}
@Test
- public void testGetPublicFoundriesInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("foundry").request().get();
+ public void testGetPublicFoundriesInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("foundry").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -115,8 +132,9 @@
}
@Test
- public void testGetFoundryInfoById() throws KustvaktException {
- Response response = target().path(API_VERSION).path("foundry").path("tt").request().get();
+ public void testGetFoundryInfoById () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("foundry")
+ .path("tt").request().get();
String ent = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
@@ -125,15 +143,17 @@
}
@Test
- public void testGetUnexistingCorpusInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("ZUW19").request().get();
+ public void testGetUnexistingCorpusInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("ZUW19").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
assertEquals(101, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/2").asText(), "[Cannot found public Corpus with ids: [ZUW19]]");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "[Cannot found public Corpus with ids: [ZUW19]]");
}
// EM: queries for an unauthorized corpus get the same responses /
@@ -141,14 +161,16 @@
// asking for an unexisting corpus info. Does it need a specific
// exception instead?
@Test
- public void testGetUnauthorizedCorpusInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus").path("BRZ10").request().get();
+ public void testGetUnauthorizedCorpusInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("corpus")
+ .path("BRZ10").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.size());
assertEquals(101, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/2").asText(), "[Cannot found public Corpus with ids: [BRZ10]]");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "[Cannot found public Corpus with ids: [BRZ10]]");
}
}
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 f683f01..9e932fc 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
@@ -35,15 +35,19 @@
@Autowired
private KustvaktConfiguration config;
- private JsonNode requestSearchWithFields(String fields) throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("fields", fields).queryParam("context", "sentence").queryParam("count", "13").request().get();
+ private JsonNode requestSearchWithFields (String fields)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("fields", fields).queryParam("context", "sentence")
+ .queryParam("count", "13").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
return node;
}
- private String createJsonQuery() {
+ private String createJsonQuery () {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=der]", "poliqarp");
s.setCollection("corpusSigle=GOE");
@@ -52,17 +56,20 @@
}
@Test
- public void testApiWelcomeMessage() {
+ public void testApiWelcomeMessage () {
Response response = target().path(API_VERSION).path("").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
String message = response.readEntity(String.class);
assertEquals(message, config.getApiWelcomeMessage());
}
@Test
- public void testSearchShowTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("show-tokens", true).request().get();
+ public void testSearchShowTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", true).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -71,8 +78,11 @@
}
@Test
- public void testSearchDisableSnippet() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("show-snippet", false).queryParam("show-tokens", true).request().get();
+ public void testSearchDisableSnippet () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("show-snippet", false)
+ .queryParam("show-tokens", true).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -81,7 +91,7 @@
}
@Test
- public void testSearchWithField() throws KustvaktException {
+ public void testSearchWithField () throws KustvaktException {
JsonNode node = requestSearchWithFields("author");
assertNotEquals(0, node.at("/matches").size());
assertEquals(node.at("/meta/fields").toString(), "[\"author\"]");
@@ -89,15 +99,18 @@
}
@Test
- public void testSearchWithMultipleFields() throws KustvaktException {
+ public void testSearchWithMultipleFields () throws KustvaktException {
JsonNode node = requestSearchWithFields("author, title");
assertNotEquals(0, node.at("/matches").size());
- assertEquals(node.at("/meta/fields").toString(), "[\"author\",\"title\"]");
+ assertEquals(node.at("/meta/fields").toString(),
+ "[\"author\",\"title\"]");
}
@Test
- public void testSearchQueryPublicCorpora() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchQueryPublicCorpora () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .request().accept(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -105,13 +118,19 @@
assertEquals(node.at("/collection/@type").asText(), "koral:doc");
assertEquals(node.at("/collection/key").asText(), "availability");
assertEquals(node.at("/collection/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
}
@Test
- public void testSearchQueryFailure() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der").queryParam("ql", "poliqarp").queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE").queryParam("count", "13").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchQueryFailure () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der").queryParam("ql", "poliqarp")
+ .queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
+ .queryParam("count", "13").request()
+ .accept(MediaType.APPLICATION_JSON).get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -124,8 +143,12 @@
}
@Test
- public void testSearchQueryWithMeta() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=Bachelor]").queryParam("ql", "poliqarp").queryParam("cutoff", "true").queryParam("count", "5").queryParam("page", "1").queryParam("context", "40-t,30-t").request().get();
+ public void testSearchQueryWithMeta () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=Bachelor]").queryParam("ql", "poliqarp")
+ .queryParam("cutoff", "true").queryParam("count", "5")
+ .queryParam("page", "1").queryParam("context", "40-t,30-t")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -137,14 +160,19 @@
assertEquals(40, node.at("/meta/context/left/1").asInt());
assertEquals(30, node.at("/meta/context/right/1").asInt());
assertEquals(-1, node.at("/meta/totalResults").asInt());
- for (String path : new String[]{"/meta/count", "/meta/startIndex", "/meta/context/left/1", "/meta/context/right/1", "/meta/totalResults", "/meta/itemsPerPage"}) {
+ for (String path : new String[] { "/meta/count", "/meta/startIndex",
+ "/meta/context/left/1", "/meta/context/right/1",
+ "/meta/totalResults", "/meta/itemsPerPage" }) {
assertTrue(node.at(path).isNumber(), path + " should be a number");
}
}
@Test
- public void testSearchQueryFreeExtern() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testSearchQueryFreeExtern () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -153,13 +181,18 @@
assertEquals(node.at("/collection/@type").asText(), "koral:doc");
assertEquals(node.at("/collection/key").asText(), "availability");
assertEquals(node.at("/collection/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
}
@Test
- public void testSearchQueryFreeIntern() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").request().header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32").get();
+ public void testSearchQueryFreeIntern () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .request().header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32")
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -168,13 +201,22 @@
assertEquals(node.at("/collection/@type").asText(), "koral:doc");
assertEquals(node.at("/collection/key").asText(), "availability");
assertEquals(node.at("/collection/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
}
@Test
- public void testSearchQueryExternAuthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testSearchQueryExternAuthorized () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -182,17 +224,31 @@
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/1/operands/0/value").asText(), "ACA.*");
- assertEquals(node.at("/collection/operands/1/operands/1/value").asText(), "QAO-NC");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(
+ node.at("/collection/operands/1/operands/0/value").asText(),
+ "ACA.*");
+ assertEquals(
+ node.at("/collection/operands/1/operands/1/value").asText(),
+ "QAO-NC");
assertEquals(node.at("/collection/operation").asText(), "operation:or");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(PUB)");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(PUB)");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
}
@Test
- public void testSearchQueryInternAuthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32").get();
+ public void testSearchQueryInternAuthorized () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "172.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -200,74 +256,121 @@
assertNotEquals(0, node.path("matches").size());
// System.out.println(node);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/1/operands/0/value").asText(), "ACA.*");
- assertEquals(node.at("/collection/operands/1/operands/1/operands/0/value").asText(), "QAO-NC");
- assertEquals(node.at("/collection/operands/1/operands/1/operands/1/value").asText(), "QAO.*");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(
+ node.at("/collection/operands/1/operands/0/value").asText(),
+ "ACA.*");
+ assertEquals(
+ node.at("/collection/operands/1/operands/1/operands/0/value")
+ .asText(),
+ "QAO-NC");
+ assertEquals(
+ node.at("/collection/operands/1/operands/1/operands/1/value")
+ .asText(),
+ "QAO.*");
assertEquals(node.at("/collection/operation").asText(), "operation:or");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(ALL)");
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(ALL)");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
}
@Test
- public void testSearchWithCorpusQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "corpusTitle=gingko").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchWithCorpusQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "corpusTitle=gingko").request()
+ .accept(MediaType.APPLICATION_JSON).get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
assertEquals(2, node.at("/collection/operands").size());
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/1/value").asText(), "gingko");
- assertEquals(node.at("/collection/operands/1/match").asText(), "match:eq");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(node.at("/collection/operands/1/value").asText(),
+ "gingko");
+ assertEquals(node.at("/collection/operands/1/match").asText(),
+ "match:eq");
assertTrue(node.at("/collection/operands/1/type").isMissingNode());
}
@Test
- public void testSearchQueryWithCollectionQueryAuthorizedWithoutIP() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("cq", "textClass=politik & corpusSigle=BRZ10").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).get();
+ public void testSearchQueryWithCollectionQueryAuthorizedWithoutIP ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "textClass=politik & corpusSigle=BRZ10")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertNotNull(node);
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
// EM: double AND operations
- assertEquals(node.at("/collection/operands/0/key").asText(), "availability");
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/1/operands/0/key").asText(), "textClass");
- assertEquals(node.at("/collection/operands/1/operands/1/key").asText(), "corpusSigle");
+ assertEquals(node.at("/collection/operands/0/key").asText(),
+ "availability");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(node.at("/collection/operands/1/operands/0/key").asText(),
+ "textClass");
+ assertEquals(node.at("/collection/operands/1/operands/1/key").asText(),
+ "corpusSigle");
}
@Test
@Disabled
- public void testSearchQueryAuthorizedWithoutIP() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).get();
+ public void testSearchQueryAuthorizedWithoutIP () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
assertEquals(node.at("/collection/operands/1/value").asText(), "ACA.*");
assertEquals(node.at("/collection/operation").asText(), "operation:or");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(PUB)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(PUB)");
}
@Test
- public void testSearchWithInvalidPage() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("page", "0").request().get();
+ public void testSearchWithInvalidPage () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("page", "0").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "page must start from 1");
}
@Test
- public void testSearchSentenceMeta() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("context", "sentence").request().get();
+ public void testSearchSentenceMeta () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("context", "sentence").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -279,10 +382,11 @@
// EM: The API is disabled
@Disabled
@Test
- public void testSearchSimpleCQL() throws KustvaktException {
+ public void testSearchSimpleCQL () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("(der) or (das)", "CQL");
- Response response = target().path(API_VERSION).path("search").request().post(Entity.json(s.toJSON()));
+ Response response = target().path(API_VERSION).path("search").request()
+ .post(Entity.json(s.toJSON()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -294,39 +398,55 @@
// EM: The API is disabled
@Test
@Disabled
- public void testSearchRawQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").request().post(Entity.json(createJsonQuery()));
+ public void testSearchRawQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search").request()
+ .post(Entity.json(createJsonQuery()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
}
// EM: The API is disabled
@Test
@Disabled
- public void testSearchPostAll() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").request().header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).post(Entity.json(createJsonQuery()));
+ public void testSearchPostAll () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "10.27.0.32")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .post(Entity.json(createJsonQuery()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(ALL)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(ALL)");
}
// EM: The API is disabled
@Test
@Disabled
- public void testSearchPostPublic() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("kustvakt", "kustvakt2015")).post(Entity.json(createJsonQuery()));
+ public void testSearchPostPublic () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("kustvakt",
+ "kustvakt2015"))
+ .post(Entity.json(createJsonQuery()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertNotEquals(0, node.path("matches").size());
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(PUB)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(PUB)");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java
index 1938b51..ef42760 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchNetworkEndpointTest.java
@@ -43,26 +43,41 @@
private String endpointURL = "http://localhost:" + port + "/searchEndpoint";
- public SearchNetworkEndpointTest() throws IOException {
- searchResult = IOUtils.toString(ClassLoader.getSystemResourceAsStream("network-output/search-result.jsonld"), StandardCharsets.UTF_8);
+ public SearchNetworkEndpointTest () throws IOException {
+ searchResult = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "network-output/search-result.jsonld"),
+ StandardCharsets.UTF_8);
}
@BeforeEach
- public void startMockServer() {
+ public void startMockServer () {
mockServer = startClientAndServer(port);
mockClient = new MockServerClient("localhost", mockServer.getPort());
}
@AfterEach
- public void stopMockServer() {
+ public void stopMockServer () {
mockServer.stop();
}
@Test
- public void testSearchNetwork() throws IOException, KustvaktException, URISyntaxException {
+ public void testSearchNetwork ()
+ throws IOException, KustvaktException, URISyntaxException {
config.setNetworkEndpointURL(endpointURL);
- mockClient.reset().when(request().withMethod("POST").withPath("/searchEndpoint").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(searchResult).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/searchEndpoint")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(searchResult).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -70,22 +85,29 @@
}
@Test
- public void testSearchWithUnknownURL() throws IOException, KustvaktException {
+ public void testSearchWithUnknownURL ()
+ throws IOException, KustvaktException {
config.setNetworkEndpointURL("http://localhost:1040/search");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testSearchWithUnknownHost() throws KustvaktException {
+ public void testSearchWithUnknownHost () throws KustvaktException {
config.setNetworkEndpointURL("http://search.com");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
index 9591933..03a019e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPipeTest.java
@@ -45,29 +45,43 @@
private String glemmUri = "http://localhost:" + port + "/glemm";
- public SearchPipeTest() throws URISyntaxException, IOException {
- pipeJson = IOUtils.toString(ClassLoader.getSystemResourceAsStream("pipe-output/test-pipes.jsonld"), StandardCharsets.UTF_8);
- pipeWithParamJson = IOUtils.toString(ClassLoader.getSystemResourceAsStream("pipe-output/with-param.jsonld"), StandardCharsets.UTF_8);
+ public SearchPipeTest () throws URISyntaxException, IOException {
+ pipeJson = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "pipe-output/test-pipes.jsonld"),
+ StandardCharsets.UTF_8);
+ pipeWithParamJson = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "pipe-output/with-param.jsonld"),
+ StandardCharsets.UTF_8);
}
@BeforeEach
- public void startMockServer() {
+ public void startMockServer () {
mockServer = startClientAndServer(port);
mockClient = new MockServerClient("localhost", mockServer.getPort());
}
@AfterEach
- public void stopMockServer() {
+ public void stopMockServer () {
mockServer.stop();
}
@Test
- public void testMockServer() throws IOException {
- mockClient.reset().when(request().withMethod("POST").withPath("/test").withHeader(new Header("Content-Type", "application/json; charset=utf-8"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody("{test}").withStatusCode(200));
+ public void testMockServer () throws IOException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/test")
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody("{test}").withStatusCode(200));
URL url = new URL("http://localhost:" + port + "/test");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+ connection.setRequestProperty("Content-Type",
+ "application/json; charset=UTF-8");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
String json = "{\"name\" : \"dory\"}";
@@ -76,21 +90,36 @@
os.write(input, 0, input.length);
}
assertEquals(200, connection.getResponseCode());
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
+ BufferedReader br = new BufferedReader(
+ new InputStreamReader(connection.getInputStream(), "utf-8"));
assertEquals(br.readLine(), "{test}");
}
@Test
- public void testSearchWithPipes() throws IOException, KustvaktException, URISyntaxException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri).request().get();
+ public void testSearchWithPipes ()
+ throws IOException, KustvaktException, URISyntaxException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
assertEquals(1, node.at("/collection/rewrites").size());
- assertEquals(node.at("/collection/rewrites/0/operation").asText(), "operation:insertion");
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(FREE)");
+ assertEquals(node.at("/collection/rewrites/0/operation").asText(),
+ "operation:insertion");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(FREE)");
node = node.at("/query/wrap/rewrites");
assertEquals(2, node.size());
assertEquals(node.at("/0/src").asText(), "Glemm");
@@ -102,20 +131,44 @@
}
@Test
- public void testSearchWithUrlEncodedPipes() throws IOException, KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
+ public void testSearchWithUrlEncodedPipes ()
+ throws IOException, KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
glemmUri = URLEncoder.encode(glemmUri, "utf-8");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri).request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
}
@Test
- public void testSearchWithMultiplePipes() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withQueryStringParameter("param").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeWithParamJson).withStatusCode(200));
+ public void testSearchWithMultiplePipes () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withQueryStringParameter("param").withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeWithParamJson).withStatusCode(200));
String glemmUri2 = glemmUri + "?param=blah";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri + "," + glemmUri2).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri + "," + glemmUri2).request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -123,9 +176,13 @@
}
@Test
- public void testSearchWithUnknownURL() throws IOException, KustvaktException {
- String url = target().getUri().toString() + API_VERSION + "/test/tralala";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", url).request().get();
+ public void testSearchWithUnknownURL ()
+ throws IOException, KustvaktException {
+ String url = target().getUri().toString() + API_VERSION
+ + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", url).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -134,8 +191,10 @@
}
@Test
- public void testSearchWithUnknownHost() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", "http://glemm").request().get();
+ public void testSearchWithUnknownHost () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", "http://glemm").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -144,21 +203,30 @@
}
@Test
- public void testSearchUnsupportedMediaType() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/non-json-pipe")).respond(response().withStatusCode(415));
+ public void testSearchUnsupportedMediaType () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/non-json-pipe"))
+ .respond(response().withStatusCode(415));
String pipeUri = "http://localhost:" + port + "/non-json-pipe";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/3").asText(), "415 Unsupported Media Type");
+ assertEquals(node.at("/warnings/0/3").asText(),
+ "415 Unsupported Media Type");
}
@Test
- public void testSearchWithMultiplePipeWarnings() throws KustvaktException {
- String url = target().getUri().toString() + API_VERSION + "/test/tralala";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", url + "," + "http://glemm").request().get();
+ public void testSearchWithMultiplePipeWarnings () throws KustvaktException {
+ String url = target().getUri().toString() + API_VERSION
+ + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", url + "," + "http://glemm").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -172,37 +240,73 @@
}
@Test
- public void testSearchWithInvalidJsonResponse() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/invalid-response").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withBody("{blah:}").withStatusCode(200).withHeaders(new Header("Content-Type", "application/json; charset=utf-8")));
+ public void testSearchWithInvalidJsonResponse () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/invalid-response")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response().withBody("{blah:}").withStatusCode(200)
+ .withHeaders(new Header("Content-Type",
+ "application/json; charset=utf-8")));
String pipeUri = "http://localhost:" + port + "/invalid-response";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testSearchWithPlainTextResponse() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/plain-text").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withBody("blah").withStatusCode(200));
+ public void testSearchWithPlainTextResponse () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/plain-text")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response().withBody("blah").withStatusCode(200));
String pipeUri = "http://localhost:" + port + "/plain-text";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testSearchWithMultipleAndUnknownPipes() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", "http://unknown" + "," + glemmUri).request().get();
+ public void testSearchWithMultipleAndUnknownPipes ()
+ throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", "http://unknown" + "," + glemmUri)
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
assertTrue(node.at("/warnings").isMissingNode());
- response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri + ",http://unknown").request().get();
+ response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri + ",http://unknown").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
index 1d1db61..aeec05e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchPublicMetadataTest.java
@@ -22,53 +22,73 @@
public class SearchPublicMetadataTest extends SpringJerseyTest {
@Test
- public void testSearchPublicMetadata() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadata () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(ALL)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(ALL)");
assertTrue(node.at("/matches/0/snippet").isMissingNode());
}
@Test
- public void testSearchPublicMetadataExtern() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("access-rewrite-disabled", "true").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testSearchPublicMetadataExtern () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(ALL)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(ALL)");
assertTrue(node.at("/matches/0/snippet").isMissingNode());
}
@Test
- public void testSearchPublicMetadataWithCustomFields() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("fields", "author,title").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithCustomFields ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,title")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(ALL)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(ALL)");
assertTrue(node.at("/matches/0/snippet").isMissingNode());
- assertEquals(node.at("/matches/0/author").asText(), "Goethe, Johann Wolfgang von");
- assertEquals(node.at("/matches/0/title").asText(), "Italienische Reise");
+ assertEquals(node.at("/matches/0/author").asText(),
+ "Goethe, Johann Wolfgang von");
+ assertEquals(node.at("/matches/0/title").asText(),
+ "Italienische Reise");
// assertEquals(3, node.at("/matches/0").size());
}
@Test
- public void testSearchPublicMetadataWithNonPublicField() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("fields", "author,title,snippet").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithNonPublicField ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,title,snippet")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "The requested non public fields are ignored");
+ assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED,
+ node.at("/warnings/0/0").asInt());
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "The requested non public fields are ignored");
assertEquals(node.at("/warnings/0/2").asText(), "snippet");
}
// EM: The API is disabled
@Disabled
@Test
- public void testSearchPostPublicMetadata() throws KustvaktException {
+ public void testSearchPostPublicMetadata () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=der]", "poliqarp");
s.setCollection("corpusSigle=GOE");
@@ -76,39 +96,55 @@
MetaQueryBuilder meta = new MetaQueryBuilder();
meta.addEntry("snippets", "true");
s.setMeta(meta);
- Response response = target().path(API_VERSION).path("search").request().post(Entity.json(s.toJSON()));
+ Response response = target().path(API_VERSION).path("search").request()
+ .post(Entity.json(s.toJSON()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(node.at("/collection/rewrites/0/scope").asText(), "availability(ALL)");
+ assertEquals(node.at("/collection/rewrites/0/scope").asText(),
+ "availability(ALL)");
assertTrue(node.at("/matches/0/snippet").isMissingNode());
}
@Test
- public void testSearchPublicMetadataWithSystemVC() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("cq", "referTo system-vc").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithSystemVC ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo system-vc")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
node = node.at("/collection/operands/1");
assertEquals(node.at("/@type").asText(), "koral:doc");
assertEquals(node.at("/value").asText(), "GOE");
assertEquals(node.at("/match").asText(), "match:eq");
assertEquals(node.at("/key").asText(), "corpusSigle");
- assertEquals(node.at("/rewrites/0/operation").asText(), "operation:deletion");
- assertEquals(node.at("/rewrites/0/scope").asText(), "@type(koral:docGroupRef)");
- assertEquals(node.at("/rewrites/1/operation").asText(), "operation:deletion");
+ assertEquals(node.at("/rewrites/0/operation").asText(),
+ "operation:deletion");
+ assertEquals(node.at("/rewrites/0/scope").asText(),
+ "@type(koral:docGroupRef)");
+ assertEquals(node.at("/rewrites/1/operation").asText(),
+ "operation:deletion");
assertEquals(node.at("/rewrites/1/scope").asText(), "ref(system-vc)");
- assertEquals(node.at("/rewrites/2/operation").asText(), "operation:insertion");
+ assertEquals(node.at("/rewrites/2/operation").asText(),
+ "operation:insertion");
}
@Test
- public void testSearchPublicMetadataWithPrivateVC() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"dory/dory-vc\"").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithPrivateVC ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"dory/dory-vc\"")
+ .queryParam("access-rewrite-disabled", "true").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/2").asText(), "guest");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
index c0e9fa7..e115f90 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchTokenSnippetTest.java
@@ -18,8 +18,12 @@
public class SearchTokenSnippetTest extends SpringJerseyTest {
@Test
- public void testSearchWithTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("show-tokens", "true").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchWithTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -31,8 +35,12 @@
}
@Test
- public void testSearchWithoutTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("show-tokens", "false").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchWithoutTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "false")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -42,8 +50,13 @@
}
@Test
- public void testSearchPublicMetadataWithTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("access-rewrite-disabled", "true").queryParam("show-tokens", "true").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchPublicMetadataWithTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
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 8bcb604..ecdad64 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
@@ -25,11 +25,14 @@
public class StatisticsControllerTest extends SpringJerseyTest {
@Test
- public void testGetStatisticsNoResource() throws IOException, KustvaktException {
+ public void testGetStatisticsNoResource ()
+ throws IOException, KustvaktException {
String corpusQuery = "corpusSigle=WPD15";
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", corpusQuery).request().get();
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", corpusQuery).request().get();
assert Status.OK.getStatusCode() == response.getStatus();
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.get("documents").asInt(), 0);
@@ -37,8 +40,10 @@
}
@Test
- public void testStatisticsWithCq() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCq () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -50,8 +55,12 @@
}
@Test
- public void testStatisticsWithCqAndCorpusQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung & corpusSigle=GOE").queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCqAndCorpusQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
+ .queryParam("corpusQuery",
+ "textType=Autobiographie & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -63,21 +72,27 @@
}
@Test
- public void testGetStatisticsWithcorpusQuery1() throws IOException, KustvaktException {
+ public void testGetStatisticsWithcorpusQuery1 ()
+ throws IOException, KustvaktException {
String corpusQuery = "corpusSigle=GOE";
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", corpusQuery).request().get();
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", corpusQuery).request().get();
assert Status.OK.getStatusCode() == response.getStatus();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.get("documents").asInt(), 11);
assertEquals(node.get("tokens").asInt(), 665842);
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "Parameter corpusQuery is deprecated in favor of cq.");
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "Parameter corpusQuery is deprecated in favor of cq.");
}
@Test
- public void testGetStatisticsWithcorpusQuery2() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "creationDate since 1810").request().get();
+ public void testGetStatisticsWithcorpusQuery2 ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "creationDate since 1810").request()
+ .get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assert Status.OK.getStatusCode() == response.getStatus();
@@ -88,30 +103,41 @@
}
@Test
- public void testGetStatisticsWithWrongcorpusQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "creationDate geq 1810").request().get();
+ public void testGetStatisticsWithWrongcorpusQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "creationDate geq 1810").request()
+ .get();
assert Status.BAD_REQUEST.getStatusCode() == response.getStatus();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(), 302);
- assertEquals(node.at("/errors/0/1").asText(), "Could not parse query >>> (creationDate geq 1810) <<<.");
- assertEquals(node.at("/errors/0/2").asText(), "(creationDate geq 1810)");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Could not parse query >>> (creationDate geq 1810) <<<.");
+ assertEquals(node.at("/errors/0/2").asText(),
+ "(creationDate geq 1810)");
}
@Test
- public void testGetStatisticsWithWrongcorpusQuery2() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "creationDate >= 1810").request().get();
+ public void testGetStatisticsWithWrongcorpusQuery2 ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "creationDate >= 1810").request()
+ .get();
String ent = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(), 305);
- assertEquals(node.at("/errors/0/1").asText(), "Operator >= is not acceptable.");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Operator >= is not acceptable.");
assertEquals(node.at("/errors/0/2").asText(), ">=");
}
@Test
- public void testGetStatisticsWithoutcorpusQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().get();
+ public void testGetStatisticsWithoutcorpusQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -122,9 +148,17 @@
}
@Test
- public void testGetStatisticsWithKoralQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{ \"collection\" : {\"@type\": " + "\"koral:doc\", \"key\": \"availability\", \"match\": " + "\"match:eq\", \"type\": \"type:regex\", \"value\": " + "\"CC-BY.*\"} }"));
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ public void testGetStatisticsWithKoralQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{ \"collection\" : {\"@type\": "
+ + "\"koral:doc\", \"key\": \"availability\", \"match\": "
+ + "\"match:eq\", \"type\": \"type:regex\", \"value\": "
+ + "\"CC-BY.*\"} }"));
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -135,28 +169,42 @@
}
@Test
- public void testGetStatisticsWithEmptyCollection() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{}"));
+ public void testGetStatisticsWithEmptyCollection ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{}"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(node.at("/errors/0/0").asInt(), de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
- assertEquals(node.at("/errors/0/1").asText(), "Collection is not found");
+ assertEquals(node.at("/errors/0/0").asInt(),
+ de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Collection is not found");
}
@Test
- public void testGetStatisticsWithIncorrectJson() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{ \"collection\" : }"));
+ public void testGetStatisticsWithIncorrectJson ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{ \"collection\" : }"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Failed deserializing json object: { \"collection\" : }");
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Failed deserializing json object: { \"collection\" : }");
}
@Test
- public void testGetStatisticsWithoutKoralQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().post(Entity.json(""));
+ public void testGetStatisticsWithoutKoralQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request().post(Entity.json(""));
String ent = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java
index 7cc5e6f..1d130b6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/TokenExpiryTest.java
@@ -32,14 +32,19 @@
@Disabled
@Test
- public void requestToken() throws KustvaktException, InterruptedException, IOException {
+ public void requestToken ()
+ throws KustvaktException, InterruptedException, IOException {
Form form = new Form();
form.param("grant_type", "password");
form.param("client_id", "fCBbQkAyYzI4NzUxMg");
form.param("client_secret", "secret");
form.param("username", "dory");
form.param("password", "password");
- Response response = target().path(API_VERSION).path("oauth2").path("token").request().header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("token").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
String token = node.at("/access_token").asText();
@@ -53,17 +58,23 @@
// because sqlite needs a trigger after INSERT to
// oauth_access_token to store created_date. Before INSERT trigger
// does not work.
- private void testSearchWithExpiredToken(String token) throws KustvaktException, IOException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Wasser").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, "Bearer " + token).get();
+ private void testSearchWithExpiredToken (String token)
+ throws KustvaktException, IOException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Wasser").queryParam("ql", "poliqarp")
+ .request().header(Attributes.AUTHORIZATION, "Bearer " + token)
+ .get();
String ent = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
assertEquals(StatusCodes.EXPIRED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Access token is expired");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Access token is expired");
}
// cannot be tested dynamically
- private void testRequestAuthorizationCodeAuthenticationTooOld(String token) throws KustvaktException {
+ private void testRequestAuthorizationCodeAuthenticationTooOld (String token)
+ throws KustvaktException {
Form form = new Form();
form.param("response_type", "code");
form.param("client_id", "fCBbQkAyYzI4NzUxMg");
@@ -72,19 +83,22 @@
form.param("scope", "search");
form.param("max_age", "1");
- Response response =
- target().path(API_VERSION).path("oauth2").path("authorize")
- .request()
- .header(Attributes.AUTHORIZATION, "Bearer " + token)
- .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
- .header(HttpHeaders.CONTENT_TYPE,
- ContentType.APPLICATION_FORM_URLENCODED)
- .post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("oauth2")
+ .path("authorize").request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + token)
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ ContentType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(form));
assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.USER_REAUTHENTICATION_REQUIRED, node.at("/errors/0/0").asInt());
- assertEquals("User reauthentication is required because the authentication " + "time is too old according to max_age", node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.USER_REAUTHENTICATION_REQUIRED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "User reauthentication is required because the authentication "
+ + "time is too old according to max_age",
+ node.at("/errors/0/1").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
index 4ecbe46..27c8512 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserControllerTest.java
@@ -25,11 +25,12 @@
private String userAuthHeader;
- public UserControllerTest() throws KustvaktException {
- userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "password");
+ public UserControllerTest () throws KustvaktException {
+ userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "password");
}
- private OAuth2ClientJson createOAuth2Client() {
+ private OAuth2ClientJson createOAuth2Client () {
OAuth2ClientJson client = new OAuth2ClientJson();
client.setName("OWID client");
client.setType(OAuth2ClientType.PUBLIC);
@@ -38,7 +39,8 @@
return client;
}
- private String registerClient() throws ProcessingException, KustvaktException {
+ private String registerClient ()
+ throws ProcessingException, KustvaktException {
OAuth2ClientJson clientJson = createOAuth2Client();
Response response = registerClient(username, clientJson);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
@@ -46,10 +48,13 @@
return clientId;
}
- private String requestOAuth2AccessToken(String clientId) throws KustvaktException {
- Response response = requestAuthorizationCode("code", clientId, "", "user_info", "", userAuthHeader);
+ private String requestOAuth2AccessToken (String clientId)
+ throws KustvaktException {
+ Response response = requestAuthorizationCode("code", clientId, "",
+ "user_info", "", userAuthHeader);
String code = parseAuthorizationCode(response);
- response = requestTokenWithAuthorizationCodeAndForm(clientId, null, code);
+ response = requestTokenWithAuthorizationCodeAndForm(clientId, null,
+ code);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -58,10 +63,13 @@
}
@Test
- public void getUsername() throws ProcessingException, KustvaktException {
+ public void getUsername () throws ProcessingException, KustvaktException {
String clientId = registerClient();
String accessToken = requestOAuth2AccessToken(clientId);
- Response response = target().path(API_VERSION).path("user").path("info").request().header(Attributes.AUTHORIZATION, "Bearer " + accessToken).get();
+ Response response = target().path(API_VERSION).path("user").path("info")
+ .request()
+ .header(Attributes.AUTHORIZATION, "Bearer " + accessToken)
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
index 99cf31a..aa6a4c6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserGroupControllerAdminTest.java
@@ -32,8 +32,12 @@
private String testUser = "group-admin";
- private JsonNode listGroup(String username) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ private JsonNode listGroup (String username)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -41,11 +45,15 @@
}
@Test
- public void testListUserGroupsUsingAdminToken() throws KustvaktException {
+ public void testListUserGroupsUsingAdminToken () throws KustvaktException {
Form f = new Form();
f.param("username", "dory");
f.param("token", "secret");
- Response response = target().path(API_VERSION).path("admin").path("group").path("list").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("list").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -75,22 +83,38 @@
// assertEquals(3, node.size());
// }
@Test
- public void testListUserGroupsUnauthorized() throws KustvaktException {
+ public void testListUserGroupsUnauthorized () throws KustvaktException {
Form f = new Form();
f.param("username", "dory");
- Response response = target().path(API_VERSION).path("admin").path("group").path("list").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("list").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testListUserGroupsWithStatus() throws KustvaktException {
+ public void testListUserGroupsWithStatus () throws KustvaktException {
Form f = new Form();
f.param("username", "dory");
f.param("status", "ACTIVE");
- Response response = target().path(API_VERSION).path("admin").path("group").path("list").queryParam("username", "dory").queryParam("status", "ACTIVE").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("list").queryParam("username", "dory")
+ .queryParam("status", "ACTIVE").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
// System.out.println(entity);
@@ -100,16 +124,31 @@
// same as list user-groups of the admin
@Test
- public void testListWithoutUsername() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testListWithoutUsername ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
assertEquals(entity, "[]");
}
@Test
- public void testListByStatusAll() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("admin").path("group").path("list").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(null);
+ public void testListByStatusAll ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("list").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(null);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -123,10 +162,21 @@
}
@Test
- public void testListByStatusHidden() throws ProcessingException, KustvaktException {
+ public void testListByStatusHidden ()
+ throws ProcessingException, KustvaktException {
Form f = new Form();
f.param("status", "HIDDEN");
- Response response = target().path(API_VERSION).path("admin").path("group").path("list").queryParam("status", "HIDDEN").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("list").queryParam("status", "HIDDEN")
+ .request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -135,9 +185,17 @@
}
@Test
- public void testUserGroupAdmin() throws ProcessingException, KustvaktException {
+ public void testUserGroupAdmin ()
+ throws ProcessingException, KustvaktException {
String groupName = "admin-test-group";
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "password")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").put(Entity.form(new Form()));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser,
+ "password"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .put(Entity.form(new Form()));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
// list user group
JsonNode node = listGroup(testUser);
@@ -150,22 +208,38 @@
testDeleteGroup(groupName);
}
- private void testMemberRole(String memberUsername, String groupName) throws ProcessingException, KustvaktException {
+ private void testMemberRole (String memberUsername, String groupName)
+ throws ProcessingException, KustvaktException {
// accept invitation
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("subscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(memberUsername, "pass")).post(Entity.form(new Form()));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("subscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ memberUsername, "pass"))
+ .post(Entity.form(new Form()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
testAddMemberRoles(groupName, memberUsername);
testDeleteMemberRoles(groupName, memberUsername);
}
- private void testAddMemberRoles(String groupName, String memberUsername) throws ProcessingException, KustvaktException {
+ private void testAddMemberRoles (String groupName, String memberUsername)
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("memberUsername", memberUsername);
// USER_GROUP_ADMIN
form.param("roleId", "1");
// USER_GROUP_MEMBER
form.param("roleId", "2");
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("role").path("add").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "password")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("role").path("add").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "password"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = retrieveGroup(groupName).at("/members");
JsonNode member;
@@ -173,18 +247,27 @@
member = node.get(i);
if (member.at("/userId").asText().equals(memberUsername)) {
assertEquals(3, member.at("/roles").size());
- assertEquals(PredefinedRole.USER_GROUP_ADMIN.name(), member.at("/roles/0").asText());
+ assertEquals(PredefinedRole.USER_GROUP_ADMIN.name(),
+ member.at("/roles/0").asText());
break;
}
}
}
- private void testDeleteMemberRoles(String groupName, String memberUsername) throws ProcessingException, KustvaktException {
+ private void testDeleteMemberRoles (String groupName, String memberUsername)
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("memberUsername", memberUsername);
// USER_GROUP_ADMIN
form.param("roleId", "1");
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("role").path("delete").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "password")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("role").path("delete").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "password"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = retrieveGroup(groupName).at("/members");
JsonNode member;
@@ -197,46 +280,77 @@
}
}
- private JsonNode retrieveGroup(String groupName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("admin").path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").post(null);
+ private JsonNode retrieveGroup (String groupName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").post(null);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
- private void testDeleteGroup(String groupName) throws ProcessingException, KustvaktException {
+ private void testDeleteGroup (String groupName)
+ throws ProcessingException, KustvaktException {
// delete group
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// check group
JsonNode node = listGroup(testUser);
assertEquals(0, node.size());
}
- private void testDeleteMember(String groupName) throws ProcessingException, KustvaktException {
+ private void testDeleteMember (String groupName)
+ throws ProcessingException, KustvaktException {
// delete marlin from group
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("~marlin").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("~marlin").request()
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// check group member
JsonNode node = listGroup(testUser);
node = node.get(0);
assertEquals(3, node.get("members").size());
assertEquals(node.at("/members/1/userId").asText(), "nemo");
- assertEquals(GroupMemberStatus.PENDING.name(), node.at("/members/1/status").asText());
+ assertEquals(GroupMemberStatus.PENDING.name(),
+ node.at("/members/1/status").asText());
}
- private void testInviteMember(String groupName) throws ProcessingException, KustvaktException {
+ private void testInviteMember (String groupName)
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("members", "marlin,nemo,darla");
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("invite").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(sysAdminUser, "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("invite").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION,
+ HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(
+ sysAdminUser, "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list group
JsonNode node = listGroup(testUser);
node = node.get(0);
assertEquals(4, node.get("members").size());
assertEquals(node.at("/members/3/userId").asText(), "darla");
- assertEquals(GroupMemberStatus.PENDING.name(), node.at("/members/1/status").asText());
+ assertEquals(GroupMemberStatus.PENDING.name(),
+ node.at("/members/1/status").asText());
assertEquals(0, node.at("/members/1/roles").size());
}
}
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 52e3bb3..5495c85 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
@@ -40,22 +40,33 @@
private String admin = "admin";
- private JsonNode retrieveUserGroups(String username) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ private JsonNode retrieveUserGroups (String username)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
return JsonUtils.readTree(entity);
}
- private void deleteGroupByName(String groupName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ private void deleteGroupByName (String groupName) throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
// dory is a group admin in dory-group
@Test
- public void testListDoryGroups() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testListDoryGroups () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -69,8 +80,11 @@
// nemo is a group member in dory-group
@Test
- public void testListNemoGroups() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("nemo", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testListNemoGroups () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("nemo", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// System.out.println(entity);
@@ -84,8 +98,11 @@
// marlin has 2 groups
@Test
- public void testListMarlinGroups() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testListMarlinGroups () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
@@ -93,17 +110,21 @@
}
@Test
- public void testListGroupGuest() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testListGroupGuest () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Unauthorized operation for user: guest");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: guest");
}
@Test
- public void testCreateGroupEmptyDescription() throws ProcessingException, KustvaktException {
+ public void testCreateGroupEmptyDescription ()
+ throws ProcessingException, KustvaktException {
String groupName = "empty_group";
Response response = testCreateUserGroup(groupName, "");
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
@@ -111,50 +132,68 @@
}
@Test
- public void testCreateGroupMissingDescription() throws ProcessingException, KustvaktException {
+ public void testCreateGroupMissingDescription ()
+ throws ProcessingException, KustvaktException {
String groupName = "missing-desc-group";
Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
deleteGroupByName(groupName);
}
- private Response testCreateUserGroup(String groupName, String description) throws ProcessingException, KustvaktException {
+ private Response testCreateUserGroup (String groupName, String description)
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("description", description);
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").put(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .put(Entity.form(form));
return response;
}
- private Response testCreateGroupWithoutDescription(String groupName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").put(Entity.form(new Form()));
+ private Response testCreateGroupWithoutDescription (String groupName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .put(Entity.form(new Form()));
return response;
}
@Test
- public void testCreateGroupInvalidName() throws ProcessingException, KustvaktException {
+ public void testCreateGroupInvalidName ()
+ throws ProcessingException, KustvaktException {
String groupName = "invalid-group-name$";
Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
// assertEquals("User-group name must only contains letters, numbers, "
// + "underscores, hypens and spaces", node.at("/errors/0/1").asText());
assertEquals(node.at("/errors/0/2").asText(), "invalid-group-name$");
}
@Test
- public void testCreateGroupNameTooShort() throws ProcessingException, KustvaktException {
+ public void testCreateGroupNameTooShort ()
+ throws ProcessingException, KustvaktException {
String groupName = "a";
Response response = testCreateGroupWithoutDescription(groupName);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "groupName must contain at least 3 characters");
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "groupName must contain at least 3 characters");
assertEquals(node.at("/errors/0/2").asText(), "groupName");
}
@Test
- public void testUserGroup() throws ProcessingException, KustvaktException {
+ public void testUserGroup () throws ProcessingException, KustvaktException {
String groupName = "new-user-group";
String description = "This is new-user-group.";
Response response = testCreateUserGroup(groupName, description);
@@ -171,9 +210,12 @@
assertEquals(username, node.get("owner").asText());
assertEquals(1, node.get("members").size());
assertEquals(username, node.at("/members/0/userId").asText());
- assertEquals(GroupMemberStatus.ACTIVE.name(), node.at("/members/0/status").asText());
- assertEquals(PredefinedRole.VC_ACCESS_ADMIN.name(), node.at("/members/0/roles/1").asText());
- assertEquals(PredefinedRole.USER_GROUP_ADMIN.name(), node.at("/members/0/roles/0").asText());
+ assertEquals(GroupMemberStatus.ACTIVE.name(),
+ node.at("/members/0/status").asText());
+ assertEquals(PredefinedRole.VC_ACCESS_ADMIN.name(),
+ node.at("/members/0/roles/1").asText());
+ assertEquals(PredefinedRole.USER_GROUP_ADMIN.name(),
+ node.at("/members/0/roles/0").asText());
testUpdateUserGroup(groupName);
testInviteMember(groupName);
testDeleteMemberUnauthorized(groupName);
@@ -183,7 +225,8 @@
testUnsubscribeToDeletedGroup(groupName);
}
- private void testUpdateUserGroup(String groupName) throws ProcessingException, KustvaktException {
+ private void testUpdateUserGroup (String groupName)
+ throws ProcessingException, KustvaktException {
String description = "Description is updated.";
Response response = testCreateUserGroup(groupName, description);
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -192,32 +235,52 @@
assertEquals(description, node.get(0).get("description").asText());
}
- private void testDeleteMember(String groupName) throws ProcessingException, KustvaktException {
+ private void testDeleteMember (String groupName)
+ throws ProcessingException, KustvaktException {
// delete darla from group
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("~darla").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("~darla").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
// check group member
- response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
node = node.get(0);
assertEquals(1, node.get("members").size());
}
- private void testDeleteMemberUnauthorized(String groupName) throws ProcessingException, KustvaktException {
+ private void testDeleteMemberUnauthorized (String groupName)
+ throws ProcessingException, KustvaktException {
// nemo is a group member
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("~darla").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("nemo", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("~darla").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("nemo", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Unauthorized operation for user: nemo");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: nemo");
}
// EM: same as cancel invitation
- private void testDeletePendingMember() throws ProcessingException, KustvaktException {
+ private void testDeletePendingMember ()
+ throws ProcessingException, KustvaktException {
// dory delete pearl
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("~pearl").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("~pearl").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// check member
JsonNode node = retrieveUserGroups("pearl");
@@ -225,20 +288,32 @@
}
@Test
- public void testDeleteDeletedMember() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("~pearl").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ public void testDeleteDeletedMember ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("~pearl").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.GROUP_MEMBER_DELETED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "pearl has already been deleted from the group dory-group");
+ assertEquals(StatusCodes.GROUP_MEMBER_DELETED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "pearl has already been deleted from the group dory-group");
assertEquals(node.at("/errors/0/2").asText(), "[pearl, dory-group]");
}
- private void testDeleteGroup(String groupName) throws ProcessingException, KustvaktException {
+ private void testDeleteGroup (String groupName)
+ throws ProcessingException, KustvaktException {
// delete group
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
Form f = new Form();
f.param("username", username);
@@ -246,7 +321,13 @@
// EM: this is so complicated because the group retrieval are not allowed
// for delete groups
// check group
- response = target().path(API_VERSION).path("admin").path("group").path("list").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ response = target().path(API_VERSION).path("admin").path("group")
+ .path("list").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -254,136 +335,214 @@
JsonNode group = node.get(j);
// check group members
for (int i = 0; i < group.at("/0/members").size(); i++) {
- assertEquals(GroupMemberStatus.DELETED.name(), group.at("/0/members/" + i + "/status").asText());
+ assertEquals(GroupMemberStatus.DELETED.name(),
+ group.at("/0/members/" + i + "/status").asText());
}
}
}
@Test
- public void testDeleteGroupUnauthorized() throws ProcessingException, KustvaktException {
+ public void testDeleteGroupUnauthorized ()
+ throws ProcessingException, KustvaktException {
// dory is a group admin in marlin-group
- Response response = target().path(API_VERSION).path("group").path("@marlin-group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@marlin-group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Unauthorized operation for user: dory");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: dory");
}
@Test
- public void testDeleteDeletedGroup() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@deleted-group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ public void testDeleteDeletedGroup ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@deleted-group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Group deleted-group has been deleted.");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Group deleted-group has been deleted.");
assertEquals(node.at("/errors/0/2").asText(), "deleted-group");
}
@Test
- public void testDeleteGroupOwner() throws ProcessingException, KustvaktException {
+ public void testDeleteGroupOwner ()
+ throws ProcessingException, KustvaktException {
// delete marlin from marlin-group
// dory is a group admin in marlin-group
- Response response = target().path(API_VERSION).path("group").path("@marlin-group").path("~marlin").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@marlin-group").path("~marlin").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").delete();
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(StatusCodes.NOT_ALLOWED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Operation 'delete group owner'is not allowed.");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Operation 'delete group owner'is not allowed.");
}
- private void testInviteMember(String groupName) throws ProcessingException, KustvaktException {
+ private void testInviteMember (String groupName)
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("members", "darla");
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("invite").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("invite").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list group
- response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
node = node.get(0);
assertEquals(2, node.get("members").size());
assertEquals(node.at("/members/1/userId").asText(), "darla");
- assertEquals(GroupMemberStatus.PENDING.name(), node.at("/members/1/status").asText());
+ assertEquals(GroupMemberStatus.PENDING.name(),
+ node.at("/members/1/status").asText());
assertEquals(0, node.at("/members/1/roles").size());
}
- private void testInviteDeletedMember() throws ProcessingException, KustvaktException {
+ private void testInviteDeletedMember ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("members", "marlin");
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("invite").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("invite").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// check member
JsonNode node = retrieveUserGroups("marlin");
assertEquals(2, node.size());
JsonNode group = node.get(1);
- assertEquals(GroupMemberStatus.PENDING.name(), group.at("/userMemberStatus").asText());
+ assertEquals(GroupMemberStatus.PENDING.name(),
+ group.at("/userMemberStatus").asText());
}
@Test
- public void testInviteDeletedMember2() throws ProcessingException, KustvaktException {
+ public void testInviteDeletedMember2 ()
+ throws ProcessingException, KustvaktException {
// pearl has status deleted in dory-group
Form form = new Form();
form.param("members", "pearl");
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("invite").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("invite").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// check member
JsonNode node = retrieveUserGroups("pearl");
assertEquals(1, node.size());
JsonNode group = node.get(0);
- assertEquals(GroupMemberStatus.PENDING.name(), group.at("/userMemberStatus").asText());
+ assertEquals(GroupMemberStatus.PENDING.name(),
+ group.at("/userMemberStatus").asText());
testDeletePendingMember();
}
@Test
- public void testInvitePendingMember() throws ProcessingException, KustvaktException {
+ public void testInvitePendingMember ()
+ throws ProcessingException, KustvaktException {
// marlin has status PENDING in dory-group
Form form = new Form();
form.param("members", "marlin");
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("invite").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("invite").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .post(Entity.form(form));
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.GROUP_MEMBER_EXISTS, node.at("/errors/0/0").asInt());
- assertEquals("Username marlin with status PENDING exists in the user-group " + "dory-group", node.at("/errors/0/1").asText());
- assertEquals(node.at("/errors/0/2").asText(), "[marlin, PENDING, dory-group]");
+ assertEquals(StatusCodes.GROUP_MEMBER_EXISTS,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "Username marlin with status PENDING exists in the user-group "
+ + "dory-group",
+ node.at("/errors/0/1").asText());
+ assertEquals(node.at("/errors/0/2").asText(),
+ "[marlin, PENDING, dory-group]");
}
@Test
- public void testInviteActiveMember() throws ProcessingException, KustvaktException {
+ public void testInviteActiveMember ()
+ throws ProcessingException, KustvaktException {
// nemo has status active in dory-group
Form form = new Form();
form.param("members", "nemo");
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("invite").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("invite").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.GROUP_MEMBER_EXISTS, node.at("/errors/0/0").asInt());
- assertEquals("Username nemo with status ACTIVE exists in the user-group " + "dory-group", node.at("/errors/0/1").asText());
- assertEquals(node.at("/errors/0/2").asText(), "[nemo, ACTIVE, dory-group]");
+ assertEquals(StatusCodes.GROUP_MEMBER_EXISTS,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "Username nemo with status ACTIVE exists in the user-group "
+ + "dory-group",
+ node.at("/errors/0/1").asText());
+ assertEquals(node.at("/errors/0/2").asText(),
+ "[nemo, ACTIVE, dory-group]");
}
@Test
- public void testInviteMemberToDeletedGroup() throws ProcessingException, KustvaktException {
+ public void testInviteMemberToDeletedGroup ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("members", "nemo");
- Response response = target().path(API_VERSION).path("group").path("@deleted-group").path("invite").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@deleted-group").path("invite").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Group deleted-group has been deleted.");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Group deleted-group has been deleted.");
assertEquals(node.at("/errors/0/2").asText(), "deleted-group");
}
// marlin has GroupMemberStatus.PENDING in dory-group
@Test
- public void testSubscribePendingMember() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("subscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).post(Entity.form(new Form()));
+ public void testSubscribePendingMember () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("subscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .post(Entity.form(new Form()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// retrieve marlin group
JsonNode node = retrieveUserGroups("marlin");
@@ -395,9 +554,12 @@
assertEquals(group.at("/owner").asText(), "dory");
// group members are not allowed to see other members
assertEquals(0, group.at("/members").size());
- assertEquals(GroupMemberStatus.ACTIVE.name(), group.at("/userMemberStatus").asText());
- assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(), group.at("/userRoles/1").asText());
- assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(), group.at("/userRoles/0").asText());
+ assertEquals(GroupMemberStatus.ACTIVE.name(),
+ group.at("/userMemberStatus").asText());
+ assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(),
+ group.at("/userRoles/1").asText());
+ assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(),
+ group.at("/userRoles/0").asText());
// unsubscribe marlin from dory-group
testUnsubscribeActiveMember("dory-group");
checkGroupMemberRole("dory-group", "marlin");
@@ -408,60 +570,104 @@
// pearl has GroupMemberStatus.DELETED in dory-group
@Test
- public void testSubscribeDeletedMember() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("subscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("pearl", "pass")).post(Entity.form(new Form()));
+ public void testSubscribeDeletedMember () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("subscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("pearl", "pass"))
+ .post(Entity.form(new Form()));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.GROUP_MEMBER_DELETED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "pearl has already been deleted from the group dory-group");
+ assertEquals(StatusCodes.GROUP_MEMBER_DELETED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "pearl has already been deleted from the group dory-group");
}
@Test
- public void testSubscribeMissingGroupName() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("subscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("bruce", "pass")).post(Entity.form(new Form()));
+ public void testSubscribeMissingGroupName () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("subscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("bruce", "pass"))
+ .post(Entity.form(new Form()));
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
@Test
- public void testSubscribeNonExistentMember() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("subscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("bruce", "pass")).post(Entity.form(new Form()));
+ public void testSubscribeNonExistentMember () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("subscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("bruce", "pass"))
+ .post(Entity.form(new Form()));
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "bruce is not found in the group");
+ assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "bruce is not found in the group");
}
@Test
- public void testSubscribeToNonExistentGroup() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@non-existent").path("subscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("pearl", "pass")).post(Entity.form(new Form()));
+ public void testSubscribeToNonExistentGroup () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@non-existent").path("subscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("pearl", "pass"))
+ .post(Entity.form(new Form()));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Group non-existent is not found");
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Group non-existent is not found");
}
- private void testSubscribeToDeletedGroup(String groupName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("subscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("nemo", "pass")).post(Entity.form(new Form()));
+ private void testSubscribeToDeletedGroup (String groupName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("subscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("nemo", "pass"))
+ .post(Entity.form(new Form()));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Group new-user-group has been deleted.");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Group new-user-group has been deleted.");
}
- private void testUnsubscribeActiveMember(String groupName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("unsubscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).delete();
+ private void testUnsubscribeActiveMember (String groupName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("unsubscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = retrieveUserGroups("marlin");
assertEquals(1, node.size());
}
- private void checkGroupMemberRole(String groupName, String deletedMemberName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("admin").path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).post(null);
+ private void checkGroupMemberRole (String groupName,
+ String deletedMemberName) throws KustvaktException {
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .post(null);
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity).at("/members");
@@ -476,23 +682,37 @@
}
@Test
- public void testUnsubscribeDeletedMember() throws ProcessingException, KustvaktException {
+ public void testUnsubscribeDeletedMember ()
+ throws ProcessingException, KustvaktException {
// pearl unsubscribes from dory-group
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("unsubscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("pearl", "pass")).delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("unsubscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("pearl", "pass"))
+ .delete();
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.GROUP_MEMBER_DELETED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "pearl has already been deleted from the group dory-group");
+ assertEquals(StatusCodes.GROUP_MEMBER_DELETED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "pearl has already been deleted from the group dory-group");
assertEquals(node.at("/errors/0/2").asText(), "[pearl, dory-group]");
}
@Test
- public void testUnsubscribePendingMember() throws ProcessingException, KustvaktException {
+ public void testUnsubscribePendingMember ()
+ throws ProcessingException, KustvaktException {
JsonNode node = retrieveUserGroups("marlin");
assertEquals(2, node.size());
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("unsubscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).delete();
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("unsubscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
node = retrieveUserGroups("marlin");
assertEquals(1, node.size());
@@ -502,46 +722,77 @@
}
@Test
- public void testUnsubscribeMissingGroupName() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("unsubscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).delete();
+ public void testUnsubscribeMissingGroupName () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("unsubscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .delete();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
@Test
- public void testUnsubscribeNonExistentMember() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@dory-group").path("unsubscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("bruce", "pass")).delete();
+ public void testUnsubscribeNonExistentMember () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@dory-group").path("unsubscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("bruce", "pass"))
+ .delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "bruce is not found in the group");
+ assertEquals(StatusCodes.GROUP_MEMBER_NOT_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "bruce is not found in the group");
}
@Test
- public void testUnsubscribeToNonExistentGroup() throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@tralala-group").path("unsubscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("pearl", "pass")).delete();
+ public void testUnsubscribeToNonExistentGroup () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@tralala-group").path("unsubscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("pearl", "pass"))
+ .delete();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Group tralala-group is not found");
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Group tralala-group is not found");
}
- private void testUnsubscribeToDeletedGroup(String groupName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("unsubscribe").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("nemo", "pass")).delete();
+ private void testUnsubscribeToDeletedGroup (String groupName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("unsubscribe").request()
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("nemo", "pass"))
+ .delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.GROUP_DELETED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Group new-user-group has been deleted.");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Group new-user-group has been deleted.");
}
@Test
- public void testAddSameMemberRole() throws ProcessingException, KustvaktException {
+ public void testAddSameMemberRole ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("memberUsername", "dory");
form.param("roleId", "1");
- Response response = target().path(API_VERSION).path("group").path("@marlin-group").path("role").path("add").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@marlin-group").path("role").path("add").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
Set<Role> roles = member.getRoles();
@@ -549,11 +800,16 @@
}
@Test
- public void testDeleteAddMemberRole() throws ProcessingException, KustvaktException {
+ public void testDeleteAddMemberRole ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("memberUsername", "dory");
form.param("roleId", "1");
- Response response = target().path(API_VERSION).path("group").path("@marlin-group").path("role").path("delete").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@marlin-group").path("role").path("delete").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
Set<Role> roles = member.getRoles();
@@ -562,10 +818,15 @@
}
@Test
- public void testEditMemberRoleEmpty() throws ProcessingException, KustvaktException {
+ public void testEditMemberRoleEmpty ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("memberUsername", "dory");
- Response response = target().path(API_VERSION).path("group").path("@marlin-group").path("role").path("edit").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@marlin-group").path("role").path("edit").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
Set<Role> roles = member.getRoles();
@@ -573,12 +834,17 @@
testEditMemberRole();
}
- private void testEditMemberRole() throws ProcessingException, KustvaktException {
+ private void testEditMemberRole ()
+ throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("memberUsername", "dory");
form.param("roleId", "1");
form.param("roleId", "3");
- Response response = target().path(API_VERSION).path("group").path("@marlin-group").path("role").path("edit").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@marlin-group").path("role").path("edit").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
UserGroupMember member = memberDao.retrieveMemberById("dory", 1);
Set<Role> roles = member.getRoles();
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
index 7f7078e..176e31b 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
@@ -30,18 +30,29 @@
private String username2 = "UserSetting.Test2";
- public Response sendPutRequest(String username, Map<String, Object> map) throws KustvaktException {
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).put(Entity.json(map));
+ public Response sendPutRequest (String username, Map<String, Object> map)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .put(Entity.json(map));
return response;
}
@Test
- public void testCreateSettingWithJson() throws KustvaktException {
- String json = "{\"pos-foundry\":\"opennlp\",\"metadata\":[\"author\", \"title\"," + "\"textSigle\", \"availability\"],\"resultPerPage\":25}";
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).put(Entity.json(json));
+ public void testCreateSettingWithJson () throws KustvaktException {
+ String json = "{\"pos-foundry\":\"opennlp\",\"metadata\":[\"author\", \"title\","
+ + "\"textSigle\", \"availability\"],\"resultPerPage\":25}";
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
int numOfResult = 25;
- String metadata = "[\"author\",\"title\",\"textSigle\"," + "\"availability\"]";
+ String metadata = "[\"author\",\"title\",\"textSigle\","
+ + "\"availability\"]";
testRetrieveSettings(username, "opennlp", numOfResult, metadata, true);
testDeleteKeyNotExist(username);
testDeleteKey(username, numOfResult, metadata, true);
@@ -49,102 +60,151 @@
}
@Test
- public void testCreateSettingWithMap() throws KustvaktException {
+ public void testCreateSettingWithMap () throws KustvaktException {
Map<String, Object> map = new HashMap<>();
map.put("pos-foundry", "opennlp");
map.put("resultPerPage", 25);
map.put("metadata", "author title textSigle availability");
Response response = sendPutRequest(username2, map);
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- testRetrieveSettings(username2, "opennlp", 25, "author title textSigle availability", false);
+ testRetrieveSettings(username2, "opennlp", 25,
+ "author title textSigle availability", false);
testUpdateSetting(username2);
testputRequestInvalidKey();
}
@Test
- public void testputRequestInvalidKey() throws KustvaktException {
+ public void testputRequestInvalidKey () throws KustvaktException {
Map<String, Object> map = new HashMap<>();
map.put("key/", "invalidKey");
Response response = sendPutRequest(username2, map);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/2").asText(), "key/");
}
@Test
- public void testPutDifferentUsername() throws KustvaktException {
- String json = "{\"pos-foundry\":\"opennlp\",\"metadata\":\"author title " + "textSigle availability\",\"resultPerPage\":25}";
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username2, "pass")).put(Entity.json(json));
+ public void testPutDifferentUsername () throws KustvaktException {
+ String json = "{\"pos-foundry\":\"opennlp\",\"metadata\":\"author title "
+ + "textSigle availability\",\"resultPerPage\":25}";
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username2, "pass"))
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testGetDifferentUsername() throws KustvaktException {
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username2, "pass")).get();
+ public void testGetDifferentUsername () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username2, "pass"))
+ .get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testGetSettingNotExist() throws KustvaktException {
+ public void testGetSettingNotExist () throws KustvaktException {
String username = "tralala";
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).get();
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .get();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
- assertEquals("No default setting for username: " + username + " is found", node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals(
+ "No default setting for username: " + username + " is found",
+ node.at("/errors/0/1").asText());
assertEquals(username, node.at("/errors/0/2").asText());
}
@Test
- public void testDeleteSettingNotExist() throws KustvaktException {
+ public void testDeleteSettingNotExist () throws KustvaktException {
String username = "tralala";
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
@Test
- public void testDeleteKeyDifferentUsername() throws KustvaktException {
- Response response = target().path(API_VERSION).path("~" + username).path("setting").path("pos-foundry").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username2, "pass")).delete();
+ public void testDeleteKeyDifferentUsername () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").path("pos-foundry").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username2, "pass"))
+ .delete();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
}
- private void testDeleteSetting(String username) throws KustvaktException {
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
+ private void testDeleteSetting (String username) throws KustvaktException {
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
assertEquals(username, node.at("/errors/0/2").asText());
}
// EM: deleting a non-existing key does not throw an error,
// because
// the purpose of the request has been achieved.
- private void testDeleteKeyNotExist(String username) throws KustvaktException {
- Response response = target().path(API_VERSION).path("~" + username).path("setting").path("lemma-foundry").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
+ private void testDeleteKeyNotExist (String username)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").path("lemma-foundry").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
- private void testDeleteKey(String username, int numOfResult, String metadata, boolean isMetadataArray) throws KustvaktException {
- Response response = target().path(API_VERSION).path("~" + username).path("setting").path("pos-foundry").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
+ private void testDeleteKey (String username, int numOfResult,
+ String metadata, boolean isMetadataArray) throws KustvaktException {
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").path("pos-foundry").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- testRetrieveSettings(username, null, numOfResult, metadata, isMetadataArray);
+ testRetrieveSettings(username, null, numOfResult, metadata,
+ isMetadataArray);
}
- private void testUpdateSetting(String username) throws KustvaktException {
+ private void testUpdateSetting (String username) throws KustvaktException {
Map<String, Object> map = new HashMap<>();
map.put("pos-foundry", "malt");
map.put("resultPerPage", 15);
@@ -154,19 +214,27 @@
testRetrieveSettings(username, "malt", 15, "author title", false);
}
- private void testRetrieveSettings(String username, String posFoundry, int numOfResult, String metadata, boolean isMetadataArray) throws KustvaktException {
- Response response = target().path(API_VERSION).path("~" + username).path("setting").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ private void testRetrieveSettings (String username, String posFoundry,
+ int numOfResult, String metadata, boolean isMetadataArray)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("~" + username)
+ .path("setting").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
if (posFoundry == null) {
assertTrue(node.at("/pos-foundry").isMissingNode());
- } else {
+ }
+ else {
assertEquals(posFoundry, node.at("/pos-foundry").asText());
}
assertEquals(numOfResult, node.at("/resultPerPage").asInt());
if (isMetadataArray) {
assertEquals(metadata, node.at("/metadata").toString());
- } else {
+ }
+ else {
assertEquals(metadata, node.at("/metadata").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
index 382535d..346b71d 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java
@@ -45,15 +45,18 @@
* @throws KustvaktException
*/
@Test
- public void testRefVcNotPrecached() throws KustvaktException {
+ public void testRefVcNotPrecached () throws KustvaktException {
JsonNode node = testSearchWithRef_VC1();
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Virtual corpus system/named-vc1 is not found.");
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Virtual corpus system/named-vc1 is not found.");
assertEquals(node.at("/errors/0/2").asText(), "system/named-vc1");
}
@Test
- public void testRefVcPrecached() throws KustvaktException, IOException, QueryException {
+ public void testRefVcPrecached ()
+ throws KustvaktException, IOException, QueryException {
int numOfMatches = testSearchWithoutRef_VC1();
vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld");
assertTrue(VirtualCorpusCache.contains("named-vc1"));
@@ -77,8 +80,12 @@
assertNull(vc);
}
- private int testSearchWithoutRef_VC1() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "textSigle=\"GOE/AGF/00000\" | textSigle=\"GOE/AGA/01784\"").request().get();
+ private int testSearchWithoutRef_VC1 () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq",
+ "textSigle=\"GOE/AGF/00000\" | textSigle=\"GOE/AGA/01784\"")
+ .request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
int size = node.at("/matches").size();
@@ -86,8 +93,12 @@
return size;
}
- private int testSearchWithoutRef_VC2() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "textSigle!=\"GOE/AGI/04846\" & textSigle!=\"GOE/AGA/01784\"").request().get();
+ private int testSearchWithoutRef_VC2 () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq",
+ "textSigle!=\"GOE/AGI/04846\" & textSigle!=\"GOE/AGA/01784\"")
+ .request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
int size = node.at("/matches").size();
@@ -95,22 +106,28 @@
return size;
}
- private JsonNode testSearchWithRef_VC1() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"system/named-vc1\"").request().get();
+ private JsonNode testSearchWithRef_VC1 () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"system/named-vc1\"").request()
+ .get();
String ent = response.readEntity(String.class);
return JsonUtils.readTree(ent);
}
- private JsonNode testSearchWithRef_VC2() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo named-vc2").request().get();
+ private JsonNode testSearchWithRef_VC2 () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo named-vc2").request().get();
String ent = response.readEntity(String.class);
return JsonUtils.readTree(ent);
}
@Test
- public void testStatisticsWithRef() throws KustvaktException {
+ public void testStatisticsWithRef () throws KustvaktException {
String corpusQuery = "availability = /CC-BY.*/ & referTo named-vc1";
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", corpusQuery).request().get();
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", corpusQuery).request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(2, node.at("/documents").asInt());
@@ -119,33 +136,45 @@
}
@Test
- public void testRefVcNotExist() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"username/vc1\"").request().get();
+ public void testRefVcNotExist () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"username/vc1\"").request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/2").asText(), "username/vc1");
}
@Test
- public void testRefNotAuthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"dory/dory-vc\"").request().get();
+ public void testRefNotAuthorized () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"dory/dory-vc\"").request().get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/2").asText(), "guest");
}
@Test
- public void testSearchWithRefPublishedVcGuest() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"marlin/published-vc\"").request().get();
+ public void testSearchWithRefPublishedVcGuest () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"marlin/published-vc\"").request()
+ .get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches").size() > 0);
- assertEquals(node.at("/collection/operands/0/value").asText(), "CC-BY.*");
- assertEquals(node.at("/collection/operands/1/@type").asText(), "koral:doc");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "CC-BY.*");
+ assertEquals(node.at("/collection/operands/1/@type").asText(),
+ "koral:doc");
assertEquals(node.at("/collection/operands/1/value").asText(), "GOE");
- assertEquals(node.at("/collection/operands/1/key").asText(), "corpusSigle");
+ assertEquals(node.at("/collection/operands/1/key").asText(),
+ "corpusSigle");
node = node.at("/collection/operands/1/rewrites");
assertEquals(3, node.size());
assertEquals(node.at("/0/operation").asText(), "operation:deletion");
@@ -156,15 +185,26 @@
}
@Test
- public void testSearchWithRefPublishedVc() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"marlin/published-vc\"").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("squirt", "pass")).get();
+ public void testSearchWithRefPublishedVc () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "referTo \"marlin/published-vc\"").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("squirt", "pass"))
+ .get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertTrue(node.at("/matches").size() > 0);
Form f = new Form();
f.param("status", "HIDDEN");
// check dory in the hidden group of the vc
- response = target().path(API_VERSION).path("admin").path("group").path("list").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ response = target().path(API_VERSION).path("admin").path("group")
+ .path("list").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAccessTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAccessTest.java
index beb1308..a1594fc 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAccessTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAccessTest.java
@@ -21,10 +21,12 @@
private String testUser = "VirtualCorpusAccessTest";
@Test
- public void testlistAccessByNonVCAAdmin() throws KustvaktException {
+ public void testlistAccessByNonVCAAdmin () throws KustvaktException {
JsonNode node = listAccessByGroup("nemo", "dory-group");
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Unauthorized operation for user: nemo");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: nemo");
}
// @Test
@@ -48,8 +50,12 @@
// assertEquals("vcId", node.at("/errors/0/1").asText());
// }
@Test
- public void testlistAccessByGroup() throws KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("access").queryParam("groupName", "dory-group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).get();
+ public void testlistAccessByGroup () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("access")
+ .queryParam("groupName", "dory-group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .get();
String entity = response.readEntity(String.class);
// System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
@@ -61,11 +67,14 @@
}
@Test
- public void testDeleteSharedVC() throws KustvaktException {
- String json = "{\"type\": \"PROJECT\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
+ public void testDeleteSharedVC () throws KustvaktException {
+ String json = "{\"type\": \"PROJECT\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
String vcName = "new_project_vc";
String username = "dory";
- String authHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass");
+ String authHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass");
createVC(authHeader, username, vcName, json);
String groupName = "dory-group";
testShareVCByCreator(username, vcName, groupName);
@@ -78,7 +87,8 @@
}
@Test
- public void testCreateDeleteAccess() throws ProcessingException, KustvaktException {
+ public void testCreateDeleteAccess ()
+ throws ProcessingException, KustvaktException {
String vcName = "marlin-vc";
String groupName = "marlin-group";
// check the vc type
@@ -116,30 +126,40 @@
String json = "{\"type\": \"" + ResourceType.PRIVATE + "\"}";
editVC("marlin", "marlin", vcName, json);
node = retrieveVCInfo("marlin", "marlin", vcName);
- assertEquals(ResourceType.PRIVATE.displayName(), node.at("/type").asText());
+ assertEquals(ResourceType.PRIVATE.displayName(),
+ node.at("/type").asText());
}
- private void testShareVC_nonUniqueAccess(String vcCreator, String vcName, String groupName) throws ProcessingException, KustvaktException {
+ private void testShareVC_nonUniqueAccess (String vcCreator, String vcName,
+ String groupName) throws ProcessingException, KustvaktException {
Response response = testShareVCByCreator(vcCreator, vcName, groupName);
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus());
- assertEquals(StatusCodes.DB_INSERT_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DB_INSERT_FAILED,
+ node.at("/errors/0/0").asInt());
// EM: message differs depending on the database used
// for testing. The message below is from sqlite.
// assertTrue(node.at("/errors/0/1").asText()
// .startsWith("[SQLITE_CONSTRAINT_UNIQUE]"));
}
- private Response testDeleteAccess(String username, String accessId) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("access").path(accessId).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).delete();
+ private Response testDeleteAccess (String username, String accessId)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("access")
+ .path(accessId).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .delete();
return response;
}
@Test
- public void testDeleteNonExistingAccess() throws ProcessingException, KustvaktException {
+ public void testDeleteNonExistingAccess ()
+ throws ProcessingException, KustvaktException {
Response response = testDeleteAccess("dory", "100");
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusClientTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusClientTest.java
index 225a331..a3b7e12 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusClientTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusClientTest.java
@@ -16,7 +16,7 @@
private String username = "VirtualCorpusClientTest";
@Test
- public void testVC_withClient() throws KustvaktException {
+ public void testVC_withClient () throws KustvaktException {
// create client
Response response = registerConfidentialClient(username);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -24,20 +24,27 @@
String clientId = node.at("/client_id").asText();
String clientSecret = node.at("/client_secret").asText();
// obtain authorization
- String userAuthHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "password");
- response = requestAuthorizationCode("code", clientId, clientRedirectUri, "create_vc vc_info delete_vc edit_vc", "myState", userAuthHeader);
+ String userAuthHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "password");
+ response = requestAuthorizationCode("code", clientId, clientRedirectUri,
+ "create_vc vc_info delete_vc edit_vc", "myState",
+ userAuthHeader);
String code = parseAuthorizationCode(response);
- response = requestTokenWithAuthorizationCodeAndForm(clientId, clientSecret, code, clientRedirectUri);
+ response = requestTokenWithAuthorizationCodeAndForm(clientId,
+ clientSecret, code, clientRedirectUri);
node = JsonUtils.readTree(response.readEntity(String.class));
String accessToken = node.at("/access_token").asText();
String accessTokenHeader = "Bearer " + accessToken;
// create VC 1
String vcName = "vc-client1";
- String vcJson = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"creationDate since 1820\"}";
+ String vcJson = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"creationDate since 1820\"}";
createVC(accessTokenHeader, username, vcName, vcJson);
// create VC 2
vcName = "vc-client2";
- vcJson = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"creationDate until 1820\"}";
+ vcJson = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"creationDate until 1820\"}";
createVC(accessTokenHeader, username, vcName, vcJson);
// edit VC
String description = "vc created from client";
@@ -58,7 +65,8 @@
deregisterClient(username, clientId);
testSearchWithRevokedAccessToken(accessToken);
// obtain authorization from another client
- response = requestTokenWithPassword(superClientId, this.clientSecret, username, "pass");
+ response = requestTokenWithPassword(superClientId, this.clientSecret,
+ username, "pass");
node = JsonUtils.readTree(response.readEntity(String.class));
accessToken = node.at("/access_token").asText();
// checking vc should still be available after client deregistration
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
index e93582f..90f9d4a 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
@@ -28,48 +28,82 @@
private String testUser = "VirtualCorpusControllerAdminTest";
- private JsonNode testAdminListVC(String username) throws ProcessingException, KustvaktException {
+ private JsonNode testAdminListVC (String username)
+ throws ProcessingException, KustvaktException {
Form f = new Form();
f.param("createdBy", username);
- Response response = target().path(API_VERSION).path("admin").path("vc").path("list").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin").path("vc")
+ .path("list").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
- private JsonNode testAdminListVC_UsingAdminToken(String username, ResourceType type) throws ProcessingException, KustvaktException {
+ private JsonNode testAdminListVC_UsingAdminToken (String username,
+ ResourceType type) throws ProcessingException, KustvaktException {
Form f = new Form();
f.param("createdBy", username);
f.param("type", type.toString());
f.param("token", "secret");
- Response response = target().path(API_VERSION).path("admin").path("vc").path("list").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin").path("vc")
+ .path("list").request()
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
@Test
- public void testCreateSystemVC() throws KustvaktException {
- String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"creationDate since 1820\"}";
- Response response = target().path(API_VERSION).path("vc").path("~system").path("new-system-vc").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateSystemVC () throws KustvaktException {
+ String json = "{\"type\": \"SYSTEM\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"creationDate since 1820\"}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~system").path("new-system-vc").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
- JsonNode node = testAdminListVC_UsingAdminToken("system", ResourceType.SYSTEM);
+ JsonNode node = testAdminListVC_UsingAdminToken("system",
+ ResourceType.SYSTEM);
assertEquals(2, node.size());
testDeleteSystemVC(admin, "new-system-vc");
}
- private void testDeleteSystemVC(String vcCreator, String vcName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~system").path(vcName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).delete();
+ private void testDeleteSystemVC (String vcCreator, String vcName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~system").path(vcName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- JsonNode node = testAdminListVC_UsingAdminToken("system", ResourceType.SYSTEM);
+ JsonNode node = testAdminListVC_UsingAdminToken("system",
+ ResourceType.SYSTEM);
assertEquals(1, node.size());
}
@Test
- public void testCreatePrivateVC() throws ProcessingException, KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
+ public void testCreatePrivateVC ()
+ throws ProcessingException, KustvaktException {
+ String json = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
String vcName = "new-vc";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path(vcName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path(vcName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
JsonNode node = testAdminListVC(testUser);
assertEquals(1, node.size());
@@ -77,16 +111,27 @@
testDeletePrivateVC(testUser, vcName);
}
- private void testEditPrivateVC(String vcCreator, String vcName) throws ProcessingException, KustvaktException {
+ private void testEditPrivateVC (String vcCreator, String vcName)
+ throws ProcessingException, KustvaktException {
String json = "{\"description\": \"edited vc\"}";
- Response response = target().path(API_VERSION).path("vc").path("~" + vcCreator).path(vcName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + vcCreator).path(vcName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
JsonNode node = testAdminListVC(testUser);
assertEquals(node.at("/0/description").asText(), "edited vc");
}
- private void testDeletePrivateVC(String vcCreator, String vcName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~" + vcCreator).path(vcName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).delete();
+ private void testDeletePrivateVC (String vcCreator, String vcName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + vcCreator).path(vcName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = testAdminListVC(vcCreator);
assertEquals(0, node.size());
@@ -116,8 +161,13 @@
//
// return node.at("/accessId").asText();
// }
- private JsonNode testlistAccessByGroup(String groupName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("access").queryParam("groupName", groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).get();
+ private JsonNode testlistAccessByGroup (String groupName)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("access")
+ .queryParam("groupName", groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.size());
@@ -125,35 +175,49 @@
}
@Test
- public void testVCSharing() throws ProcessingException, KustvaktException {
+ public void testVCSharing () throws ProcessingException, KustvaktException {
String vcCreator = "marlin";
String vcName = "marlin-vc";
String groupName = "marlin-group";
- JsonNode node2 = testAdminListVC_UsingAdminToken(vcCreator, ResourceType.PROJECT);
+ JsonNode node2 = testAdminListVC_UsingAdminToken(vcCreator,
+ ResourceType.PROJECT);
assertEquals(0, node2.size());
testCreateVCAccess(vcCreator, vcName, groupName);
JsonNode node = testlistAccessByGroup(groupName);
String accessId = node.at("/accessId").asText();
testDeleteVCAccess(accessId);
- node2 = testAdminListVC_UsingAdminToken(vcCreator, ResourceType.PROJECT);
+ node2 = testAdminListVC_UsingAdminToken(vcCreator,
+ ResourceType.PROJECT);
assertEquals(1, node2.size());
String json = "{\"type\": \"" + ResourceType.PRIVATE + "\"}";
editVC(admin, vcCreator, vcName, json);
node = retrieveVCInfo(admin, vcCreator, vcName);
- assertEquals(ResourceType.PRIVATE.displayName(), node.at("/type").asText());
- node2 = testAdminListVC_UsingAdminToken(vcCreator, ResourceType.PROJECT);
+ assertEquals(ResourceType.PRIVATE.displayName(),
+ node.at("/type").asText());
+ node2 = testAdminListVC_UsingAdminToken(vcCreator,
+ ResourceType.PROJECT);
assertEquals(0, node2.size());
}
- private void testCreateVCAccess(String vcCreator, String vcName, String groupName) throws ProcessingException, KustvaktException {
+ private void testCreateVCAccess (String vcCreator, String vcName,
+ String groupName) throws ProcessingException, KustvaktException {
Response response;
// share VC
- response = target().path(API_VERSION).path("vc").path("~" + vcCreator).path(vcName).path("share").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).post(Entity.form(new Form()));
+ response = target().path(API_VERSION).path("vc").path("~" + vcCreator)
+ .path(vcName).path("share").path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .post(Entity.form(new Form()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
- private void testDeleteVCAccess(String accessId) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("access").path(accessId).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).delete();
+ private void testDeleteVCAccess (String accessId)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("access")
+ .path(accessId).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .delete();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
}
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 fe45cec..a9ff786 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
@@ -34,13 +34,16 @@
private String authHeader;
- public VirtualCorpusControllerTest() throws KustvaktException {
- authHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass");
+ public VirtualCorpusControllerTest () throws KustvaktException {
+ authHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass");
}
@Test
- public void testCreatePrivateVC() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
+ public void testCreatePrivateVC () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
createVC(authHeader, testUser, "new_vc", json);
// list user VC
JsonNode node = listVC(testUser);
@@ -54,8 +57,10 @@
}
@Test
- public void testCreatePublishedVC() throws KustvaktException {
- String json = "{\"type\": \"PUBLISHED\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
+ public void testCreatePublishedVC () throws KustvaktException {
+ String json = "{\"type\": \"PUBLISHED\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
String vcName = "new-published-vc";
createVC(authHeader, testUser, vcName, json);
// test list owner vc
@@ -76,44 +81,64 @@
deleteVC(vcName, testUser, testUser);
// EM: check if the hidden groups are deleted as well
node = testCheckHiddenGroup(groupName);
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
- assertEquals("Group " + groupName + " is not found", node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Group " + groupName + " is not found",
+ node.at("/errors/0/1").asText());
}
- private JsonNode testCheckHiddenGroup(String groupName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("admin").path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").post(null);
+ private JsonNode testCheckHiddenGroup (String groupName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").post(null);
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
@Test
- public void testCreateVCWithInvalidToken() throws IOException, KustvaktException {
- String json = "{\"type\": \"PRIVATE\"," + "\"corpusQuery\": \"corpusSigle=GOE\"}";
- InputStream is = getClass().getClassLoader().getResourceAsStream("test-invalid-signature.token");
+ public void testCreateVCWithInvalidToken ()
+ throws IOException, KustvaktException {
+ String json = "{\"type\": \"PRIVATE\","
+ + "\"corpusQuery\": \"corpusSigle=GOE\"}";
+ InputStream is = getClass().getClassLoader()
+ .getResourceAsStream("test-invalid-signature.token");
String authToken;
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(is))) {
authToken = reader.readLine();
}
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc").request().header(Attributes.AUTHORIZATION, AuthenticationScheme.BEARER.displayName() + " " + authToken).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc").request()
+ .header(Attributes.AUTHORIZATION,
+ AuthenticationScheme.BEARER.displayName() + " "
+ + authToken)
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ACCESS_TOKEN, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Access token is invalid");
+ assertEquals(StatusCodes.INVALID_ACCESS_TOKEN,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Access token is invalid");
checkWWWAuthenticateHeader(response);
}
@Test
- public void testCreateVCWithExpiredToken() throws IOException, KustvaktException {
+ public void testCreateVCWithExpiredToken ()
+ throws IOException, KustvaktException {
String json = "{\"type\": \"PRIVATE\","
+ "\"corpusQuery\": \"corpusSigle=GOE\"}";
//String authToken = "fia0123ikBWn931470H8s5gRqx7Moc4p";
String authToken = createExpiredAccessToken();
-
+
Response response = target().path(API_VERSION).path("vc")
- .path("~marlin").path("new_vc")
- .request()
+ .path("~marlin").path("new_vc").request()
.header(Attributes.AUTHORIZATION,
AuthenticationScheme.BEARER.displayName() + " "
+ authToken)
@@ -121,130 +146,201 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(Entity.json(json));
-
String entity = response.readEntity(String.class);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.EXPIRED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Access token is expired");
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Access token is expired");
checkWWWAuthenticateHeader(response);
}
@Test
- public void testCreateSystemVC() throws KustvaktException {
- String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"pubDate since 1820\"}";
+ public void testCreateSystemVC () throws KustvaktException {
+ String json = "{\"type\": \"SYSTEM\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"pubDate since 1820\"}";
String vcName = "new_system_vc";
- Response response = target().path(API_VERSION).path("vc").path("~system").path(vcName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~system").path(vcName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
JsonNode node = listSystemVC("pearl");
assertEquals(2, node.size());
- assertEquals(ResourceType.SYSTEM.displayName(), node.at("/0/type").asText());
- assertEquals(ResourceType.SYSTEM.displayName(), node.at("/1/type").asText());
+ assertEquals(ResourceType.SYSTEM.displayName(),
+ node.at("/0/type").asText());
+ assertEquals(ResourceType.SYSTEM.displayName(),
+ node.at("/1/type").asText());
deleteVC(vcName, "system", "admin");
node = listSystemVC("pearl");
assertEquals(1, node.size());
}
@Test
- public void testCreateSystemVC_unauthorized() throws KustvaktException {
- String json = "{\"type\": \"SYSTEM\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"creationDate since 1820\"}";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateSystemVC_unauthorized () throws KustvaktException {
+ String json = "{\"type\": \"SYSTEM\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"creationDate since 1820\"}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
testResponseUnauthorized(response, testUser);
}
@Test
- public void testCreateVC_invalidName() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"creationDate since 1820\"}";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new $vc").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateVC_invalidName () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"creationDate since 1820\"}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new $vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testCreateVC_nameTooShort() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"creationDate since 1820\"}";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("ne").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateVC_nameTooShort () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"creationDate since 1820\"}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("ne").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "queryName must contain at least 3 characters");
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "queryName must contain at least 3 characters");
}
@Test
- public void testCreateVC_unauthorized() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"," + "\"corpusQuery\": \"creationDate since 1820\"}";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc").request().header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateVC_unauthorized () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\","
+ + "\"corpusQuery\": \"creationDate since 1820\"}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc").request()
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Unauthorized operation for user: guest");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: guest");
checkWWWAuthenticateHeader(response);
}
@Test
- public void testCreateVC_withoutCorpusQuery() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + "}";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateVC_withoutCorpusQuery () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\"" + "}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "corpusQuery is null");
assertEquals(node.at("/errors/0/2").asText(), "corpusQuery");
}
@Test
- public void testCreateVC_withoutEntity() throws KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(""));
+ public void testCreateVC_withoutEntity () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(""));
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "request entity is null");
assertEquals(node.at("/errors/0/2").asText(), "request entity");
}
@Test
- public void testCreateVC_withoutType() throws KustvaktException {
- String json = "{\"corpusQuery\": " + "\"creationDate since 1820\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + "}";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateVC_withoutType () throws KustvaktException {
+ String json = "{\"corpusQuery\": " + "\"creationDate since 1820\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\"" + "}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
String entity = response.readEntity(String.class);
// System.out.println(entity);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "type is null");
assertEquals(node.at("/errors/0/2").asText(), "type");
}
@Test
- public void testCreateVC_withWrongType() throws KustvaktException {
- String json = "{\"type\": \"PRIVAT\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"creationDate since 1820\"}";
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ public void testCreateVC_withWrongType () throws KustvaktException {
+ String json = "{\"type\": \"PRIVAT\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"creationDate since 1820\"}";
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertTrue(node.at("/errors/0/1").asText().startsWith("Cannot deserialize value of type `de.ids_mannheim.korap.constant." + "ResourceType` from String \"PRIVAT\""));
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertTrue(node.at("/errors/0/1").asText().startsWith(
+ "Cannot deserialize value of type `de.ids_mannheim.korap.constant."
+ + "ResourceType` from String \"PRIVAT\""));
}
@Test
- public void testMaxNumberOfVC() throws KustvaktException {
- String json = "{\"type\": \"PRIVATE\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
+ public void testMaxNumberOfVC () throws KustvaktException {
+ String json = "{\"type\": \"PRIVATE\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
for (int i = 1; i < 6; i++) {
createVC(authHeader, testUser, "new_vc_" + i, json);
}
- Response response = target().path(API_VERSION).path("vc").path("~" + testUser).path("new_vc_6").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~" + testUser).path("new_vc_6").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NOT_ALLOWED, node.at("/errors/0/0").asInt());
- assertEquals("Cannot create virtual corpus. The maximum number of " + "virtual corpus has been reached.", node.at("/errors/0/1").asText());
+ assertEquals(
+ "Cannot create virtual corpus. The maximum number of "
+ + "virtual corpus has been reached.",
+ node.at("/errors/0/1").asText());
// list user VC
node = listVC(testUser);
// including 1 system-vc
@@ -260,13 +356,15 @@
}
@Test
- public void testDeleteVC_unauthorized() throws KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("dory-vc").request().header(Attributes.AUTHORIZATION, authHeader).delete();
+ public void testDeleteVC_unauthorized () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("dory-vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader).delete();
testResponseUnauthorized(response, testUser);
}
@Test
- public void testEditVC() throws KustvaktException {
+ public void testEditVC () throws KustvaktException {
// 1st edit
String json = "{\"description\": \"edited vc\"}";
editVC("dory", "dory", "dory-vc", json);
@@ -282,20 +380,28 @@
}
@Test
- public void testEditVCName() throws KustvaktException {
+ public void testEditVCName () throws KustvaktException {
String json = "{\"name\": \"new-name\"}";
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("dory-vc").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("dory-vc").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testEditCorpusQuery() throws ProcessingException, KustvaktException {
+ public void testEditCorpusQuery ()
+ throws ProcessingException, KustvaktException {
JsonNode node = testRetrieveKoralQuery("dory", "dory-vc");
assertEquals(node.at("/collection/@type").asText(), "koral:docGroup");
- assertEquals(node.at("/collection/operation").asText(), "operation:and");
+ assertEquals(node.at("/collection/operation").asText(),
+ "operation:and");
assertEquals(2, node.at("/collection/operands").size());
String json = "{\"corpusQuery\": \"corpusSigle=WPD17\"}";
editVC("dory", "dory", "dory-vc", json);
@@ -305,8 +411,14 @@
assertEquals(node.at("/collection/value").asText(), "WPD17");
}
- private JsonNode testRetrieveKoralQuery(String username, String vcName) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("koralQuery").path("~" + username).path(vcName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).get();
+ private JsonNode testRetrieveKoralQuery (String username, String vcName)
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc")
+ .path("koralQuery").path("~" + username).path(vcName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -314,30 +426,39 @@
}
@Test
- public void testEditVC_notOwner() throws KustvaktException {
+ public void testEditVC_notOwner () throws KustvaktException {
String json = "{\"description\": \"edited vc\"}";
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("dory-vc").request().header(Attributes.AUTHORIZATION, authHeader).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).put(Entity.json(json));
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("dory-vc").request()
+ .header(Attributes.AUTHORIZATION, authHeader)
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .put(Entity.json(json));
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals("Unauthorized operation for user: " + testUser, node.at("/errors/0/1").asText());
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals("Unauthorized operation for user: " + testUser,
+ node.at("/errors/0/1").asText());
checkWWWAuthenticateHeader(response);
}
@Test
- public void testPublishProjectVC() throws KustvaktException {
+ public void testPublishProjectVC () throws KustvaktException {
String vcName = "group-vc";
// check the vc type
JsonNode node = retrieveVCInfo("dory", "dory", vcName);
- assertEquals(ResourceType.PROJECT.displayName(), node.get("type").asText());
+ assertEquals(ResourceType.PROJECT.displayName(),
+ node.get("type").asText());
// edit vc
String json = "{\"type\": \"PUBLISHED\"}";
editVC("dory", "dory", vcName, json);
// check VC
node = testListOwnerVC("dory");
JsonNode n = node.get(1);
- assertEquals(ResourceType.PUBLISHED.displayName(), n.get("type").asText());
+ assertEquals(ResourceType.PUBLISHED.displayName(),
+ n.get("type").asText());
// check hidden VC access
node = listAccessByGroup("admin", "");
assertEquals(4, node.size());
@@ -349,7 +470,8 @@
json = "{\"type\": \"PROJECT\"}";
editVC("dory", "dory", vcName, json);
node = testListOwnerVC("dory");
- assertEquals(ResourceType.PROJECT.displayName(), node.get(1).get("type").asText());
+ assertEquals(ResourceType.PROJECT.displayName(),
+ node.get(1).get("type").asText());
// check VC access
node = listAccessByGroup("admin", "");
assertEquals(3, node.size());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
index 1e06bd3..27c527d 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
@@ -32,23 +32,37 @@
@Autowired
private QueryDao dao;
- private JsonNode testRetrieveField(String username, String vcName, String field) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("field").path("~" + username).path(vcName).queryParam("fieldName", field).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).get();
+ private JsonNode testRetrieveField (String username, String vcName,
+ String field) throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("field")
+ .path("~" + username).path(vcName)
+ .queryParam("fieldName", field).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
- private void testRetrieveProhibitedField(String username, String vcName, String field) throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("field").path("~" + username).path(vcName).queryParam("fieldName", field).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).get();
+ private void testRetrieveProhibitedField (String username, String vcName,
+ String field) throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("field")
+ .path("~" + username).path(vcName)
+ .queryParam("fieldName", field).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NOT_ALLOWED, node.at("/errors/0/0").asInt());
}
- private void deleteVcFromDB(String vcName) throws KustvaktException {
+ private void deleteVcFromDB (String vcName) throws KustvaktException {
QueryDO vc = dao.retrieveQueryByName(vcName, "system");
dao.deleteQuery(vc);
vc = dao.retrieveQueryByName(vcName, "system");
@@ -56,15 +70,18 @@
}
@Test
- public void testRetrieveFieldsNamedVC1() throws IOException, QueryException, KustvaktException {
+ public void testRetrieveFieldsNamedVC1 ()
+ throws IOException, QueryException, KustvaktException {
vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld");
JsonNode n = testRetrieveField("system", "named-vc1", "textSigle");
- assertEquals(n.at("/@context").asText(), "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld");
+ assertEquals(n.at("/@context").asText(),
+ "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld");
assertEquals(n.at("/corpus/key").asText(), "textSigle");
assertEquals(2, n.at("/corpus/value").size());
n = testRetrieveField("system", "named-vc1", "author");
assertEquals(2, n.at("/corpus/value").size());
- assertEquals(n.at("/corpus/value/0").asText(), "Goethe, Johann Wolfgang von");
+ assertEquals(n.at("/corpus/value/0").asText(),
+ "Goethe, Johann Wolfgang von");
testRetrieveUnknownTokens();
testRetrieveProhibitedField("system", "named-vc1", "tokens");
testRetrieveProhibitedField("system", "named-vc1", "base");
@@ -72,14 +89,16 @@
deleteVcFromDB("named-vc1");
}
- private void testRetrieveUnknownTokens() throws ProcessingException, KustvaktException {
+ private void testRetrieveUnknownTokens ()
+ throws ProcessingException, KustvaktException {
JsonNode n = testRetrieveField("system", "named-vc1", "unknown");
assertEquals(n.at("/corpus/key").asText(), "unknown");
assertEquals(0, n.at("/corpus/value").size());
}
@Test
- public void testRetrieveTextSigleNamedVC2() throws IOException, QueryException, KustvaktException {
+ public void testRetrieveTextSigleNamedVC2 ()
+ throws IOException, QueryException, KustvaktException {
vcLoader.loadVCToCache("named-vc2", "/vc/named-vc2.jsonld");
JsonNode n = testRetrieveField("system", "named-vc2", "textSigle");
assertEquals(2, n.at("/corpus/value").size());
@@ -88,7 +107,8 @@
}
@Test
- public void testRetrieveTextSigleNamedVC3() throws IOException, QueryException, KustvaktException {
+ public void testRetrieveTextSigleNamedVC3 ()
+ throws IOException, QueryException, KustvaktException {
vcLoader.loadVCToCache("named-vc3", "/vc/named-vc3.jsonld");
JsonNode n = testRetrieveField("system", "named-vc3", "textSigle");
n = n.at("/corpus/value");
@@ -99,14 +119,23 @@
}
@Test
- public void testRetrieveFieldUnauthorized() throws KustvaktException, IOException, QueryException {
+ public void testRetrieveFieldUnauthorized ()
+ throws KustvaktException, IOException, QueryException {
vcLoader.loadVCToCache("named-vc3", "/vc/named-vc3.jsonld");
- Response response = target().path(API_VERSION).path("vc").path("field").path("~system").path("named-vc3").queryParam("fieldName", "textSigle").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON).get();
+ Response response = target().path(API_VERSION).path("vc").path("field")
+ .path("~system").path("named-vc3")
+ .queryParam("fieldName", "textSigle").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .get();
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Unauthorized operation for user: dory");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: dory");
VirtualCorpusCache.delete("named-vc3");
deleteVcFromDB("named-vc3");
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusInfoTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusInfoTest.java
index 168edbb..4d20c0f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusInfoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusInfoTest.java
@@ -26,64 +26,96 @@
private String testUser = "VirtualCorpusInfoTest";
@Test
- public void testRetrieveSystemVC() throws ProcessingException, KustvaktException {
+ public void testRetrieveSystemVC ()
+ throws ProcessingException, KustvaktException {
JsonNode node = retrieveVCInfo(testUser, "system", "system-vc");
assertEquals(node.at("/name").asText(), "system-vc");
- assertEquals(ResourceType.SYSTEM.displayName(), node.at("/type").asText());
+ assertEquals(ResourceType.SYSTEM.displayName(),
+ node.at("/type").asText());
// assertEquals("koral:doc", node.at("/koralQuery/collection/@type").asText());
assertTrue(node.at("/query").isMissingNode());
assertTrue(node.at("/queryLanguage").isMissingNode());
}
@Test
- public void testRetrieveSystemVCGuest() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~system").path("system-vc").request().get();
+ public void testRetrieveSystemVCGuest ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~system").path("system-vc").request().get();
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(node.at("/name").asText(), "system-vc");
- assertEquals(ResourceType.SYSTEM.displayName(), node.at("/type").asText());
+ assertEquals(ResourceType.SYSTEM.displayName(),
+ node.at("/type").asText());
}
@Test
- public void testRetrieveOwnerPrivateVC() throws ProcessingException, KustvaktException {
+ public void testRetrieveOwnerPrivateVC ()
+ throws ProcessingException, KustvaktException {
JsonNode node = retrieveVCInfo("dory", "dory", "dory-vc");
assertEquals(node.at("/name").asText(), "dory-vc");
- assertEquals(ResourceType.PRIVATE.displayName(), node.at("/type").asText());
+ assertEquals(ResourceType.PRIVATE.displayName(),
+ node.at("/type").asText());
}
@Test
- public void testRetrievePrivateVCUnauthorized() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("dory-vc").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).get();
+ public void testRetrievePrivateVCUnauthorized ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("dory-vc").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .get();
testResponseUnauthorized(response, testUser);
}
@Test
- public void testRetrieveProjectVC() throws ProcessingException, KustvaktException {
+ public void testRetrieveProjectVC ()
+ throws ProcessingException, KustvaktException {
JsonNode node = retrieveVCInfo("nemo", "dory", "group-vc");
assertEquals(node.at("/name").asText(), "group-vc");
- assertEquals(ResourceType.PROJECT.displayName(), node.at("/type").asText());
+ assertEquals(ResourceType.PROJECT.displayName(),
+ node.at("/type").asText());
}
@Test
- public void testRetrieveProjectVCUnauthorized() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("group-vc").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass")).get();
+ public void testRetrieveProjectVCUnauthorized ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("group-vc").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass"))
+ .get();
testResponseUnauthorized(response, testUser);
}
@Test
- public void testRetrieveProjectVCbyNonActiveMember() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("group-vc").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("marlin", "pass")).get();
+ public void testRetrieveProjectVCbyNonActiveMember ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("group-vc").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("marlin", "pass"))
+ .get();
testResponseUnauthorized(response, "marlin");
}
@Test
- public void testRetrievePublishedVC() throws ProcessingException, KustvaktException {
+ public void testRetrievePublishedVC ()
+ throws ProcessingException, KustvaktException {
JsonNode node = retrieveVCInfo("gill", "marlin", "published-vc");
assertEquals(node.at("/name").asText(), "published-vc");
- assertEquals(ResourceType.PUBLISHED.displayName(), node.at("/type").asText());
+ assertEquals(ResourceType.PUBLISHED.displayName(),
+ node.at("/type").asText());
Form f = new Form();
f.param("status", "HIDDEN");
// check gill in the hidden group of the vc
- Response response = target().path(API_VERSION).path("admin").path("group").path("list").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED).post(Entity.form(f));
+ Response response = target().path(API_VERSION).path("admin")
+ .path("group").path("list").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
@@ -93,8 +125,13 @@
}
@Test
- public void testAdminRetrievePrivateVC() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("dory-vc").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).get();
+ public void testAdminRetrievePrivateVC ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("dory-vc").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -103,12 +140,18 @@
}
@Test
- public void testAdminRetrieveProjectVC() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~dory").path("group-vc").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(admin, "pass")).get();
+ public void testAdminRetrieveProjectVC ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .path("group-vc").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(admin, "pass"))
+ .get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(node.at("/name").asText(), "group-vc");
- assertEquals(ResourceType.PROJECT.displayName(), node.at("/type").asText());
+ assertEquals(ResourceType.PROJECT.displayName(),
+ node.at("/type").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusListTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusListTest.java
index df1ac17..f1e1d17 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusListTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusListTest.java
@@ -19,7 +19,8 @@
public class VirtualCorpusListTest extends VirtualCorpusTestBase {
@Test
- public void testListVCNemo() throws ProcessingException, KustvaktException {
+ public void testListVCNemo ()
+ throws ProcessingException, KustvaktException {
JsonNode node = testListOwnerVC("nemo");
assertEquals(1, node.size());
node = listSystemVC("nemo");
@@ -29,7 +30,8 @@
}
@Test
- public void testListVCPearl() throws ProcessingException, KustvaktException {
+ public void testListVCPearl ()
+ throws ProcessingException, KustvaktException {
JsonNode node = testListOwnerVC("pearl");
assertEquals(0, node.size());
node = listVC("pearl");
@@ -37,7 +39,8 @@
}
@Test
- public void testListVCDory() throws ProcessingException, KustvaktException {
+ public void testListVCDory ()
+ throws ProcessingException, KustvaktException {
JsonNode node = testListOwnerVC("dory");
assertEquals(2, node.size());
node = listVC("dory");
@@ -45,29 +48,43 @@
}
@Test
- public void testListAvailableVCGuest() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").request().get();
+ public void testListAvailableVCGuest ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").request()
+ .get();
testResponseUnauthorized(response, "guest");
}
@Disabled
@Deprecated
@Test
- public void testListAvailableVCByOtherUser() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").path("~dory").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("pearl", "pass")).get();
+ public void testListAvailableVCByOtherUser ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc").path("~dory")
+ .request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("pearl", "pass"))
+ .get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
- assertEquals(StatusCodes.AUTHORIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Unauthorized operation for user: pearl");
+ assertEquals(StatusCodes.AUTHORIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Unauthorized operation for user: pearl");
checkWWWAuthenticateHeader(response);
}
@Disabled
@Deprecated
@Test
- public void testListUserVC() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("vc").queryParam("username", "dory").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("admin", "pass")).get();
+ public void testListUserVC ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("vc")
+ .queryParam("username", "dory").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("admin", "pass"))
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusSharingTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusSharingTest.java
index 288c9e3..d7de5a3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusSharingTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusSharingTest.java
@@ -25,40 +25,60 @@
private String testUser = "VirtualCorpusSharingTest";
@Test
- public void testShareUnknownVC() throws ProcessingException, KustvaktException {
- Response response = testShareVCByCreator("marlin", "non-existing-vc", "marlin group");
+ public void testShareUnknownVC ()
+ throws ProcessingException, KustvaktException {
+ Response response = testShareVCByCreator("marlin", "non-existing-vc",
+ "marlin group");
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testShareUnknownGroup() throws ProcessingException, KustvaktException {
- Response response = testShareVCByCreator("marlin", "marlin-vc", "non-existing-group");
+ public void testShareUnknownGroup ()
+ throws ProcessingException, KustvaktException {
+ Response response = testShareVCByCreator("marlin", "marlin-vc",
+ "non-existing-group");
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testShareVC_notOwner() throws ProcessingException, KustvaktException {
+ public void testShareVC_notOwner ()
+ throws ProcessingException, KustvaktException {
// dory is VCA in marlin group
- Response response = target().path(API_VERSION).path("vc").path("~marlin").path("marlin-vc").path("share").path("@marlin group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("dory", "pass")).post(Entity.form(new Form()));
+ Response response = target().path(API_VERSION).path("vc")
+ .path("~marlin").path("marlin-vc").path("share")
+ .path("@marlin group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("dory", "pass"))
+ .post(Entity.form(new Form()));
testResponseUnauthorized(response, "dory");
}
@Test
- public void testShareVC_byMember() throws ProcessingException, KustvaktException {
+ public void testShareVC_byMember ()
+ throws ProcessingException, KustvaktException {
// nemo is not VCA in marlin group
- Response response = target().path(API_VERSION).path("vc").path("~nemo").path("nemo-vc").path("share").path("@marlin-group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("nemo", "pass")).post(Entity.form(new Form()));
+ Response response = target().path(API_VERSION).path("vc").path("~nemo")
+ .path("nemo-vc").path("share").path("@marlin-group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("nemo", "pass"))
+ .post(Entity.form(new Form()));
testResponseUnauthorized(response, "nemo");
}
@Test
- public void testCreateShareProjectVC() throws KustvaktException {
- String json = "{\"type\": \"PROJECT\"" + ",\"queryType\": \"VIRTUAL_CORPUS\"" + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
+ public void testCreateShareProjectVC () throws KustvaktException {
+ String json = "{\"type\": \"PROJECT\""
+ + ",\"queryType\": \"VIRTUAL_CORPUS\""
+ + ",\"corpusQuery\": \"corpusSigle=GOE\"}";
String vcName = "new_project_vc";
- String authHeader = HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(testUser, "pass");
+ String authHeader = HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(testUser, "pass");
createVC(authHeader, testUser, vcName, json);
// retrieve vc info
JsonNode vcInfo = retrieveVCInfo(testUser, testUser, vcName);
@@ -96,54 +116,87 @@
response = searchWithVCRef(memberName, testUser, vcName);
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
node = JsonUtils.readTree(response.readEntity(String.class));
- assertEquals(StatusCodes.NO_RESOURCE_FOUND, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.NO_RESOURCE_FOUND,
+ node.at("/errors/0/0").asInt());
}
- private Response createUserGroup(String username, String groupName, String description) throws ProcessingException, KustvaktException {
+ private Response createUserGroup (String username, String groupName,
+ String description) throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("description", description);
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).put(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .put(Entity.form(form));
return response;
}
- private JsonNode listUserGroup(String username, String groupName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).get();
+ private JsonNode listUserGroup (String username, String groupName)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
return node;
}
- private void testInviteMember(String username, String groupName, String memberName) throws ProcessingException, KustvaktException {
+ private void testInviteMember (String username, String groupName,
+ String memberName) throws ProcessingException, KustvaktException {
Form form = new Form();
form.param("members", memberName);
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("invite").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("invite").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .post(Entity.form(form));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
// list group
JsonNode node = listUserGroup(username, groupName);
node = node.get(0);
assertEquals(2, node.get("members").size());
assertEquals(memberName, node.at("/members/1/userId").asText());
- assertEquals(GroupMemberStatus.PENDING.name(), node.at("/members/1/status").asText());
+ assertEquals(GroupMemberStatus.PENDING.name(),
+ node.at("/members/1/status").asText());
assertEquals(0, node.at("/members/1/roles").size());
}
- private void subscribeToGroup(String username, String groupName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("group").path("@" + groupName).path("subscribe").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).post(Entity.form(new Form()));
+ private void subscribeToGroup (String username, String groupName)
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("group")
+ .path("@" + groupName).path("subscribe").request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .post(Entity.form(new Form()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
- private void checkMemberInGroup(String memberName, String testUser, String groupName) throws KustvaktException {
+ private void checkMemberInGroup (String memberName, String testUser,
+ String groupName) throws KustvaktException {
JsonNode node = listUserGroup(testUser, groupName).get(0);
assertEquals(2, node.get("members").size());
assertEquals(memberName, node.at("/members/1/userId").asText());
- assertEquals(GroupMemberStatus.ACTIVE.name(), node.at("/members/1/status").asText());
- assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(), node.at("/members/1/roles/1").asText());
- assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(), node.at("/members/1/roles/0").asText());
+ assertEquals(GroupMemberStatus.ACTIVE.name(),
+ node.at("/members/1/status").asText());
+ assertEquals(PredefinedRole.VC_ACCESS_MEMBER.name(),
+ node.at("/members/1/roles/1").asText());
+ assertEquals(PredefinedRole.USER_GROUP_MEMBER.name(),
+ node.at("/members/1/roles/0").asText());
}
- private Response searchWithVCRef(String username, String vcCreator, String vcName) throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("cq", "referTo \"" + vcCreator + "/" + vcName + "\"").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue(username, "pass")).get();
+ private Response searchWithVCRef (String username, String vcCreator,
+ String vcName) throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("cq",
+ "referTo \"" + vcCreator + "/" + vcName + "\"")
+ .request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue(username, "pass"))
+ .get();
return response;
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
index 7293e04..04538e9 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
@@ -43,7 +43,7 @@
return JsonUtils.readTree(entity);
}
- protected void createVC (String authHeader,String username, String vcName,
+ protected void createVC (String authHeader, String username, String vcName,
String vcJson) throws KustvaktException {
Response response = target().path(API_VERSION).path("vc")
.path("~" + username).path(vcName).request()
@@ -78,7 +78,7 @@
// System.out.println(entity);
return JsonUtils.readTree(entity);
}
-
+
protected JsonNode listVCWithAuthHeader (String authHeader)
throws ProcessingException, KustvaktException {
Response response = target().path(API_VERSION).path("vc").request()
@@ -88,7 +88,7 @@
String entity = response.readEntity(String.class);
return JsonUtils.readTree(entity);
}
-
+
protected JsonNode testListOwnerVC (String username)
throws ProcessingException, KustvaktException {
Response response = target().path(API_VERSION).path("vc")
@@ -146,7 +146,7 @@
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
-
+
protected void testResponseUnauthorized (Response response, String username)
throws KustvaktException {
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -158,19 +158,22 @@
node.at("/errors/0/0").asInt());
assertEquals("Unauthorized operation for user: " + username,
node.at("/errors/0/1").asText());
-
+
checkWWWAuthenticateHeader(response);
}
-
+
protected void checkWWWAuthenticateHeader (Response response) {
- Set<Entry<String, List<Object>>> headers =
- response.getHeaders().entrySet();
+ Set<Entry<String, List<Object>>> headers = response.getHeaders()
+ .entrySet();
for (Entry<String, List<Object>> header : headers) {
if (header.getKey().equals(ContainerRequest.WWW_AUTHENTICATE)) {
- assertThat(header.getValue(), not(hasItem("Api realm=\"Kustvakt\"")));
- assertThat(header.getValue(), hasItem("Bearer realm=\"Kustvakt\""));
- assertThat(header.getValue(), hasItem("Basic realm=\"Kustvakt\""));
+ assertThat(header.getValue(),
+ not(hasItem("Api realm=\"Kustvakt\"")));
+ assertThat(header.getValue(),
+ hasItem("Bearer realm=\"Kustvakt\""));
+ assertThat(header.getValue(),
+ hasItem("Basic realm=\"Kustvakt\""));
}
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java
index f8b2b1d..27054fd 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/InfoControllerTest.java
@@ -25,15 +25,21 @@
private SearchKrill krill;
@Test
- public void testInfo() throws KustvaktException {
- Response response = target().path(API_VERSION).path("info").request().get();
+ public void testInfo () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("info").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(config.getCurrentVersion(), node.at("/latest_api_version").asText());
- assertEquals(config.getSupportedVersions().size(), node.at("/supported_api_versions").size());
- assertEquals(ServiceInfo.getInfo().getVersion(), node.at("/kustvakt_version").asText());
- assertEquals(krill.getIndex().getVersion(), node.at("/krill_version").asText());
- assertEquals(ServiceInfo.getInfo().getKoralVersion(), node.at("/koral_version").asText());
+ assertEquals(config.getCurrentVersion(),
+ node.at("/latest_api_version").asText());
+ assertEquals(config.getSupportedVersions().size(),
+ node.at("/supported_api_versions").size());
+ assertEquals(ServiceInfo.getInfo().getVersion(),
+ node.at("/kustvakt_version").asText());
+ assertEquals(krill.getIndex().getVersion(),
+ node.at("/krill_version").asText());
+ assertEquals(ServiceInfo.getInfo().getKoralVersion(),
+ node.at("/koral_version").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java
index c037f20..5d93355 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteMultipleCorpusQueryTest.java
@@ -18,8 +18,12 @@
public class LiteMultipleCorpusQueryTest extends LiteJerseyTest {
@Test
- public void testSearchGet() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "das").queryParam("ql", "poliqarp").queryParam("cq", "pubPlace=München").queryParam("cq", "textSigle=\"GOE/AGA/01784\"").request().get();
+ public void testSearchGet () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "das").queryParam("ql", "poliqarp")
+ .queryParam("cq", "pubPlace=München")
+ .queryParam("cq", "textSigle=\"GOE/AGA/01784\"").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -36,8 +40,11 @@
}
@Test
- public void testStatisticsWithMultipleCq() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung").queryParam("cq", "corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithMultipleCq ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung")
+ .queryParam("cq", "corpusSigle=GOE").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -49,8 +56,12 @@
}
@Test
- public void testStatisticsWithMultipleCorpusQuery() throws ProcessingException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "textType=Autobiographie").queryParam("corpusQuery", "corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithMultipleCorpusQuery ()
+ throws ProcessingException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "textType=Autobiographie")
+ .queryParam("corpusQuery", "corpusSigle=GOE").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -59,6 +70,7 @@
assertEquals(19387, node.at("/sentences").asInt());
assertEquals(514, node.at("/paragraphs").asInt());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "Parameter corpusQuery is deprecated in favor of cq.");
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "Parameter corpusQuery is deprecated in favor of cq.");
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java
index 60b6550..610646c0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchControllerTest.java
@@ -43,8 +43,11 @@
// EM: The API is disabled
@Disabled
@Test
- public void testGetJSONQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("context", "sentence").queryParam("count", "13").request().method("GET");
+ public void testGetJSONQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -58,13 +61,17 @@
// EM: The API is disabled
@Disabled
@Test
- public void testbuildAndPostQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE").request().method("GET");
+ public void testbuildAndPostQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
- response = target().path(API_VERSION).path("search").request().post(Entity.json(query));
+ response = target().path(API_VERSION).path("search").request()
+ .post(Entity.json(query));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String matches = response.readEntity(String.class);
JsonNode match_node = JsonUtils.readTree(matches);
@@ -72,17 +79,21 @@
}
@Test
- public void testApiWelcomeMessage() {
+ public void testApiWelcomeMessage () {
Response response = target().path(API_VERSION).path("").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String message = response.readEntity(String.class);
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
assertEquals(message, config.getApiWelcomeMessage());
}
@Test
- public void testQueryGet() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testQueryGet () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -94,8 +105,11 @@
}
@Test
- public void testQueryFailure() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das").queryParam("ql", "poliqarp").queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE").queryParam("count", "13").request().get();
+ public void testQueryFailure () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das").queryParam("ql", "poliqarp")
+ .queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
+ .queryParam("count", "13").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -108,8 +122,11 @@
}
@Test
- public void testFoundryRewrite() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testFoundryRewrite () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -121,10 +138,11 @@
// EM: The API is disabled
@Test
@Disabled
- public void testQueryPost() throws KustvaktException {
+ public void testQueryPost () throws KustvaktException {
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=das]", "poliqarp");
- Response response = target().path(API_VERSION).path("search").request().post(Entity.json(s.toJSON()));
+ Response response = target().path(API_VERSION).path("search").request()
+ .post(Entity.json(s.toJSON()));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -134,71 +152,105 @@
}
@Test
- public void testParameterField() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("fields", "author,docSigle").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testParameterField () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,docSigle")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals(node.at("/query/wrap/layer").asText(), "orth");
assertNotEquals(0, node.at("/matches").size());
- assertEquals(node.at("/meta/fields").toString(), "[\"author\",\"docSigle\"]");
+ assertEquals(node.at("/meta/fields").toString(),
+ "[\"author\",\"docSigle\"]");
}
@Test
- public void testMatchInfoGetWithoutSpans() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo").queryParam("foundry", "*").queryParam("spans", "false").request().get();
+ public void testMatchInfoGetWithoutSpans () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "*").queryParam("spans", "false")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoGetWithoutHighlights() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo").queryParam("foundry", "xy").queryParam("spans", "false").request().get();
+ public void testMatchInfoGetWithoutHighlights () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "xy").queryParam("spans", "false")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
- assertEquals(node.at("/snippet").asText(), "<span class=\"context-left\"></span><span class=\"match\">der alte freie Weg nach Mainz war gesperrt, ich mußte über die Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark> auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span><span class=\"context-right\"></span>");
+ assertEquals(node.at("/snippet").asText(),
+ "<span class=\"context-left\"></span><span class=\"match\">der alte freie Weg nach Mainz war gesperrt, ich mußte über die Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark> auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span><span class=\"context-right\"></span>");
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoWithoutExtension() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42").queryParam("foundry", "-").queryParam("spans", "false").queryParam("expand", "false").request().get();
+ public void testMatchInfoWithoutExtension () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42")
+ .queryParam("foundry", "-").queryParam("spans", "false")
+ .queryParam("expand", "false").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
- assertEquals(node.at("/snippet").asText(), "<span class=\"context-left\"><span class=\"more\"></span></span><span class=\"match\"><mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark></span><span class=\"context-right\"><span class=\"more\"></span></span>");
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(node.at("/snippet").asText(),
+ "<span class=\"context-left\"><span class=\"more\"></span></span><span class=\"match\"><mark>gefüttert; der Ort ist sehr zerschossen; dann über die Schiffbrücke</mark></span><span class=\"context-right\"><span class=\"more\"></span></span>");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoGetWithHighlights() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo").queryParam("foundry", "xy").queryParam("spans", "false").queryParam("hls", "true").request().get();
+ public void testMatchInfoGetWithHighlights () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46(5)37-45(2)38-42/matchInfo")
+ .queryParam("foundry", "xy").queryParam("spans", "false")
+ .queryParam("hls", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals(node.at("/textSigle").asText(), "GOE/AGA/01784");
- assertEquals("<span class=\"context-left\"></span><span class=\"match\">" + "der alte freie Weg nach Mainz war gesperrt, ich mußte über die " + "Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; " + "<mark class=\"class-5 level-0\">der <mark class=\"class-2 level-1\">" + "Ort ist sehr zerschossen; dann</mark> über die Schiffbrücke</mark></mark> " + "auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem " + "zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span>" + "<span class=\"context-right\"></span>", node.at("/snippet").asText());
- assertEquals(node.at("/matchID").asText(), "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
+ assertEquals(
+ "<span class=\"context-left\"></span><span class=\"match\">"
+ + "der alte freie Weg nach Mainz war gesperrt, ich mußte über die "
+ + "Schiffbrücke bei Rüsselsheim; in Ginsheim ward <mark>gefüttert; "
+ + "<mark class=\"class-5 level-0\">der <mark class=\"class-2 level-1\">"
+ + "Ort ist sehr zerschossen; dann</mark> über die Schiffbrücke</mark></mark> "
+ + "auf die Nonnenaue, wo viele Bäume niedergehauen lagen, sofort auf dem "
+ + "zweiten Teil der Schiffbrücke über den größern Arm des Rheins.</span>"
+ + "<span class=\"context-right\"></span>",
+ node.at("/snippet").asText());
+ assertEquals(node.at("/matchID").asText(),
+ "match-GOE/AGA/01784-p36-46(5)37-45(2)38-42");
assertEquals(node.at("/title").asText(), "Belagerung von Mainz");
}
@Test
- public void testMatchInfoGet2() throws KustvaktException {
- Response response = target().path(API_VERSION).path("corpus/GOE/AGA/01784/p36-46/matchInfo").queryParam("foundry", "*").request().get();
+ public void testMatchInfoGet2 () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("corpus/GOE/AGA/01784/p36-46/matchInfo")
+ .queryParam("foundry", "*").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -210,16 +262,27 @@
// EM: The API is disabled
@Disabled
@Test
- public void testCollectionQueryParameter() throws KustvaktException {
- Response response = target().path(API_VERSION).path("query").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("fields", "author, docSigle").queryParam("context", "sentence").queryParam("count", "13").queryParam("cq", "textClass=Politik & corpus=WPD").request().method("GET");
+ public void testCollectionQueryParameter () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("query")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author, docSigle")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .queryParam("cq", "textClass=Politik & corpus=WPD").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals(node.at("/query/wrap/layer").asText(), "orth");
- assertEquals(node.at("/collection/operands/0/value").asText(), "Politik");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "Politik");
assertEquals(node.at("/collection/operands/1/value").asText(), "WPD");
- response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("fields", "author, docSigle").queryParam("context", "sentence").queryParam("count", "13").queryParam("cq", "textClass=Politik & corpus=WPD").request().get();
+ response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author, docSigle")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .queryParam("cq", "textClass=Politik & corpus=WPD").request()
+ .get();
// String version =
// LucenePackage.get().getImplementationVersion();;
// System.out.println("VERSION "+ version);
@@ -229,22 +292,33 @@
node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals(node.at("/query/wrap/layer").asText(), "orth");
- assertEquals(node.at("/collection/operands/0/value").asText(), "Politik");
+ assertEquals(node.at("/collection/operands/0/value").asText(),
+ "Politik");
assertEquals(node.at("/collection/operands/1/value").asText(), "WPD");
}
@Test
- public void testTokenRetrieval() throws KustvaktException {
- Response response = target().path(API_VERSION).path("/corpus/GOE/AGA/01784/p104-105/").request().method("GET");
+ public void testTokenRetrieval () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("/corpus/GOE/AGA/01784/p104-105/").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String resp = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(resp);
assertTrue(node.at("/hasSnippet").asBoolean());
assertFalse(node.at("/hasTokens").asBoolean());
assertTrue(node.at("/tokens").isMissingNode());
- assertEquals("<span class=\"context-left\"><span class=\"more\"></span></span>" + "<span class=\"match\"><mark>die</mark></span>" + "<span class=\"context-right\"><span class=\"more\"></span></span>", node.at("/snippet").asText());
+ assertEquals(
+ "<span class=\"context-left\"><span class=\"more\"></span></span>"
+ + "<span class=\"match\"><mark>die</mark></span>"
+ + "<span class=\"context-right\"><span class=\"more\"></span></span>",
+ node.at("/snippet").asText());
// Tokens
- response = target().path(API_VERSION).path("/corpus/GOE/AGA/01784/p104-105").queryParam("show-snippet", "false").queryParam("show-tokens", "true").queryParam("expand", "false").request().method("GET");
+ response = target().path(API_VERSION)
+ .path("/corpus/GOE/AGA/01784/p104-105")
+ .queryParam("show-snippet", "false")
+ .queryParam("show-tokens", "true").queryParam("expand", "false")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
resp = response.readEntity(String.class);
node = JsonUtils.readTree(resp);
@@ -256,8 +330,9 @@
}
@Test
- public void testMetaFields() throws KustvaktException {
- Response response = target().path(API_VERSION).path("/corpus/GOE/AGA/01784").request().method("GET");
+ public void testMetaFields () throws KustvaktException {
+ Response response = target().path(API_VERSION)
+ .path("/corpus/GOE/AGA/01784").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String resp = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(resp);
@@ -276,7 +351,8 @@
break;
case "author":
assertEquals(field.at("/type").asText(), "type:text");
- assertEquals(field.at("/value").asText(), "Goethe, Johann Wolfgang von");
+ assertEquals(field.at("/value").asText(),
+ "Goethe, Johann Wolfgang von");
checkC++;
break;
case "docSigle":
@@ -286,7 +362,8 @@
break;
case "docTitle":
assertEquals(field.at("/type").asText(), "type:text");
- assertEquals(field.at("/value").asText(), "Goethe: Autobiographische Schriften II, (1817-1825, 1832)");
+ assertEquals(field.at("/value").asText(),
+ "Goethe: Autobiographische Schriften II, (1817-1825, 1832)");
checkC++;
break;
case "pubDate":
@@ -294,32 +371,37 @@
assertEquals(1982, field.at("/value").asInt());
checkC++;
break;
- }
- ;
- }
- ;
+ };
+ };
assertEquals(5, checkC);
}
@Test
- public void testSearchWithoutVersion() throws KustvaktException {
- Response response = target().path("api").path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchWithoutVersion () throws KustvaktException {
+ Response response = target().path("api").path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .request().accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals(location.getPath(), "/api/v1.0/search");
}
@Test
- public void testSearchWrongVersion() throws KustvaktException {
- Response response = target().path("api").path("v0.2").path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").request().accept(MediaType.APPLICATION_JSON).get();
+ public void testSearchWrongVersion () throws KustvaktException {
+ Response response = target().path("api").path("v0.2").path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .request().accept(MediaType.APPLICATION_JSON).get();
assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
URI location = response.getLocation();
assertEquals(location.getPath(), "/api/v1.0/search");
}
@Test
- public void testSearchWithIP() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Wasser").queryParam("ql", "poliqarp").request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testSearchWithIP () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Wasser").queryParam("ql", "poliqarp")
+ .request().header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -327,8 +409,13 @@
}
@Test
- public void testSearchWithAuthorizationHeader() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Wasser").queryParam("ql", "poliqarp").request().header(Attributes.AUTHORIZATION, HttpAuthorizationHandler.createBasicAuthorizationHeaderValue("test", "pwd")).header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
+ public void testSearchWithAuthorizationHeader () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Wasser").queryParam("ql", "poliqarp")
+ .request()
+ .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+ .createBasicAuthorizationHeaderValue("test", "pwd"))
+ .header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32").get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -336,8 +423,10 @@
}
@Test
- public void testSearchPublicMetadata() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadata () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -345,45 +434,61 @@
}
@Test
- public void testSearchPublicMetadataWithCustomFields() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("fields", "author,title").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithCustomFields ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,title")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertTrue(node.at("/matches/0/snippet").isMissingNode());
- assertEquals(node.at("/matches/0/author").asText(), "Goethe, Johann Wolfgang von");
- assertEquals(node.at("/matches/0/title").asText(), "Italienische Reise");
+ assertEquals(node.at("/matches/0/author").asText(),
+ "Goethe, Johann Wolfgang von");
+ assertEquals(node.at("/matches/0/title").asText(),
+ "Italienische Reise");
// assertEquals(3, node.at("/matches/0").size());
}
@Test
- public void testSearchPublicMetadataWithNonPublicField() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "Sonne").queryParam("ql", "poliqarp").queryParam("fields", "author,title,snippet").queryParam("access-rewrite-disabled", "true").request().get();
+ public void testSearchPublicMetadataWithNonPublicField ()
+ throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "Sonne").queryParam("ql", "poliqarp")
+ .queryParam("fields", "author,title,snippet")
+ .queryParam("access-rewrite-disabled", "true").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "The requested non public fields are ignored");
+ assertEquals(StatusCodes.NON_PUBLIC_FIELD_IGNORED,
+ node.at("/warnings/0/0").asInt());
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "The requested non public fields are ignored");
assertEquals(node.at("/warnings/0/2").asText(), "snippet");
}
@Test
- public void testSearchWithInvalidPage() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=die]").queryParam("ql", "poliqarp").queryParam("page", "0").request().get();
+ public void testSearchWithInvalidPage () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=die]").queryParam("ql", "poliqarp")
+ .queryParam("page", "0").request().get();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.INVALID_ARGUMENT, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(), "page must start from 1");
}
@Test
- public void testCloseIndex() throws IOException, KustvaktException {
+ public void testCloseIndex () throws IOException, KustvaktException {
searchKrill.getStatistics(null);
assertEquals(true, searchKrill.getIndex().isReaderOpen());
Form form = new Form();
form.param("token", "secret");
- Response response = target().path(API_VERSION).path("index").path("close").request().post(Entity.form(form));
+ Response response = target().path(API_VERSION).path("index")
+ .path("close").request().post(Entity.form(form));
assertEquals(HttpStatus.OK_200, response.getStatus());
assertEquals(false, searchKrill.getIndex().isReaderOpen());
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java
index f747934..704ae5f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchPipeTest.java
@@ -45,29 +45,43 @@
private String glemmUri = "http://localhost:" + port + "/glemm";
- public LiteSearchPipeTest() throws IOException {
- pipeJson = IOUtils.toString(ClassLoader.getSystemResourceAsStream("pipe-output/test-pipes.jsonld"), StandardCharsets.UTF_8);
- pipeWithParamJson = IOUtils.toString(ClassLoader.getSystemResourceAsStream("pipe-output/with-param.jsonld"), StandardCharsets.UTF_8);
+ public LiteSearchPipeTest () throws IOException {
+ pipeJson = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "pipe-output/test-pipes.jsonld"),
+ StandardCharsets.UTF_8);
+ pipeWithParamJson = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "pipe-output/with-param.jsonld"),
+ StandardCharsets.UTF_8);
}
@BeforeEach
- public void startMockServer() {
+ public void startMockServer () {
mockServer = startClientAndServer(port);
mockClient = new MockServerClient("localhost", mockServer.getPort());
}
@AfterEach
- public void stopMockServer() {
+ public void stopMockServer () {
mockServer.stop();
}
@Test
- public void testMockServer() throws IOException {
- mockClient.reset().when(request().withMethod("POST").withPath("/test").withHeader(new Header("Content-Type", "application/json; charset=utf-8"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody("{test}").withStatusCode(200));
+ public void testMockServer () throws IOException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/test")
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody("{test}").withStatusCode(200));
URL url = new URL("http://localhost:" + port + "/test");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+ connection.setRequestProperty("Content-Type",
+ "application/json; charset=UTF-8");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
String json = "{\"name\" : \"dory\"}";
@@ -76,14 +90,27 @@
os.write(input, 0, input.length);
}
assertEquals(200, connection.getResponseCode());
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
+ BufferedReader br = new BufferedReader(
+ new InputStreamReader(connection.getInputStream(), "utf-8"));
assertEquals(br.readLine(), "{test}");
}
@Test
- public void testSearchWithPipes() throws IOException, KustvaktException, URISyntaxException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri).request().get();
+ public void testSearchWithPipes ()
+ throws IOException, KustvaktException, URISyntaxException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -99,20 +126,44 @@
}
@Test
- public void testSearchWithUrlEncodedPipes() throws IOException, KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
+ public void testSearchWithUrlEncodedPipes ()
+ throws IOException, KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
glemmUri = URLEncoder.encode(glemmUri, "utf-8");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri).request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
}
@Test
- public void testSearchWithMultiplePipes() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withQueryStringParameter("param").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeWithParamJson).withStatusCode(200));
+ public void testSearchWithMultiplePipes () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withQueryStringParameter("param").withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeWithParamJson).withStatusCode(200));
String glemmUri2 = glemmUri + "?param=blah";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri + "," + glemmUri2).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri + "," + glemmUri2).request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -120,9 +171,13 @@
}
@Test
- public void testSearchWithUnknownURL() throws IOException, KustvaktException {
- String url = target().getUri().toString() + API_VERSION + "/test/tralala";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", url).request().get();
+ public void testSearchWithUnknownURL ()
+ throws IOException, KustvaktException {
+ String url = target().getUri().toString() + API_VERSION
+ + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", url).request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -131,8 +186,10 @@
}
@Test
- public void testSearchWithUnknownHost() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", "http://glemm").request().get();
+ public void testSearchWithUnknownHost () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", "http://glemm").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -141,21 +198,30 @@
}
@Test
- public void testSearchUnsupportedMediaType() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/non-json-pipe")).respond(response().withStatusCode(415));
+ public void testSearchUnsupportedMediaType () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/non-json-pipe"))
+ .respond(response().withStatusCode(415));
String pipeUri = "http://localhost:" + port + "/non-json-pipe";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.PIPE_FAILED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/3").asText(), "415 Unsupported Media Type");
+ assertEquals(node.at("/warnings/0/3").asText(),
+ "415 Unsupported Media Type");
}
@Test
- public void testSearchWithMultiplePipeWarnings() throws KustvaktException {
- String url = target().getUri().toString() + API_VERSION + "/test/tralala";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", url + "," + "http://glemm").request().get();
+ public void testSearchWithMultiplePipeWarnings () throws KustvaktException {
+ String url = target().getUri().toString() + API_VERSION
+ + "/test/tralala";
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", url + "," + "http://glemm").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -169,37 +235,73 @@
}
@Test
- public void testSearchWithInvalidJsonResponse() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/invalid-response").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withBody("{blah:}").withStatusCode(200).withHeaders(new Header("Content-Type", "application/json; charset=utf-8")));
+ public void testSearchWithInvalidJsonResponse () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/invalid-response")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response().withBody("{blah:}").withStatusCode(200)
+ .withHeaders(new Header("Content-Type",
+ "application/json; charset=utf-8")));
String pipeUri = "http://localhost:" + port + "/invalid-response";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testSearchWithPlainTextResponse() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/plain-text").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withBody("blah").withStatusCode(200));
+ public void testSearchWithPlainTextResponse () throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/plain-text")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response().withBody("blah").withStatusCode(200));
String pipeUri = "http://localhost:" + port + "/plain-text";
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", pipeUri).request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", pipeUri).request().get();
String entity = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
}
@Test
- public void testSearchWithMultipleAndUnknownPipes() throws KustvaktException {
- mockClient.reset().when(request().withMethod("POST").withPath("/glemm").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(pipeJson).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", "http://unknown" + "," + glemmUri).request().get();
+ public void testSearchWithMultipleAndUnknownPipes ()
+ throws KustvaktException {
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/glemm")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(pipeJson).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", "http://unknown" + "," + glemmUri)
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(2, node.at("/query/wrap/key").size());
assertTrue(node.at("/warnings").isMissingNode());
- response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("pipes", glemmUri + ",http://unknown").request().get();
+ response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("pipes", glemmUri + ",http://unknown").request()
+ .get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
entity = response.readEntity(String.class);
node = JsonUtils.readTree(entity);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java
index 75b9920..fb78508 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteSearchTokenSnippetTest.java
@@ -18,8 +18,12 @@
public class LiteSearchTokenSnippetTest extends LiteJerseyTest {
@Test
- public void testSearchWithTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("show-tokens", "true").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchWithTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -31,8 +35,12 @@
}
@Test
- public void testSearchWithoutTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("show-tokens", "false").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchWithoutTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("show-tokens", "false")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
@@ -42,8 +50,13 @@
}
@Test
- public void testSearchPublicMetadataWithTokens() throws KustvaktException {
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=das]").queryParam("ql", "poliqarp").queryParam("access-rewrite-disabled", "true").queryParam("show-tokens", "true").queryParam("context", "sentence").queryParam("count", "13").request().get();
+ public void testSearchPublicMetadataWithTokens () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
+ .queryParam("access-rewrite-disabled", "true")
+ .queryParam("show-tokens", "true")
+ .queryParam("context", "sentence").queryParam("count", "13")
+ .request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java
index 65e57c3..4314ef0 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java
@@ -21,10 +21,13 @@
public class LiteStatisticControllerTest extends LiteJerseyTest {
@Test
- public void testStatisticsWithCq() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCq () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
@@ -35,8 +38,12 @@
}
@Test
- public void testStatisticsWithCqAndCorpusQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("cq", "textType=Abhandlung & corpusSigle=GOE").queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCqAndCorpusQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
+ .queryParam("corpusQuery",
+ "textType=Autobiographie & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -48,8 +55,11 @@
}
@Test
- public void testStatisticsWithCorpusQuery() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "textType=Autobiographie & corpusSigle=GOE").request().method("GET");
+ public void testStatisticsWithCorpusQuery () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery",
+ "textType=Autobiographie & corpusSigle=GOE")
+ .request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -58,12 +68,14 @@
assertEquals(19387, node.at("/sentences").asInt());
assertEquals(514, node.at("/paragraphs").asInt());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
- assertEquals(node.at("/warnings/0/1").asText(), "Parameter corpusQuery is deprecated in favor of cq.");
+ assertEquals(node.at("/warnings/0/1").asText(),
+ "Parameter corpusQuery is deprecated in favor of cq.");
}
@Test
- public void testEmptyStatistics() throws KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").queryParam("corpusQuery", "").request().method("GET");
+ public void testEmptyStatistics () throws KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .queryParam("corpusQuery", "").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
@@ -71,7 +83,8 @@
assertEquals(665842, node.at("/tokens").asInt());
assertEquals(25074, node.at("/sentences").asInt());
assertEquals(772, node.at("/paragraphs").asInt());
- response = target().path(API_VERSION).path("statistics").request().method("GET");
+ response = target().path(API_VERSION).path("statistics").request()
+ .method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
query = response.readEntity(String.class);
node = JsonUtils.readTree(query);
@@ -82,11 +95,19 @@
}
@Test
- public void testGetStatisticsWithKoralQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{ \"collection\" : {\"@type\": " + "\"koral:doc\", \"key\": \"availability\", \"match\": " + "\"match:eq\", \"type\": \"type:regex\", \"value\": " + "\"CC-BY.*\"} }"));
+ public void testGetStatisticsWithKoralQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{ \"collection\" : {\"@type\": "
+ + "\"koral:doc\", \"key\": \"availability\", \"match\": "
+ + "\"match:eq\", \"type\": \"type:regex\", \"value\": "
+ + "\"CC-BY.*\"} }"));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
- assertEquals(response.getHeaders().getFirst("X-Index-Revision"), "Wes8Bd4h1OypPqbWF5njeQ==");
+ assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
+ "Wes8Bd4h1OypPqbWF5njeQ==");
JsonNode node = JsonUtils.readTree(ent);
assertEquals(2, node.at("/documents").asInt());
assertEquals(72770, node.at("/tokens").asInt());
@@ -95,28 +116,42 @@
}
@Test
- public void testGetStatisticsWithEmptyCollection() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{}"));
+ public void testGetStatisticsWithEmptyCollection ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{}"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(node.at("/errors/0/0").asInt(), de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
- assertEquals(node.at("/errors/0/1").asText(), "Collection is not found");
+ assertEquals(node.at("/errors/0/0").asInt(),
+ de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Collection is not found");
}
@Test
- public void testGetStatisticsWithIncorrectJson() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).post(Entity.json("{ \"collection\" : }"));
+ public void testGetStatisticsWithIncorrectJson ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .post(Entity.json("{ \"collection\" : }"));
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
- assertEquals(StatusCodes.DESERIALIZATION_FAILED, node.at("/errors/0/0").asInt());
- assertEquals(node.at("/errors/0/1").asText(), "Failed deserializing json object: { \"collection\" : }");
+ assertEquals(StatusCodes.DESERIALIZATION_FAILED,
+ node.at("/errors/0/0").asInt());
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Failed deserializing json object: { \"collection\" : }");
}
@Test
- public void testGetStatisticsWithoutKoralQuery() throws IOException, KustvaktException {
- Response response = target().path(API_VERSION).path("statistics").request().post(Entity.json(""));
+ public void testGetStatisticsWithoutKoralQuery ()
+ throws IOException, KustvaktException {
+ Response response = target().path(API_VERSION).path("statistics")
+ .request().post(Entity.json(""));
String ent = response.readEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java b/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java
index fa72cee..81c2430 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/lite/SearchNetworkEndpointTest.java
@@ -42,26 +42,41 @@
private String endpointURL = "http://localhost:" + port + "/searchEndpoint";
- public SearchNetworkEndpointTest() throws IOException {
- searchResult = IOUtils.toString(ClassLoader.getSystemResourceAsStream("network-output/search-result.jsonld"), StandardCharsets.UTF_8);
+ public SearchNetworkEndpointTest () throws IOException {
+ searchResult = IOUtils.toString(
+ ClassLoader.getSystemResourceAsStream(
+ "network-output/search-result.jsonld"),
+ StandardCharsets.UTF_8);
}
@BeforeEach
- public void startMockServer() {
+ public void startMockServer () {
mockServer = startClientAndServer(port);
mockClient = new MockServerClient("localhost", mockServer.getPort());
}
@AfterEach
- public void stopMockServer() {
+ public void stopMockServer () {
mockServer.stop();
}
@Test
- public void testSearchNetwork() throws IOException, KustvaktException, URISyntaxException {
+ public void testSearchNetwork ()
+ throws IOException, KustvaktException, URISyntaxException {
config.setNetworkEndpointURL(endpointURL);
- mockClient.reset().when(request().withMethod("POST").withPath("/searchEndpoint").withHeaders(new Header("Content-Type", "application/json; charset=utf-8"), new Header("Accept", "application/json"))).respond(response().withHeader(new Header("Content-Type", "application/json; charset=utf-8")).withBody(searchResult).withStatusCode(200));
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ mockClient.reset()
+ .when(request().withMethod("POST").withPath("/searchEndpoint")
+ .withHeaders(
+ new Header("Content-Type",
+ "application/json; charset=utf-8"),
+ new Header("Accept", "application/json")))
+ .respond(response()
+ .withHeader(new Header("Content-Type",
+ "application/json; charset=utf-8"))
+ .withBody(searchResult).withStatusCode(200));
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
@@ -69,22 +84,29 @@
}
@Test
- public void testSearchWithUnknownURL() throws IOException, KustvaktException {
+ public void testSearchWithUnknownURL ()
+ throws IOException, KustvaktException {
config.setNetworkEndpointURL("http://localhost:1040/search");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
@Test
- public void testSearchWithUnknownHost() throws KustvaktException {
+ public void testSearchWithUnknownHost () throws KustvaktException {
config.setNetworkEndpointURL("http://search.com");
- Response response = target().path(API_VERSION).path("search").queryParam("q", "[orth=der]").queryParam("ql", "poliqarp").queryParam("engine", "network").request().get();
+ Response response = target().path(API_VERSION).path("search")
+ .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+ .queryParam("engine", "network").request().get();
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
- assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED, node.at("/errors/0/0").asInt());
+ assertEquals(StatusCodes.SEARCH_NETWORK_ENDPOINT_FAILED,
+ node.at("/errors/0/0").asInt());
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
}
diff --git a/full/src/test/resources/test-config-icc.xml b/full/src/test/resources/test-config-icc.xml
index 9d65017..d418f05 100644
--- a/full/src/test/resources/test-config-icc.xml
+++ b/full/src/test/resources/test-config-icc.xml
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
@@ -15,7 +18,8 @@
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
- <context:component-scan base-package="de.ids_mannheim.korap" />
+ <context:component-scan
+ base-package="de.ids_mannheim.korap" />
<context:annotation-config />
<bean id="props"
@@ -44,17 +48,12 @@
</array>
</property>
</bean>
-
- <!--
- <bean id='cacheManager' class='org.springframework.cache.ehcache.EhCacheCacheManager'
- p:cacheManager-ref='ehcache' />
- <bean id='ehcache'
- class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
- p:configLocation='classpath:ehcache.xml' p:shared='true' />
- -->
- <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
- lazy-init="true">
+ <!-- <bean id='cacheManager' class='org.springframework.cache.ehcache.EhCacheCacheManager'
+ p:cacheManager-ref='ehcache' /> <bean id='ehcache' class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
+ p:configLocation='classpath:ehcache.xml' p:shared='true' /> -->
+ <bean id="dataSource"
+ class="org.apache.commons.dbcp2.BasicDataSource" lazy-init="true">
<!-- <property name="driverClassName" value="${jdbc.driverClassName}" /> -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
@@ -86,7 +85,8 @@
</property>
</bean>
- <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
+ <bean id="c3p0DataSource"
+ class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
@@ -99,21 +99,24 @@
</bean>
<!-- to configure database for sqlite, mysql, etc. migrations -->
- <bean id="flywayConfig" class="org.flywaydb.core.api.configuration.ClassicConfiguration">
+ <bean id="flywayConfig"
+ class="org.flywaydb.core.api.configuration.ClassicConfiguration">
<!-- drop existing tables and create new tables -->
<property name="validateOnMigrate" value="true" />
<property name="cleanOnValidationError" value="true" />
<property name="baselineOnMigrate" value="false" />
- <property name="locations" value="#{'${jdbc.schemaPath}'.split(',')}"/>
+ <property name="locations"
+ value="#{'${jdbc.schemaPath}'.split(',')}" />
<property name="dataSource" ref="sqliteDataSource" />
<!-- <property name="dataSource" ref="dataSource" /> -->
<property name="outOfOrder" value="true" />
</bean>
-
- <bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
- <constructor-arg ref="flywayConfig"/>
+
+ <bean id="flyway" class="org.flywaydb.core.Flyway"
+ init-method="migrate">
+ <constructor-arg ref="flywayConfig" />
</bean>
-
+
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
@@ -129,7 +132,8 @@
<property name="jpaVendorAdapter">
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
- <property name="databasePlatform" value="${hibernate.dialect}" />
+ <property name="databasePlatform"
+ value="${hibernate.dialect}" />
</bean>
</property>
<property name="jpaProperties">
@@ -150,8 +154,10 @@
<tx:annotation-driven proxy-target-class="true"
transaction-manager="transactionManager" />
- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory" />
+ <bean id="transactionManager"
+ class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory"
+ ref="entityManagerFactory" />
</bean>
<bean id="transactionTemplate"
@@ -161,75 +167,95 @@
<!-- Data access objects -->
<bean id="adminDao" class="de.ids_mannheim.korap.dao.AdminDaoImpl" />
- <bean id="resourceDao" class="de.ids_mannheim.korap.dao.ResourceDao" />
- <bean id="accessScopeDao" class="de.ids_mannheim.korap.oauth2.dao.AccessScopeDao" />
- <bean id="authorizationDao" class="de.ids_mannheim.korap.oauth2.dao.CachedAuthorizationDaoImpl" />
-
+ <bean id="resourceDao"
+ class="de.ids_mannheim.korap.dao.ResourceDao" />
+ <bean id="accessScopeDao"
+ class="de.ids_mannheim.korap.oauth2.dao.AccessScopeDao" />
+ <bean id="authorizationDao"
+ class="de.ids_mannheim.korap.oauth2.dao.CachedAuthorizationDaoImpl" />
+
<!-- Services -->
- <bean id="scopeService" class="de.ids_mannheim.korap.oauth2.service.OAuth2ScopeServiceImpl" />
-
-
+ <bean id="scopeService"
+ class="de.ids_mannheim.korap.oauth2.service.OAuth2ScopeServiceImpl" />
+
+
<!-- Controller -->
-
-
+
+
<!-- props are injected from default-config.xml -->
- <bean id="kustvakt_config" class="de.ids_mannheim.korap.config.FullConfiguration">
+ <bean id="kustvakt_config"
+ class="de.ids_mannheim.korap.config.FullConfiguration">
<constructor-arg name="properties" ref="props" />
</bean>
- <bean id="initializator" class="de.ids_mannheim.korap.init.Initializator"
+ <bean id="initializator"
+ class="de.ids_mannheim.korap.init.Initializator"
init-method="initTest">
</bean>
<!-- Krill -->
- <bean id="search_krill" class="de.ids_mannheim.korap.web.SearchKrill">
+ <bean id="search_krill"
+ class="de.ids_mannheim.korap.web.SearchKrill">
<constructor-arg value="${krill.indexDir}" />
</bean>
<!-- Validator -->
- <bean id="validator" class="de.ids_mannheim.korap.validator.ApacheValidator"/>
-
+ <bean id="validator"
+ class="de.ids_mannheim.korap.validator.ApacheValidator" />
+
<!-- URLValidator -->
- <bean id="redirectURIValidator" class="org.apache.commons.validator.routines.UrlValidator">
+ <bean id="redirectURIValidator"
+ class="org.apache.commons.validator.routines.UrlValidator">
<constructor-arg value="http,https" index="0" />
- <constructor-arg index="1" type="long"
- value="#{T(org.apache.commons.validator.routines.UrlValidator).ALLOW_LOCAL_URLS +
- T(org.apache.commons.validator.routines.UrlValidator).NO_FRAGMENTS}"/>
+ <constructor-arg index="1" type="long"
+ value="#{T(org.apache.commons.validator.routines.UrlValidator).ALLOW_LOCAL_URLS +
+ T(org.apache.commons.validator.routines.UrlValidator).NO_FRAGMENTS}" />
</bean>
- <bean id="urlValidator" class="org.apache.commons.validator.routines.UrlValidator">
+ <bean id="urlValidator"
+ class="org.apache.commons.validator.routines.UrlValidator">
<constructor-arg value="http,https" />
</bean>
<!-- Rewrite -->
- <bean id="foundryRewrite" class="de.ids_mannheim.korap.rewrite.FoundryRewrite"/>
- <bean id="collectionRewrite" class="de.ids_mannheim.korap.rewrite.CollectionRewrite"/>
- <bean id="collectionCleanRewrite" class="de.ids_mannheim.korap.rewrite.CollectionCleanRewrite"/>
- <bean id="virtualCorpusRewrite" class="de.ids_mannheim.korap.rewrite.VirtualCorpusRewrite"/>
- <bean id="collectionConstraint" class="de.ids_mannheim.korap.rewrite.CollectionConstraint"/>
- <bean id="queryReferenceRewrite" class="de.ids_mannheim.korap.rewrite.QueryReferenceRewrite"/>
-
+ <bean id="foundryRewrite"
+ class="de.ids_mannheim.korap.rewrite.FoundryRewrite" />
+ <bean id="collectionRewrite"
+ class="de.ids_mannheim.korap.rewrite.CollectionRewrite" />
+ <bean id="collectionCleanRewrite"
+ class="de.ids_mannheim.korap.rewrite.CollectionCleanRewrite" />
+ <bean id="virtualCorpusRewrite"
+ class="de.ids_mannheim.korap.rewrite.VirtualCorpusRewrite" />
+ <bean id="collectionConstraint"
+ class="de.ids_mannheim.korap.rewrite.CollectionConstraint" />
+ <bean id="queryReferenceRewrite"
+ class="de.ids_mannheim.korap.rewrite.QueryReferenceRewrite" />
+
<util:list id="rewriteTasks"
value-type="de.ids_mannheim.korap.rewrite.RewriteTask">
- <!-- <ref bean="collectionConstraint" />
- <ref bean="collectionCleanRewrite" /> -->
+ <!-- <ref bean="collectionConstraint" /> <ref bean="collectionCleanRewrite"
+ /> -->
<ref bean="foundryRewrite" />
<!-- <ref bean="collectionRewrite" /> -->
<ref bean="virtualCorpusRewrite" />
<ref bean="queryReferenceRewrite" />
</util:list>
-
- <bean id="rewriteHandler" class="de.ids_mannheim.korap.rewrite.RewriteHandler">
- <constructor-arg ref="rewriteTasks"/>
+
+ <bean id="rewriteHandler"
+ class="de.ids_mannheim.korap.rewrite.RewriteHandler">
+ <constructor-arg ref="rewriteTasks" />
</bean>
- <bean id="kustvaktResponseHandler" class="de.ids_mannheim.korap.web.KustvaktResponseHandler">
+ <bean id="kustvaktResponseHandler"
+ class="de.ids_mannheim.korap.web.KustvaktResponseHandler">
</bean>
<!-- OAuth -->
- <bean id="oauth2ResponseHandler" class="de.ids_mannheim.korap.web.OAuth2ResponseHandler">
+ <bean id="oauth2ResponseHandler"
+ class="de.ids_mannheim.korap.web.OAuth2ResponseHandler">
</bean>
- <bean name="kustvakt_encryption" class="de.ids_mannheim.korap.encryption.KustvaktEncryption">
+ <bean name="kustvakt_encryption"
+ class="de.ids_mannheim.korap.encryption.KustvaktEncryption">
<constructor-arg ref="kustvakt_config" />
</bean>
@@ -251,7 +277,8 @@
<!-- specify type for constructor argument -->
<bean id="authenticationManager"
class="de.ids_mannheim.korap.authentication.KustvaktAuthenticationManager">
- <constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.EncryptionIface"
ref="kustvakt_encryption" />
<constructor-arg ref="kustvakt_config" />
<!-- inject authentication providers to use -->
@@ -266,7 +293,8 @@
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
- <tx:method name="get*" read-only="true" rollback-for="KorAPException" />
+ <tx:method name="get*" read-only="true"
+ rollback-for="KorAPException" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*" rollback-for="KorAPException" />
</tx:attributes>
@@ -287,11 +315,13 @@
</bean>
<!-- mail -->
- <bean id="authenticator" class="de.ids_mannheim.korap.service.MailAuthenticator">
+ <bean id="authenticator"
+ class="de.ids_mannheim.korap.service.MailAuthenticator">
<constructor-arg index="0" value="${mail.username}" />
<constructor-arg index="1" value="${mail.password}" />
</bean>
- <bean id="smtpSession" class="jakarta.mail.Session" factory-method="getInstance">
+ <bean id="smtpSession" class="jakarta.mail.Session"
+ factory-method="getInstance">
<constructor-arg index="0">
<props>
<prop key="mail.smtp.submitter">${mail.username}</prop>
@@ -304,10 +334,12 @@
</constructor-arg>
<constructor-arg index="1" ref="authenticator" />
</bean>
- <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
+ <bean id="mailSender"
+ class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="smtpSession" />
</bean>
- <bean id="velocityEngine" class="org.apache.velocity.app.VelocityEngine">
+ <bean id="velocityEngine"
+ class="org.apache.velocity.app.VelocityEngine">
<constructor-arg index="0">
<props>
<prop key="resource.loader">class</prop>
diff --git a/full/src/test/resources/test-config-lite.xml b/full/src/test/resources/test-config-lite.xml
index 96ac3bf..5de7bd6 100644
--- a/full/src/test/resources/test-config-lite.xml
+++ b/full/src/test/resources/test-config-lite.xml
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
@@ -10,8 +12,9 @@
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
-
- <context:component-scan base-package="
+
+ <context:component-scan
+ base-package="
de.ids_mannheim.korap.core.service,
de.ids_mannheim.korap.core.web,
de.ids_mannheim.korap.web.filter,
@@ -44,14 +47,16 @@
</property>
</bean>
- <bean id="config" class="de.ids_mannheim.korap.config.KustvaktConfiguration">
- <constructor-arg index="0" name="properties" ref="properties" />
+ <bean id="config"
+ class="de.ids_mannheim.korap.config.KustvaktConfiguration">
+ <constructor-arg index="0" name="properties"
+ ref="properties" />
</bean>
<!-- Database -->
- <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
- lazy-init="true">
+ <bean id="dataSource"
+ class="org.apache.commons.dbcp2.BasicDataSource" lazy-init="true">
<!-- <property name="driverClassName" value="${jdbc.driverClassName}" /> -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
@@ -66,7 +71,8 @@
<bean id="sqliteDataSource"
class="org.springframework.jdbc.datasource.SingleConnectionDataSource"
lazy-init="true">
- <property name="driverClassName" value="${jdbc.driverClassName}" />
+ <property name="driverClassName"
+ value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
@@ -82,17 +88,20 @@
</property>
</bean>
- <bean id="flywayConfig" class="org.flywaydb.core.api.configuration.ClassicConfiguration">
- <property name="baselineOnMigrate" value="true" />
+ <bean id="flywayConfig"
+ class="org.flywaydb.core.api.configuration.ClassicConfiguration">
+ <property name="baselineOnMigrate" value="true" />
<!-- <property name="validateOnMigrate" value="false" /> -->
<!-- <property name="cleanOnValidationError" value="true" /> -->
- <property name="locations" value="#{'${jdbc.schemaPath}'.split(',')}"/>
+ <property name="locations"
+ value="#{'${jdbc.schemaPath}'.split(',')}" />
<property name="dataSource" ref="dataSource" />
<property name="outOfOrder" value="true" />
</bean>
-
- <bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
- <constructor-arg ref="flywayConfig"/>
+
+ <bean id="flyway" class="org.flywaydb.core.Flyway"
+ init-method="migrate">
+ <constructor-arg ref="flywayConfig" />
</bean>
<bean id="entityManagerFactory"
@@ -107,7 +116,8 @@
<property name="jpaVendorAdapter">
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
- <property name="databasePlatform" value="${hibernate.dialect}" />
+ <property name="databasePlatform"
+ value="${hibernate.dialect}" />
</bean>
</property>
<property name="jpaProperties">
@@ -127,8 +137,10 @@
<tx:annotation-driven proxy-target-class="true"
transaction-manager="transactionManager" />
- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory" />
+ <bean id="transactionManager"
+ class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory"
+ ref="entityManagerFactory" />
</bean>
<bean id="transactionTemplate"
@@ -141,10 +153,11 @@
</bean>
<!-- Search Engine -->
- <bean id="search_krill" class="de.ids_mannheim.korap.web.SearchKrill">
+ <bean id="search_krill"
+ class="de.ids_mannheim.korap.web.SearchKrill">
<constructor-arg value="${krill.indexDir}" />
</bean>
-
+
<!-- Filters -->
<!-- <bean id="APIVersionFilter" class="de.ids_mannheim.korap.web.APIVersionFilter"
@@ -154,37 +167,42 @@
class="de.ids_mannheim.korap.authentication.DummyAuthenticationManager" />
<!-- Response handler -->
- <bean id="kustvaktResponseHandler" class="de.ids_mannheim.korap.web.KustvaktResponseHandler">
+ <bean id="kustvaktResponseHandler"
+ class="de.ids_mannheim.korap.web.KustvaktResponseHandler">
</bean>
<!-- Controllers -->
- <!-- added via component-scan
- <bean id="annotationController"
- class="de.ids_mannheim.korap.web.controller.AnnotationController" />
- <bean id="searchController" class="de.ids_mannheim.korap.web.controller.SearchController" />
- <bean id="statisticController"
- class="de.ids_mannheim.korap.web.controller.StatisticController" />
- -->
+ <!-- added via component-scan <bean id="annotationController" class="de.ids_mannheim.korap.web.controller.AnnotationController"
+ /> <bean id="searchController" class="de.ids_mannheim.korap.web.controller.SearchController"
+ /> <bean id="statisticController" class="de.ids_mannheim.korap.web.controller.StatisticController"
+ /> -->
<!-- Services -->
<bean id="scopeService"
class="de.ids_mannheim.korap.oauth2.service.DummyOAuth2ScopeServiceImpl" />
<!-- DAO -->
- <bean id="adminDao" class="de.ids_mannheim.korap.dao.DummyAdminDaoImpl" />
- <bean id="annotationDao" class="de.ids_mannheim.korap.dao.AnnotationDao" />
+ <bean id="adminDao"
+ class="de.ids_mannheim.korap.dao.DummyAdminDaoImpl" />
+ <bean id="annotationDao"
+ class="de.ids_mannheim.korap.dao.AnnotationDao" />
<!-- DTO Converter -->
- <bean id="annotationConverter" class="de.ids_mannheim.korap.dto.converter.AnnotationConverter" />
+ <bean id="annotationConverter"
+ class="de.ids_mannheim.korap.dto.converter.AnnotationConverter" />
<!-- Rewrite -->
- <bean id="layerMapper" class="de.ids_mannheim.korap.rewrite.LayerMapper" />
- <bean id="foundryInject" class="de.ids_mannheim.korap.rewrite.FoundryInject" />
+ <bean id="layerMapper"
+ class="de.ids_mannheim.korap.rewrite.LayerMapper" />
+ <bean id="foundryInject"
+ class="de.ids_mannheim.korap.rewrite.FoundryInject" />
- <util:list id="rewriteTasks" value-type="de.ids_mannheim.korap.rewrite.RewriteTask">
+ <util:list id="rewriteTasks"
+ value-type="de.ids_mannheim.korap.rewrite.RewriteTask">
<ref bean="foundryInject" />
</util:list>
- <bean id="rewriteHandler" class="de.ids_mannheim.korap.rewrite.RewriteHandler">
+ <bean id="rewriteHandler"
+ class="de.ids_mannheim.korap.rewrite.RewriteHandler">
<constructor-arg ref="rewriteTasks" />
</bean>
</beans>
\ No newline at end of file
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index b3ae6f3..d1dd61c 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
@@ -15,7 +18,8 @@
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
- <context:component-scan base-package="de.ids_mannheim.korap" />
+ <context:component-scan
+ base-package="de.ids_mannheim.korap" />
<context:annotation-config />
<bean id="props"
@@ -45,15 +49,12 @@
</property>
</bean>
- <!-- <bean id='cacheManager' class='org.springframework.cache.ehcache.EhCacheCacheManager'
- p:cacheManager-ref='ehcache' />
-
- <bean id='ehcache'
- class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
+ <!-- <bean id='cacheManager' class='org.springframework.cache.ehcache.EhCacheCacheManager'
+ p:cacheManager-ref='ehcache' /> <bean id='ehcache' class='org.springframework.cache.ehcache.EhCacheManagerFactoryBean'
p:configLocation='classpath:ehcache.xml' p:shared='true' /> -->
- <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
- lazy-init="true">
+ <bean id="dataSource"
+ class="org.apache.commons.dbcp2.BasicDataSource" lazy-init="true">
<!-- <property name="driverClassName" value="${jdbc.driverClassName}" /> -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
@@ -85,7 +86,8 @@
</property>
</bean>
- <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
+ <bean id="c3p0DataSource"
+ class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
@@ -98,21 +100,24 @@
</bean>
<!-- to configure database for sqlite, mysql, etc. migrations -->
- <bean id="flywayConfig" class="org.flywaydb.core.api.configuration.ClassicConfiguration">
+ <bean id="flywayConfig"
+ class="org.flywaydb.core.api.configuration.ClassicConfiguration">
<!-- drop existing tables and create new tables -->
<property name="validateOnMigrate" value="true" />
<property name="cleanOnValidationError" value="true" />
<property name="baselineOnMigrate" value="false" />
- <property name="locations" value="#{'${jdbc.schemaPath}'.split(',')}"/>
+ <property name="locations"
+ value="#{'${jdbc.schemaPath}'.split(',')}" />
<!-- <property name="dataSource" ref="sqliteDataSource" /> -->
<property name="dataSource" ref="dataSource" />
<property name="outOfOrder" value="true" />
</bean>
-
- <bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
- <constructor-arg ref="flywayConfig"/>
+
+ <bean id="flyway" class="org.flywaydb.core.Flyway"
+ init-method="migrate">
+ <constructor-arg ref="flywayConfig" />
</bean>
-
+
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
@@ -128,7 +133,8 @@
<property name="jpaVendorAdapter">
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
- <property name="databasePlatform" value="${hibernate.dialect}" />
+ <property name="databasePlatform"
+ value="${hibernate.dialect}" />
</bean>
</property>
<property name="jpaProperties">
@@ -149,8 +155,10 @@
<tx:annotation-driven proxy-target-class="true"
transaction-manager="transactionManager" />
- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory" />
+ <bean id="transactionManager"
+ class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory"
+ ref="entityManagerFactory" />
</bean>
<bean id="transactionTemplate"
@@ -160,71 +168,91 @@
<!-- Data access objects -->
<bean id="adminDao" class="de.ids_mannheim.korap.dao.AdminDaoImpl" />
- <bean id="resourceDao" class="de.ids_mannheim.korap.dao.ResourceDao" />
- <bean id="accessScopeDao" class="de.ids_mannheim.korap.oauth2.dao.AccessScopeDao" />
- <bean id="authorizationDao" class="de.ids_mannheim.korap.oauth2.dao.CachedAuthorizationDaoImpl" />
-
+ <bean id="resourceDao"
+ class="de.ids_mannheim.korap.dao.ResourceDao" />
+ <bean id="accessScopeDao"
+ class="de.ids_mannheim.korap.oauth2.dao.AccessScopeDao" />
+ <bean id="authorizationDao"
+ class="de.ids_mannheim.korap.oauth2.dao.CachedAuthorizationDaoImpl" />
+
<!-- Services -->
- <bean id="scopeService" class="de.ids_mannheim.korap.oauth2.service.OAuth2ScopeServiceImpl" />
-
+ <bean id="scopeService"
+ class="de.ids_mannheim.korap.oauth2.service.OAuth2ScopeServiceImpl" />
+
<!-- props are injected from default-config.xml -->
- <bean id="kustvakt_config" class="de.ids_mannheim.korap.config.FullConfiguration">
+ <bean id="kustvakt_config"
+ class="de.ids_mannheim.korap.config.FullConfiguration">
<constructor-arg name="properties" ref="props" />
</bean>
- <bean id="initializator" class="de.ids_mannheim.korap.init.Initializator"
+ <bean id="initializator"
+ class="de.ids_mannheim.korap.init.Initializator"
init-method="initTest">
</bean>
<!-- Krill -->
- <bean id="search_krill" class="de.ids_mannheim.korap.web.SearchKrill">
+ <bean id="search_krill"
+ class="de.ids_mannheim.korap.web.SearchKrill">
<constructor-arg value="${krill.indexDir}" />
</bean>
<!-- Validator -->
- <bean id="validator" class="de.ids_mannheim.korap.validator.ApacheValidator"/>
-
+ <bean id="validator"
+ class="de.ids_mannheim.korap.validator.ApacheValidator" />
+
<!-- URLValidator -->
- <bean id="redirectURIValidator" class="org.apache.commons.validator.routines.UrlValidator">
+ <bean id="redirectURIValidator"
+ class="org.apache.commons.validator.routines.UrlValidator">
<constructor-arg value="http,https" index="0" />
- <constructor-arg index="1" type="long"
- value="#{T(org.apache.commons.validator.routines.UrlValidator).ALLOW_LOCAL_URLS +
- T(org.apache.commons.validator.routines.UrlValidator).NO_FRAGMENTS}"/>
+ <constructor-arg index="1" type="long"
+ value="#{T(org.apache.commons.validator.routines.UrlValidator).ALLOW_LOCAL_URLS +
+ T(org.apache.commons.validator.routines.UrlValidator).NO_FRAGMENTS}" />
</bean>
- <bean id="urlValidator" class="org.apache.commons.validator.routines.UrlValidator">
+ <bean id="urlValidator"
+ class="org.apache.commons.validator.routines.UrlValidator">
<constructor-arg value="http,https" />
</bean>
<!-- Rewrite -->
- <bean id="foundryRewrite" class="de.ids_mannheim.korap.rewrite.FoundryRewrite"/>
- <bean id="collectionRewrite" class="de.ids_mannheim.korap.rewrite.CollectionRewrite"/>
- <bean id="collectionCleanRewrite" class="de.ids_mannheim.korap.rewrite.CollectionCleanRewrite"/>
- <bean id="virtualCorpusRewrite" class="de.ids_mannheim.korap.rewrite.VirtualCorpusRewrite"/>
- <bean id="collectionConstraint" class="de.ids_mannheim.korap.rewrite.CollectionConstraint"/>
- <bean id="queryReferenceRewrite" class="de.ids_mannheim.korap.rewrite.QueryReferenceRewrite"/>
-
+ <bean id="foundryRewrite"
+ class="de.ids_mannheim.korap.rewrite.FoundryRewrite" />
+ <bean id="collectionRewrite"
+ class="de.ids_mannheim.korap.rewrite.CollectionRewrite" />
+ <bean id="collectionCleanRewrite"
+ class="de.ids_mannheim.korap.rewrite.CollectionCleanRewrite" />
+ <bean id="virtualCorpusRewrite"
+ class="de.ids_mannheim.korap.rewrite.VirtualCorpusRewrite" />
+ <bean id="collectionConstraint"
+ class="de.ids_mannheim.korap.rewrite.CollectionConstraint" />
+ <bean id="queryReferenceRewrite"
+ class="de.ids_mannheim.korap.rewrite.QueryReferenceRewrite" />
+
<util:list id="rewriteTasks"
value-type="de.ids_mannheim.korap.rewrite.RewriteTask">
- <!-- <ref bean="collectionConstraint" />
- <ref bean="collectionCleanRewrite" /> -->
+ <!-- <ref bean="collectionConstraint" /> <ref bean="collectionCleanRewrite"
+ /> -->
<ref bean="foundryRewrite" />
<ref bean="collectionRewrite" />
<ref bean="virtualCorpusRewrite" />
<ref bean="queryReferenceRewrite" />
</util:list>
-
- <bean id="rewriteHandler" class="de.ids_mannheim.korap.rewrite.RewriteHandler">
- <constructor-arg ref="rewriteTasks"/>
+
+ <bean id="rewriteHandler"
+ class="de.ids_mannheim.korap.rewrite.RewriteHandler">
+ <constructor-arg ref="rewriteTasks" />
</bean>
- <bean id="kustvaktResponseHandler" class="de.ids_mannheim.korap.web.KustvaktResponseHandler">
+ <bean id="kustvaktResponseHandler"
+ class="de.ids_mannheim.korap.web.KustvaktResponseHandler">
</bean>
<!-- OAuth -->
- <bean id="oauth2ResponseHandler" class="de.ids_mannheim.korap.web.OAuth2ResponseHandler">
+ <bean id="oauth2ResponseHandler"
+ class="de.ids_mannheim.korap.web.OAuth2ResponseHandler">
</bean>
- <bean name="kustvakt_encryption" class="de.ids_mannheim.korap.encryption.KustvaktEncryption">
+ <bean name="kustvakt_encryption"
+ class="de.ids_mannheim.korap.encryption.KustvaktEncryption">
<constructor-arg ref="kustvakt_config" />
</bean>
@@ -235,9 +263,11 @@
<bean id="session_auth"
class="de.ids_mannheim.korap.authentication.SessionAuthentication">
- <constructor-arg type="de.ids_mannheim.korap.config.KustvaktConfiguration"
+ <constructor-arg
+ type="de.ids_mannheim.korap.config.KustvaktConfiguration"
ref="kustvakt_config" />
- <constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.EncryptionIface"
ref="kustvakt_encryption" />
</bean>
@@ -255,7 +285,8 @@
<!-- specify type for constructor argument -->
<bean id="authenticationManager"
class="de.ids_mannheim.korap.authentication.KustvaktAuthenticationManager">
- <constructor-arg type="de.ids_mannheim.korap.interfaces.EncryptionIface"
+ <constructor-arg
+ type="de.ids_mannheim.korap.interfaces.EncryptionIface"
ref="kustvakt_encryption" />
<constructor-arg ref="kustvakt_config" />
<!-- inject authentication providers to use -->
@@ -270,7 +301,8 @@
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
- <tx:method name="get*" read-only="true" rollback-for="KorAPException" />
+ <tx:method name="get*" read-only="true"
+ rollback-for="KorAPException" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*" rollback-for="KorAPException" />
</tx:attributes>
@@ -291,11 +323,13 @@
</bean>
<!-- mail -->
- <bean id="authenticator" class="de.ids_mannheim.korap.service.MailAuthenticator">
+ <bean id="authenticator"
+ class="de.ids_mannheim.korap.service.MailAuthenticator">
<constructor-arg index="0" value="${mail.username}" />
<constructor-arg index="1" value="${mail.password}" />
</bean>
- <bean id="smtpSession" class="jakarta.mail.Session" factory-method="getInstance">
+ <bean id="smtpSession" class="jakarta.mail.Session"
+ factory-method="getInstance">
<constructor-arg index="0">
<props>
<prop key="mail.smtp.submitter">${mail.username}</prop>
@@ -308,10 +342,12 @@
</constructor-arg>
<constructor-arg index="1" ref="authenticator" />
</bean>
- <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
+ <bean id="mailSender"
+ class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="smtpSession" />
</bean>
- <bean id="velocityEngine" class="org.apache.velocity.app.VelocityEngine">
+ <bean id="velocityEngine"
+ class="org.apache.velocity.app.VelocityEngine">
<constructor-arg index="0">
<props>
<prop key="resource.loader">class</prop>
diff --git a/full/src/test/resources/test-resource-config.xml b/full/src/test/resources/test-resource-config.xml
index 28eea3e..f26182c 100644
--- a/full/src/test/resources/test-resource-config.xml
+++ b/full/src/test/resources/test-resource-config.xml
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
@@ -15,8 +18,9 @@
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
- <import resource="classpath:test-config.xml"/>
- <bean id="initializator" class="de.ids_mannheim.korap.init.Initializator"
+ <import resource="classpath:test-config.xml" />
+ <bean id="initializator"
+ class="de.ids_mannheim.korap.init.Initializator"
init-method="initResourceTest">
</bean>