minor
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / service / PreferenceServiceImplTest.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.cdm.api.service;
11
12 import java.io.FileNotFoundException;
13
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.unitils.dbunit.annotation.DataSet;
17 import org.unitils.spring.annotation.SpringBeanByType;
18
19 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
20 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
21 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
22 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
23 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
24
25 /**
26 * @author a.mueller
27 *
28 */
29 public class PreferenceServiceImplTest extends CdmIntegrationTest {
30
31 @SpringBeanByType
32 IPreferenceService service;
33
34 /************ TESTS ********************************/
35
36 @Test
37 @DataSet
38 public void testService() {
39 Assert.assertNotNull(service);
40 }
41
42 @Test
43 @DataSet
44 public void testGet() {
45 PrefKey key = CdmPreference.NewKey(PreferenceSubject.Database, PreferencePredicate.NomenclaturalCode);
46 CdmPreference pref = service.get(key);
47 Assert.assertNotNull("CdmPreference for given key must exist", pref);
48 Assert.assertEquals("ICNAFP", pref.getValue());
49
50 key = CdmPreference.NewKey(PreferenceSubject.Database, PreferencePredicate.Test);
51 pref = service.get(key);
52 Assert.assertNull("CdmPreference for given key must not exist", pref);
53 }
54
55
56 @Test
57 @DataSet
58 public void testCount() {
59 int countStart = service.count();
60 Assert.assertEquals("There should be 1 preference in the CDM store", 1, countStart);
61 }
62
63 @Test
64 @DataSet
65 public void testSet() {
66 int countStart = service.count();
67 Assert.assertEquals(1, countStart);
68
69 CdmPreference pref = CdmPreference.NewInstance(PreferenceSubject.Database, PreferencePredicate.Test, "200");
70 service.set(pref);
71 int count = service.count();
72 Assert.assertEquals("There should be 1 new preference", countStart + 1, count);
73
74
75 pref = CdmPreference.NewInstance(PreferenceSubject.Database, PreferencePredicate.NomenclaturalCode, "ICZN");
76 service.set(pref);
77
78 count = service.count();
79 Assert.assertEquals("There should be only 1 new preference", countStart + 1, count);
80
81 }
82
83 /* (non-Javadoc)
84 * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
85 */
86 @Override
87 public void createTestDataSet() throws FileNotFoundException {
88 // TODO Auto-generated method stub
89
90 }
91 }