-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support multiple news locales * Update page header for multiple country news * Update controller & templates * Add tests * Update VERSION
- Loading branch information
Showing
16 changed files
with
261 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.6.1 | ||
0.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/it/garambo/retrosearch/configuration/NewsSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package it.garambo.retrosearch.configuration; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class NewsSettings { | ||
|
||
private final boolean enabled; | ||
private final long rateLimiter; | ||
private final List<Locale> locales; | ||
|
||
public NewsSettings(boolean enabled, long rateLimiter, List<Locale> locales) { | ||
this.enabled = enabled; | ||
this.rateLimiter = rateLimiter; | ||
this.locales = locales; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
<a href="/"><img th:src="@{__${@logoPath}__}" alt="A RetroSearch Logo"></a> | ||
<th:block th:if="${@environment.getProperty('retrosearch.news.enable') and | ||
|
||
<th:block th:if="${@environment.getProperty('retrosearch.news.enable') or | ||
@environment.getProperty('retrosearch.sports.football.enable')}"> | ||
<h4><a href="/">Search and Browse</a> - <a href="/news">News</a> - <a href="/football">Football scores</a></h4> | ||
<h4> | ||
<a href="/">Home</a> | ||
<th:block th:if="${@environment.getProperty('retrosearch.news.enable')}"> | ||
- News ( | ||
<th:block th:each="locale,iteration: ${@newsSettings.getLocales()}"> | ||
<a th:href="@{ /news(country=${locale.getDisplayCountry()}) }" th:text="${locale.getDisplayCountry()}"></a> | ||
<th:block th:text="${!iteration.last ? '|' : ''}"></th:block> | ||
</th:block> | ||
) | ||
</th:block> | ||
|
||
<th:block th:if="${@environment.getProperty('retrosearch.sports.football.enable')}"> | ||
- <a href="/football">Football scores</a> | ||
</th:block> | ||
</h4> | ||
</th:block> | ||
|
||
<form action="/search" method="get"> | ||
Search Query:<input type="text" th:value="${searchResults?.query}" name="query"> | ||
<input type="submit" value="Go!"> | ||
</form> | ||
<br> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/it/garambo/retrosearch/news/client/GNewsApiClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package it.garambo.retrosearch.news.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.when; | ||
|
||
import it.garambo.retrosearch.PrimaryTestConfiguration; | ||
import it.garambo.retrosearch.http.HttpService; | ||
import it.garambo.retrosearch.news.model.GNewsApiResponse; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
@SpringBootTest(classes = PrimaryTestConfiguration.class) | ||
class GNewsApiClientTest { | ||
|
||
@Mock private HttpService httpService; | ||
|
||
@InjectMocks GNewsApiClient client; | ||
|
||
@BeforeEach | ||
void setup() { | ||
ReflectionTestUtils.setField(client, "apiKey", "testKey"); | ||
} | ||
|
||
@Test | ||
void testFetchNews(@Value("classpath:news/response.json") Resource responseJson) | ||
throws IOException, URISyntaxException { | ||
URI uri = new URI("https://gnews.io/api/v4/top-headlines"); | ||
|
||
Map<String, String> params = | ||
Map.of( | ||
"category", "general", | ||
"max", "10", | ||
"lang", "it", | ||
"country", "it", | ||
"apikey", "testKey"); | ||
|
||
when(httpService.get(eq(uri), eq(params))) | ||
.thenReturn(responseJson.getContentAsString(StandardCharsets.UTF_8)); | ||
|
||
GNewsApiResponse response = client.fetchNews("it", "it"); | ||
assertNotNull(response); | ||
assertEquals(54904, response.totalArticles()); | ||
assertNotNull(response.articles()); | ||
assertEquals(1, response.articles().size()); | ||
} | ||
} |
Oops, something went wrong.