Skip to content

Commit e0341e3

Browse files
bodom91php-coder
authored andcommitted
/collection/{slug}: fix EmptyResultDataAccessException for not existing collection.
Fix #449
1 parent 649e7ee commit e0341e3

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/main/java/ru/mystamps/web/dao/impl/JdbcCollectionDao.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.slf4j.LoggerFactory;
2929

3030
import org.springframework.beans.factory.annotation.Value;
31+
import org.springframework.dao.EmptyResultDataAccessException;
3132
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
3233
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
3334
import org.springframework.jdbc.support.GeneratedKeyHolder;
@@ -173,11 +174,15 @@ public void removeSeriesFromCollection(Integer collectionId, Integer seriesId) {
173174

174175
@Override
175176
public CollectionInfoDto findCollectionInfoBySlug(String slug) {
176-
return jdbcTemplate.queryForObject(
177-
findCollectionInfoBySlugSql,
178-
Collections.singletonMap("slug", slug),
179-
RowMappers::forCollectionInfoDto
180-
);
177+
try {
178+
return jdbcTemplate.queryForObject(
179+
findCollectionInfoBySlugSql,
180+
Collections.singletonMap("slug", slug),
181+
RowMappers::forCollectionInfoDto
182+
);
183+
} catch (EmptyResultDataAccessException ignored) {
184+
return null;
185+
}
181186
}
182187

183188
}

src/test/config/testng.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@
163163
</classes>
164164
</test>
165165

166+
<test name="When anonymous user open not existing collection page">
167+
<classes>
168+
<class name="ru.mystamps.web.tests.cases.WhenAnonymousUserOpenNotExistingCollectionPage" />
169+
</classes>
170+
</test>
171+
166172
</suite>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2009-2016 Slava Semushin <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
package ru.mystamps.web.tests.cases;
19+
20+
import java.net.HttpURLConnection;
21+
22+
import org.testng.annotations.Test;
23+
24+
import ru.mystamps.web.Url;
25+
import ru.mystamps.web.tests.page.NotFoundErrorPage;
26+
27+
import static ru.mystamps.web.tests.TranslationUtils.tr;
28+
29+
import static org.fest.assertions.api.Assertions.assertThat;
30+
31+
public class WhenAnonymousUserOpenNotExistingCollectionPage
32+
extends WhenAnyUserAtAnyPage<NotFoundErrorPage> {
33+
34+
public WhenAnonymousUserOpenNotExistingCollectionPage() {
35+
super(NotFoundErrorPage.class);
36+
hasTitleWithoutStandardPrefix(tr("t_404_title"));
37+
hasResponseServerCode(HttpURLConnection.HTTP_NOT_FOUND);
38+
}
39+
40+
@Test(groups = "logic")
41+
public void shouldShow404Page() {
42+
String url = Url.INFO_COLLECTION_PAGE.replace("{slug}", "collection-404-error-test");
43+
page.open(url);
44+
45+
checkStandardStructure();
46+
47+
assertThat(page.getErrorMessage()).isEqualTo(tr("t_404_description", "\n"));
48+
assertThat(page.getErrorCode()).isEqualTo("404");
49+
}
50+
51+
}

0 commit comments

Comments
 (0)