package com.gentics.mesh.core.node;

import static com.gentics.mesh.demo.TestDataProvider.PROJECT_NAME;
import static com.gentics.mesh.test.performance.StopWatch.loggingStopWatch;
import static com.gentics.mesh.util.MeshAssert.assertSuccess;
import static com.gentics.mesh.util.MeshAssert.latchFor;

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.rest.node.NodeCreateRequest;
import com.gentics.mesh.core.rest.node.NodeResponse;
import com.gentics.mesh.core.rest.schema.SchemaReference;
import com.gentics.mesh.core.verticle.node.NodeVerticle;
import com.gentics.mesh.parameter.impl.PagingParameters;
import com.gentics.mesh.test.AbstractIsolatedRestVerticleTest;
import com.gentics.mesh.test.performance.StopWatchLogger;
import com.gentics.mesh.util.FieldUtil;

import io.vertx.core.Future;

public class NodeVerticlePerformanceTest extends AbstractIsolatedRestVerticleTest {

	@Autowired
	private NodeVerticle verticle;

	private StopWatchLogger logger = StopWatchLogger.logger(getClass());

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

	@Test
	public void testReadPerformance() {
		loggingStopWatch(logger, "node.read", 200, (step) -> {
			call(() -> getClient().findNodes(PROJECT_NAME, new PagingParameters().setPerPage(100)));
		});
	}

	@Test
	public void testCreatePerformance() throws Exception {
		String uuid = db.noTrx(() -> folder("news").getUuid());
		loggingStopWatch(logger, "node.create", 200, (step) -> {
			NodeCreateRequest request = new NodeCreateRequest();
			request.setSchema(new SchemaReference().setName("content"));
			request.setLanguage("en");
			request.getFields().put("title", FieldUtil.createStringField("some title"));
			request.getFields().put("name", FieldUtil.createStringField("some name"));
			request.getFields().put("filename", FieldUtil.createStringField("new-page_" + step + ".html"));
			request.getFields().put("content", FieldUtil.createStringField("Blessed mealtime again!"));
			request.setParentNodeUuid(uuid);
			call(() -> getClient().createNode(PROJECT_NAME, request));
		});
	}

}

@@ -176,127 +176,8 @@
 tch;
-%0Aimport static com.gentics.mesh.util.MeshAssert.assertSuccess;%0Aimport static com.gentics.mesh.util.MeshAssert.latchFor;
 %0A%0Aim
@@ -428,61 +428,8 @@
 st;%0A
-import com.gentics.mesh.core.rest.node.NodeResponse;%0A
 impo
@@ -762,38 +762,8 @@
 l;%0A%0A
-import io.vertx.core.Future;%0A%0A
 publ
@@ -1164,22 +1164,285 @@
 eadP
-erformance() %7B
+age() %7B%0A%09%09loggingStopWatch(logger, %22node.read-page-100%22, 200, (step) -%3E %7B%0A%09%09%09call(() -%3E getClient().findNodes(PROJECT_NAME, new PagingParameters().setPerPage(100)));%0A%09%09%7D);%0A%09%7D%0A%09%0A%09@Test%0A%09public void testReadSingleNode() %7B%0A%09%09String uuid = db.noTrx(() -%3E folder(%22news%22).getUuid());
 %0A%09%09l
@@ -1475,16 +1475,24 @@
 ode.read
+-by-uuid
 %22, 200, 
@@ -1529,33 +1529,38 @@
 lient().findNode
-s
+ByUuid
 (PROJECT_NAME, n
@@ -1549,32 +1549,38 @@
 id(PROJECT_NAME,
+ uuid,
  new PagingParam

Add more performance tests