mirror of
https://github.com/sismics/docs.git
synced 2025-12-18 04:01:42 +00:00
#202 Actions on route transition
This commit is contained in:
@@ -12,7 +12,7 @@ import javax.ws.rs.core.Form;
|
||||
|
||||
/**
|
||||
* Test the route model resource.
|
||||
*
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class TestRouteModelResource extends BaseJerseyTest {
|
||||
@@ -23,9 +23,17 @@ public class TestRouteModelResource extends BaseJerseyTest {
|
||||
public void testRouteModelResource() {
|
||||
// Login admin
|
||||
String adminToken = clientUtil.login("admin", "admin", false);
|
||||
|
||||
|
||||
// Create a tag
|
||||
JsonObject json = target().path("/tag").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
.param("name", "TagRoute")
|
||||
.param("color", "#ff0000")), JsonObject.class);
|
||||
String tagRouteId = json.getString("id");
|
||||
|
||||
// Get all route models
|
||||
JsonObject json = target().path("/routemodel")
|
||||
json = target().path("/routemodel")
|
||||
.queryParam("sort_column", "2")
|
||||
.queryParam("asc", "false")
|
||||
.request()
|
||||
@@ -34,12 +42,12 @@ public class TestRouteModelResource extends BaseJerseyTest {
|
||||
JsonArray routeModels = json.getJsonArray("routemodels");
|
||||
Assert.assertEquals(1, routeModels.size());
|
||||
|
||||
// Create a route model
|
||||
// Create a route model without actions
|
||||
json = target().path("/routemodel").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
.param("name", "Workflow validation 1")
|
||||
.param("steps", "[{\"type\":\"VALIDATE\",\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]")), JsonObject.class);
|
||||
.param("steps", "[{\"type\":\"VALIDATE\",\"transitions\":[{\"name\":\"VALIDATED\",\"actions\":[]}],\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]")), JsonObject.class);
|
||||
String routeModelId = json.getString("id");
|
||||
|
||||
// Get all route models
|
||||
@@ -61,14 +69,14 @@ public class TestRouteModelResource extends BaseJerseyTest {
|
||||
.get(JsonObject.class);
|
||||
Assert.assertEquals(routeModelId, json.getString("id"));
|
||||
Assert.assertEquals("Workflow validation 1", json.getString("name"));
|
||||
Assert.assertEquals("[{\"type\":\"VALIDATE\",\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]", json.getString("steps"));
|
||||
Assert.assertEquals("[{\"type\":\"VALIDATE\",\"transitions\":[{\"name\":\"VALIDATED\",\"actions\":[]}],\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]", json.getString("steps"));
|
||||
|
||||
// Update the route model
|
||||
// Update the route model with actions
|
||||
target().path("/routemodel/" + routeModelId).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.post(Entity.form(new Form()
|
||||
.param("name", "Workflow validation 2")
|
||||
.param("steps", "[{\"type\":\"APPROVE\",\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]")), JsonObject.class);
|
||||
.param("steps", "[{\"type\":\"APPROVE\",\"transitions\":[{\"name\":\"APPROVED\",\"actions\":[{\"type\":\"ADD_TAG\",\"tag\":\"" + tagRouteId + "\"}]},{\"name\":\"REJECTED\",\"actions\":[]}],\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]")), JsonObject.class);
|
||||
|
||||
// Get the route model
|
||||
json = target().path("/routemodel/" + routeModelId)
|
||||
@@ -77,7 +85,7 @@ public class TestRouteModelResource extends BaseJerseyTest {
|
||||
.get(JsonObject.class);
|
||||
Assert.assertEquals(routeModelId, json.getString("id"));
|
||||
Assert.assertEquals("Workflow validation 2", json.getString("name"));
|
||||
Assert.assertEquals("[{\"type\":\"APPROVE\",\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]", json.getString("steps"));
|
||||
Assert.assertEquals("[{\"type\":\"APPROVE\",\"transitions\":[{\"name\":\"APPROVED\",\"actions\":[{\"type\":\"ADD_TAG\",\"tag\":\"" + tagRouteId + "\"}]},{\"name\":\"REJECTED\",\"actions\":[]}],\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]", json.getString("steps"));
|
||||
|
||||
// Delete the route model
|
||||
target().path("/routemodel/" + routeModelId)
|
||||
|
||||
@@ -9,7 +9,6 @@ import javax.json.JsonObject;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.Form;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
@@ -50,14 +49,11 @@ public class TestRouteResource extends BaseJerseyTest {
|
||||
Assert.assertEquals(1, routeModels.size());
|
||||
|
||||
// Create a document
|
||||
long create1Date = new Date().getTime();
|
||||
json = target().path("/document").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, route1Token)
|
||||
.put(Entity.form(new Form()
|
||||
.param("title", "My super title document 1")
|
||||
.param("description", "My super description for document 1")
|
||||
.param("language", "eng")
|
||||
.param("create_date", Long.toString(create1Date))), JsonObject.class);
|
||||
.param("language", "eng")), JsonObject.class);
|
||||
String document1Id = json.getString("id");
|
||||
|
||||
// Start the default route on document 1
|
||||
@@ -354,4 +350,100 @@ public class TestRouteResource extends BaseJerseyTest {
|
||||
documents = json.getJsonArray("documents");
|
||||
Assert.assertEquals(0, documents.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test actions on workflow step.
|
||||
*/
|
||||
@Test
|
||||
public void testAction() {
|
||||
// Login admin
|
||||
String adminToken = clientUtil.login("admin", "admin", false);
|
||||
|
||||
// Create a tag
|
||||
JsonObject json = target().path("/tag").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
.param("name", "Approved")
|
||||
.param("color", "#ff0000")), JsonObject.class);
|
||||
String tagApprovedId = json.getString("id");
|
||||
|
||||
// Create a new route model with actions
|
||||
json = target().path("/routemodel").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
.param("name", "Workflow action 1")
|
||||
.param("steps", "[{\"type\":\"APPROVE\",\"transitions\":[{\"name\":\"APPROVED\",\"actions\":[{\"type\":\"ADD_TAG\",\"tag\":\"" + tagApprovedId + "\"}]},{\"name\":\"REJECTED\",\"actions\":[]}],\"target\":{\"name\":\"administrators\",\"type\":\"GROUP\"},\"name\":\"Check the document's metadata\"}]")), JsonObject.class);
|
||||
String routeModelId = json.getString("id");
|
||||
|
||||
// Create a document
|
||||
json = target().path("/document").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
.param("title", "My super title document 1")
|
||||
.param("description", "My super description for document 1")
|
||||
.param("language", "eng")), JsonObject.class);
|
||||
String document1Id = json.getString("id");
|
||||
|
||||
// Start the route on document 1
|
||||
json = target().path("/route/start").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.post(Entity.form(new Form()
|
||||
.param("documentId", document1Id)
|
||||
.param("routeModelId", routeModelId)), JsonObject.class);
|
||||
JsonObject step = json.getJsonObject("route_step");
|
||||
Assert.assertEquals("Check the document's metadata", step.getString("name"));
|
||||
|
||||
// Check tags on document 1
|
||||
json = target().path("/document/" + document1Id).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
JsonArray tags = json.getJsonArray("tags");
|
||||
Assert.assertEquals(0, tags.size());
|
||||
|
||||
// Validate the current step with admin
|
||||
target().path("/route/validate").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.post(Entity.form(new Form()
|
||||
.param("documentId", document1Id)
|
||||
.param("transition", "APPROVED")), JsonObject.class);
|
||||
|
||||
// Check tags on document 1
|
||||
json = target().path("/document/" + document1Id).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
tags = json.getJsonArray("tags");
|
||||
Assert.assertEquals(1, tags.size());
|
||||
Assert.assertEquals(tagApprovedId, tags.getJsonObject(0).getString("id"));
|
||||
|
||||
// Create a document
|
||||
json = target().path("/document").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.put(Entity.form(new Form()
|
||||
.param("title", "My super title document 2")
|
||||
.param("language", "eng")), JsonObject.class);
|
||||
String document2Id = json.getString("id");
|
||||
|
||||
// Start the route on document 2
|
||||
json = target().path("/route/start").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.post(Entity.form(new Form()
|
||||
.param("documentId", document2Id)
|
||||
.param("routeModelId", routeModelId)), JsonObject.class);
|
||||
step = json.getJsonObject("route_step");
|
||||
Assert.assertEquals("Check the document's metadata", step.getString("name"));
|
||||
|
||||
// Validate the current step with admin
|
||||
target().path("/route/validate").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.post(Entity.form(new Form()
|
||||
.param("documentId", document2Id)
|
||||
.param("transition", "REJECTED")), JsonObject.class);
|
||||
|
||||
// Check tags on document 2
|
||||
json = target().path("/document/" + document2Id).request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
|
||||
.get(JsonObject.class);
|
||||
tags = json.getJsonArray("tags");
|
||||
Assert.assertEquals(0, tags.size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user