Make no assumptions about configured scripts in ITs

This commit is contained in:
Yura Bondarenko
2021-09-01 13:51:48 +02:00
parent 7cb25c6121
commit c9e4bb8106

View File

@@ -22,6 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.io.IOException;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@@ -81,24 +82,14 @@ public class ScriptRestRepositoryIT extends AbstractControllerIntegrationTest {
getClient(token).perform(get("/api/system/scripts"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.scripts", containsInAnyOrder(
ScriptMatcher.matchScript(scriptConfigurations.get(0).getName(),
scriptConfigurations.get(0).getDescription()),
ScriptMatcher.matchScript(scriptConfigurations.get(1).getName(),
scriptConfigurations.get(1).getDescription()),
ScriptMatcher.matchScript(scriptConfigurations.get(2).getName(),
scriptConfigurations.get(2).getDescription()),
ScriptMatcher.matchScript(scriptConfigurations.get(3).getName(),
scriptConfigurations.get(3).getDescription()),
ScriptMatcher.matchScript(scriptConfigurations.get(4).getName(),
scriptConfigurations.get(4).getDescription()),
ScriptMatcher.matchScript(scriptConfigurations.get(5).getName(),
scriptConfigurations.get(5).getDescription()),
ScriptMatcher.matchScript(scriptConfigurations.get(6).getName(),
scriptConfigurations.get(6).getDescription()),
ScriptMatcher.matchScript(scriptConfigurations.get(7).getName(),
scriptConfigurations.get(7).getDescription())
scriptConfigurations
.stream()
.map(scriptConfiguration -> ScriptMatcher.matchScript(
scriptConfiguration.getName(),
scriptConfiguration.getDescription()
))
.collect(Collectors.toList())
)));
}
@@ -113,66 +104,74 @@ public class ScriptRestRepositoryIT extends AbstractControllerIntegrationTest {
@Test
public void findAllScriptsPaginationTest() throws Exception {
List<ScriptConfiguration> alphabeticScripts =
scriptConfigurations.stream()
.sorted(Comparator.comparing(s -> s.getClass().getName()))
.collect(Collectors.toList());
int totalPages = scriptConfigurations.size();
int lastPage = totalPages - 1;
String token = getAuthToken(admin.getEmail(), password);
// NOTE: the scripts are always returned in alphabetical order by fully qualified class name.
getClient(token).perform(get("/api/system/scripts").param("size", "1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.scripts", Matchers.not(Matchers.hasItem(
ScriptMatcher.matchScript(scriptConfigurations.get(2).getName(),
scriptConfigurations.get(2).getDescription())
ScriptMatcher.matchScript(alphabeticScripts.get(1).getName(),
alphabeticScripts.get(1).getDescription())
))))
.andExpect(jsonPath("$._embedded.scripts", hasItem(
ScriptMatcher.matchScript(scriptConfigurations.get(5).getName(),
scriptConfigurations.get(5).getDescription())
ScriptMatcher.matchScript(alphabeticScripts.get(0).getName(),
alphabeticScripts.get(0).getDescription())
)))
.andExpect(jsonPath("$._links.first.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=0"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=0"), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$._links.self.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("size=1"))))
.andExpect(jsonPath("$._links.next.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=1"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=1"), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$._links.last.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=7"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=" + lastPage), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(0)))
.andExpect(jsonPath("$.page.totalPages", is(8)))
.andExpect(jsonPath("$.page.totalElements", is(8)));
.andExpect(jsonPath("$.page.totalPages", is(totalPages)))
.andExpect(jsonPath("$.page.totalElements", is(totalPages)));
getClient(token).perform(get("/api/system/scripts").param("size", "1").param("page", "1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.scripts", hasItem(
ScriptMatcher.matchScript(scriptConfigurations.get(2).getName(),
scriptConfigurations.get(2).getDescription())
ScriptMatcher.matchScript(alphabeticScripts.get(1).getName(),
alphabeticScripts.get(1).getDescription())
)))
.andExpect(jsonPath("$._embedded.scripts", Matchers.not(hasItem(
ScriptMatcher.matchScript(scriptConfigurations.get(5).getName(),
scriptConfigurations.get(5).getDescription())
ScriptMatcher.matchScript(alphabeticScripts.get(0).getName(),
alphabeticScripts.get(0).getDescription())
))))
.andExpect(jsonPath("$._links.first.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=0"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=0"), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$._links.prev.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=0"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=0"), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$._links.self.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=1"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=1"), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$._links.next.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=2"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=2"), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$._links.last.href", Matchers.allOf(
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=7"), Matchers.containsString("size=1"))))
Matchers.containsString("/api/system/scripts?"),
Matchers.containsString("page=" + lastPage), Matchers.containsString("size=1"))))
.andExpect(jsonPath("$.page.size", is(1)))
.andExpect(jsonPath("$.page.number", is(1)))
.andExpect(jsonPath("$.page.totalPages", is(8)))
.andExpect(jsonPath("$.page.totalElements", is(8)));
.andExpect(jsonPath("$.page.totalPages", is(totalPages)))
.andExpect(jsonPath("$.page.totalElements", is(totalPages)));
}
@Test
@@ -182,8 +181,16 @@ public class ScriptRestRepositoryIT extends AbstractControllerIntegrationTest {
getClient(token).perform(get("/api/system/scripts/mock-script"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", ScriptMatcher
.matchMockScript(
scriptConfigurations.get(scriptConfigurations.size() - 1).getOptions())));
.matchMockScript(
scriptConfigurations
.stream()
.filter(scriptConfiguration
-> scriptConfiguration.getName().equals("mock-script"))
.findAny()
.orElseThrow()
.getOptions()
)
));
}
@Test