Project

General

Profile

Download (2.9 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.api.service;
2

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

    
5
import java.util.HashMap;
6
import java.util.Map;
7

    
8
import org.apache.log4j.Logger;
9
import org.junit.Assert;
10
import org.junit.BeforeClass;
11
import org.junit.Test;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.unitils.UnitilsJUnit4;
14
import org.unitils.spring.annotation.SpringBeanByType;
15

    
16
import eu.etaxonomy.cdm.api.service.statistics.Statistics;
17
import eu.etaxonomy.cdm.api.service.statistics.StatisticsConfigurator;
18
import eu.etaxonomy.cdm.api.service.statistics.StatisticsPartEnum;
19
import eu.etaxonomy.cdm.api.service.statistics.StatisticsTypeEnum;
20
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
21

    
22
public class StatisticsServiceImplTest extends CdmTransactionalIntegrationTest {// UnitilsJUnit4
23

    
24
	/**
25
	 * this is the place to put the values in. only the types listed here are
26
	 * tested:
27
	 */
28
	private static Map<StatisticsTypeEnum, Number> prototype = new HashMap<StatisticsTypeEnum, Number>() {
29
		{
30
			put(StatisticsTypeEnum.ALL_TAXA, 0);
31
			put(StatisticsTypeEnum.ACCEPTED_TAXA, 0);
32
			put(StatisticsTypeEnum.CLASSIFICATION, 0);
33
			put(StatisticsTypeEnum.ALL_REFERENCES, 0);
34
			put(StatisticsTypeEnum.SYNONYMS, 0);
35
			put(StatisticsTypeEnum.TAXON_NAMES, 0);
36
			put(StatisticsTypeEnum.NOMECLATURAL_REFERENCES, 0);
37
//			put(StatisticsTypeEnum.DESCRIPTIVE_SOURCE_REFERENCES, 0);
38

    
39
		}
40
	};
41

    
42
	private static final Logger logger = Logger
43
			.getLogger(StatisticsServiceImplTest.class);
44

    
45
	StatisticsConfigurator configurator;
46

    
47
	@SpringBeanByType
48
	private IStatisticsService service;
49

    
50
	// @Autowired
51
	// public void setService(IStatisticsService service) {
52
	// this.service = service;
53
	// }
54

    
55
	// ---------- test--------------
56

    
57
	@Test
58
	@Ignore
59
	public void testGetCountStatistics_partAll() {
60

    
61
		createConfigurator();
62
		boolean check = true;
63
		Statistics resultStat = service.getCountStatistics(configurator);
64
		Map<String, Number> resultCountMap = resultStat.getCountMap();
65

    
66
		for (Map.Entry<StatisticsTypeEnum, Number> protoEntry : prototype
67
				.entrySet()) {
68

    
69
			logger.info(protoEntry.getKey().getLabel()+":\texpected count: "
70
					+ "\t\t" + protoEntry.getValue() + "\tactual count: "
71
					+ resultCountMap.get(protoEntry.getKey().getLabel()));
72

    
73
			if (!((resultCountMap.get(protoEntry.getKey().getLabel()))
74
					.equals((Number) 0))) {
75
				check = false;
76
			}
77
		}
78
//		Assert.assertFalse("everything was counted right!!!", check);
79
		Assert.assertTrue("some count did not match!!!", check);
80
//		fail("Not yet implemented");
81
	}
82

    
83
	@Test
84
	@Ignore
85
	public void testGetCountStatistics_partCLASSIFICATION() {
86
		fail("Not yet implemented");
87
	}
88

    
89
	// ------------------------------------------------------------------
90

    
91
	private void createConfigurator() {
92
		configurator = new StatisticsConfigurator();
93
		configurator.addPart(StatisticsPartEnum.ALL);
94
		for (StatisticsTypeEnum type : StatisticsTypeEnum.values()) {
95
			configurator.addType(type);
96
		}
97

    
98
	}
99

    
100
}
(12-12/18)