CatgirlIntelligenceAgency/code/services-application/api-service/test/nu/marginalia/api/svc/ResponseCacheTest.java
Viktor Lofgren 1d34224416 (refac) Remove src/main from all source code paths.
Look, this will make the git history look funny, but trimming unnecessary depth from the source tree is a very necessary sanity-preserving measure when dealing with a super-modularized codebase like this one.

While it makes the project configuration a bit less conventional, it will save you several clicks every time you jump between modules.  Which you'll do a lot, because it's *modul*ar.  The src/main/java convention makes a lot of sense for a non-modular project though.  This ain't that.
2024-02-23 16:13:40 +01:00

93 lines
2.8 KiB
Java

package nu.marginalia.api.svc;
import nu.marginalia.api.model.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.*;
class ResponseCacheTest {
ResponseCache responseCache;
ApiLicense licenseA = new ApiLicense(
"keyA",
"Public Domain",
"Steven",
0
);
ApiLicense licenseB = new ApiLicense(
"keyB",
"Public Domain",
"Jeff",
0
);
ApiSearchResults resultsA = new ApiSearchResults("x", "y", Collections.emptyList());
ApiSearchResults resultsB = new ApiSearchResults("x", "y", Collections.emptyList());
@BeforeEach
public void setUp() {
responseCache = new ResponseCache();
}
@AfterEach
public void tearDown() {
responseCache.cleanUp();
}
@Test
public void testSunnyDay() {
responseCache.putResults(licenseA, "how do magnets work", "count=1", resultsA);
var result = responseCache.getResults(licenseA, "how do magnets work", "count=1");
assertTrue(result.isPresent());
assertEquals(resultsA, result.get());
}
@Test
public void testSunnyDay2() {
responseCache.putResults(licenseA, "how do magnets work", "count=1", resultsA);
responseCache.putResults(licenseA, "how do magnets work", "count=1", resultsB);
var result = responseCache.getResults(licenseA, "how do magnets work", "count=1");
assertTrue(result.isPresent());
assertEquals(resultsB, result.get());
}
@Test
public void testSunnyDay3() {
responseCache.putResults(licenseA, "how do magnets work", "count=1", resultsA);
responseCache.putResults(licenseA, "how many wives did Henry VIII have?", "count=1", resultsB);
var result = responseCache.getResults(licenseA, "how do magnets work", "count=1");
assertTrue(result.isPresent());
assertEquals(resultsA, result.get());
}
@Test
public void testSunnyDay4() {
responseCache.putResults(licenseA, "how do magnets work", "count=1", resultsA);
responseCache.putResults(licenseA, "how do magnets work", "count=2", resultsB);
var result = responseCache.getResults(licenseA, "how do magnets work", "count=1");
assertTrue(result.isPresent());
assertEquals(resultsA, result.get());
}
@Test
public void testSunnyDay5() {
responseCache.putResults(licenseA, "how do magnets work", "count=1", resultsA);
responseCache.putResults(licenseB, "how do magnets work", "count=1", resultsB);
var result = responseCache.getResults(licenseA, "how do magnets work", "count=1");
assertTrue(result.isPresent());
assertEquals(resultsA, result.get());
}
}