View Javadoc
1   package test.integration;
2   
3   import static org.junit.Assert.assertEquals;
4   import generated.model.de.fhdw.partner.NatuerlichePerson;
5   import generated.model.de.fhdw.partner.service.PersonService;
6   
7   import java.util.Iterator;
8   
9   import org.junit.Test;
10  
11  import de.fhdw.wtf.context.model.Anything;
12  import de.fhdw.wtf.context.model.Str;
13  import de.fhdw.wtf.context.model.collections.MutableList;
14  import de.fhdw.wtf.persistence.exception.PersistenceException;
15  
16  /**
17   * This test case has to run from the Project Context-DB or Context-NoDB
18   */
19  public abstract class TestMutableSetIterator extends IntegrationTestSuperClass {
20  	
21  	abstract protected PersonService getPersonService() throws PersistenceException;
22  	
23  	@Test
24  	public void test1() throws PersistenceException {
25  		final PersonService service = this.getPersonService();
26  		service.publish();
27  		
28  		final Anything person = new NatuerlichePerson(new Str("Yoghurt"));
29  		
30  		final MutableList<Anything> set = new MutableList<>();
31  		set.insert(person);
32  		
33  		final Iterator<Anything> i = set.iterator();
34  		
35  		assertEquals(person, i.next());
36  	}
37  	
38  	@Test
39  	public void test2() throws PersistenceException {
40  		final PersonService service = this.getPersonService();
41  		service.publish();
42  		
43  		final Anything person = new NatuerlichePerson(new Str("Yoghurt"));
44  		
45  		final MutableList<Anything> set = new MutableList<>();
46  		set.insert(person);
47  		set.insert(person);
48  		
49  		final Iterator<Anything> i = set.iterator();
50  		
51  		assertEquals(person, i.next());
52  		assertEquals(person, i.next());
53  	}
54  	
55  	@Test
56  	public void testMutableSet() throws PersistenceException {
57  		final PersonService service = this.getPersonService();
58  		service.publish();
59  		
60  		final MutableList<Anything> innerSet = new MutableList<>();
61  		
62  		final MutableList<Anything> set = new MutableList<>();
63  		set.insert(innerSet);
64  		set.insert(innerSet);
65  		
66  		final Iterator<Anything> i = set.iterator();
67  		
68  		assertEquals(innerSet, i.next());
69  		assertEquals(innerSet, i.next());
70  	}
71  	
72  	@Test
73  	public void testMutableSetMutableSet() throws PersistenceException {
74  		final PersonService service = this.getPersonService();
75  		service.publish();
76  		
77  		final NatuerlichePerson person = new NatuerlichePerson(new Str("Yoghurt"));
78  		
79  		final MutableList<NatuerlichePerson> innerSet = new MutableList<>();
80  		innerSet.insert(person);
81  		
82  		final MutableList<MutableList<NatuerlichePerson>> set = new MutableList<>();
83  		set.insert(innerSet);
84  		set.insert(innerSet);
85  		
86  		final Iterator<MutableList<NatuerlichePerson>> outerI = set.iterator();
87  		
88  		while (outerI.hasNext()) {
89  			final MutableList<NatuerlichePerson> current = outerI.next();
90  			final Iterator<NatuerlichePerson> innerI = current.iterator();
91  			
92  			while (innerI.hasNext()) {
93  				final NatuerlichePerson p = innerI.next();
94  				assertEquals(person, p);
95  			}
96  			
97  		}
98  	}
99  	
100 }