mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-15 03:55:09 +08:00
test(wiki): isolate profile/metadata E2E tests from the shared file DB
This commit is contained in:
parent
16a7aadbcd
commit
7a79fe93d0
@ -33,12 +33,16 @@ class WikiPageTypeProfileServiceE2ETest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private WikiPageTypeProfileService service;
|
private WikiPageTypeProfileService service;
|
||||||
|
|
||||||
|
// Persistent file-DB isolation: fresh kb ids per test.
|
||||||
|
private static final java.util.concurrent.atomic.AtomicLong SEQ =
|
||||||
|
new java.util.concurrent.atomic.AtomicLong(System.nanoTime());
|
||||||
|
|
||||||
private static final String EPISODE_JSON =
|
private static final String EPISODE_JSON =
|
||||||
"{\"version\":1,\"pageTypes\":{\"episode\":{\"label\":\"Episode\"}}}";
|
"{\"version\":1,\"pageTypes\":{\"episode\":{\"label\":\"Episode\"}}}";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveThenResolve_roundTrips() {
|
void saveThenResolve_roundTrips() {
|
||||||
long kb = 5001L;
|
long kb = SEQ.incrementAndGet();
|
||||||
service.saveProfile(kb, "liquidity", EPISODE_JSON);
|
service.saveProfile(kb, "liquidity", EPISODE_JSON);
|
||||||
|
|
||||||
WikiPageTypeProfileEntity row = service.findEnabledRow(kb);
|
WikiPageTypeProfileEntity row = service.findEnabledRow(kb);
|
||||||
@ -50,7 +54,7 @@ class WikiPageTypeProfileServiceE2ETest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveTwice_upsertsInPlaceAndBumpsVersion() {
|
void saveTwice_upsertsInPlaceAndBumpsVersion() {
|
||||||
long kb = 5002L;
|
long kb = SEQ.incrementAndGet();
|
||||||
service.saveProfile(kb, "v1", EPISODE_JSON);
|
service.saveProfile(kb, "v1", EPISODE_JSON);
|
||||||
// Saving again must update the single enabled row, not insert a second
|
// Saving again must update the single enabled row, not insert a second
|
||||||
// (which would violate the one-enabled-per-KB generated-column UNIQUE).
|
// (which would violate the one-enabled-per-KB generated-column UNIQUE).
|
||||||
@ -64,7 +68,7 @@ class WikiPageTypeProfileServiceE2ETest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resetToDefault_removesRowAndFallsBack() {
|
void resetToDefault_removesRowAndFallsBack() {
|
||||||
long kb = 5003L;
|
long kb = SEQ.incrementAndGet();
|
||||||
service.saveProfile(kb, "custom", EPISODE_JSON);
|
service.saveProfile(kb, "custom", EPISODE_JSON);
|
||||||
assertNotNull(service.findEnabledRow(kb));
|
assertNotNull(service.findEnabledRow(kb));
|
||||||
|
|
||||||
@ -79,7 +83,7 @@ class WikiPageTypeProfileServiceE2ETest {
|
|||||||
@Test
|
@Test
|
||||||
void invalidConfig_isRejectedOnSave() {
|
void invalidConfig_isRejectedOnSave() {
|
||||||
try {
|
try {
|
||||||
service.saveProfile(5004L, "bad", "{ not json");
|
service.saveProfile(SEQ.incrementAndGet(), "bad", "{ not json");
|
||||||
org.junit.jupiter.api.Assertions.fail("expected IllegalArgumentException");
|
org.junit.jupiter.api.Assertions.fail("expected IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException expected) {
|
} catch (IllegalArgumentException expected) {
|
||||||
// ok
|
// ok
|
||||||
|
|||||||
@ -32,6 +32,15 @@ class WikiPageTypeProfileMapperE2ETest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private WikiPageTypeProfileMapper mapper;
|
private WikiPageTypeProfileMapper mapper;
|
||||||
|
|
||||||
|
// The test H2 is a persistent file DB shared across runs, so each test
|
||||||
|
// uses fresh kb ids to stay isolated from earlier runs' rows.
|
||||||
|
private static final java.util.concurrent.atomic.AtomicLong SEQ =
|
||||||
|
new java.util.concurrent.atomic.AtomicLong(System.nanoTime());
|
||||||
|
|
||||||
|
private long uniqueKb() {
|
||||||
|
return SEQ.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
private WikiPageTypeProfileEntity profile(long kbId, String name, int enabled) {
|
private WikiPageTypeProfileEntity profile(long kbId, String name, int enabled) {
|
||||||
WikiPageTypeProfileEntity p = new WikiPageTypeProfileEntity();
|
WikiPageTypeProfileEntity p = new WikiPageTypeProfileEntity();
|
||||||
p.setKbId(kbId);
|
p.setKbId(kbId);
|
||||||
@ -46,40 +55,43 @@ class WikiPageTypeProfileMapperE2ETest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void insertsAndReadsBack() {
|
void insertsAndReadsBack() {
|
||||||
WikiPageTypeProfileEntity p = profile(9001L, "default", 1);
|
long kb = uniqueKb();
|
||||||
|
WikiPageTypeProfileEntity p = profile(kb, "default", 1);
|
||||||
mapper.insert(p);
|
mapper.insert(p);
|
||||||
assertNotNull(p.getId());
|
assertNotNull(p.getId());
|
||||||
WikiPageTypeProfileEntity loaded = mapper.selectById(p.getId());
|
WikiPageTypeProfileEntity loaded = mapper.selectById(p.getId());
|
||||||
assertEquals("default", loaded.getName());
|
assertEquals("default", loaded.getName());
|
||||||
assertEquals(9001L, loaded.getKbId());
|
assertEquals(kb, loaded.getKbId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void secondEnabledProfileForSameKb_isRejected() {
|
void secondEnabledProfileForSameKb_isRejected() {
|
||||||
mapper.insert(profile(9002L, "default", 1));
|
long kb = uniqueKb();
|
||||||
|
mapper.insert(profile(kb, "default", 1));
|
||||||
// A different name but also enabled for the same KB must violate the
|
// A different name but also enabled for the same KB must violate the
|
||||||
// generated-column UNIQUE (one enabled profile per KB).
|
// generated-column UNIQUE (one enabled profile per KB).
|
||||||
assertThrows(Exception.class, () -> mapper.insert(profile(9002L, "regulation", 1)));
|
assertThrows(Exception.class, () -> mapper.insert(profile(kb, "regulation", 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multipleDisabledProfilesForSameKb_coexist() {
|
void multipleDisabledProfilesForSameKb_coexist() {
|
||||||
mapper.insert(profile(9003L, "default", 1));
|
long kb = uniqueKb();
|
||||||
|
mapper.insert(profile(kb, "default", 1));
|
||||||
// enabled=0 rows yield NULL in the generated column and are exempt from
|
// enabled=0 rows yield NULL in the generated column and are exempt from
|
||||||
// the unique check, so several may coexist.
|
// the unique check, so several may coexist.
|
||||||
mapper.insert(profile(9003L, "draft-a", 0));
|
mapper.insert(profile(kb, "draft-a", 0));
|
||||||
mapper.insert(profile(9003L, "draft-b", 0));
|
mapper.insert(profile(kb, "draft-b", 0));
|
||||||
long count = mapper.selectCount(
|
long count = mapper.selectCount(
|
||||||
com.baomidou.mybatisplus.core.toolkit.Wrappers
|
com.baomidou.mybatisplus.core.toolkit.Wrappers
|
||||||
.<WikiPageTypeProfileEntity>lambdaQuery()
|
.<WikiPageTypeProfileEntity>lambdaQuery()
|
||||||
.eq(WikiPageTypeProfileEntity::getKbId, 9003L));
|
.eq(WikiPageTypeProfileEntity::getKbId, kb));
|
||||||
assertEquals(3, count);
|
assertEquals(3, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void enabledProfilesInDifferentKbs_coexist() {
|
void enabledProfilesInDifferentKbs_coexist() {
|
||||||
mapper.insert(profile(9101L, "default", 1));
|
mapper.insert(profile(uniqueKb(), "default", 1));
|
||||||
mapper.insert(profile(9102L, "default", 1));
|
mapper.insert(profile(uniqueKb(), "default", 1));
|
||||||
assertTrue(true); // no exception thrown — different KBs are independent
|
assertTrue(true); // no exception thrown — different KBs are independent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,9 +28,13 @@ class WikiPageMetadataE2ETest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private WikiPageService pageService;
|
private WikiPageService pageService;
|
||||||
|
|
||||||
|
// Persistent file-DB isolation: fresh kb ids per test.
|
||||||
|
private static final java.util.concurrent.atomic.AtomicLong SEQ =
|
||||||
|
new java.util.concurrent.atomic.AtomicLong(System.nanoTime());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyMetadata_persistsColumns_withoutTouchingContent() {
|
void applyMetadata_persistsColumns_withoutTouchingContent() {
|
||||||
long kb = 6001L;
|
long kb = SEQ.incrementAndGet();
|
||||||
WikiPageEntity page = pageService.createPage(kb, "episode-x", "Episode X",
|
WikiPageEntity page = pageService.createPage(kb, "episode-x", "Episode X",
|
||||||
"## Body\n\noriginal content", "summary", "[1]", "episode");
|
"## Body\n\noriginal content", "summary", "[1]", "episode");
|
||||||
assertNotNull(page.getId());
|
assertNotNull(page.getId());
|
||||||
@ -49,7 +53,7 @@ class WikiPageMetadataE2ETest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyMetadata_warningStatusAndJson() {
|
void applyMetadata_warningStatusAndJson() {
|
||||||
long kb = 6002L;
|
long kb = SEQ.incrementAndGet();
|
||||||
WikiPageEntity page = pageService.createPage(kb, "episode-y", "Episode Y",
|
WikiPageEntity page = pageService.createPage(kb, "episode-y", "Episode Y",
|
||||||
"body", "summary", "[1]", "episode");
|
"body", "summary", "[1]", "episode");
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user