Merge branch 'master' into history
[potlatch2.git] / tests / src / net / systemeD / halcyon / connection / actions / AddMemberToRelationActionTest.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import org.flexunit.Assert;
4     import net.systemeD.halcyon.connection.actions.AddMemberToRelationAction;
5     import net.systemeD.halcyon.connection.Relation;
6     import net.systemeD.halcyon.connection.Node;
7     import net.systemeD.halcyon.connection.RelationMember;
8     import net.systemeD.halcyon.connection.UndoableAction;
9     import net.systemeD.halcyon.connection.*;
10
11     [RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
12     public class AddMemberToRelationActionTest {
13
14         [Mock(type="net.systemeD.halcyon.connection.Connection", argsList="constructorArgs")]
15         public var connection:Connection;
16         public var constructorArgs:Array = ["name", "api", "policy"];
17
18         [Before]
19         public function setUp():void {
20             //Instantiate the connection first to prevent errors
21             //Connection.getConnection();
22         }
23
24
25         [Test]
26         public function addMember():void {
27
28             var n:Node = new Node(connection,1,1,{},true,5,10);
29
30             var rel:Relation = new Relation(connection,1,1,{},true,[]);
31             var member:RelationMember = new RelationMember(n, "foo");
32
33             rel.appendMember(member, function(action:UndoableAction):void { action.doAction(); });
34             Assert.assertEquals(1, rel.length);
35
36         }
37
38         [Test]
39         public function spliceStuff():void {
40
41             // create an array
42             var arr:Array = ["a", "b", "c", "d"];
43             Assert.assertEquals(4, arr.length);
44
45             // doesn't actually splice onto the end, inserts at position 4
46             arr.splice(-1, 0, "e");
47             Assert.assertEquals(5, arr.length);
48             Assert.assertEquals("e", arr[3]);
49             Assert.assertEquals("d", arr[4]);
50         }
51
52         [Test]
53         public function appendMember():void {
54             var n:Node = new Node(connection,1,1,{},true,5,10);
55             var n2:Node = new Node(connection,2,1,{},true,5,10);
56             var n3:Node = new Node(connection,3,1,{},true,5,10);
57
58             var member1:RelationMember = new RelationMember(n, "first");
59             var member2:RelationMember = new RelationMember(n2, "second");
60             var member3:RelationMember = new RelationMember(n3, "third");
61
62             var rel:Relation = new Relation(connection,1,1,{},true, [member1, member2]);
63             Assert.assertEquals(2, rel.length);
64
65             rel.appendMember(member3, function(action:UndoableAction):void { action.doAction(); });
66             Assert.assertEquals(member3, rel.getMember(2));
67         }
68
69         [Test]
70         public function setMember():void {
71             var n:Node = new Node(connection,1,1,{},true,5,10);
72             var n2:Node = new Node(connection,2,1,{},true,5,10);
73             var n3:Node = new Node(connection,3,1,{},true,5,10);
74
75             var member1:RelationMember = new RelationMember(n, "first");
76             var member2:RelationMember = new RelationMember(n2, "second");
77             var member3:RelationMember = new RelationMember(n3, "third");
78
79             var rel:Relation = new Relation(connection,1,1,{},true, [member1, member2]);
80             Assert.assertEquals(2, rel.length);
81
82             rel.setMember(1, member3, function(action:UndoableAction):void { action.doAction(); });
83             Assert.assertEquals(member3, rel.getMember(1));
84
85             Assert.assertEquals(2, rel.length);
86         }
87     }
88 }