Project

General

Profile

Download (2.65 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.persistence.validation;
10

    
11
import org.junit.Assert;
12
import org.junit.Before;
13
import org.junit.Test;
14

    
15
public class EntityValidationTaskQueueTest {
16

    
17
	private EntityValidationTaskBase evt1;
18
	private EntityValidationTaskBase evt2;
19
	private EntityValidationTaskBase evt3;
20

    
21

    
22
	/*
23
	 * Creates two equal EntityValidationTasks. EntityValidationTasks are equal if the entities
24
	 * they validate are equal and if the ValidationGroups applied are equal. The simplisticc
25
	 * equals() method on Employee makes the employees created in setUp() equal, while
26
	 * Level2ValidationTask extends EntityValidationTask in that in only validates constraints
27
	 * belonging to the "Level2" validation group.
28
	 */
29
	@Before
30
	public void setUp(){
31

    
32
		Employee emp1 = new Employee();
33
		emp1.setGivenName("John");
34
		emp1.setFamilyName("Smith");
35

    
36
		Employee emp2 = new Employee();
37
		emp2.setGivenName("John");
38
		emp2.setFamilyName("Smith");
39

    
40
		//TODO dao
41
		evt1 = new Level2ValidationTask(emp1, null);
42
		evt2 = new Level2ValidationTask(emp2, null);
43
		evt3 = new Level2ValidationTask(emp1, null);
44

    
45
	}
46

    
47

    
48
	/*
49
	 * Tests that the queue cannot contain two equal EntityValidationTasks, and that the
50
	 * EntityValidationTask that has driven out the two previously added tasks
51
	 */
52
	@Test
53
	public void testOffer(){
54
		EntityValidationTaskQueue queue = new EntityValidationTaskQueue(10);
55
		queue.offer(evt1);
56
		queue.offer(evt2);
57
		queue.offer(evt3);
58
		Assert.assertEquals(queue.size(), 1);
59
		Assert.assertTrue(queue.iterator().next() == evt3);
60
	}
61

    
62

    
63
	/*
64
	 * Tests that the queue cannot contain two equal EntityValidationTasks, and that the
65
	 * EntityValidationTask that was last added will be in the queue.
66
	 */
67
	@Test
68
	public void testAdd(){
69
		EntityValidationTaskQueue queue = new EntityValidationTaskQueue(10);
70
		queue.add(evt1);
71
		queue.add(evt2);
72
		Assert.assertEquals(queue.size(), 1);
73
		Assert.assertTrue(queue.iterator().next() == evt2);
74
	}
75

    
76

    
77
	/*
78
	 * Tests that the queue cannot contain two equal EntityValidationTasks, and that the
79
	 * EntityValidationTask that was last added will be in the queue.
80
	 */
81
	@Test
82
	public void testPut() throws InterruptedException{
83
		EntityValidationTaskQueue queue = new EntityValidationTaskQueue(10);
84
		queue.put(evt1);
85
		queue.put(evt2);
86
		Assert.assertEquals(queue.size(), 1);
87
		Assert.assertTrue(queue.iterator().next() == evt2);
88
	}
89

    
90
}
(8-8/12)