/* * Adds two entityNodes and puts a normal edge between them * Finally it checks the sketch to see if it has been added */ @Test public void testAddingSketchEdge() throws QueryException { EntityNode en1 = new EntityNode("A", _sketch); EntityNode en2 = new EntityNode("B", _sketch); _sketch.addEntity(en1, en2); NormalEdge sk = new NormalEdge(en1, en2, "edge"); _sketch.addEdge(sk); assertEquals( "There is one edge and it is called edge", true, _sketch.getEdges().containsKey("edge")); }
/* * Creates two SketchEdges with the same name and adds them at the same time * Not really sure what shoud happen here */ @Test public void testDuplicateEdgeNameCreation() { EntityNode en = new EntityNode("I", _sketch); EntityNode en1 = new EntityNode("J", _sketch); _sketch.addEntity(en, en1); NormalEdge sk = new NormalEdge(en, en1, "e"); NormalEdge sk1 = new NormalEdge(en, en1, "e"); _sketch.addEdge(sk, sk1); assertEquals("Names should not be equal", false, sk.getName().equals(sk1.getName())); }
/* * Try to query an attribute that doesn't exist * Should throw an exception */ @Test(expected = QueryException.class) public void testQueryMissingAtt() throws QueryException { EntityNode en = new EntityNode("G", _sketch); _sketch.addEntity(en); QueryNode qn = new QueryNode("TestNode", _view, ""); qn.setQuery("Select a from G"); }
/* * Creates two entityNodes with the same name and adds them at the same time * Not really sure what shoud happen here */ @Test public void testDuplicateNameCreation() { EntityNode en = new EntityNode("TestNode", _sketch); EntityNode en1 = new EntityNode("TestNode", _sketch); _sketch.addEntity(en, en1); assertEquals("Names should not be equal", false, en.getName().equals(en1.getName())); }
/* * This test to see if we can create a simple queryNode with * a basic query. */ @Test public void testSimpleQuery() throws QueryException { EntityNode en = new EntityNode("F", _sketch); _sketch.addEntity(en); QueryNode qn = new QueryNode("TestNode", _view, ""); qn.setQuery("Select * from F"); _view.addEntity(qn); assertEquals("We queried F so must be F", "F", qn.getQueriedEntity().getName()); }
@BeforeClass public static void testSetup() { _AppFrame = new ApplicationFrame(); _overview = _AppFrame.getOverview(); _sketchNode = _overview.addNewSketch("sketch", 20, 20); _sketchFrame = _sketchNode.getFrame(); _sketch = _sketchNode.getMModel(); _sketch.setWarnings(false); _viewNode = _overview.addNewView(_sketchNode, "view"); _viewFrame = _viewNode.getFrame(); _view = _viewNode.getMModel(); }
/* * Adds two entities to sketch and an edge between them * queries both and adds them one at a time to see if the * edge is added between them */ @Test public void testAutoAddEdge() throws QueryException { EntityNode en1 = new EntityNode("C", _sketch); EntityNode en2 = new EntityNode("D", _sketch); _sketch.addEntity(en1, en2); NormalEdge sk = new NormalEdge(en1, en2, "e"); _sketch.addEdge(sk); QueryNode qn1 = new QueryNode("v_C", _view, "Select * from C"); QueryNode qn2 = new QueryNode("v_D", _view, "Select * from D"); _view.addEntity(qn1); assertEquals( "Only one node added so should be no edge", false, _view.getEdges().containsKey("e")); _view.addEntity(qn2); assertEquals( "Both nodes added so should be edge in between them called edge", true, _view.getEdges().containsKey("e")); }
/* * Creates two EntityNodes, an edge between them, queries them both * and then renames everything. */ @Test public void testModelNameChanges() throws QueryException { EntityNode en = new EntityNode("oldK", _sketch); EntityNode en1 = new EntityNode("oldL", _sketch); _sketch.addEntity(en, en1); NormalEdge sk = new NormalEdge(en, en1, "old"); _sketch.addEdge(sk); QueryNode qn = new QueryNode("v_K", _view, "Select * from oldK"); QueryNode qn1 = new QueryNode("v_L", _view, "Select * from oldL"); _view.addEntity(qn, qn1); assertEquals("Edge name in view should be old", true, _view.getEdges().containsKey("old")); sk.setName("new"); en.setName("newK"); en1.setName("newL"); assertEquals("Queried Node in v_K should be newK", "newK", qn.getQueriedEntity().getName()); assertEquals("Queried Node in v_L should be newL", "newL", qn1.getQueriedEntity().getName()); assertEquals( "Edge name in view should have changed to new", true, _view.getEdges().containsKey("new")); }
/* * Tries to query an attribute that does exist * Should work fine */ @Test public void testQueryExistingAtt() throws QueryException { EntityNode en = new EntityNode("H", _sketch); en.addEntityAttribute( new EntityAttribute<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge>( "h", new Int(), en)); _sketch.addEntity(en); QueryNode qn = new QueryNode("TestNode", _view, ""); qn.setQuery("Select h from H"); _view.addEntity(qn); assertEquals( "We only queried h from H so must be h", "h", qn.getEntityAttributes().get(0).getName()); }