mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
add category integration tests
This commit is contained in:
@@ -22,8 +22,10 @@ import org.mockserver.integration.ClientAndServer;
|
|||||||
import org.mockserver.model.HttpRequest;
|
import org.mockserver.model.HttpRequest;
|
||||||
import org.mockserver.model.HttpResponse;
|
import org.mockserver.model.HttpResponse;
|
||||||
|
|
||||||
|
import com.commafeed.frontend.model.Category;
|
||||||
import com.commafeed.frontend.model.Entries;
|
import com.commafeed.frontend.model.Entries;
|
||||||
import com.commafeed.frontend.model.Subscription;
|
import com.commafeed.frontend.model.Subscription;
|
||||||
|
import com.commafeed.frontend.model.request.AddCategoryRequest;
|
||||||
import com.commafeed.frontend.model.request.SubscribeRequest;
|
import com.commafeed.frontend.model.request.SubscribeRequest;
|
||||||
|
|
||||||
import io.restassured.RestAssured;
|
import io.restassured.RestAssured;
|
||||||
@@ -88,10 +90,31 @@ public abstract class BaseIT {
|
|||||||
return setCookieHeaders.stream().flatMap(h -> HttpCookie.parse(h.getValue()).stream()).toList();
|
return setCookieHeaders.stream().flatMap(h -> HttpCookie.parse(h.getValue()).stream()).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String createCategory(String name) {
|
||||||
|
AddCategoryRequest addCategoryRequest = new AddCategoryRequest();
|
||||||
|
addCategoryRequest.setName(name);
|
||||||
|
return RestAssured.given()
|
||||||
|
.body(addCategoryRequest)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.post("rest/category/add")
|
||||||
|
.then()
|
||||||
|
.extract()
|
||||||
|
.as(String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Category getRootCategory() {
|
||||||
|
return RestAssured.given().get("rest/category/get").then().statusCode(HttpStatus.SC_OK).extract().as(Category.class);
|
||||||
|
}
|
||||||
|
|
||||||
protected Long subscribe(String feedUrl) {
|
protected Long subscribe(String feedUrl) {
|
||||||
|
return subscribe(feedUrl, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Long subscribe(String feedUrl, String categoryId) {
|
||||||
SubscribeRequest subscribeRequest = new SubscribeRequest();
|
SubscribeRequest subscribeRequest = new SubscribeRequest();
|
||||||
subscribeRequest.setUrl(feedUrl);
|
subscribeRequest.setUrl(feedUrl);
|
||||||
subscribeRequest.setTitle("my title for this feed");
|
subscribeRequest.setTitle("my title for this feed");
|
||||||
|
subscribeRequest.setCategoryId(categoryId);
|
||||||
return RestAssured.given()
|
return RestAssured.given()
|
||||||
.body(subscribeRequest)
|
.body(subscribeRequest)
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
@@ -103,7 +126,11 @@ public abstract class BaseIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Long subscribeAndWaitForEntries(String feedUrl) {
|
protected Long subscribeAndWaitForEntries(String feedUrl) {
|
||||||
Long subscriptionId = subscribe(feedUrl);
|
return subscribeAndWaitForEntries(feedUrl, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Long subscribeAndWaitForEntries(String feedUrl, String categoryId) {
|
||||||
|
Long subscriptionId = subscribe(feedUrl, categoryId);
|
||||||
Awaitility.await().atMost(Duration.ofSeconds(15)).until(() -> getFeedEntries(subscriptionId), e -> e.getEntries().size() == 2);
|
Awaitility.await().atMost(Duration.ofSeconds(15)).until(() -> getFeedEntries(subscriptionId), e -> e.getEntries().size() == 2);
|
||||||
return subscriptionId;
|
return subscriptionId;
|
||||||
}
|
}
|
||||||
@@ -126,6 +153,15 @@ public abstract class BaseIT {
|
|||||||
.as(Entries.class);
|
.as(Entries.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Entries getCategoryEntries(String categoryId) {
|
||||||
|
return RestAssured.given()
|
||||||
|
.get("rest/category/entries?id={id}&readType=all", categoryId)
|
||||||
|
.then()
|
||||||
|
.statusCode(HttpStatus.SC_OK)
|
||||||
|
.extract()
|
||||||
|
.as(Entries.class);
|
||||||
|
}
|
||||||
|
|
||||||
protected int forceRefreshAllFeeds() {
|
protected int forceRefreshAllFeeds() {
|
||||||
return RestAssured.given().get("rest/feed/refreshAll").then().extract().statusCode();
|
return RestAssured.given().get("rest/feed/refreshAll").then().extract().statusCode();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package com.commafeed.integration.rest;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.commafeed.frontend.model.Category;
|
||||||
|
import com.commafeed.frontend.model.Entries;
|
||||||
|
import com.commafeed.frontend.model.Entry;
|
||||||
|
import com.commafeed.frontend.model.request.CategoryModificationRequest;
|
||||||
|
import com.commafeed.frontend.model.request.CollapseRequest;
|
||||||
|
import com.commafeed.frontend.model.request.IDRequest;
|
||||||
|
import com.commafeed.frontend.model.request.StarRequest;
|
||||||
|
import com.commafeed.frontend.resource.CategoryREST;
|
||||||
|
import com.commafeed.integration.BaseIT;
|
||||||
|
|
||||||
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
|
import io.restassured.RestAssured;
|
||||||
|
|
||||||
|
@QuarkusTest
|
||||||
|
class CategoryIT extends BaseIT {
|
||||||
|
@BeforeEach
|
||||||
|
void setup() {
|
||||||
|
RestAssured.authentication = RestAssured.preemptive().basic("admin", "admin");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void cleanup() {
|
||||||
|
RestAssured.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void modifyCategory() {
|
||||||
|
String category1Id = createCategory("test-category-1");
|
||||||
|
String category2Id = createCategory("test-category-2");
|
||||||
|
|
||||||
|
CategoryModificationRequest request = new CategoryModificationRequest();
|
||||||
|
request.setId(Long.valueOf(category2Id));
|
||||||
|
request.setName("modified-category");
|
||||||
|
request.setParentId(category1Id);
|
||||||
|
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/modify").then().statusCode(200);
|
||||||
|
|
||||||
|
Category root = getRootCategory();
|
||||||
|
Assertions.assertEquals(1, root.getChildren().size());
|
||||||
|
Assertions.assertEquals("test-category-1", root.getChildren().get(0).getName());
|
||||||
|
Assertions.assertEquals(1, root.getChildren().get(0).getChildren().size());
|
||||||
|
Assertions.assertEquals("modified-category", root.getChildren().get(0).getChildren().get(0).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void collapseCategory() {
|
||||||
|
String categoryId = createCategory("test-category");
|
||||||
|
|
||||||
|
Category root = getRootCategory();
|
||||||
|
Assertions.assertEquals(1, root.getChildren().size());
|
||||||
|
Assertions.assertTrue(root.getChildren().get(0).isExpanded());
|
||||||
|
|
||||||
|
CollapseRequest request = new CollapseRequest();
|
||||||
|
request.setId(Long.valueOf(categoryId));
|
||||||
|
request.setCollapse(true);
|
||||||
|
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/collapse").then().statusCode(200);
|
||||||
|
|
||||||
|
root = getRootCategory();
|
||||||
|
Assertions.assertEquals(1, root.getChildren().size());
|
||||||
|
Assertions.assertFalse(root.getChildren().get(0).isExpanded());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deleteCategory() {
|
||||||
|
String categoryId = createCategory("test-category");
|
||||||
|
Assertions.assertEquals(1, getRootCategory().getChildren().size());
|
||||||
|
|
||||||
|
IDRequest request = new IDRequest();
|
||||||
|
request.setId(Long.valueOf(categoryId));
|
||||||
|
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/delete").then().statusCode(200);
|
||||||
|
Assertions.assertEquals(0, getRootCategory().getChildren().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class GetEntries {
|
||||||
|
@Test
|
||||||
|
void all() {
|
||||||
|
subscribeAndWaitForEntries(getFeedUrl());
|
||||||
|
Entries entries = getCategoryEntries(CategoryREST.ALL);
|
||||||
|
Assertions.assertEquals(2, entries.getEntries().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void starred() {
|
||||||
|
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||||
|
Assertions.assertEquals(0, getCategoryEntries(CategoryREST.STARRED).getEntries().size());
|
||||||
|
|
||||||
|
Entry entry = getFeedEntries(subscriptionId).getEntries().get(0);
|
||||||
|
|
||||||
|
StarRequest starRequest = new StarRequest();
|
||||||
|
starRequest.setId(entry.getId());
|
||||||
|
starRequest.setFeedId(subscriptionId);
|
||||||
|
starRequest.setStarred(true);
|
||||||
|
RestAssured.given().body(starRequest).contentType(MediaType.APPLICATION_JSON).post("rest/entry/star");
|
||||||
|
|
||||||
|
Entries starredEntries = getCategoryEntries(CategoryREST.STARRED);
|
||||||
|
Assertions.assertEquals(1, starredEntries.getEntries().size());
|
||||||
|
Assertions.assertEquals(entry.getId(), starredEntries.getEntries().get(0).getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void specificCategory() {
|
||||||
|
String categoryId = createCategory("test-category");
|
||||||
|
subscribeAndWaitForEntries(getFeedUrl(), categoryId);
|
||||||
|
Entries entries = getCategoryEntries(categoryId);
|
||||||
|
Assertions.assertEquals(2, entries.getEntries().size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user