some bugfixes to new Amplification modelling #4541
[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 org.junit.Assert;
13 import org.junit.Test;
14 import org.unitils.dbunit.annotation.DataSet;
15 import org.unitils.spring.annotation.SpringBeanByType;
16
17 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
18 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
19 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
20 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
21 import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
22
23 /**
24 * @author a.mueller
25 *
26 */
27 public class PreferenceServiceImplTest extends CdmIntegrationTest {
28
29 @SpringBeanByType
30 IPreferenceService service;
31
32 /************ TESTS ********************************/
33
34 @Test
35 @DataSet
36 public void testService() {
37 Assert.assertNotNull(service);
38 }
39
40 @Test
41 @DataSet
42 public void testGet() {
43 PrefKey key = CdmPreference.NewKey(PreferenceSubject.Database, PreferencePredicate.NomenclaturalCode);
44 CdmPreference pref = service.get(key);
45 Assert.assertNotNull("CdmPreference for given key must exist", pref);
46 Assert.assertEquals("ICNAFP", pref.getValue());
47
48 key = CdmPreference.NewKey(PreferenceSubject.Database, PreferencePredicate.Test);
49 pref = service.get(key);
50 Assert.assertNull("CdmPreference for given key must not exist", pref);
51 }
52
53
54 @Test
55 @DataSet
56 public void testCount() {
57 int countStart = service.count();
58 Assert.assertEquals("There should be 1 preference in the CDM store", 1, countStart);
59 }
60
61 @Test
62 @DataSet
63 public void testSet() {
64 int countStart = service.count();
65 Assert.assertEquals(1, countStart);
66
67 CdmPreference pref = CdmPreference.NewInstance(PreferenceSubject.Database, PreferencePredicate.Test, "200");
68 service.set(pref);
69 int count = service.count();
70 Assert.assertEquals("There should be 1 new preference", countStart + 1, count);
71
72
73 pref = CdmPreference.NewInstance(PreferenceSubject.Database, PreferencePredicate.NomenclaturalCode, "ICZN");
74 service.set(pref);
75
76 count = service.count();
77 Assert.assertEquals("There should be only 1 new preference", countStart + 1, count);
78
79 }
80 }