package com.gentics.mesh.core.data.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

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

import com.gentics.mesh.core.data.model.root.LanguageRoot;
import com.gentics.mesh.core.data.model.root.MeshRoot;
import com.gentics.mesh.core.data.model.root.ProjectRoot;
import com.gentics.mesh.core.data.model.root.TagFamily;
import com.gentics.mesh.core.data.model.root.TagFamilyRoot;
import com.gentics.mesh.core.data.model.tinkerpop.Language;
import com.gentics.mesh.core.data.model.tinkerpop.Project;
import com.gentics.mesh.core.data.model.tinkerpop.Tag;
import com.gentics.mesh.core.data.service.LanguageService;
import com.gentics.mesh.core.data.service.MeshRootService;
import com.gentics.mesh.core.data.service.TagService;
import com.gentics.mesh.test.AbstractDBTest;

public class AtomicTagTest extends AbstractDBTest {

	@Autowired
	private TagService tagService;

	@Autowired
	private LanguageService languageService;

	@Autowired
	private MeshRootService rootService;

	@Test
	public void testTagCreation() {
		LanguageRoot languageRoot = data().getMeshRoot().getLanguageRoot();
		assertNotNull(languageRoot);
		Language language = languageRoot.create("Deutsch", "de");

		MeshRoot meshRoot = rootService.create();
		ProjectRoot projectRoot = meshRoot.createProjectRoot();
		Project project = projectRoot.create("dummy");
		TagFamilyRoot tagFamilyRoot = project.create();
		TagFamily tagFamily = tagFamilyRoot.create("basic");

		Tag tag = tagFamily.create("dummyName");
		assertNotNull(tag);
		assertEquals("dummyName", tag.getName());

		Tag reloadedTag = tagService.findByUUID(tag.getUuid());
		assertNotNull(reloadedTag);
		assertNotNull(reloadedTag.getI18nProperties());
		assertEquals(1, reloadedTag.getI18nProperties().size());
		assertEquals("test content", reloadedTag.getI18nProperties().get(0).getProperty("content"));
	}
}

@@ -1139,16 +1139,60 @@
 ion() %7B%0A
+%09%09MeshRoot meshRoot = rootService.create();%0A
 %09%09Langua
@@ -1217,32 +1217,23 @@
 t = 
-data().getMeshRoot().get
+meshRoot.create
 Lang
@@ -1339,53 +1339,68 @@
 %22);%0A
-%0A
 %09%09
-MeshRoot meshRoot = rootService.create(
+Language english = languageRoot.create(%22English%22, %22en%22
 );%0A
+%0A
 %09%09Pr
@@ -1716,16 +1716,46 @@
 Name());
+%0A%09%09tag.setName(%22renamed tag%22);
 %0A%0A%09%09Tag 
@@ -1965,20 +1965,19 @@
 ls(%22
-test content
+renamed tag
 %22, r
@@ -1994,53 +1994,13 @@
 .get
-I18nProperties().get(0).getProperty(%22content%22
+Name(
 ));%0A

Update test code