1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-16 03:06:22 +00:00

Unified documents search, tag validation

This commit is contained in:
jendib
2013-08-16 15:01:53 +02:00
parent b4e58212f0
commit 988f55de3f
12 changed files with 196 additions and 99 deletions

View File

@@ -35,7 +35,7 @@ public class TestDocumentResource extends BaseJerseyTest {
WebResource tagResource = resource().path("/tag");
tagResource.addFilter(new CookieAuthenticationFilter(document1Token));
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
postParams.add("name", "Super tag");
postParams.add("name", "SuperTag");
postParams.add("color", "#ffff00");
ClientResponse response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@@ -82,7 +82,7 @@ public class TestDocumentResource extends BaseJerseyTest {
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
Assert.assertEquals(1, tags.length());
Assert.assertEquals(tag1Id, tags.getJSONObject(0).getString("id"));
Assert.assertEquals("Super tag", tags.getJSONObject(0).getString("name"));
Assert.assertEquals("SuperTag", tags.getJSONObject(0).getString("name"));
Assert.assertEquals("#ffff00", tags.getJSONObject(0).getString("color"));
// Search documents by query
@@ -102,8 +102,7 @@ public class TestDocumentResource extends BaseJerseyTest {
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
getParams = new MultivaluedMapImpl();
getParams.putSingle("create_date_min", create1Date - 3600000);
getParams.putSingle("create_date_max", create1Date + 1800000);
getParams.putSingle("search", "after:2010 before:2040-08");
response = documentResource.queryParams(getParams).get(ClientResponse.class);
json = response.getEntity(JSONObject.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@@ -115,7 +114,7 @@ public class TestDocumentResource extends BaseJerseyTest {
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
getParams = new MultivaluedMapImpl();
getParams.putSingle("tags", tag1Id);
getParams.putSingle("search", "tag:super");
response = documentResource.queryParams(getParams).get(ClientResponse.class);
json = response.getEntity(JSONObject.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@@ -127,7 +126,20 @@ public class TestDocumentResource extends BaseJerseyTest {
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
getParams = new MultivaluedMapImpl();
getParams.putSingle("shared", true);
getParams.putSingle("search", "shared:yes");
response = documentResource.queryParams(getParams).get(ClientResponse.class);
json = response.getEntity(JSONObject.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
documents = json.getJSONArray("documents");
Assert.assertTrue(documents.length() == 1);
Assert.assertEquals(document1Id, documents.getJSONObject(0).getString("id"));
Assert.assertEquals(true, documents.getJSONObject(0).getBoolean("shared"));
// Search documents with multiple criteria
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
getParams = new MultivaluedMapImpl();
getParams.putSingle("search", "after:2010 before:2040-08 tag:super shared:yes for");
response = documentResource.queryParams(getParams).get(ClientResponse.class);
json = response.getEntity(JSONObject.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@@ -147,6 +159,28 @@ public class TestDocumentResource extends BaseJerseyTest {
documents = json.getJSONArray("documents");
Assert.assertTrue(documents.length() == 0);
// Search documents (nothing)
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
getParams = new MultivaluedMapImpl();
getParams.putSingle("search", "after:2010 before:2011-05-20");
response = documentResource.queryParams(getParams).get(ClientResponse.class);
json = response.getEntity(JSONObject.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
documents = json.getJSONArray("documents");
Assert.assertTrue(documents.length() == 0);
// Search documents (nothing)
documentResource = resource().path("/document/list");
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
getParams = new MultivaluedMapImpl();
getParams.putSingle("search", "tag:Nop");
response = documentResource.queryParams(getParams).get(ClientResponse.class);
json = response.getEntity(JSONObject.class);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
documents = json.getJSONArray("documents");
Assert.assertTrue(documents.length() == 0);
// Get a document
documentResource = resource().path("/document/" + document1Id);
documentResource.addFilter(new CookieAuthenticationFilter(document1Token));
@@ -162,7 +196,7 @@ public class TestDocumentResource extends BaseJerseyTest {
tagResource = resource().path("/tag");
tagResource.addFilter(new CookieAuthenticationFilter(document1Token));
postParams = new MultivaluedMapImpl();
postParams.add("name", "Super tag 2");
postParams.add("name", "SuperTag2");
postParams.add("color", "#00ffff");
response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));

View File

@@ -32,7 +32,7 @@ public class TestTagResource extends BaseJerseyTest {
WebResource tagResource = resource().path("/tag");
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
MultivaluedMapImpl postParams = new MultivaluedMapImpl();
postParams.add("name", "Tag 3");
postParams.add("name", "Tag3");
postParams.add("color", "#ff0000");
ClientResponse response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@@ -44,7 +44,7 @@ public class TestTagResource extends BaseJerseyTest {
tagResource = resource().path("/tag");
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
postParams = new MultivaluedMapImpl();
postParams.add("name", "Tag 4");
postParams.add("name", "Tag4");
postParams.add("color", "#00ff00");
response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@@ -52,6 +52,14 @@ public class TestTagResource extends BaseJerseyTest {
String tag4Id = json.optString("id");
Assert.assertNotNull(tag4Id);
// Create a tag with space (not allowed)
tagResource = resource().path("/tag");
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
postParams = new MultivaluedMapImpl();
postParams.add("name", "Tag 4");
response = tagResource.put(ClientResponse.class, postParams);
Assert.assertEquals(Status.BAD_REQUEST, Status.fromStatusCode(response.getStatus()));
// Create a document
WebResource documentResource = resource().path("/document");
documentResource.addFilter(new CookieAuthenticationFilter(tag1Token));
@@ -91,14 +99,14 @@ public class TestTagResource extends BaseJerseyTest {
json = response.getEntity(JSONObject.class);
JSONArray tags = json.getJSONArray("tags");
Assert.assertTrue(tags.length() > 0);
Assert.assertEquals("Tag 4", tags.getJSONObject(1).getString("name"));
Assert.assertEquals("Tag4", tags.getJSONObject(1).getString("name"));
Assert.assertEquals("#00ff00", tags.getJSONObject(1).getString("color"));
// Update a tag
tagResource = resource().path("/tag/" + tag4Id);
tagResource.addFilter(new CookieAuthenticationFilter(tag1Token));
postParams = new MultivaluedMapImpl();
postParams.add("name", "Updated name");
postParams.add("name", "UpdatedName");
postParams.add("color", "#0000ff");
response = tagResource.post(ClientResponse.class, postParams);
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
@@ -113,7 +121,7 @@ public class TestTagResource extends BaseJerseyTest {
json = response.getEntity(JSONObject.class);
tags = json.getJSONArray("tags");
Assert.assertTrue(tags.length() > 0);
Assert.assertEquals("Updated name", tags.getJSONObject(1).getString("name"));
Assert.assertEquals("UpdatedName", tags.getJSONObject(1).getString("name"));
Assert.assertEquals("#0000ff", tags.getJSONObject(1).getString("color"));
// Deletes a tag