package com.gentics.mesh.core.node;

import static com.gentics.mesh.assertj.MeshAssertions.assertThat;
import static com.gentics.mesh.demo.TestDataProvider.PROJECT_NAME;
import static com.gentics.mesh.util.MeshAssert.assertSuccess;
import static com.gentics.mesh.util.MeshAssert.latchFor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.gentics.mesh.core.AbstractSpringVerticle;
import com.gentics.mesh.core.data.node.Node;
import com.gentics.mesh.core.rest.common.GenericMessageResponse;
import com.gentics.mesh.core.verticle.node.NodeVerticle;
import com.gentics.mesh.test.AbstractRestVerticleTest;

import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

public class NodeLanguagesVerticleTest extends AbstractRestVerticleTest {

	private static final Logger log = LoggerFactory.getLogger(NodeLanguagesVerticleTest.class);

	@Autowired
	private NodeVerticle verticle;

	@Override
	public List<AbstractSpringVerticle> getVertices() {
		List<AbstractSpringVerticle> list = new ArrayList<>();
		list.add(verticle);
		return list;
	}

	@Test
	public void testDeleteLanguage() {
		Node node = content();
		int nLanguagesBefore = node.getAvailableLanguageNames().size();
		assertTrue(node.getAvailableLanguageNames().contains("en"));
		Future<GenericMessageResponse> future = getClient().deleteNode(PROJECT_NAME, node.getUuid(), "en");
		latchFor(future);
		assertSuccess(future);
		expectMessageResponse("node_deleted_language", future, node.getUuid(), "en");
		assertThat(searchProvider).recordedDeleteEvents(1);
		assertFalse(node.getAvailableLanguageNames().contains("en"));
		assertEquals(nLanguagesBefore - 1, node.getAvailableLanguageNames().size());
	}

}

@@ -282,16 +282,88 @@
 tchFor;%0A
+import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN;%0A
 import s
@@ -399,16 +399,16 @@
 Equals;%0A
-
 import s
@@ -897,25 +897,97 @@
 rticleTest;%0A
+import static com.gentics.mesh.core.data.relationship.GraphPermission.*;
 %0A
-
 import io.ve
@@ -1780,16 +1780,19 @@
 uture);%0A
+%09%09%0A
 %09%09assert
@@ -1808,16 +1808,33 @@
 uture);%0A
+%09%09node.reload();%0A
 %09%09expect
@@ -2106,10 +2106,332 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09public void testDeleteLanguageNoPerm() %7B%0A%09%09Node node = content();%0A%09%09role().revokePermissions(node, DELETE_PERM);%0A%09%09Future%3CGenericMessageResponse%3E future = getClient().deleteNode(PROJECT_NAME, node.getUuid(), %22en%22);%0A%09%09latchFor(future);%0A%09%09expectException(future, FORBIDDEN, %22error_missing_perm%22, node.getUuid());%0A%09%7D%0A
 %7D%0A

Add another testcase