/*
 * DISCLAIMER
 *
 * Copyright 2018 ArangoDB GmbH, Cologne, Germany
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright holder is ArangoDB GmbH, Cologne, Germany
 */

package com.arangodb;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import com.arangodb.ArangoDB.Builder;
import com.arangodb.entity.ViewEntity;
import com.arangodb.entity.ViewType;

/**
 * @author Mark Vollmary
 *
 */
@RunWith(Parameterized.class)
public class ArangoViewTest extends BaseTest {

	private static final String VIEW_NAME = "view_test";

	public ArangoViewTest(final Builder builder) {
		super(builder);
		if (requireVersion(3, 4)) {
			db.createView(VIEW_NAME, ViewType.ARANGO_SEARCH);
		}
	}

	@Test
	public void exists() {
		if (!requireVersion(3, 4)) {
			return;
		}
		assertThat(db.view(VIEW_NAME).exists(), is(true));
	}

	@Test
	public void getInfo() {
		if (!requireVersion(3, 4)) {
			return;
		}
		final ViewEntity info = db.view(VIEW_NAME).getInfo();
		assertThat(info, is(not(nullValue())));
		assertThat(info.getId(), is(not(nullValue())));
		assertThat(info.getName(), is(VIEW_NAME));
		assertThat(info.getType(), is(ViewType.ARANGO_SEARCH));
	}

	@Test
	public void drop() {
		if (!requireVersion(3, 4)) {
			return;
		}
		final String name = VIEW_NAME + "_droptest";
		db.createView(name, ViewType.ARANGO_SEARCH);
		final ArangoView view = db.view(name);
		view.drop();
		assertThat(view.exists(), is(false));
	}

	@Test
	public void rename() {
		if (!requireVersion(3, 4)) {
			return;
		}
		final String name = VIEW_NAME + "_renametest";
		final String newName = name + "_new";
		db.createView(name, ViewType.ARANGO_SEARCH);
		db.view(name).rename(newName);
		assertThat(db.view(name).exists(), is(false));
		assertThat(db.view(newName).exists(), is(true));
	}

}

@@ -879,16 +879,40 @@
 tThat;%0A%0A
+import org.junit.After;%0A
 import o
@@ -1034,24 +1034,63 @@
 DB.Builder;%0A
+import com.arangodb.entity.ServerRole;%0A
 import com.a
@@ -1394,34 +1394,50 @@
 );%0A%09
-%09if (requireVersion(3, 4))
+%7D%0A%0A%09@After%0A%09public void teardown() %7B%0A%09%09try
  %7B%0A%09
@@ -1437,31 +1437,25 @@
 try %7B%0A%09%09%09db.
-createV
+v
 iew(VIEW_NAM
@@ -1459,34 +1459,57 @@
 NAME
-, ViewType.ARANGO_SEARCH);
+).drop();%0A%09%09%7D catch (final ArangoDBException e) %7B
 %0A%09%09%7D
@@ -1590,16 +1590,68 @@
 rn;%0A%09%09%7D%0A
+%09%09db.createView(VIEW_NAME, ViewType.ARANGO_SEARCH);%0A
 %09%09assert
@@ -1769,32 +1769,84 @@
 %0A%09%09%09return;%0A%09%09%7D%0A
+%09%09db.createView(VIEW_NAME, ViewType.ARANGO_SEARCH);%0A
 %09%09final ViewEnti
@@ -2163,55 +2163,8 @@
 %09%09%7D%0A
-%09%09final String name = VIEW_NAME + %22_droptest%22;%0A
 %09%09db
@@ -2167,36 +2167,41 @@
 %09%09db.createView(
-name
+VIEW_NAME
 , ViewType.ARANG
@@ -2245,20 +2245,25 @@
 db.view(
-name
+VIEW_NAME
 );%0A%09%09vie
@@ -2343,24 +2343,88 @@
  rename() %7B%0A
+%09%09if (arangoDB.getRole() != ServerRole.SINGLE) %7B%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09if (!requi
@@ -2494,55 +2494,8 @@
 ME +
- %22_renametest%22;%0A%09%09final String newName = name +
  %22_n
@@ -2569,23 +2569,25 @@
 .rename(
-newName
+VIEW_NAME
 );%0A%09%09ass
@@ -2655,15 +2655,17 @@
 iew(
-newName
+VIEW_NAME
 ).ex

Fix tests for cluster