CategoryPartitionAddEdgeMultiGraph.java

package org.graphstream.graph.implementations;

import static org.junit.Assert.*;

import java.util.Random;

import org.databene.benerator.anno.Source;
import org.databene.feed4junit.Feeder;
import org.graphstream.graph.Edge;
import org.graphstream.graph.IdAlreadyInUseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;

@RunWith(Feeder.class)
public class CategoryPartitionAddEdgeMultiGraph {

	
	// idExistance,idValue,graphNrNodes,graphStrictChecking,
	// graphNrEdges,graphAutoCreate,sourceEx
	
	@Rule
	public ExpectedException exception = ExpectedException.none();
	
	@Test
	@Source("csvFiles/CategoryPartitionAddEdgeMultiGraph.csv")
	public void testAddEdge(Boolean idExistance, String idValue, String nrNodes,
			Boolean strictChecking, String nrEdges, Boolean autoCreate,
			Boolean sourceEx) {
			String idOfEdge = "";
			int numNodes=0;
			int numEdges = 0;
			
			System.out.println("id::"+idExistance +"-"+" idval::"+ idValue +"-"+ " nrnod::"+ nrNodes +"-"+ " strtCheck::"+
					strictChecking +"-"+ " nrEdges::"+  nrEdges +"-"+ " autoC::"+ autoCreate +"-"+ " sourceex::" +
					sourceEx);
			/*SetUp of ID
			 *based on the value coming from the .csv file
			 **/
			
			if(idValue.equals("correct")){ idOfEdge = "myEdge"; }
			else if(idValue.equals("malformed")){ idOfEdge = "%$#!~b(*<>";}
			else if(idValue.equals("''")){	idOfEdge = "empty";}
			else if(idValue.equals("null")){ idOfEdge = null;}
			
			//System.out.println(idOfGraph);
			
			MultiGraph multiGraph = new MultiGraph("MyMultiGraph", strictChecking, autoCreate);
			/*Creating "many nodes based on random value"*/
			
			if (nrNodes.equals("many")){
				numNodes = new Random().nextInt(100)+1;
				for (int i = 0; i < numNodes; i++) {
					multiGraph.addNode("node_"+i);
				}
			}
			
			/*Creating "many" edges based on random value*/
			
			if(nrEdges.equals("many")){
				numEdges = new Random().nextInt(numNodes)+1;
				for (int i = 0; i < numEdges-2; i++) {
					multiGraph.addEdge("edge_"+i, "node_"+i, "node_"+(i+1));
				}
			}
			
			if(idExistance){
				if(numNodes>0){
					//System.out.println("waaaa1");
					if(!strictChecking){
							//edges created with same end-points
							Edge e1 = multiGraph.addEdge(idOfEdge, "node_1", "node_2");
							Edge e2 = multiGraph.addEdge(idOfEdge, "node_1", "node_2");
							
							
							//edges created with different end-points
							multiGraph.addEdge(idOfEdge, "node_1", "node_2");
							Edge e3 = multiGraph.addEdge(idOfEdge, "node_2", "node_3");

							assertEquals(e1.getSourceNode(), e2.getSourceNode());
							assertEquals(e1.getTargetNode(), e2.getTargetNode());
							assertEquals(e1.getId(), e2.getId());
							assertEquals(e3, null);
							
					}else{
						exception.expect(IdAlreadyInUseException.class);
					}
				}
			}else{
				if(numNodes>0){
					if(autoCreate && !strictChecking){
						//edges created with on nodes that doesn't exists
						Edge e4 = multiGraph.addEdge(idOfEdge, "node_"+numNodes+2, "node_"+numNodes+3);
						assertEquals(e4.getId(), idOfEdge);
					}
				}
			}
//			System.out.println(idExistance +"-"+ idValue +"-"+ graphNrNodes +"-"+
//			graphStrictChecking +"-"+  graphNrEdges +"-"+ graphAutoCreate +"-"+
//			sourceEx);
	}
	

	

}