Start debug copy V00.01
authorymh <ymh.work@gmail.com>
Sat, 16 Mar 2013 04:36:50 +0100
changeset 90 fa7d68b9d8b0
parent 89 31109c66a482
child 91 5e7a8805d9f6
Start debug copy force long pooling correct project creation
server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryImpl.java
server/src/main/webapp/WEB-INF/templates/projectIndex.html
server/src/main/webapp/static/js/config.js
server/src/test/java/org/iri_research/renkan/test/repositories/ProjectsRepositoryTest.java
--- a/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryImpl.java	Fri Mar 15 23:21:21 2013 +0100
+++ b/server/src/main/java/org/iri_research/renkan/repositories/ProjectsRepositoryImpl.java	Sat Mar 16 04:36:50 2013 +0100
@@ -70,7 +70,7 @@
 		this.nodesRepository.save(p.getNodes());
 		this.edgesRepository.save(p.getEdges());
 		
-		return this.projectsRepository.save(p);
+		return this.projectsRepository.save(res);
 	}
 
 }
--- a/server/src/main/webapp/WEB-INF/templates/projectIndex.html	Fri Mar 15 23:21:21 2013 +0100
+++ b/server/src/main/webapp/WEB-INF/templates/projectIndex.html	Sat Mar 16 04:36:50 2013 +0100
@@ -89,8 +89,7 @@
                     dataType: "json",
                     contentType: "application/json; charset=UTF-8"                    
                 }).done(function(project){
-                	var template_url = /*[[@{'/p/<%=project_id%>'(cowebkey='')}]]*/"p/<%=project_id%>?cowebkey=<%=project_key%>";
-                	window.location = _.template(template_url+'<%=project_key%>', {project_id: project.id, project_key: project.key});
+                	window.location.reload();
                 });
                 
             }
--- a/server/src/main/webapp/static/js/config.js	Fri Mar 15 23:21:21 2013 +0100
+++ b/server/src/main/webapp/static/js/config.js	Sat Mar 16 04:36:50 2013 +0100
@@ -26,6 +26,6 @@
     baseUrl: window.location.protocol + '//' + window.location.host,
 	adminUrl : dojoConfig.baseUrl+'admin',
 	debug: false,
-	useWebSockets: "WebSocket" in window,
+	useWebSockets: false,
 };
 
--- a/server/src/test/java/org/iri_research/renkan/test/repositories/ProjectsRepositoryTest.java	Fri Mar 15 23:21:21 2013 +0100
+++ b/server/src/test/java/org/iri_research/renkan/test/repositories/ProjectsRepositoryTest.java	Sat Mar 16 04:36:50 2013 +0100
@@ -7,8 +7,12 @@
 import java.util.Map;
 import java.util.UUID;
 
+import org.iri_research.renkan.models.Edge;
+import org.iri_research.renkan.models.Node;
 import org.iri_research.renkan.models.Project;
 import org.iri_research.renkan.models.Space;
+import org.iri_research.renkan.repositories.EdgesRepository;
+import org.iri_research.renkan.repositories.NodesRepository;
 import org.iri_research.renkan.repositories.ProjectsRepository;
 import org.iri_research.renkan.repositories.SpacesRepository;
 import org.junit.After;
@@ -19,9 +23,16 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.geo.Point;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
+import com.mongodb.BasicDBObject;
+import com.mongodb.DBCollection;
+import com.mongodb.DBCursor;
+import com.mongodb.DBObject;
+
 
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration("repositories-context.xml")
@@ -36,13 +47,26 @@
 	
 	@Autowired
 	private SpacesRepository spacesRepository;
+		
+	@Autowired
+	private NodesRepository nodesRepository;
+	
+	@Autowired
+	private EdgesRepository edgesRepository;
+	
+	@Autowired
+	private MongoTemplate mongoTemplate;
 	
 	private ArrayList<Project> testProjects = new ArrayList<Project>();
+	private List<Node> testNodes = new ArrayList<Node>();
+	private List<Edge> testEdges = new ArrayList<>();
 	
 	private Date creationDate = new Date();
 	
 	private List<String> spaceIds = new ArrayList<>(); 
 	
+	private Project copyProject;
+	
 	public ProjectsRepositoryTest() {
 	}
 	
@@ -63,12 +87,31 @@
 		for(Project p: projectsRepository.save(pl)) {
 			this.testProjects.add(p);
 		}
+		copyProject = this.testProjects.get(0);
 		
+		for(int i=0;i<3;i++) {
+			Node node = new Node("Node"+i, "Node"+i, "Node "+i, "http://renkan.org/nodes/node"+i, "#ffff0"+i, "test_user", new Point(0, i), "http://renkan.org/images/node"+i, i, copyProject.getId());
+			node = this.nodesRepository.save(node);
+			copyProject.getNodes().add(node);
+			this.testNodes.add(node);
+		}
+		
+		for(int i=0;i<3;i++) {
+			Edge edge = new Edge("Node"+i, "Node"+i, "Node "+i, "http://renkan.org/edges/edge"+i, "#ffff0"+i, this.testNodes.get((i+2)%3), this.testNodes.get(i), "test_user", copyProject.getId());
+			edge = this.edgesRepository.save(edge);
+			copyProject.getEdges().add(edge);
+			this.testEdges.add(edge);
+		}
+		
+		this.projectsRepository.save(copyProject);
+
 	}
 	
 	@After
 	public void teardown() {
 		logger.debug("Teardown");
+		edgesRepository.deleteAll();
+		nodesRepository.deleteAll();
 		projectsRepository.deleteAll();
 		spacesRepository.deleteAll();
 	}
@@ -155,5 +198,41 @@
 		Assert.assertNull("Last space id has no project i.e count is null", groupRes.get(this.spaceIds.get(SPACE_NB-1)));		
 	}
 	
+	@Test
+	public void testCopyProjectCreation() {
+		DBCollection coll = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Project.class));
+		
+		DBObject filter = new BasicDBObject();
+		filter.put("_id", copyProject.getId());
+		
+		DBCursor resFind = coll.find(filter);
+		
+		Assert.assertEquals("The project must be found", 1, resFind.count());
+		
+		for(DBObject obj: coll.find(filter)) {
+			Assert.assertEquals("id must be equal", copyProject.getId(), obj.get("_id"));
+		}
+	}
+	
+	@Test
+	public void testCopyProjectCopy() {
+		
+		Project newProject = this.projectsRepository.copy(this.copyProject, "copy_project");
+		
+		DBCollection coll = mongoTemplate.getCollection(mongoTemplate.getCollectionName(Project.class));
+		
+		DBObject filter = new BasicDBObject();
+		filter.put("_id", newProject.getId());
+		
+		DBCursor resFind = coll.find(filter);
+		
+		Assert.assertEquals("The project must be found", 1, resFind.count());
+		
+		for(DBObject obj: coll.find(filter)) {
+			Assert.assertEquals("id must be equal", newProject.getId(), obj.get("_id"));
+			Assert.assertEquals("title must be must be copy_project", "copy_project", obj.get("title"));
+			Assert.assertEquals("space_id must be must be same than copyProject", this.copyProject.getSpaceId(), obj.get("space_id"));
+		}
+	}
 	
 }