package com.gentics.mesh.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.gentics.mesh.core.data.GenericVertex;
import com.gentics.mesh.core.data.relationship.GraphPermission;
import com.gentics.mesh.core.data.service.BasicObjectTestcases;
import com.gentics.mesh.core.field.bool.AbstractBasicDBTest;
import com.gentics.mesh.graphdb.Trx;
import com.gentics.mesh.handler.InternalActionContext;

import io.vertx.ext.web.RoutingContext;

public abstract class AbstractBasicObjectTest extends AbstractBasicDBTest implements BasicObjectTestcases {

	protected void testPermission(GraphPermission perm, GenericVertex<?> node) {
		try (Trx tx = db.trx()) {
			role().grantPermissions(node, perm);
			tx.success();
		}

		RoutingContext rc = getMockedRoutingContext("");
		InternalActionContext ac = InternalActionContext.create(rc);
		assertTrue(role().hasPermission(perm, node));
		assertTrue(getRequestUser().hasPermission(ac, node, perm));
		role().revokePermissions(node, perm);
		rc.data().clear();
		assertFalse(role().hasPermission(perm, node));
		assertFalse(getRequestUser().hasPermission(ac, node, perm));
	}

}

@@ -762,16 +762,45 @@
 );%0A%09%09%7D%0A%0A
+%09%09try (Trx tx = db.trx()) %7B%0A%09
 %09%09Routin
@@ -842,16 +842,17 @@
 xt(%22%22);%0A
+%09
 %09%09Intern
@@ -904,24 +904,25 @@
 eate(rc);%0A%09%09
+%09
 assertTrue(r
@@ -947,32 +947,33 @@
 n(perm, node));%0A
+%09
 %09%09assertTrue(get
@@ -1018,16 +1018,17 @@
 perm));%0A
+%09
 %09%09role()
@@ -1061,16 +1061,17 @@
 erm);%0A%09%09
+%09
 rc.data(
@@ -1081,16 +1081,17 @@
 lear();%0A
+%09
 %09%09assert
@@ -1133,16 +1133,17 @@
 de));%0A%09%09
+%09
 assertFa
@@ -1195,14 +1195,18 @@
 perm));%0A
+%09%09%7D%0A
 %09%7D%0A%0A%7D%0A

Fix permission unit tests