/*
 * Copyright (c) 2002-2016 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This product is licensed to you under the Apache License, Version 2.0 (the "License").
 * You may not use this product except in compliance with the License.
 *
 * This product may include a number of subcomponents with
 * separate copyright notices and license terms. Your use of the source
 * code for these subcomponents is subject to the terms and
 *  conditions of the subcomponent's license, as noted in the LICENSE file.
 */

package org.neo4j.ogm.persistence.model;

import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.ogm.domain.cineasts.minimum.Actor;
import org.neo4j.ogm.domain.cineasts.minimum.Movie;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.testutil.GraphTestUtils;
import org.neo4j.ogm.testutil.MultiDriverTestClass;

import java.io.IOException;

/**
 * The purpose of these tests is to describe the behaviour of the
 * mapper when a RelationshipEntity object is not referenced by
 * both of its Related entities.
 *
 * @author Vince Bickers
 */
public class RelationshipEntityPartialMappingTest extends MultiDriverTestClass {

	private static final SessionFactory sessionFactory = new SessionFactory(baseConfiguration, "org.neo4j.ogm.domain.cineasts.minimum");

	private Session session;

	@Before
	public void init() throws IOException {
		session = sessionFactory.openSession();
		session.purgeDatabase();
	}


	@Test
	public void testCreateActorRoleAndMovie() {

		Actor keanu = new Actor("Keanu Reeves");
		Movie matrix = new Movie("The Matrix");


		// note: this does not establish a role relationsip on the matrix
		keanu.addRole("Neo", matrix);

		session.save(keanu);
		GraphTestUtils.assertSameGraph(getGraphDatabaseService(),
				"create (a:Actor {name:'Keanu Reeves'}) " +
						"create (m:Movie {name:'The Matrix'}) " +
						"create (a)-[:ACTS_IN {played:'Neo'}]->(m)");
	}
}

@@ -590,16 +590,45 @@
 model;%0A%0A
+import java.io.IOException;%0A%0A
 import o
@@ -661,20 +661,27 @@
 g.junit.
-Test
+BeforeClass
 ;%0Aimport
@@ -689,42 +689,18 @@
 org.
-neo4j.graphdb.GraphDatabaseService
+junit.Test
 ;%0Aim
@@ -987,37 +987,8 @@
 s;%0A%0A
-import java.io.IOException;%0A%0A
 /**%0A
@@ -1264,17 +1264,20 @@
 lass %7B%0A%0A
-%09
+    
 private 
@@ -1287,14 +1287,8 @@
 tic 
-final 
 Sess
@@ -1297,16 +1297,128 @@
 nFactory
+ sessionFactory;%0A%0A    private Session session;%0A%0A    @BeforeClass%0A    public static void oneTimeSetup() %7B%0A       
  session
@@ -1511,45 +1511,28 @@
 %22);%0A
-%0A%09private Session session;%0A%0A%09
+    %7D%0A%0A%0A    
 @Before%0A
 %09pub
@@ -1527,17 +1527,20 @@
 @Before%0A
-%09
+    
 public v
@@ -1571,18 +1571,24 @@
 ption %7B%0A
-%09%09
+        
 session 
@@ -1619,18 +1619,24 @@
 sion();%0A
-%09%09
+        
 session.
@@ -1656,21 +1656,30 @@
 ();%0A
-%09%7D%0A%0A%0A%09
+    %7D%0A%0A%0A    
 @Test%0A
-%09
+    
 publ
@@ -1719,18 +1719,24 @@
 ie() %7B%0A%0A
-%09%09
+        
 Actor ke
@@ -1768,18 +1768,24 @@
 eves%22);%0A
-%09%09
+        
 Movie ma
@@ -1817,19 +1817,24 @@
 rix%22);%0A%0A
-%0A%09%09
+        
 // note:
@@ -1891,18 +1891,24 @@
  matrix%0A
-%09%09
+        
 keanu.ad
@@ -1930,18 +1930,24 @@
 trix);%0A%0A
-%09%09
+        
 session.
@@ -1959,18 +1959,24 @@
 keanu);%0A
-%09%09
+        
 GraphTes
@@ -2025,20 +2025,32 @@
 vice(),%0A
-%09%09%09%09
+                
 %22create 
@@ -2077,38 +2077,56 @@
 u Reeves'%7D) %22 +%0A
-%09%09%09%09%09%09
+                        
 %22create (m:Movie
@@ -2155,14 +2155,32 @@
 %22 +%0A
-%09%09%09%09%09%09
+                        
 %22cre
@@ -2225,9 +2225,12 @@
 %22);%0A
-%09
+    
 %7D%0A%7D%0A

Fix broken TC build.