Add mock MusicBrainz client for full test coverage (88.1%, zero exclusions)
Build & Deploy / build (push) Successful in 1m34s
Build & Deploy / build (push) Successful in 1m34s
This commit is contained in:
@@ -84,6 +84,18 @@
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>5.23.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>5.23.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
@@ -110,16 +122,7 @@
|
||||
<goals><goal>report</goal></goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>com/discdrop/client/dto/*</exclude>
|
||||
<exclude>com/discdrop/client/MusicBrainzClient.class</exclude>
|
||||
<exclude>com/discdrop/client/UserAgentFilter.class</exclude>
|
||||
<exclude>com/discdrop/service/ArtistService.class</exclude>
|
||||
<exclude>com/discdrop/service/ReleaseGroupService.class</exclude>
|
||||
<exclude>com/discdrop/web/ArtistController.class</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.quarkus</groupId>
|
||||
|
||||
@@ -47,9 +47,7 @@ class ArtistControllerExtendedTest {
|
||||
void testMonitoringToggleSingle() {
|
||||
db.insertArtist(new TrackedArtist("mon-ts", "ToggleS", "", "",
|
||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||
|
||||
given().queryParam("type", "single").patch("/api/artists/mon-ts/monitor").then().statusCode(200);
|
||||
|
||||
var artist = db.findByMbid("mon-ts").orElseThrow();
|
||||
assertTrue(artist.singleMonitored());
|
||||
assertTrue(artist.albumMonitored());
|
||||
@@ -59,27 +57,47 @@ class ArtistControllerExtendedTest {
|
||||
void testMonitoringToggleAlbum() {
|
||||
db.insertArtist(new TrackedArtist("mon-ta", "ToggleA", "", "",
|
||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||
|
||||
given().queryParam("type", "album").patch("/api/artists/mon-ta/monitor").then().statusCode(200);
|
||||
|
||||
var artist = db.findByMbid("mon-ta").orElseThrow();
|
||||
assertFalse(artist.albumMonitored());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMonitoringNonexistent() {
|
||||
given()
|
||||
.queryParam("type", "album")
|
||||
.patch("/api/artists/no-such/monitor")
|
||||
.then().statusCode(404);
|
||||
given().queryParam("type", "album").patch("/api/artists/no-such/monitor").then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMonitoringMissingType() {
|
||||
db.insertArtist(new TrackedArtist("mon-mt", "MissType", "", "",
|
||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||
given().patch("/api/artists/mon-mt/monitor").then().statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTrackArtist() {
|
||||
given()
|
||||
.patch("/api/artists/mon-mt/monitor")
|
||||
.then().statusCode(400);
|
||||
.when().post("/api/artists/mock-mbid-1/track")
|
||||
.then().statusCode(200);
|
||||
|
||||
assertTrue(db.exists("mock-mbid-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTrackArtistUpdatesFeed() {
|
||||
given().post("/api/artists/mock-mbid-1/track").then().statusCode(200);
|
||||
given().get("/api/artists/feed-table").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteTrackedArtistFromSearch() {
|
||||
given().post("/api/artists/mock-mbid-1/track").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.queryParam("q", "Mock")
|
||||
.delete("/api/artists/mock-mbid-1/from-search")
|
||||
.then().statusCode(200);
|
||||
|
||||
assertFalse(db.exists("mock-mbid-1"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,15 +30,50 @@ class ArtistServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddArtistWithDefaultMonitoring() {
|
||||
var artist = new TrackedArtist("add-1", "Add Artist", "", "US",
|
||||
true, false, false, false, false, Instant.now(), Instant.now());
|
||||
db.insertArtist(artist);
|
||||
void testSearchUsesMock() {
|
||||
var results = artistService.search("Mock");
|
||||
assertEquals(1, results.size());
|
||||
assertEquals("Mock Band", results.get(0).name());
|
||||
assertFalse(results.get(0).alreadyTracked());
|
||||
}
|
||||
|
||||
assertTrue(db.exists("add-1"));
|
||||
var found = db.findByMbid("add-1");
|
||||
assertTrue(found.isPresent());
|
||||
assertEquals("Add Artist", found.get().name());
|
||||
@Test
|
||||
void testSearchEmpty() {
|
||||
var results = artistService.search("");
|
||||
assertTrue(results.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddArtist() {
|
||||
var artist = artistService.addArtist("mock-mbid-1");
|
||||
assertEquals("Mock Band", artist.name());
|
||||
assertTrue(db.exists("mock-mbid-1"));
|
||||
assertTrue(artist.albumMonitored());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddArtistThenSearchShowsTracked() {
|
||||
artistService.addArtist("mock-mbid-1");
|
||||
var results = artistService.search("Mock");
|
||||
assertTrue(results.get(0).alreadyTracked());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveArtist() {
|
||||
artistService.addArtist("mock-mbid-2");
|
||||
assertTrue(db.exists("mock-mbid-2"));
|
||||
artistService.removeArtist("mock-mbid-2");
|
||||
assertFalse(db.exists("mock-mbid-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateMonitoring() {
|
||||
artistService.addArtist("mock-mbid-3");
|
||||
artistService.updateMonitoring("mock-mbid-3", new MonitoringFlags(false, true, false, false, false));
|
||||
|
||||
var artist = db.findByMbid("mock-mbid-3").orElseThrow();
|
||||
assertFalse(artist.albumMonitored());
|
||||
assertTrue(artist.singleMonitored());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,29 +83,8 @@ class ArtistServiceTest {
|
||||
|
||||
@Test
|
||||
void testFindAll() {
|
||||
db.insertArtist(new TrackedArtist("all-1", "First", "", "", true, false, false, false, false, Instant.now(), Instant.now()));
|
||||
db.insertArtist(new TrackedArtist("all-2", "Second", "", "", true, false, false, false, false, Instant.now(), Instant.now()));
|
||||
|
||||
artistService.addArtist("mock-mbid-4");
|
||||
artistService.addArtist("mock-mbid-5");
|
||||
assertEquals(2, artistService.findAll().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveArtist() {
|
||||
db.insertArtist(new TrackedArtist("rem-1", "Remove Me", "", "", true, false, false, false, false, Instant.now(), Instant.now()));
|
||||
assertTrue(db.exists("rem-1"));
|
||||
|
||||
artistService.removeArtist("rem-1");
|
||||
assertFalse(db.exists("rem-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateMonitoring() {
|
||||
db.insertArtist(new TrackedArtist("upd-1", "Update", "", "", true, true, false, false, false, Instant.now(), Instant.now()));
|
||||
artistService.updateMonitoring("upd-1", new MonitoringFlags(false, false, true, false, false));
|
||||
|
||||
var artist = db.findByMbid("upd-1").orElseThrow();
|
||||
assertFalse(artist.albumMonitored());
|
||||
assertFalse(artist.singleMonitored());
|
||||
assertTrue(artist.epMonitored());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.discdrop;
|
||||
|
||||
import com.discdrop.service.FeedService;
|
||||
import com.discdrop.service.CacheService;
|
||||
import com.discdrop.db.DatabaseService;
|
||||
import com.discdrop.db.Record.TrackedArtist;
|
||||
import com.discdrop.db.Record.ReleaseGroup;
|
||||
import com.discdrop.db.Record.TrackedArtist;
|
||||
import com.discdrop.service.FeedService;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -21,9 +20,6 @@ class FeedServiceTest {
|
||||
@Inject
|
||||
FeedService feedService;
|
||||
|
||||
@Inject
|
||||
CacheService cacheService;
|
||||
|
||||
@Inject
|
||||
DatabaseService db;
|
||||
|
||||
@@ -97,4 +93,14 @@ class FeedServiceTest {
|
||||
|
||||
assertTrue(feedService.getAllFeedEntries().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFeedWithArtistThatNeedsRefresh() {
|
||||
db.insertArtist(new TrackedArtist("mock-artist", "Mock", "", "",
|
||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||
db.setSetting("cache_ttl_hours", "0");
|
||||
|
||||
var feed = feedService.getAllFeedEntries();
|
||||
assertNotNull(feed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.discdrop;
|
||||
|
||||
import com.discdrop.client.MusicBrainzClient;
|
||||
import com.discdrop.client.dto.*;
|
||||
import io.quarkus.test.Mock;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||
import java.util.List;
|
||||
|
||||
@Mock
|
||||
@ApplicationScoped
|
||||
@RestClient
|
||||
public class MockMusicBrainz implements MusicBrainzClient {
|
||||
|
||||
@Override
|
||||
public ArtistSearchResponse searchArtists(String query, int limit, String fmt) {
|
||||
if (query == null || query.isBlank() || query.equals("artist:")) {
|
||||
return new ArtistSearchResponse(List.of(), 0);
|
||||
}
|
||||
return new ArtistSearchResponse(
|
||||
List.of(new ArtistSearchResponse.Artist(
|
||||
"mock-mbid-1", "Mock Band", "a mock band",
|
||||
new ArtistSearchResponse.Area("US"), "Group", "US")),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArtistDetailsResponse getArtistDetails(String mbid, String inc, String fmt) {
|
||||
return new ArtistDetailsResponse(
|
||||
mbid, "Mock Band", "a mock band",
|
||||
new ArtistDetailsResponse.Area("US"), "Group", "US",
|
||||
List.of()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReleaseGroupBrowseResponse browseReleaseGroups(String artistMbid, int limit, int offset, String inc, String fmt) {
|
||||
return new ReleaseGroupBrowseResponse(
|
||||
List.of(new ReleaseGroupBrowseResponse.ReleaseGroup(
|
||||
"mock-rg-1", "Mock Album", "2020-01-15",
|
||||
"Album", List.of("Studio"),
|
||||
List.of(new ReleaseGroupBrowseResponse.ReleaseGroup.ArtistCredit(
|
||||
new ReleaseGroupBrowseResponse.ReleaseGroup.ArtistCredit.Artist(artistMbid, "Mock Band")
|
||||
))
|
||||
)),
|
||||
1
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user