3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.strategy
.cache
.reference
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.junit
.Assert
;
15 import org
.junit
.Before
;
16 import org
.junit
.BeforeClass
;
17 import org
.junit
.Test
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
20 import eu
.etaxonomy
.cdm
.model
.reference
.IBook
;
21 import eu
.etaxonomy
.cdm
.model
.reference
.IGeneric
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
24 import eu
.etaxonomy
.cdm
.strategy
.parser
.TimePeriodParser
;
31 public class GenericDefaultCacheStrategyTest
{
32 @SuppressWarnings("unused")
33 private static final Logger logger
= Logger
.getLogger(GenericDefaultCacheStrategyTest
.class);
35 private static IGeneric generic1
;
36 private static Team team1
;
37 private static GenericDefaultCacheStrategy defaultStrategy
;
38 private static final String detail1
= "55";
41 * @throws java.lang.Exception
44 public static void setUpBeforeClass() throws Exception
{
45 defaultStrategy
= GenericDefaultCacheStrategy
.NewInstance();
49 * @throws java.lang.Exception
52 public void setUp() throws Exception
{
53 generic1
= ReferenceFactory
.newGeneric();
54 generic1
.setCacheStrategy(defaultStrategy
);
55 team1
= Team
.NewTitledInstance("Authorteam", "TT.");
58 //**************************** TESTS ***********************************
62 public void testGetTitleCache(){
63 generic1
.setTitle("auct.");
64 Assert
.assertEquals("Unexpected title cache.", "auct.", generic1
.getTitleCache());
69 public void testGetInRef(){
70 generic1
.setTitle("auct.");
71 IBook book1
= ReferenceFactory
.newBook();
72 book1
.setTitle("My book title");
73 book1
.setAuthorTeam(team1
);
74 Reference
<?
> inRef
= (Reference
<?
>)book1
;
75 generic1
.setInReference(inRef
);
76 generic1
.setTitleCache(null); //reset cache in case aspectJ is not enabled
77 Assert
.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1
.getNomenclaturalCitation("2"));
81 public void testGetInRefWithoutInRef(){
82 generic1
.setTitle("My generic title");
83 generic1
.setAuthorTeam(team1
);
84 generic1
.setTitleCache(null); //reset cache in case aspectJ is not enabled
85 Assert
.assertEquals("Unexpected title cache.", "My generic title: 2", generic1
.getNomenclaturalCitation("2"));
89 public void testGetTitleCache2(){
90 generic1
.setTitle("Part Title");
91 IBook book1
= ReferenceFactory
.newBook();
92 book1
.setTitle("My book title");
93 book1
.setAuthorTeam(team1
);
94 Reference
<?
> inRef
= (Reference
<?
>)book1
;
95 generic1
.setInReference(inRef
);
96 generic1
.setTitleCache(null); //reset cache in case aspectJ is not enabled
97 Assert
.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1
.getTitleCache());
101 public void testGetTitleCacheWithoutInRef(){
102 generic1
.setTitle("My generic title");
103 generic1
.setAuthorTeam(team1
);
104 generic1
.setTitleCache(null); //reset cache in case aspectJ is not enabled
105 Assert
.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1
.getTitleCache());
109 public void testAuthorOnly(){
110 generic1
.setAuthorTeam(team1
);
111 generic1
.setTitleCache(null); //reset cache in case aspectJ is not enabled
112 Assert
.assertEquals("Unexpected title cache.", "Authorteam", generic1
.getTitleCache());
116 public void testYearAndAuthorOnly(){
117 generic1
.setAuthorTeam(team1
);
118 generic1
.setDatePublished(TimePeriodParser
.parseString("1792"));
119 generic1
.setTitleCache(null); //reset cache in case aspectJ is not enabled
120 Assert
.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1
.getTitleCache());