Project

General

Profile

Download (4.55 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.io.markup;
2

    
3
import static org.junit.Assert.*;
4

    
5
import java.util.ArrayList;
6
import java.util.Arrays;
7
import java.util.Collection;
8
import java.util.Collections;
9
import java.util.HashMap;
10
import java.util.HashSet;
11
import java.util.List;
12
import java.util.Map;
13
import java.util.Set;
14
import java.util.UUID;
15

    
16
import org.junit.Assert;
17
import org.junit.Before;
18
import org.junit.BeforeClass;
19
import org.junit.Test;
20

    
21
import com.google.common.collect.Lists;
22

    
23
import eu.etaxonomy.cdm.io.markup.FeatureSorter;
24

    
25
public class FeatureSorterTest {
26

    
27
	static UUID uuid1a = UUID.randomUUID();
28
	static UUID uuid1b = UUID.randomUUID();
29
	static UUID uuid1c = UUID.randomUUID();
30
	static UUID uuid1d = UUID.randomUUID();
31
	static UUID uuid1e = UUID.randomUUID();
32
	static UUID uuid2a = UUID.randomUUID();
33
	static UUID uuid2b = UUID.randomUUID();
34
	static UUID uuid2c = UUID.randomUUID();
35
	static UUID uuid2c_c1 = UUID.randomUUID();
36
	static UUID uuid2c_c2 = UUID.randomUUID();
37
	static UUID uuid2d = UUID.randomUUID();
38
	static UUID uuid3a = UUID.randomUUID();
39
	static UUID uuid3b = UUID.randomUUID();
40
	static UUID uuid4a = UUID.randomUUID();
41
	static UUID uuid4b = UUID.randomUUID();
42
	static UUID uuid4c = UUID.randomUUID();
43
	static UUID uuid4d = UUID.randomUUID();
44
	
45
	static UUID[] uuidList1;
46
	static UUID[]  uuidList2;
47
	static UUID[]  uuidList3;
48
	static UUID[]  uuidList4;
49
	
50
	@BeforeClass
51
	public static void setUpBeforeClass() throws Exception {
52
		uuidList1 = new UUID[]{uuid1a, uuid1b, uuid1c, uuid1d, uuid4c};
53
		uuidList2 = new UUID[]{uuid1a, uuid2a, uuid2c, uuid4d};
54
		uuidList3 = new UUID[]{uuid2b, uuid2c, uuid1c, uuid4d};
55
		uuidList4 = new UUID[]{uuid1b, uuid2c, uuid2a};
56
//		printArray(uuidList1);
57
//		printArray(uuidList2);
58
//		printArray(uuidList3);
59
//		printArray(uuidList4);
60
	}
61

    
62
	@Before
63
	public void setUp() throws Exception {		
64

    
65
	}
66

    
67
	@Test
68
	public void testGetSortOrder() {
69
		FeatureSorter sorter = new FeatureSorter();
70
		Map<String,List<FeatureSorterInfo>> orderLists = getOrderLists();
71
		List<UUID> result = sorter.getSortOrder(orderLists);
72
//		System.out.println("A:" + result);
73
		int i = 0;
74
		Assert.assertEquals("uuid1a should be first", uuid1a, result.get(i++));
75
		Assert.assertEquals("uuid1b should be next", uuid1b, result.get(i++));
76
		Assert.assertEquals("uuid2b should be next", uuid2b, result.get(i++));
77
//		Assert.assertEquals("uuid1c should be next", uuid1c, result.get(i++));
78
		
79

    
80
		
81
	}
82

    
83
	@Test
84
	public void testGetSortOrderWithChildren() {
85
		FeatureSorter sorter = new FeatureSorter();
86
		Map<String,List<FeatureSorterInfo>> orderLists = getOrderLists();
87
		addChildren(orderLists);
88
		List<UUID> result = sorter.getSortOrder(orderLists);
89
//		System.out.println("B:" + result);
90
		int i = 0;
91
		Assert.assertEquals("uuid1a should be first", uuid1a, result.get(i++));
92
		Assert.assertEquals("uuid1b should be next", uuid1b, result.get(i++));
93
		Assert.assertEquals("uuid2b should be next", uuid2b, result.get(i++));
94
//		Assert.assertEquals("uuid1c should be next", uuid1c, result.get(i++));
95

    
96
		Assert.assertEquals(2 + getAllUuids().size(), result.size());
97
	}
98

    
99
	
100
	private Set<UUID> getAllUuids() {
101
		Set<UUID> all = new HashSet<UUID>();
102
		List<UUID[]> arrayList = new ArrayList<UUID[]>();
103
		arrayList.add(uuidList1);
104
		arrayList.add(uuidList2);
105
		arrayList.add(uuidList3);
106
		arrayList.add(uuidList4);
107
		for (UUID[] array : arrayList){
108
			for (UUID uuid: array){
109
				all.add(uuid);
110
			}
111
		}
112
		return all;
113
	}
114

    
115
	private static void printArray(UUID[] uuidArray) {
116
		List<UUID> list = new ArrayList<UUID>();
117
		for (UUID uuid : uuidArray){
118
			list.add(uuid);
119
		}
120
		System.out.println(list);
121
	}
122

    
123
	private void addChildren(Map<String, List<FeatureSorterInfo>> orderLists) {
124
		orderLists.get("2").get(1).addSubFeature(new FeatureSorterInfo(uuid2c_c1));
125
		orderLists.get("2").get(1).addSubFeature(new FeatureSorterInfo(uuid2c_c2));
126
		
127
	}
128

    
129
	private Map<String, List<FeatureSorterInfo>> getOrderLists() {
130
		Map<String,List<FeatureSorterInfo>> orderLists = new HashMap<String, List<FeatureSorterInfo>>();
131
		orderLists.put("1", getFeatureSorterInfoList(uuidList1));
132
		orderLists.put("2", getFeatureSorterInfoList(uuidList2));
133
		orderLists.put("3", getFeatureSorterInfoList(uuidList3));
134
		orderLists.put("4", getFeatureSorterInfoList(uuidList4));
135
		return orderLists;
136
	}
137

    
138
	private List<FeatureSorterInfo> getFeatureSorterInfoList(UUID[] uuidList) {
139
		List<FeatureSorterInfo> result= new ArrayList<FeatureSorterInfo>();
140
		for(UUID uuid : uuidList){
141
			result.add(new FeatureSorterInfo(uuid));
142
		}
143
		return result;
144
	}
145

    
146
}
    (1-1/1)