Project

General

Profile

Revision ee537bcd

IDee537bcd7aa8bda55a442e8f465a140dde77be76
Parent d4657a24
Child 14f21806

Added by Andreas Müller over 6 years ago

better handling of abbreviated title cache in references, series -> seriesPart and some improvements in the reference cache strategies #4280, #4239 , changes in tests

View differences:

cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/ArticleDefaultCacheStrategyTest.java
80 80

  
81 81
		article1.setInJournal(null);
82 82
		//TODO should not be needed here
83
		article1.setTitleCache(null);
83
		article1.setTitleCache(null, false);
84 84
		Assert.assertEquals("Team1, My article in " + ArticleDefaultCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());	
85 85
	}
86 86
	
......
116 116

  
117 117
		article1.setInJournal(null);
118 118
		//TODO should not be needed here
119
		article1.setTitleCache(null);
119
		article1.setTitleCache(null, false);
120 120
		Assert.assertEquals("Team1, My article in " + ArticleDefaultCacheStrategy.UNDEFINED_JOURNAL + ". 1975", article1.getTitleCache());	
121 121
	}
122 122

  
123 123
	@Test
124 124
	public void testGetNomenclaturalCitation(){
125 125
		journal1.setTitle("My journal");
126
		journal1.setTitle("M. J.");
126 127
		journal1.setAuthorTeam(team2);
127 128
		article1.setTitle("My article");
128 129
		article1.setInJournal(journal1);
129 130
		article1.setAuthorTeam(team1);
130 131
		article1.setDatePublished(TimePeriod.NewInstance(1975));
131
		Assert.assertEquals("in My journal: 55. 1975", article1.getNomenclaturalCitation(detail1));
132
		Assert.assertEquals("in M. J.: 55. 1975", article1.getNomenclaturalCitation(detail1));
133
		
134
		article1.setVolume("22");
135
		Assert.assertEquals("in M. J. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
136
		article1.setSeriesPart("ser. 11");
137
		Assert.assertEquals("in M. J., ser. 11, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
138
		
139
	}
140

  
141
	/**
142
	 * After ser. , sect. , abt. we want to have a comma, if there is not yet one following anyway 
143
	 */
144
	@Test
145
	public void testGetNomenclaturalCitationSerSectAbt(){
146
		article1.setInJournal(journal1);
147
		article1.setVolume("22");
148
		journal1.setAbbrevTitle("J. Pl. Eur.");
149
		journal1.setAuthorTeam(team2);
150
		article1.setDatePublished(TimePeriod.NewInstance(1975));
151
		//no ser, sect, abt
152
		Assert.assertEquals("in J. Pl. Eur. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
153
		//ser
154
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3");
155
		Assert.assertEquals("in J. Pl. Eur., ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
156
		journal1.setAbbrevTitle("J. Pl. Eur., Ser. 3");
157
		Assert.assertEquals("in J. Pl. Eur., Ser. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
158
		journal1.setAbbrevTitle("J. Pl. Eur., ser. 3, s.n.");
159
		Assert.assertEquals("in J. Pl. Eur., ser. 3, s.n. 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
160
		//sect
161
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
162
		Assert.assertEquals("in J. Pl. Eur., sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
163
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3");
164
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
165
		journal1.setAbbrevTitle("J. Pl. Eur., Sect. 3, something");
166
		Assert.assertEquals("in J. Pl. Eur., Sect. 3, something 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
167
		//abt
168
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3");
169
		Assert.assertEquals("in J. Pl. Eur., abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
170
		journal1.setAbbrevTitle("J. Pl. Eur., Abt. 3");
171
		Assert.assertEquals("in J. Pl. Eur., Abt. 3, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
172
		journal1.setAbbrevTitle("J. Pl. Eur., abt. 3, no comma");
173
		Assert.assertEquals("in J. Pl. Eur., abt. 3, no comma 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
174
		
175
		journal1.setAbbrevTitle("J. Pl. Eur., sect. 3");
176
		article1.setSeriesPart("1");
177
		Assert.assertEquals("in J. Pl. Eur., sect. 3, ser. 1, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
178
		article1.setSeriesPart("Series 2");
179
		Assert.assertEquals("in J. Pl. Eur., sect. 3, Series 2, 22: 55. 1975", article1.getNomenclaturalCitation(detail1));
132 180
	}
133 181

  
182

  
134 183
	
135 184
	@Test 
136 185
	public void testGetTitleWithoutYearAndAuthor(){
......
140 189
		article1.setInJournal(journal1);
141 190
		article1.setAuthorTeam(team1);
142 191
		article1.setVolume("34");
143
		article1.setSeries("ser. 2");
192
		article1.setSeriesPart("ser. 2");
144 193
		article1.setDatePublished(TimePeriod.NewInstance(1975));
145
		Assert.assertEquals("in My journal ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference<?>)article1, false));
194
		Assert.assertEquals("in My journal, ser. 2, 34", defaultStrategy.getTitleWithoutYearAndAuthor((Reference<?>)article1, false));
146 195
	}
147 196
	
148 197
	@Test 
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/BookDefaultCacheStrategyTest.java
73 73
		book1.setTitleCache(null, false);
74 74
		//TODO this behaviour needs to be discussed. Maybe better the complete date published string should be returned.
75 75
		Assert.assertEquals("Unexpected title cache.", "Book Author, My book, ed. 3", book1.getTitleCache());
76
		
77
		
76

  
77
	}
78
	
79
	
80
	@Test
81
	public void testGetBookTitleCache(){
82
		//series
83
		IBook book1 = ReferenceFactory.newBook();
84
		book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
85
		book1.setSeriesPart("1");
86
		book1.setVolume("Fasc. 11");
87
		book1.setDatePublished(TimePeriodParser.parseString("1955"));
88
		Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11. 1955", book1.getTitleCache());
89
		Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
90
	}
91
	
92
	
93
	@Test
94
	public void testGetBookTitleCache2(){
95
		//series
96
		IBook book1 = ReferenceFactory.newBook();
97
		book1.setAbbrevTitle("Acta Inst. Bot. Acad. Sci. URSS");
98
		book1.setVolume("Fasc. 11");
99
		book1.setDatePublished(TimePeriodParser.parseString("1955"));
100
		Assert.assertEquals("Unexpected abbrev title cache", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11. 1955", book1.getTitleCache());
101
		Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
102
		book1.setSeriesPart("1");
103
		Assert.assertEquals("Unexpected nomencl. reference", "Acta Inst. Bot. Acad. Sci. URSS, ser. 1, Fasc. 11: 248. 1955", book1.getNomenclaturalCitation("248"));
78 104
	}
79 105
	
80 106

  
......
85 111
		book1.setAuthorTeam(bookTeam1);
86 112
		book1.setDatePublished(TimePeriod.NewInstance(1975));
87 113
		Assert.assertEquals("My book: 55. 1975", book1.getNomenclaturalCitation(detail1));
114
		book1.setAbbrevTitle("Analect. Bot.");
115
		Assert.assertEquals("Analect. Bot. 1975", book1.getNomenclaturalCitation(null));
88 116
	}
89 117
	
90 118
}
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/BookSectionDefaultCacheStrategyTest.java
74 74
		Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1975", bookSection1.getTitleCache());
75 75
		book1.setDatePublished(null);
76 76
		bookSection1.setDatePublished(TimePeriod.NewInstance(1976));
77
		bookSection1.setTitleCache(null);
78
		book1.setTitleCache(null);
77
		bookSection1.setTitleCache(null, false);
78
		book1.setTitleCache(null, false);
79 79
		Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
80 80
		book1.setDatePublished(TimePeriod.NewInstance(1977));
81
		bookSection1.setTitleCache(null);
82
		book1.setTitleCache(null);
81
		bookSection1.setTitleCache(null, false);
82
		book1.setTitleCache(null, false);
83 83
		Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
84
		bookSection1.setTitleCache(null, false);
85
		book1.setTitleCache(null, false);
86
		book1.setSeriesPart("2");
87
		Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book, ser. 2. 1976", bookSection1.getTitleCache());
84 88
		
85 89
		bookSection1.setInBook(null);
86
		bookSection1.setTitleCache(null);
90
		bookSection1.setTitleCache(null, false);
87 91
		Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
88 92
		
89 93
	}
......
91 95
	@Ignore
92 96
	@Test
93 97
	//This test is just to show that there is still the title cache bug which is not
94
	//set to null by setInBook(null) and otheres
98
	//set to null by setInBook(null) and others
95 99
	public void testGetTitleCache2(){
96 100
		book1.setTitle("My book");
97 101
		book1.setAuthorTeam(bookTeam1);
......
106 110
		book1.setDatePublished(TimePeriod.NewInstance(1977));
107 111
		Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in Book Author, My book. 1976", bookSection1.getTitleCache());
108 112
		
113
		
109 114
		bookSection1.setInBook(null);
110 115
		Assert.assertEquals("Unexpected title cache.", "Section Author - My chapter in - undefined book -. 1976", bookSection1.getTitleCache());
111 116
		
......
120 125
		bookSection1.setInBook(book1);
121 126
		bookSection1.setAuthorTeam(sectionTeam1);
122 127
		book1.setDatePublished(TimePeriod.NewInstance(1975));
123
		Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
128
		//TODO still unclear which is correct
129
//		Assert.assertEquals("in Book Author, My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
130
		Assert.assertEquals("in TT., My book: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
131
		
132
		book1.setSeriesPart("2");
133
		Assert.assertEquals("in TT., My book, ser. 2: 55. 1975", bookSection1.getNomenclaturalCitation(detail1));
124 134
	}
125 135
	
126 136
	@Test
......
140 150
		bookSection.setInBook(book);
141 151
		bookSection.setAuthorTeam(sectionTeam);
142 152
		bookSection.setPages("222-251");
143
		System.out.println(bookSection.getTitleCache());
144 153
		Assert.assertEquals("Chaudhary S. A. - 73. Hedypnois - 87. Crepis in Chaudhary S. A.(ed.), Flora of the Kingdom of Saudi Arabia 2(3). 2000", bookSection.getTitleCache());
145 154
		
146 155
	}
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/cache/reference/GenericDefaultCacheStrategyTest.java
52 52
	public void setUp() throws Exception {
53 53
		generic1 = ReferenceFactory.newGeneric();
54 54
		generic1.setCacheStrategy(defaultStrategy);
55
		team1 = Team.NewTitledInstance("Authorteam", "TT.");
55
		team1 = Team.NewTitledInstance("Authorteam", "AT.");
56 56
	}
57 57
	
58 58
//**************************** TESTS ***********************************
......
73 73
		book1.setAuthorTeam(team1);
74 74
		Reference<?> inRef = (Reference<?>)book1;
75 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"));
76
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
77
		//TODO author still unclear
78
//		Assert.assertEquals("Unexpected title cache.", "in Authorteam, My book title: 2", generic1.getNomenclaturalCitation("2"));
79
		Assert.assertEquals("Unexpected title cache.", "in AT., My book title: 2", generic1.getNomenclaturalCitation("2"));
78 80
	}
79 81

  
80 82
	@Test
81 83
	public void testGetInRefWithoutInRef(){
82 84
		generic1.setTitle("My generic title");
83 85
		generic1.setAuthorTeam(team1);
84
		generic1.setTitleCache(null);  //reset cache in case aspectJ is not enabled
86
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
85 87
		Assert.assertEquals("Unexpected title cache.", "My generic title: 2", generic1.getNomenclaturalCitation("2"));
86 88
	}
87 89
	
......
93 95
		book1.setAuthorTeam(team1);
94 96
		Reference<?> inRef = (Reference<?>)book1;
95 97
		generic1.setInReference(inRef);
96
		generic1.setTitleCache(null);  //reset cache in case aspectJ is not enabled
98
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
97 99
		Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title", generic1.getTitleCache());
98 100
	}
99 101

  
102
	
103
	@Test
104
	public void testGetAbbrevTitleCache(){
105
		generic1.setTitle("Part Title");
106
		generic1.setAbbrevTitle("Pt. Tit.");
107
		generic1.setDatePublished(TimePeriodParser.parseString("1987"));
108
		IBook book1 = ReferenceFactory.newBook();
109
		book1.setTitle("My book title");
110
		book1.setAbbrevTitle("My bk. tit.");
111
		book1.setAuthorTeam(team1);  //TODO handling not yet defined
112
		Reference<?> inRef = (Reference<?>)book1;
113
		generic1.setInReference(inRef);
114
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
115
		generic1.setAbbrevTitleCache(null, false);  //reset cache in case aspectJ is not enabled
116
		Assert.assertEquals("Unexpected abbrev title cache.", "Pt. Tit. in AT., My bk. tit. 1987", generic1.getAbbrevTitleCache());
117
		Assert.assertEquals("Title cache must still be the same", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
118
		//TODO author still unclear
119
//		Assert.assertEquals("Unexpected nom. ref.", "in Authorteam, My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
120
		Assert.assertEquals("Unexpected nom. ref.", "in AT., My bk. tit.: pp. 44. 1987", generic1.getNomenclaturalCitation("pp. 44"));
121
		
122
		
123
		//protected
124
		generic1.setAbbrevTitleCache("My prot. abb. tit. in a bk.", true);
125
		Assert.assertEquals("Unexpected abbrev title cache.", "My prot. abb. tit. in a bk.", generic1.getAbbrevTitleCache());
126
		Assert.assertEquals("Unexpected title cache.", "Part Title in Authorteam, My book title. 1987", generic1.getTitleCache());
127
		
128
		generic1.setDatePublished(null);
129
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(null));
130
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.", generic1.getNomenclaturalCitation(""));
131
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44", generic1.getNomenclaturalCitation("pp. 44"));
132
		
133
		generic1.setDatePublished(TimePeriodParser.parseString("1893"));
134
		Assert.assertEquals("Unexpected nom. ref.", "My prot. abb. tit. in a bk.: pp. 44. 1893", generic1.getNomenclaturalCitation("pp. 44"));
135
		
136
	}
137

  
100 138
	@Test
101 139
	public void testGetTitleCacheWithoutInRef(){
102 140
		generic1.setTitle("My generic title");
103 141
		generic1.setAuthorTeam(team1);
104
		generic1.setTitleCache(null);  //reset cache in case aspectJ is not enabled
142
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
105 143
		Assert.assertEquals("Unexpected title cache.", "Authorteam, My generic title", generic1.getTitleCache());
106 144
	}
107 145
	
108 146
	@Test
109 147
	public void testAuthorOnly(){
110 148
		generic1.setAuthorTeam(team1);
111
		generic1.setTitleCache(null);  //reset cache in case aspectJ is not enabled
149
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
112 150
		Assert.assertEquals("Unexpected title cache.", "Authorteam", generic1.getTitleCache());
113 151
		Assert.assertEquals("", generic1.getNomenclaturalCitation(null));
114 152
	}
......
117 155
	public void testYearAndAuthorOnly(){
118 156
		generic1.setAuthorTeam(team1);
119 157
		generic1.setDatePublished(TimePeriodParser.parseString("1792"));
120
		generic1.setTitleCache(null);  //reset cache in case aspectJ is not enabled
158
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
121 159
		Assert.assertEquals("Unexpected title cache.", "Authorteam, 1792", generic1.getTitleCache());	
122 160
		Assert.assertEquals("1792", generic1.getNomenclaturalCitation(null));
123 161
	}
......
128 166
		String detail = "sine no.";
129 167
		generic1.setAbbrevTitle("My title");
130 168
		generic1.setDatePublished(TimePeriodParser.parseString("1883-1884"));
131
		generic1.setTitleCache(null);  //reset cache in case aspectJ is not enabled
169
		generic1.setTitleCache(null, false);  //reset cache in case aspectJ is not enabled
132 170
		Assert.assertEquals("My title: sine no. 1883-1884", generic1.getNomenclaturalCitation(detail));
133
		
134
		
135 171
	}
136 172

  
137 173

  
cdmlib-model/src/test/java/eu/etaxonomy/cdm/test/function/strategy/TestBookDefaultCacheStrategies.java
71 71
		generic.setEditor("EditorString");
72 72
		
73 73
		generic.setPages("p.124-754");
74
		generic.setSeries("ser2");
74
		generic.setSeriesPart("ser2");
75 75
		generic.setVolume("33");
76 76
		System.out.println("FULL: " + generic.getNomenclaturalCitation("4444"));
77 77
		System.out.println("Citation: " + generic.getCitation());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)