From fcd8a15f2339dc1981e2a59fe0f32db6b9c1e9c8 Mon Sep 17 00:00:00 2001 From: Nikita Smirnov <46124551+Nikita-Smirnov-Exactpro@users.noreply.github.com> Date: Wed, 6 Mar 2024 19:39:26 +0400 Subject: [PATCH] [Th2-5165] Cradle API uses page day cache (#3) * Transformed Unit tests to integration * Updated github workflow --------- Co-authored-by: Oleg Smirnov --- ...blish-docker.yml => build-dev-release.yml} | 14 +- .github/workflows/build-release.yml | 14 + ...-publish-docker.yml => build-sanpshot.yml} | 13 +- .github/workflows/integration-tests.yml | 26 ++ .github/workflows/java-publish-docker.yml | 20 - .gitignore | 2 +- build.gradle | 34 +- cradle-admin-tool-cli/build.gradle | 4 - .../th2/cradle/adm/cli/Application.java | 50 ++- .../th2/cradle/adm/cli/ResultPrinter.java | 11 +- .../th2/cradle/adm/cli/AbstractCliTest.java | 41 +- .../th2/cradle/adm/cli/BookCliTest.java | 157 +++---- .../th2/cradle/adm/cli/PagesCliTest.java | 286 ++++++++----- .../cradle/adm/cli/ViewersAllBooksTest.java | 79 ++++ .../th2/cradle/adm/cli/ViewersTest.java | 371 +++++++++------- .../src/test/resources/log4j.properties | 7 - .../src/test/resources/log4j2.properties | 33 ++ cradle-admin-tool-http/build.gradle | 4 - .../th2/cradle/adm/http/AbstractHttpTest.java | 54 ++- .../th2/cradle/adm/http/BookHttpTest.java | 96 +++-- .../th2/cradle/adm/http/PagesHttpTest.java | 222 ++++++---- .../th2/cradle/adm/http/ViewersTest.java | 135 ++++-- gradle.properties | 2 +- .../th2/cradle/adm/modes/RemovePageMode.java | 46 +- .../cradle/adm/params/RemovePageParams.java | 13 +- .../th2/cradle/adm/TestBookCache.java | 55 --- ...Executor.java => TestBookPageBuilder.java} | 40 +- .../th2/cradle/adm/TestCommonFactory.java | 40 -- .../th2/cradle/adm/TestCradleManager.java | 42 -- .../th2/cradle/adm/TestCradleStorage.java | 395 ------------------ 30 files changed, 1113 insertions(+), 1193 deletions(-) rename .github/workflows/{dev-release-java-publish-docker.yml => build-dev-release.yml} (51%) create mode 100644 .github/workflows/build-release.yml rename .github/workflows/{dev-java-publish-docker.yml => build-sanpshot.yml} (58%) create mode 100644 .github/workflows/integration-tests.yml delete mode 100644 .github/workflows/java-publish-docker.yml create mode 100644 cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersAllBooksTest.java delete mode 100644 cradle-admin-tool-cli/src/test/resources/log4j.properties create mode 100755 cradle-admin-tool-cli/src/test/resources/log4j2.properties delete mode 100644 src/test/java/com/exactpro/th2/cradle/adm/TestBookCache.java rename src/test/java/com/exactpro/th2/cradle/adm/{TestExecutor.java => TestBookPageBuilder.java} (59%) delete mode 100644 src/test/java/com/exactpro/th2/cradle/adm/TestCommonFactory.java delete mode 100644 src/test/java/com/exactpro/th2/cradle/adm/TestCradleManager.java delete mode 100644 src/test/java/com/exactpro/th2/cradle/adm/TestCradleStorage.java diff --git a/.github/workflows/dev-release-java-publish-docker.yml b/.github/workflows/build-dev-release.yml similarity index 51% rename from .github/workflows/dev-release-java-publish-docker.yml rename to .github/workflows/build-dev-release.yml index 57ef373..59d4309 100644 --- a/.github/workflows/dev-release-java-publish-docker.yml +++ b/.github/workflows/build-dev-release.yml @@ -1,18 +1,14 @@ -name: Build and release Docker image. +name: Build and publish dev release Docker image to Github Container Registry ghcr.io -on: - push: - tags: - - \d+.\d+.\d+-dev +on: workflow_dispatch jobs: build: uses: th2-net/.github/.github/workflows/compound-java.yml@main with: build-target: 'Docker' - runsOn: ubuntu-latest - gradleVersion: '7' - docker-username: ${{ github.actor }} devRelease: true + createTag: true + docker-username: ${{ github.actor }} secrets: - docker-password: ${{ secrets.GITHUB_TOKEN }} + docker-password: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..8f35742 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,14 @@ +name: Build and publish release Docker image to Github Container Registry ghcr.io + +on: workflow_dispatch + +jobs: + build: + uses: th2-net/.github/.github/workflows/compound-java.yml@main + with: + build-target: 'Docker' + devRelease: false + createTag: true + docker-username: ${{ github.actor }} + secrets: + docker-password: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/dev-java-publish-docker.yml b/.github/workflows/build-sanpshot.yml similarity index 58% rename from .github/workflows/dev-java-publish-docker.yml rename to .github/workflows/build-sanpshot.yml index 5effbf6..1618698 100644 --- a/.github/workflows/dev-java-publish-docker.yml +++ b/.github/workflows/build-sanpshot.yml @@ -1,26 +1,19 @@ -name: Dev build and publish Docker image +name: Build and publish Docker image to Github Container Registry ghcr.io on: push: branches-ignore: - master - version-* - - dependabot* + - dependabot** paths-ignore: - README.md - # paths: - # - gradle.properties jobs: build-job: uses: th2-net/.github/.github/workflows/compound-java-dev.yml@main with: build-target: 'Docker' - runsOn: ubuntu-latest - gradleVersion: '7' docker-username: ${{ github.actor }} secrets: - docker-password: ${{ secrets.GITHUB_TOKEN }} - - - + docker-password: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 0000000..766f817 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,26 @@ +name: "Run integration tests for cradle admin tool" + +on: + push: + branches: + - '*' + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 'zulu' '11' + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: '11' + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - name: Build with Gradle + run: ./gradlew --info clean integrationTest + - uses: actions/upload-artifact@v3 + if: failure() + with: + name: integration-test-results + path: build/reports/tests/integrationTest/ diff --git a/.github/workflows/java-publish-docker.yml b/.github/workflows/java-publish-docker.yml deleted file mode 100644 index feb5496..0000000 --- a/.github/workflows/java-publish-docker.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Build and release Docker image. - -on: - push: - branches: - - master - - version-* - paths: - - gradle.properties - -jobs: - build: - uses: th2-net/.github/.github/workflows/compound-java.yml@main - with: - build-target: 'Docker' - runsOn: ubuntu-latest - gradleVersion: '7' - docker-username: ${{ github.actor }} - secrets: - docker-password: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 6fee9b6..0a0b2ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /.gradle/ /logs /.settings -/bin **/build /schema /.idea +bin/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index 33e0ca1..1dc0af9 100644 --- a/build.gradle +++ b/build.gradle @@ -12,8 +12,8 @@ apply plugin: 'application' ext { - commonVersion = '5.4.2-dev' - cradleVersion = '5.1.4-dev' + commonVersion = '5.8.0-dev' + cradleVersion = '5.2.0-dev' } allprojects { @@ -51,21 +51,33 @@ allprojects { } implementation "com.exactpro.th2:cradle-core:$cradleVersion" implementation "com.exactpro.th2:cradle-cassandra:$cradleVersion" - implementation 'org.apache.commons:commons-lang3:3.12.0' + implementation 'org.apache.commons:commons-lang3' implementation "org.slf4j:slf4j-api" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2' - testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.2' + testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - testImplementation 'org.mockito:mockito-inline:4.10.0' - testImplementation 'org.mockito:mockito-junit-jupiter:4.10.0' + testImplementation 'org.mockito:mockito-inline:5.2.0' + testImplementation 'org.mockito:mockito-junit-jupiter:5.10.0' + testImplementation 'com.exactpro.th2:junit-jupiter-integration:0.0.1-master-6956603819-5241ee5-SNAPSHOT' + } + + test { + useJUnitPlatform { + excludeTags('integration') + } } -} -test { - useJUnitPlatform() + tasks.register('integrationTest', Test) { + group = 'verification' + useJUnitPlatform { + includeTags('integration') + } + testLogging { + showStandardStreams = true + } + } } dependencyLocking { diff --git a/cradle-admin-tool-cli/build.gradle b/cradle-admin-tool-cli/build.gradle index 680343d..8b481bd 100644 --- a/cradle-admin-tool-cli/build.gradle +++ b/cradle-admin-tool-cli/build.gradle @@ -6,10 +6,6 @@ dependencies { testImplementation project(':').sourceSets.test.output } -test { - useJUnitPlatform() -} - jar { archivesBaseName = 'th2-cradle-admin-cli' manifest { diff --git a/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/Application.java b/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/Application.java index 5cc62c2..81e6d53 100644 --- a/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/Application.java +++ b/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ import java.util.Optional; import java.util.Spliterator; import java.util.Spliterators; +import java.util.function.Function; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -56,34 +57,43 @@ public class Application { private static String BUILD_DATE; - public static void main(String[] args) throws Exception { + public static void main(String[] args) { + run(args, CommonFactory::createFromArguments); + } - initApplication(args); - Options options = buildOptions(); - - CommandLine cmdLine = new DefaultParser().parse(options, args); + static void run(String[] args, Function createFactory) { + try { + initApplication(args); + Options options = buildOptions(); + try { - try (CommonFactory commonFactory = CommonFactory.createFromArguments(buildSchemaParams(cmdLine))) { - - AbstractMode mode = Mode.getMode(cmdLine); - if (mode instanceof CliMode && !((CliMode)mode).initParams(cmdLine)) { - return; - } - try (CradleManager mngr = commonFactory.getCradleManager()) { + CommandLine cmdLine = new DefaultParser().parse(options, args); + + try (CommonFactory commonFactory = createFactory.apply(buildSchemaParams(cmdLine))) { - CradleStorage storage = mngr.getStorage(); - mode.init(storage); - SimpleResult result = mode.execute(); - ResultPrinter.printToCmd(result); + AbstractMode mode = Mode.getMode(cmdLine); + if (mode instanceof CliMode && !((CliMode) mode).initParams(cmdLine)) { + return; + } + try (CradleManager manager = commonFactory.getCradleManager()) { + + CradleStorage storage = manager.getStorage(); + mode.init(storage); + SimpleResult result = mode.execute(); + ResultPrinter.printToCmd(result); + + } + } + } catch (Exception e) { + logger.error("Cannot start application, cause {}", e.getMessage(), e); + printHelp(options); } } catch (Exception e) { - logger.error("Cannot start application, cause {}", e.getMessage(), e); - printHelp(options); + logger.error("Cannot init application, cause {}", e.getMessage(), e); } } - private static Options buildOptions() { Options options = new Options(); options.addOption(new Option(CmdParams.COMMON_CFG_SHORT, CmdParams.COMMON_CFG_LONG, true, null)); diff --git a/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/ResultPrinter.java b/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/ResultPrinter.java index 205e259..898639b 100644 --- a/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/ResultPrinter.java +++ b/cradle-admin-tool-cli/src/main/java/com/exactpro/th2/cradle/adm/cli/ResultPrinter.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2021-2021 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,11 @@ package com.exactpro.th2.cradle.adm.cli; -import com.exactpro.cradle.BookListEntry; -import com.exactpro.th2.cradle.adm.results.*; +import com.exactpro.th2.cradle.adm.results.BooksListInfo; +import com.exactpro.th2.cradle.adm.results.ResultBookDetailedInfo; +import com.exactpro.th2.cradle.adm.results.ResultBookInfo; +import com.exactpro.th2.cradle.adm.results.ResultPageInfo; +import com.exactpro.th2.cradle.adm.results.SimpleResult; import java.util.List; diff --git a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/AbstractCliTest.java b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/AbstractCliTest.java index b913c36..92b79d3 100644 --- a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/AbstractCliTest.java +++ b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/AbstractCliTest.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,12 +12,17 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.cli; +import com.exactpro.cradle.CradleManager; +import com.exactpro.th2.cradle.adm.TestBookPageBuilder; +import com.exactpro.th2.test.annotations.Th2IntegrationTest; +import com.exactpro.th2.test.spec.CradleSpec; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import java.io.ByteArrayOutputStream; @@ -25,20 +30,36 @@ import java.util.Arrays; import java.util.regex.Pattern; +@Th2IntegrationTest public class AbstractCliTest { - public static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$"); + protected ByteArrayOutputStream outContent; + protected ByteArrayOutputStream errContent; + + protected TestBookPageBuilder testBookPageBuilder; + private PrintStream originalOut; + private PrintStream originalErr; - protected final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - protected final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - private final PrintStream originalOut = System.out; - private final PrintStream originalErr = System.err; + @SuppressWarnings("unused") + public final CradleSpec cradleSpec = CradleSpec.Companion.create() + .disableAutoPages() + .reuseKeyspace(); - public static final String INITIAL_BOOK = "init_book"; - public static final String INITIAL_PAGE = "init_page"; + @BeforeAll + public static void initStorage(CradleManager manager) { + // init database schema + manager.getStorage(); + } @BeforeEach public void before() { + testBookPageBuilder = TestBookPageBuilder.builder(); + + outContent = new ByteArrayOutputStream(); + errContent = new ByteArrayOutputStream(); + originalOut = System.out; + originalErr = System.err; + System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); } diff --git a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/BookCliTest.java b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/BookCliTest.java index b552787..47cad7a 100644 --- a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/BookCliTest.java +++ b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/BookCliTest.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,103 +12,110 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.cli; +import com.exactpro.cradle.BookId; import com.exactpro.cradle.BookInfo; -import com.exactpro.cradle.PageInfo; -import com.exactpro.th2.cradle.adm.TestExecutor; -import org.junit.jupiter.api.Assertions; +import com.exactpro.cradle.CradleManager; +import com.exactpro.cradle.CradleStorage; +import com.exactpro.th2.common.schema.factory.CommonFactory; +import com.exactpro.th2.test.annotations.Th2AppFactory; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; - import java.time.Instant; import java.time.temporal.ChronoUnit; -public class BookCliTest extends AbstractCliTest{ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +@Tag("integration") +public class BookCliTest extends AbstractCliTest { @Test - public void addBookTest() throws Exception { - - new TestExecutor() - .execTest( - (cradleStorage) -> { + public void addBookTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + int initNumberOfBooks = cradleStorage.listBooks().size(); - Application.main(new String[]{"-c=stub/", "--book", "-bookName", "dev_test_6"}); + String bookName = "addBookTest"; - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - BookInfo dev_test_6 = cradleStorage.getBook("dev_test_6"); - Assertions.assertEquals(0, dev_test_6.getPages().size()); + Application.run(new String[]{"-c=stub/", "--book", "-bookName", bookName}, args -> appFactory); + BookInfo bookInfo = cradleStorage.getBook(new BookId(bookName)); + assertEquals(initNumberOfBooks + 1, cradleStorage.listBooks().size()); + assertEquals(0, bookInfo.getPages().size()); - checkOutput(true, null); - } - ); + checkOutput(true, null); } @Test - public void addBookWithoutTimeTest() throws Exception { - - new TestExecutor() - .execTest( - (cradleStorage) -> { - - Instant i1 = Instant.now(); - Application.main(new String[]{"-c=stub/", "--book", "-bookName", "dev_test_6"}); - - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - BookInfo dev_test_5 = cradleStorage.getBook("dev_test_6"); - - Assertions.assertNotNull(dev_test_5); - Assertions.assertNotNull(dev_test_5.getCreated()); - Assertions.assertTrue(dev_test_5.getCreated().isAfter(i1)); - Assertions.assertTrue(dev_test_5.getCreated().isBefore(Instant.now())); - - checkOutput(true, null); - } - ); + public void addBookWithoutTimeTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + int initNumberOfBooks = cradleStorage.listBooks().size(); + + Instant i1 = Instant.now(); + String bookName = "addBookWithoutTimeTest"; + Application.run(new String[]{"-c=stub/", "--book", "-bookName", bookName}, args -> appFactory); + + BookInfo bookInfo = cradleStorage.getBook(new BookId(bookName)); + assertEquals(initNumberOfBooks + 1, cradleStorage.listBooks().size()); + assertNotNull(bookInfo); + assertNotNull(bookInfo.getCreated()); + assertTrue(bookInfo.getCreated().isAfter(i1)); + assertTrue(bookInfo.getCreated().isBefore(Instant.now())); + + checkOutput(true, null); } @Test - public void addBookWithParamsTest() throws Exception { - - new TestExecutor() - .execTest( - (cradleStorage) -> { - Instant created = Instant.now().minus(20, ChronoUnit.MINUTES); - String bookName = "dev_test_6"; - String bookFullName = "This book is created in addBookWithParamsTest for unit test purposes"; - String bookDesc = "book DESC123"; - Application.main(new String[]{"-c=stub/", "--book", "-bookName", bookName, - "-createdTime", created.toString(), - "-desc", bookDesc, "-fullName", bookFullName}); - - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - BookInfo dev_test_6 = cradleStorage.getBook("dev_test_6"); - Assertions.assertEquals(bookFullName, dev_test_6.getFullName()); - Assertions.assertEquals(bookDesc, dev_test_6.getDesc()); - Assertions.assertEquals(created, dev_test_6.getCreated()); - Assertions.assertEquals(0, dev_test_6.getPages().size()); - - - checkOutput(true, null); - } - ); + public void addBookWithParamsTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + int initNumberOfBooks = cradleStorage.listBooks().size(); + + Instant created = Instant.now().minus(20, ChronoUnit.MINUTES); + String bookName = "addBookWithParamsTest"; + BookId bookId = new BookId(bookName); + String bookFullName = "This book is created in addBookWithParamsTest for unit test purposes"; + String bookDesc = "book DESC123"; + + Application.run(new String[]{"-c=stub/", "--book", "-bookName", bookName, + "-createdTime", created.toString(), + "-desc", bookDesc, "-fullName", bookFullName}, + args -> appFactory); + + + BookInfo bookInfo = cradleStorage.getBook(bookId); + assertEquals(initNumberOfBooks + 1, cradleStorage.listBooks().size()); + assertNotNull(bookInfo); + assertEquals(bookFullName, bookInfo.getFullName()); + assertEquals(bookDesc, bookInfo.getDesc()); + assertEquals(created.truncatedTo(ChronoUnit.MILLIS), bookInfo.getCreated()); + assertEquals(0, bookInfo.getPages().size()); + + checkOutput(true, null); } @Test - public void addExistedBookTest() throws Exception { - - new TestExecutor().addBookIds(INITIAL_BOOK, Instant.now()) - .execTest( - (cradleStorage) -> { - Application.main(new String[]{"-c=stub/", "--book", "-bookName", INITIAL_BOOK}); - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - checkOutput(false, String.format("Book '%s' is already present in storage", INITIAL_BOOK)); - } - ); - } + public void addExistedBookTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + int initNumberOfBooks = cradleStorage.listBooks().size(); + + String bookName = "addExistedBookTest"; + BookId bookId = new BookId(bookName); + testBookPageBuilder.addBookIds(bookName, Instant.now()) + .exec(cradleStorage); + assertEquals(initNumberOfBooks + 1, cradleStorage.listBooks().size()); + Application.run(new String[]{"-c=stub/", "--book", "-bookName", bookName}, args -> appFactory); + + assertNotNull(cradleStorage.getBook(bookId)); + checkOutput(false, String.format("Query to insert book '%s' was not applied. Probably, book already exists", bookName.toLowerCase())); + } } diff --git a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/PagesCliTest.java b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/PagesCliTest.java index c472bd2..26a4e2f 100644 --- a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/PagesCliTest.java +++ b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/PagesCliTest.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,141 +12,213 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.cli; import com.exactpro.cradle.BookId; import com.exactpro.cradle.BookInfo; +import com.exactpro.cradle.CradleManager; +import com.exactpro.cradle.CradleStorage; import com.exactpro.cradle.PageId; import com.exactpro.cradle.PageInfo; -import com.exactpro.th2.cradle.adm.TestExecutor; -import org.junit.jupiter.api.Assertions; +import com.exactpro.th2.common.schema.factory.CommonFactory; +import com.exactpro.th2.test.annotations.Th2AppFactory; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import java.time.Instant; import java.time.temporal.ChronoUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Tag("integration") public class PagesCliTest extends AbstractCliTest { @Test - public void addPageBeforeTest() throws Exception { - - new TestExecutor().addBookIds(INITIAL_BOOK, Instant.now()) - .execTest( - (cradleStorage) -> { - cradleStorage.addPage(new BookId(INITIAL_BOOK), INITIAL_PAGE, Instant.now().plusSeconds(30), "test"); - Assertions.assertEquals(1, cradleStorage.getBook(INITIAL_BOOK).getPages().size()); - Application.main(new String[]{"-c=stub/", "--page", "-pageName", "page123", "-bookId", INITIAL_BOOK, "-pageStart", Instant.parse("2022-01-22T00:10:00Z").toString()}); - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - BookInfo dev_test_5 = cradleStorage.getBook(INITIAL_BOOK); - Assertions.assertEquals(1, dev_test_5.getPages().size()); - checkOutput(false, "You can only create pages which start more than"); - } - ); + public void addPageBeforeTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + String bookName = "addPageBeforeTest"; + BookId bookId = new BookId(bookName); + String pageName = "addPageBeforeTest"; + testBookPageBuilder.addBookIds(bookName, Instant.now()) + .exec(cradleStorage); + BookInfo bookInfo = cradleStorage.getBook(bookId); + assertNotNull(bookInfo); + assertEquals(0, cradleStorage.getBook(bookId).getPages().size()); + assertSame(bookInfo, cradleStorage.addPage(bookId, pageName, Instant.now().plusSeconds(30), "test")); + assertEquals(1, cradleStorage.getBook(bookId).getPages().size()); + + Application.run( + new String[]{"-c=stub/", "--page", + "-pageName", "page123", + "-bookId", bookName, + "-pageStart", Instant.parse("2022-01-22T00:10:00Z").toString()}, + args -> appFactory); + + cradleStorage.refreshBook(bookName); + assertEquals(1, cradleStorage.getBook(bookId).getPages().size()); + checkOutput(false, "You can only create pages which start more than"); } @Test - public void addPageCurrentTimeTest() throws Exception { - - new TestExecutor().addBookIds(INITIAL_BOOK, Instant.now()) - .execTest( - (cradleStorage) -> { - cradleStorage.addPage(new BookId(INITIAL_BOOK), INITIAL_PAGE, Instant.now().plusSeconds(30), "test"); - Assertions.assertEquals(1, cradleStorage.getBook(INITIAL_BOOK).getPages().size()); - Application.main(new String[]{"-c=stub/", "--page", "-pageName", "page123", "-bookId", INITIAL_BOOK, "-pageStart", Instant.now().toString()}); - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - BookInfo dev_test_5 = cradleStorage.getBook(INITIAL_BOOK); - Assertions.assertEquals(1, dev_test_5.getPages().size()); - checkOutput(false, "You can only create pages which start more than"); - } - ); + public void addPageCurrentTimeTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + String bookName = "addPageCurrentTimeTest"; + BookId bookId = new BookId(bookName); + String pageName = "addPageCurrentTimeTest"; + testBookPageBuilder.addBookIds(bookName, Instant.now()) + .exec(cradleStorage); + BookInfo bookInfo = cradleStorage.getBook(bookId); + assertNotNull(bookInfo); + assertEquals(0, cradleStorage.getBook(bookId).getPages().size()); + assertSame(bookInfo, cradleStorage.addPage(bookId, pageName, Instant.now().plusSeconds(30), "test")); + assertEquals(1, cradleStorage.getBook(bookId).getPages().size()); + + Application.run( + new String[]{"-c=stub/", "--page", + "-pageName", "page123", + "-bookId", bookName, + "-pageStart", Instant.now().toString()}, + args -> appFactory); + + cradleStorage.refreshBook(bookName); + assertEquals(1, bookInfo.getPages().size()); + checkOutput(false, "You can only create pages which start more than"); } @Test - public void addPageCorrectTest() throws Exception { - - new TestExecutor().addBookIds(INITIAL_BOOK, Instant.now()) - .execTest( - (cradleStorage) -> { - - Application.main(new String[]{"-c=stub/", "--page", "-pageName", "page123", "-bookId", INITIAL_BOOK, "-pageStart", Instant.now().plus(1, ChronoUnit.MINUTES).toString()}); - - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - BookInfo dev_test_5 = cradleStorage.getBook(INITIAL_BOOK); - Assertions.assertEquals(1, dev_test_5.getPages().size()); - PageInfo newPage = dev_test_5.getPage(new PageId(dev_test_5.getId(), "page123")); - - Assertions.assertNotNull(newPage); - - //todo incorrect logic now -// Assertions.assertTrue(oldPage.isActive()); - - Assertions.assertNotNull(newPage.getStarted()); - Assertions.assertNull(newPage.getEnded()); -// Assertions.assertFalse(newPage.isActive()); - - checkOutput(true, null); - } - ); + public void addPageCorrectTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + String bookName = "addPageCorrectTest"; + BookId bookId = new BookId(bookName); + String pageName = "addPageCorrectTest"; + Instant pageStart = Instant.now().plus(1, ChronoUnit.MINUTES); + testBookPageBuilder.addBookIds(bookName, Instant.now()) + .exec(cradleStorage); + BookInfo bookInfo = cradleStorage.getBook(bookId); + assertNotNull(bookInfo); + assertEquals(0, cradleStorage.getBook(bookId).getPages().size()); + + Application.run( + new String[]{"-c=stub/", "--page", + "-pageName", pageName, + "-bookId", bookName, + "-pageStart", pageStart.toString()}, + args -> appFactory); + + cradleStorage.refreshBook(bookName); + assertEquals(1, bookInfo.getPages().size()); + PageInfo newPage = bookInfo.getPage(new PageId(bookId, pageStart, pageName)); + assertNotNull(newPage); + assertNull(newPage.getEnded()); + + checkOutput(true, null); } @Test - public void addPageWithoutNameTest() throws Exception { - - new TestExecutor().addBookIds(INITIAL_BOOK, Instant.now()) - .execTest( - (cradleStorage) -> { - - Application.main(new String[]{"-c=stub/", "--page", "-bookId", INITIAL_BOOK, "-pageStart", Instant.now().plus(1, ChronoUnit.MINUTES).toString()}); - - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - BookInfo dev_test_5 = cradleStorage.getBook(INITIAL_BOOK); - Assertions.assertEquals(1, dev_test_5.getPages().size()); - Assertions.assertTrue(UUID_REGEX.matcher(dev_test_5.getLastPage().getId().getName()).find()); - - checkOutput(true, null); - } - ); + public void addPageWithoutNameTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + String bookName = "addPageWithoutNameTest"; + BookId bookId = new BookId(bookName); + Instant pageStart = Instant.now().plus(1, ChronoUnit.MINUTES); + testBookPageBuilder.addBookIds(bookName, Instant.now()) + .exec(cradleStorage); + BookInfo bookInfo = cradleStorage.getBook(bookId); + assertNotNull(bookInfo); + assertEquals(0, cradleStorage.getBook(bookId).getPages().size()); + + Application.run( + new String[]{ + "-c=stub/", "--page", + "-bookId", bookName, + "-pageStart", pageStart.toString()}, + args -> appFactory); + + cradleStorage.refreshBook(bookName); + assertEquals(1, bookInfo.getPages().size()); + PageInfo lastPage = bookInfo.getLastPage(); + assertNotNull(lastPage); + assertTrue(UUID_REGEX.matcher(lastPage.getName()).find()); + + checkOutput(true, null); } @Test - public void addPageWithParamsTest() throws Exception { - - new TestExecutor().addBookIds(INITIAL_BOOK, Instant.now()) - .execTest( - (cradleStorage) -> { - Instant pageStart = Instant.now().plus(20, ChronoUnit.MINUTES); - String pageName = "test_page_1234"; - String pageComment = "This PAGE is created in addPageWithParamsTest for unit test purposes"; - Application.main(new String[]{"-c=stub/", "--page", "-bookId", INITIAL_BOOK, - "-pageStart", pageStart.toString(), "-pageName", pageName, "-pageComment", pageComment}); - - PageInfo createdPage = cradleStorage.getPage(new PageId(new BookId(INITIAL_BOOK), pageName)); - Assertions.assertEquals(pageName, createdPage.getId().getName()); - Assertions.assertEquals(pageComment, createdPage.getComment()); - Assertions.assertNull(createdPage.getEnded()); - Assertions.assertEquals(pageStart, createdPage.getStarted()); - - checkOutput(true, null); - } - ); + public void addPageWithParamsTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + String bookName = "addPageWithParamsTest"; + BookId bookId = new BookId(bookName); + String pageName = "addPageWithParamsTest"; + String pageComment = "This PAGE is created in addPageWithParamsTest for unit test purposes"; + Instant pageStart = Instant.now().plus(20, ChronoUnit.MINUTES); + testBookPageBuilder.addBookIds(bookName, Instant.now()) + .exec(cradleStorage); + BookInfo bookInfo = cradleStorage.getBook(bookId); + assertNotNull(bookInfo); + assertEquals(0, cradleStorage.getBook(bookId).getPages().size()); + + Application.run( + new String[]{"-c=stub/", "--page", + "-bookId", bookName, + "-pageStart", pageStart.toString(), + "-pageName", pageName, + "-pageComment", pageComment}, + args -> appFactory); + + cradleStorage.refreshBook(bookName); + PageInfo createdPage = bookInfo.getPage(new PageId(bookId, pageStart, pageName)); + assertEquals(pageName, createdPage.getName()); + assertEquals(pageComment, createdPage.getComment()); + assertNull(createdPage.getEnded()); + assertEquals(pageStart, createdPage.getStarted()); + + checkOutput(true, null); } @Test - public void addExistedPageTest() throws Exception { - - new TestExecutor().addBookIds(INITIAL_BOOK, Instant.now()) - .execTest( - (cradleStorage) -> { - cradleStorage.addPage(new BookId(INITIAL_BOOK), INITIAL_PAGE, Instant.now().plusSeconds(30), "test"); - Assertions.assertEquals(1,cradleStorage.getBook(new BookId(INITIAL_BOOK)).getPages().size()); - Application.main(new String[]{"-c=stub/", "--page", "-pageName", INITIAL_PAGE, "-bookId", INITIAL_BOOK, "-pageStart", Instant.now().plus(3, ChronoUnit.MINUTES).toString()}); - Assertions.assertEquals(1, cradleStorage.getBooksCount()); - Assertions.assertEquals(1,cradleStorage.getBook(new BookId(INITIAL_BOOK)).getPages().size()); - checkOutput(false, String.format("Page '%s' is already present in book '%s'", INITIAL_PAGE, INITIAL_BOOK)); - } - ); + public void addExistedPageTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + String bookName = "addExistedPageTest"; + BookId bookId = new BookId(bookName); + String pageName = "addExistedPageTest"; + testBookPageBuilder.addBookIds(bookName, Instant.now()) + .exec(cradleStorage); + BookInfo bookInfo = cradleStorage.getBook(bookId); + assertNotNull(bookInfo); + assertEquals(0, cradleStorage.getBook(bookId).getPages().size()); + assertSame(bookInfo, cradleStorage.addPage(bookId, pageName, Instant.now().plusSeconds(30), "test")); + assertEquals(1, cradleStorage.getBook(bookId).getPages().size()); + + Application.run( + new String[]{"-c=stub/", "--page", + "-pageName", pageName, + "-bookId", bookName, + "-pageStart", Instant.now().plus(3, ChronoUnit.MINUTES).toString()}, + args -> appFactory); + + cradleStorage.refreshBook(bookName); + assertEquals(1, bookInfo.getPages().size()); + checkOutput(false, String.format( + "Query to insert page '%s' book '%s' was not applied. Probably, page already exists", + pageName, + bookName.toLowerCase())); } } diff --git a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersAllBooksTest.java b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersAllBooksTest.java new file mode 100644 index 0000000..7fc8c67 --- /dev/null +++ b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersAllBooksTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2024 Exactpro (Exactpro Systems Limited) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.exactpro.th2.cradle.adm.cli; + +import com.exactpro.cradle.CradleManager; +import com.exactpro.cradle.CradleStorage; +import com.exactpro.th2.common.schema.factory.CommonFactory; +import com.exactpro.th2.cradle.adm.TestBookPageBuilder; +import com.exactpro.th2.test.annotations.Th2AppFactory; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; + +import static java.time.temporal.ChronoUnit.MILLIS; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Tag("integration") +public class ViewersAllBooksTest extends AbstractCliTest { + @Test + public void printAllBooksTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + String book1Name = "Book1"; + Instant book1Start = Instant.now(); + String book2Name = "Book2"; + Instant book2Start = Instant.now().minus(20, ChronoUnit.MINUTES); + String book3Name = "Book3"; + Instant book3Start = Instant.now().minus(40, ChronoUnit.MINUTES); + TestBookPageBuilder.builder() + .addBookIds(book1Name, book1Start) + .addBookIds(book2Name, book2Start) + .addBookIds(book3Name, book3Start) + .exec(cradleStorage); + + Application.run(new String[]{"-c=stub/", "--getAllBooks"}, args -> appFactory); + + String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + + "Started with arguments: [-c=stub/, --getAllBooks]\n" + + "Success\n" + + "\n" + + "book #1\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n" + + "\n" + + "book #2\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n" + + "\n" + + "book #3\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n", + book3Name.toLowerCase(), + book3Start.truncatedTo(MILLIS), + book2Name.toLowerCase(), + book2Start.truncatedTo(MILLIS), + book1Name.toLowerCase(), + book1Start.truncatedTo(MILLIS) + ); + + assertEquals(expected, this.outContent.toString()); + } +} diff --git a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersTest.java b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersTest.java index 6d12328..4ce931a 100644 --- a/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersTest.java +++ b/cradle-admin-tool-cli/src/test/java/com/exactpro/th2/cradle/adm/cli/ViewersTest.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,185 +12,262 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.cli; import com.exactpro.cradle.BookId; +import com.exactpro.cradle.BookInfo; +import com.exactpro.cradle.CradleManager; import com.exactpro.cradle.CradleStorage; -import com.exactpro.cradle.PageId; -import com.exactpro.th2.cradle.adm.TestExecutor; -import org.junit.jupiter.api.Assertions; +import com.exactpro.cradle.PageInfo; +import com.exactpro.cradle.utils.CradleStorageException; +import com.exactpro.th2.common.schema.factory.CommonFactory; +import com.exactpro.th2.cradle.adm.TestBookPageBuilder; +import com.exactpro.th2.test.annotations.Th2AppFactory; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +@Tag("integration") public class ViewersTest extends AbstractCliTest { + public static final String DEFAULT_REMOVED_TIME = "+292278994-08-17T07:12:55.807Z"; + private static final String BOOK_1 = "BOOK_1"; + private static final String BOOK_2 = "BOOK_2"; + private static final String BOOK_3 = "BOOK_3"; + private static final String PAGE_1 = "PAGE_1"; + private static final String PAGE_2 = "PAGE_2"; - private final Instant book1Start = Instant.now(); - private final String page2Name = "page2"; - private final Instant page2Time = book1Start.plus(20, ChronoUnit.MINUTES); - private final String page3Name = "page3"; - private final Instant page3Time = page2Time.plus(20, ChronoUnit.MINUTES); + @Test + public void printUnknownBookTest(@Th2AppFactory CommonFactory appFactory) { + Application.run(new String[]{"-c=stub/", "--getBookInfo", "-bookId", "unknown_book"}, args -> appFactory); - private final String book1Str = this.book1Start.toString(); - private final String page2Str = this.page2Time.toString(); - private final String page3Str = this.page3Time.toString(); + checkOutput(false, "No books found by given params"); + } - private final Instant book2Start = Instant.now().minus(20, ChronoUnit.MINUTES); - private final Instant book3Start = Instant.now().minus(40, ChronoUnit.MINUTES); + @Test + public void printBookTest(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); - private final String book2StartStr = this.book2Start.toString(); - private final String book3StartStr = this.book3Start.toString(); + DBMetadata result = getInitData(cradleStorage, "printBookTest"); - private final String book2 = "test_book2"; - private final String book3 = "test_book3"; + BookMetadata book1 = result.books.get(BOOK_1); + Application.run(new String[]{"-c=stub/", "--getBookInfo", "-bookId", book1.name}, args -> appFactory); - private TestExecutor createDataExecutor() { - return new TestExecutor().addBookIds(INITIAL_BOOK, book1Start) - .addPageIds(INITIAL_BOOK, page2Name, page2Time, null) - .addPageIds(INITIAL_BOOK, page3Name, page3Time, null) - .addBookIds(book2, book2Start) - .addBookIds(book3, book3Start); + PageMetadata page1 = book1.pages.get(PAGE_1); + PageMetadata page2 = book1.pages.get(PAGE_2); + String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + + "Started with arguments: [-c=stub/, --getBookInfo, -bookId, %s]\n" + + "Success\n" + + "\n" + + "book #1\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n" + + "\tPage #1\n" + + "\t\tPageId: %s\n" + + "\t\tStarted: %s\n" + + "\t\tEnded: %s\n" + + "\t\tUpdated: %s\n" + + "\t\tRemoved: %s\n" + + "\tPage #2\n" + + "\t\tPageId: %s\n" + + "\t\tStarted: %s\n" + + "\t\tUpdated: %s\n" + + "\t\tRemoved: %s\n", + book1.name, + book1.name.toLowerCase(), + book1.start.truncatedTo(ChronoUnit.MILLIS), + page1.name, + page1.start, + page1.end, + page1.start.truncatedTo(ChronoUnit.MILLIS), + DEFAULT_REMOVED_TIME, + page2.name, + page2.start, + page2.start.truncatedTo(ChronoUnit.MILLIS), + DEFAULT_REMOVED_TIME); + assertEquals(expected, this.outContent.toString()); } @Test - public void printUnknownBookTest() throws Exception { - createDataExecutor().execTest( - (cradleStorage) -> { - Application.main(new String[]{"-c=stub/", "--getBookInfo", "-bookId", "unknown_book"}); - checkOutput(false, "No books found by given params"); - } - ); + public void printBookTest2(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + DBMetadata result = getInitData(cradleStorage, "printBookTest2"); + + BookMetadata book2 = result.books.get(BOOK_2); + BookMetadata book3 = result.books.get(BOOK_3); + Application.run(new String[]{"-c=stub/", "--getBookInfo", "-bookId", book2.name, "-bookId", book3.name}, args -> appFactory); + + String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + + "Started with arguments: [-c=stub/, --getBookInfo, -bookId, %s, -bookId, %s]\n" + + "Success\n" + + "\n" + + "book #1\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n" + + "\n" + + "book #2\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n", + book2.name, + book3.name, + book3.name.toLowerCase(), + book3.start.truncatedTo(ChronoUnit.MILLIS), + book2.name.toLowerCase(), + book2.start.truncatedTo(ChronoUnit.MILLIS)); + assertEquals(expected, this.outContent.toString()); } @Test - public void printBookTest() throws Exception { - - createDataExecutor().execTest( - (cradleStorage) -> { - Application.main(new String[]{"-c=stub/", "--getBookInfo", "-bookId", INITIAL_BOOK}); - String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + - "Started with arguments: [-c=stub/, --getBookInfo, -bookId, init_book]\n" + - "Success\n" + - "\n" + - "book #1\n" + - "\tBookId: init_book\n" + - "\tBookCreatedTime: %s\n" + - "\tPage #1\n" + - "\t\tPageId: page2\n" + - "\t\tStarted: %s\n" + - "\t\tEnded: %s\n" + - "\tPage #2\n" + - "\t\tPageId: page3\n" + - "\t\tStarted: %s\n", book1Str, page2Str, page3Str, page3Str); - Assertions.assertEquals(expected, this.outContent.toString()); - } - ); + public void printBookTestWithRemovedPages(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + DBMetadata result = getInitData(cradleStorage, "printBookTestWithRemovedPages"); + + BookMetadata book1 = result.books.get(BOOK_1); + PageMetadata page1 = book1.pages.get(PAGE_1); + PageMetadata page2 = book1.pages.get(PAGE_2); + + BookId book1Id = new BookId(book1.name); + BookInfo bookInfo = cradleStorage.getBook(book1Id); + assertNotNull(bookInfo); + assertEquals(2, bookInfo.getPages().size()); + PageInfo pageInfo2 = getPageInfo(cradleStorage, book1Id, page1.name); + cradleStorage.removePage(pageInfo2.getId()); + + Application.run(new String[]{"-c=stub/", "--getBookInfo", "-bookId", book1.name, "-loadRemovedPages"}, + args -> appFactory); + String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + + "Started with arguments: [-c=stub/, --getBookInfo, -bookId, %s, -loadRemovedPages]\n" + + "Success\n" + + "\n" + + "book #1\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n" + + "\tPage #1\n" + + "\t\tPageId: %s\n" + + "\t\tStarted: %s\n" + + "\t\tUpdated: %s\n" + + "\t\tRemoved: %s\n", + book1.name, + book1.name.toLowerCase(), + book1.start.truncatedTo(ChronoUnit.MILLIS), + page2.name, + page2.start, + page2.start.truncatedTo(ChronoUnit.MILLIS), + DEFAULT_REMOVED_TIME); + String outContent = this.outContent.toString(); + assertEquals(expected, outContent); } @Test - public void printBookTest2() throws Exception { - - createDataExecutor().execTest( - (cradleStorage) -> { - Application.main(new String[]{"-c=stub/", "--getBookInfo", "-bookId", book2, "-bookId", book3}); - String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + - "Started with arguments: [-c=stub/, --getBookInfo, -bookId, test_book2, -bookId, test_book3]\n" + - "Success\n" + - "\n" + - "book #1\n" + - "\tBookId: test_book3\n" + - "\tBookCreatedTime: %s\n" + - "\n" + - "book #2\n" + - "\tBookId: test_book2\n" + - "\tBookCreatedTime: %s\n" - , book3StartStr, book2StartStr); - Assertions.assertEquals(expected, this.outContent.toString()); - } - ); + public void printBookTestWithoutPages(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + CradleStorage cradleStorage = manager.getStorage(); + + DBMetadata result = getInitData(cradleStorage, "printBookTestWithoutPages"); + + BookMetadata book1 = result.books.get(BOOK_1); + + Application.run(new String[]{"-c=stub/", "--getBookInfo", "-bookId", book1.name, "-withPages", "false"}, + args -> appFactory); + + String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + + "Started with arguments: [-c=stub/, --getBookInfo, -bookId, %s, -withPages, false]\n" + + "Success\n" + + "\n" + + "book #1\n" + + "\tBookId: %s\n" + + "\tBookCreatedTime: %s\n", + book1.name, + book1.name.toLowerCase(), + book1.start.truncatedTo(ChronoUnit.MILLIS)); + assertEquals(expected, this.outContent.toString()); } - @Test - public void printBookTestWithRemovedPages() throws Exception { - - createDataExecutor().execTest( - (cradleStorage) -> { - Instant removeInstant = Instant.now().plus(1, ChronoUnit.MINUTES); - Assertions.assertEquals(2,cradleStorage.getBook(new BookId(INITIAL_BOOK)).getPages().size() ); - - cradleStorage.setNextRemovedTime(removeInstant); - cradleStorage.removePage(new PageId(new BookId(INITIAL_BOOK), page2Name)); - - Application.main(new String[]{"-c=stub/", "--getBookInfo", "-bookId", INITIAL_BOOK, "-loadRemovedPages"}); - String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + - "Started with arguments: [-c=stub/, --getBookInfo, -bookId, init_book, -loadRemovedPages]\n" + - "Success\n" + - "\n" + - "book #1\n" + - "\tBookId: init_book\n" + - "\tBookCreatedTime: %s\n" + - "\tPage #1\n" + - "\t\tPageId: page2\n" + - "\t\tStarted: %s\n" + - "\t\tEnded: %s\n" + - "\t\tRemoved: %s\n" + - "\tPage #2\n" + - "\t\tPageId: page3\n" + - "\t\tStarted: %s\n", book1Str, page2Str, page3Str, removeInstant, page3Str); - Assertions.assertEquals(expected, this.outContent.toString()); - } + @NotNull + private static DBMetadata getInitData(CradleStorage cradleStorage, String baseName) throws Exception { + String book1Name = baseName + "Book1"; + Instant book1Start = Instant.now(); + String page1Name = baseName + "Page1"; + Instant page1Time = book1Start.plus(20, ChronoUnit.MINUTES); + String page2Name = baseName + "Page2"; + Instant page2Time = page1Time.plus(20, ChronoUnit.MINUTES); + String book2Name = baseName + "Book2"; + Instant book2Start = Instant.now().minus(20, ChronoUnit.MINUTES); + String book3Name = baseName + "Book3"; + Instant book3Start = Instant.now().minus(40, ChronoUnit.MINUTES); + TestBookPageBuilder.builder().addBookIds(book1Name, book1Start) + .addPageIds(book1Name, page1Name, page1Time, null) + .addPageIds(book1Name, page2Name, page2Time, null) + .addBookIds(book2Name, book2Start) + .addBookIds(book3Name, book3Start) + .exec(cradleStorage); + return new DBMetadata( + Map.of( + BOOK_1, new BookMetadata(book1Name, book1Start, Map.of( + PAGE_1, new PageMetadata(page1Name, page1Time, page2Time), + PAGE_2, new PageMetadata(page2Name, page2Time))), + BOOK_2, new BookMetadata(book2Name, book2Start), + BOOK_3, new BookMetadata(book3Name, book3Start) + ) ); } - @Test - public void printBookTestWithoutPages() throws Exception { - - createDataExecutor().execTest( - (cradleStorage) -> { - Application.main(new String[]{"-c=stub/", "--getBookInfo", "-bookId", INITIAL_BOOK, "-withPages", "false"}); - String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + - "Started with arguments: [-c=stub/, --getBookInfo, -bookId, init_book, -withPages, false]\n" + - "Success\n" + - "\n" + - "book #1\n" + - "\tBookId: init_book\n" + - "\tBookCreatedTime: %s\n", book1Str); - Assertions.assertEquals(expected, this.outContent.toString()); - } - ); + @NotNull + private static PageInfo getPageInfo(CradleStorage cradleStorage, BookId bookId, String pageName) throws CradleStorageException { + return cradleStorage.getAllPages(bookId).stream() + .filter(page -> Objects.equals(pageName, page.getName())) + .findFirst() + .orElseThrow(); } - @Test - public void printAllBooksTest() throws Exception { - - createDataExecutor().execTest( - (cradleStorage) -> { - Application.main(new String[]{"-c=stub/", "--getAllBooks"}); - String expected = String.format("Cradle TH2 Admin tool (CLI), version null, build-date null\n" + - "Started with arguments: [-c=stub/, --getAllBooks]\n" + - "Success\n" + - "\n" + - "book #1\n" + - "\tBookId: test_book3\n" + - "\tBookCreatedTime: %s\n" + - "\n" + - "book #2\n" + - "\tBookId: init_book\n" + - "\tBookCreatedTime: %s\n" + - "\n" + - "book #3\n" + - "\tBookId: test_book2\n" + - "\tBookCreatedTime: %s\n", book3StartStr, book1Str, book2StartStr); - Assertions.assertEquals(expected, this.outContent.toString()); - } - ); + private static class PageMetadata { + public final String name; + public final Instant start; + public final Instant end; + + private PageMetadata(String name, Instant start, Instant end) { + this.name = name; + this.start = start; + this.end = end; + } + private PageMetadata(String name, Instant start) { + this(name, start, null); + } } + private static class BookMetadata { + public final String name; + public final Instant start; + public final Map pages; + private BookMetadata(String name, Instant start, Map pages) { + this.name = name; + this.start = start; + this.pages = pages; + } + private BookMetadata(String name, Instant start) { + this(name, start, Collections.emptyMap()); + } + } + private static class DBMetadata { + public final Map books; + + private DBMetadata(Map books) { + this.books = books; + } + } } diff --git a/cradle-admin-tool-cli/src/test/resources/log4j.properties b/cradle-admin-tool-cli/src/test/resources/log4j.properties deleted file mode 100644 index 2f4ed73..0000000 --- a/cradle-admin-tool-cli/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.debug=false - -log4j.rootLogger=OFF, console - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/cradle-admin-tool-cli/src/test/resources/log4j2.properties b/cradle-admin-tool-cli/src/test/resources/log4j2.properties new file mode 100755 index 0000000..f30edaf --- /dev/null +++ b/cradle-admin-tool-cli/src/test/resources/log4j2.properties @@ -0,0 +1,33 @@ +# +# Copyright 2024 Exactpro (Exactpro Systems Limited) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name=Th2Logger +# Console appender configuration +appender.console.type=Console +appender.console.name=consoleLogger +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-6p [%-15t] %c - %m%n + +logger.th2.name=com.exactpro.th2 +logger.th2.level=INFO + +logger.datastax.name=com.datastax +logger.datastax.level=INFO + +# Root logger level +rootLogger.level=INFO +# Root logger referring to console appender +rootLogger.appenderRef.stdout.ref=consoleLogger \ No newline at end of file diff --git a/cradle-admin-tool-http/build.gradle b/cradle-admin-tool-http/build.gradle index 504ccc2..46fe1ae 100644 --- a/cradle-admin-tool-http/build.gradle +++ b/cradle-admin-tool-http/build.gradle @@ -27,10 +27,6 @@ application { mainClassName = "com.exactpro.th2.cradle.adm.http.Application" } -test { - useJUnitPlatform() -} - applicationName = 'service' distTar { diff --git a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/AbstractHttpTest.java b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/AbstractHttpTest.java index 5db8336..a074e62 100644 --- a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/AbstractHttpTest.java +++ b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/AbstractHttpTest.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022-2023 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,37 +12,58 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.http; import com.exactpro.cradle.BookId; import com.exactpro.cradle.BookToAdd; +import com.exactpro.cradle.CradleManager; +import com.exactpro.cradle.CradleStorage; +import com.exactpro.cradle.PageId; import com.exactpro.cradle.PageToAdd; -import com.exactpro.th2.cradle.adm.TestCradleStorage; +import com.exactpro.cradle.utils.CradleStorageException; +import com.exactpro.th2.common.schema.factory.CommonFactory; +import com.exactpro.th2.test.annotations.Th2AppFactory; +import com.exactpro.th2.test.annotations.Th2IntegrationTest; +import com.exactpro.th2.test.spec.CradleSpec; import org.eclipse.jetty.http.HttpTester; import org.eclipse.jetty.server.LocalConnector; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import java.io.IOException; import java.util.Collections; +@Tag("integration") +@Th2IntegrationTest public class AbstractHttpTest { + @SuppressWarnings("unused") + public final CradleSpec cradleSpec = CradleSpec.Companion.create() + .disableAutoPages() + .reuseKeyspace(); protected TestHttpServer testHttpServer; protected LocalConnector connector; - protected TestCradleStorage storage; + protected CradleStorage storage; + + @BeforeAll + public static void initStorage(CradleManager manager) { + // init database schema + manager.getStorage(); + } @BeforeEach - public void init() throws Exception { - this.storage = new TestCradleStorage(); - this.testHttpServer = new TestHttpServer(new Configuration(), this.storage); + public void init(@Th2AppFactory CommonFactory appFactory, + CradleManager manager) throws Exception { + this.storage = manager.getStorage(); + this.testHttpServer = new TestHttpServer(new Configuration(), appFactory.getCradleManager().getStorage()); this.testHttpServer.run(); this.connector = testHttpServer.getLocalConnector(); this.testHttpServer.run(); - - storage.init(false); } @AfterEach @@ -66,7 +87,7 @@ protected void checkPlainResponse(String str, boolean status, String test) { protected void checkPlainResponseContains(String body, boolean expected, String test) { PlainResponse rsp = new PlainResponse(body.trim()); - Assertions.assertEquals(expected ? "Success": "Failed", rsp.status); + Assertions.assertEquals(rsp.status, expected ? "Success": "Failed", rsp.toString()); Assertions.assertTrue(rsp.comment.contains(test), () -> String.format("Comment should contain text: %s but actual text is %s", test, rsp.comment)); } @@ -78,6 +99,9 @@ protected void addPage(BookId bookId, PageToAdd page) throws Exception { this.storage.addPages(bookId, Collections.singletonList(page)); } + protected void removePage(PageId pageId) throws CradleStorageException, IOException { + this.storage.removePage(pageId); + } protected static class PlainResponse { public String status; @@ -88,6 +112,14 @@ protected PlainResponse(String str) { status = spl[0]; comment = spl.length > 1 ? spl[1] : null; } + + @Override + public String toString() { + return "PlainResponse{" + + "status='" + status + '\'' + + ", comment='" + comment + '\'' + + '}'; + } } } diff --git a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/BookHttpTest.java b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/BookHttpTest.java index 60fc34b..7e00095 100644 --- a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/BookHttpTest.java +++ b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/BookHttpTest.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,98 +12,102 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.http; import com.exactpro.cradle.BookId; import com.exactpro.cradle.BookInfo; - import com.exactpro.cradle.BookToAdd; import org.eclipse.jetty.http.HttpTester; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.time.Instant; +import static java.time.temporal.ChronoUnit.MILLIS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class BookHttpTest extends AbstractHttpTest{ @Test public void addBookTest() throws Exception { - Assertions.assertEquals(0, this.storage.getBooksCount()); - HttpTester.Response response = this.executeGet("/new-book?book-name=test_01_underscores"); - Assertions.assertEquals(200, response.getStatus()); + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "test_01_underscores"; + HttpTester.Response response = this.executeGet("/new-book?book-name=" + bookName); + assertEquals(200, response.getStatus()); PlainResponse plainResponse = new PlainResponse(response.getContent()); - Assertions.assertEquals("Success", plainResponse.status); - Assertions.assertTrue(plainResponse.comment.startsWith("Book created name = test_01_underscores")); - Assertions.assertEquals(1, this.storage.getBooksCount()); - Assertions.assertNotNull(this.storage.getBook(new BookId("test_01_underscores"))); + assertEquals("Success", plainResponse.status); + assertTrue(plainResponse.comment.startsWith("Book created name = " + bookName)); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + assertNotNull(this.storage.getBook(new BookId(bookName))); } @Test public void addBookTestWithParams() throws Exception { - Assertions.assertEquals(0, this.storage.getBooksCount()); - String bookName = "test_01_underscores"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "test_02_underscores"; String pageName = "PAGE1"; - String fullname = "FILLBOOKNAME"; + String fullName = "FILL_BOOK_NAME"; String desc = "description0001"; Instant time = Instant.now(); HttpTester.Response response = this.executeGet(String.format("/new-book?book-name=%s&created-time=%s" + - "&first-page-name=%s&full-name=%s&desc=%s", bookName, time.toString(), pageName, fullname, desc)); - Assertions.assertEquals(200, response.getStatus()); + "&first-page-name=%s&full-name=%s&desc=%s", bookName, time.toString(), pageName, fullName, desc)); + assertEquals(200, response.getStatus()); PlainResponse plainResponse = new PlainResponse(response.getContent()); - Assertions.assertEquals("Success", plainResponse.status); - Assertions.assertTrue(plainResponse.comment.startsWith("Book created name = test_01_underscores")); - Assertions.assertEquals(1, this.storage.getBooksCount()); - BookInfo createdBook = this.storage.getBook(new BookId("test_01_underscores")); - Assertions.assertNotNull(createdBook); - Assertions.assertEquals(time, createdBook.getCreated()); - Assertions.assertEquals(fullname, createdBook.getFullName()); - Assertions.assertEquals(desc, createdBook.getDesc()); - Assertions.assertEquals(0, createdBook.getPages().size()); + assertEquals("Success", plainResponse.status); + assertTrue(plainResponse.comment.startsWith("Book created name = " + bookName)); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + BookInfo createdBook = this.storage.getBook(new BookId(bookName)); + assertNotNull(createdBook); + assertEquals(time.truncatedTo(MILLIS), createdBook.getCreated()); + assertEquals(fullName, createdBook.getFullName()); + assertEquals(desc, createdBook.getDesc()); + assertEquals(0, createdBook.getPages().size()); } @Test public void testEscapingSymbols() throws Exception { - Assertions.assertEquals(0, this.storage.getBooksCount()); - String bookName = "test_01_underscores"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "test_03_underscores"; String pageName = "PAG%$%_=dE1"; - String fullname = "FILL ;596-*/30 ddd.. BOOKNAME"; - String desc = "descript333345678900987635i><\ton0dd001"; + String fullName = "FILL ;596-*/30 ddd.. BOOK_NAME"; + String desc = "descriptor333345678900987635i><\ton0dd001"; Instant time = Instant.now(); String url = String.format("/new-book?book-name=%s&created-time=%s" + "&first-page-name=%s&full-name=%s&desc=%s", bookName, time.toString(), URLEncoder.encode(pageName, StandardCharsets.UTF_8), - URLEncoder.encode(fullname, StandardCharsets.UTF_8), + URLEncoder.encode(fullName, StandardCharsets.UTF_8), URLEncoder.encode(desc, StandardCharsets.UTF_8)); HttpTester.Response response = this.executeGet(url); - PlainResponse plainResponse = new PlainResponse(response.getContent()); - Assertions.assertEquals(200, response.getStatus()); - this.checkPlainResponseContains(response.getContent(), true,"Book created name = test_01_underscores"); - Assertions.assertEquals(1, this.storage.getBooksCount()); - BookInfo createdBook = this.storage.getBook(new BookId("test_01_underscores")); - Assertions.assertNotNull(createdBook); - Assertions.assertEquals(time, createdBook.getCreated()); - Assertions.assertEquals(fullname, createdBook.getFullName()); - Assertions.assertEquals(desc, createdBook.getDesc()); - Assertions.assertEquals(0, createdBook.getPages().size()); + assertEquals(200, response.getStatus()); + this.checkPlainResponseContains(response.getContent(), true,"Book created name = " + bookName); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + BookInfo createdBook = this.storage.getBook(new BookId(bookName)); + assertNotNull(createdBook); + assertEquals(time.truncatedTo(MILLIS), createdBook.getCreated()); + assertEquals(fullName, createdBook.getFullName()); + assertEquals(desc, createdBook.getDesc()); + assertEquals(0, createdBook.getPages().size()); } @Test public void addExistedBook() throws Exception { - - String bookName = "testBook"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "addExistedBook"; this.addBook(new BookToAdd(bookName, Instant.now())); - Assertions.assertEquals(1, this.storage.getBooksCount()); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); HttpTester.Response response = this.executeGet("/new-book?book-name=" + bookName); - this.checkPlainResponseContains(response.getContent(), false, String.format("Book '%s' is already present in storage", + this.checkPlainResponseContains(response.getContent(), false, + String.format("Query to insert book '%s' was not applied. Probably, book already exists", bookName.toLowerCase())); - Assertions.assertEquals(1, this.storage.getBooksCount()); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); } } diff --git a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/PagesHttpTest.java b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/PagesHttpTest.java index 19588ac..30ca184 100644 --- a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/PagesHttpTest.java +++ b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/PagesHttpTest.java @@ -1,5 +1,5 @@ /* -* Copyright 2022-2023 Exactpro (Exactpro Systems Limited) +* Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,156 +23,216 @@ import com.exactpro.cradle.PageInfo; import com.exactpro.cradle.PageToAdd; import org.eclipse.jetty.http.HttpTester; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Pattern; +import static com.exactpro.cradle.utils.EscapeUtils.escape; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class PagesHttpTest extends AbstractHttpTest { public static final Pattern UUID_REGEX = Pattern.compile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$"); @Test public void addPageTest() throws Exception { - - String bookId = "testBook"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "addPageTest"; String pageName = "page2"; Instant time = Instant.now().plus(2, ChronoUnit.MINUTES); - addBook(new BookToAdd(bookId, Instant.now())); + addBook(new BookToAdd(bookName, Instant.now())); HttpTester.Response response = this.executeGet(String.format("/new-page?book-id=%s&page-name=%s&page-start=%s", - bookId, pageName, time.toString())); - Assertions.assertEquals(200, response.getStatus()); + bookName, pageName, time.toString())); + assertEquals(200, response.getStatus()); this.checkPlainResponse(response.getContent(), true, - String.format("Page created bookId = %s,pageName = %s,pageStart = %s", bookId.toLowerCase(), pageName, time)); - Assertions.assertEquals(1, this.storage.getBooksCount()); - BookId bookIdkey = new BookId(bookId); - BookInfo bookIdObj = this.storage.getBook(bookIdkey); - Assertions.assertNotNull(bookIdObj.getPage(new PageId(bookIdkey, pageName))); + String.format("Page created bookId = %s,pageName = %s,pageStart = %s", bookName.toLowerCase(), pageName, time)); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + BookId bookId = new BookId(bookName); + BookInfo bookIdObj = this.storage.getBook(bookId); + assertNotNull(bookIdObj.getPage(new PageId(bookId, time, pageName))); } @Test public void addPageTestMillis() throws Exception { - - String bookId = "testBook"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "addPageTestMillis"; String pageName = "page2"; - Instant time = Instant.now().plus(2, ChronoUnit.MINUTES); - addBook(new BookToAdd(bookId, Instant.now())); + Instant time = Instant.now().plus(2, ChronoUnit.MINUTES).truncatedTo(ChronoUnit.MILLIS); + addBook(new BookToAdd(bookName, Instant.now())); HttpTester.Response response = this.executeGet(String.format("/new-page?book-id=%s&page-name=%s&page-start=%s", - bookId, pageName, time.toEpochMilli())); - Assertions.assertEquals(200, response.getStatus()); + bookName, pageName, time.toEpochMilli())); + assertEquals(200, response.getStatus()); Instant instant = Instant.ofEpochMilli(time.toEpochMilli()); // reset nanos this.checkPlainResponse(response.getContent(), true, - String.format("Page created bookId = %s,pageName = %s,pageStart = %s", bookId.toLowerCase(), pageName, instant)); - Assertions.assertEquals(1, this.storage.getBooksCount()); - BookId bookIdkey = new BookId(bookId); - BookInfo bookIdObj = this.storage.getBook(bookIdkey); - Assertions.assertNotNull(bookIdObj.getPage(new PageId(bookIdkey, pageName))); + String.format("Page created bookId = %s,pageName = %s,pageStart = %s", bookName.toLowerCase(), pageName, instant)); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + BookId bookId = new BookId(bookName); + BookInfo bookIdObj = this.storage.getBook(bookId); + assertNotNull(bookIdObj.getPage(new PageId(bookId, time, pageName))); } @Test public void addPageWithNoNameTest() throws Exception { - String bookId = "testBook"; + String bookName = "addPageWithNoNameTest"; Instant time = Instant.now().plus(2, ChronoUnit.MINUTES); - addBook(new BookToAdd(bookId, Instant.now())); + addBook(new BookToAdd(bookName, Instant.now())); HttpTester.Response response = this.executeGet(String.format("/new-page?book-id=%s&page-start=%s", - bookId, time.toString())); - Assertions.assertEquals(200, response.getStatus()); - Assertions.assertEquals(1, this.storage.getBooksCount()); - BookId bookIdkey = new BookId(bookId); - BookInfo bookIdObj = this.storage.getBook(bookIdkey); - Assertions.assertEquals(1, bookIdObj.getPages().size()); + bookName, time.toString())); + assertEquals(200, response.getStatus()); + assertEquals(1, storage.listBooks().size()); + BookId bookId = new BookId(bookName); + BookInfo bookIdObj = this.storage.getBook(bookId); + assertEquals(1, bookIdObj.getPages().size()); String pageName = bookIdObj.findPage(time).getId().getName(); this.checkPlainResponseContains(response.getContent(), true, - String.format("Page created bookId = %s,pageName = %s,pageStart = %s", bookId.toLowerCase(), pageName, time)); - Assertions.assertTrue(UUID_REGEX.matcher(pageName).find()); + String.format("Page created bookId = %s,pageName = %s,pageStart = %s", bookName.toLowerCase(), pageName, time)); + assertTrue(UUID_REGEX.matcher(pageName).find()); } @Test public void addPageWithParamsTest() throws Exception { - - String bookId = "testBook"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "addPageWithParamsTest"; String pageName = "page2"; Instant time = Instant.now().plus(2, ChronoUnit.MINUTES); String comment = "text_comment_1234567890_text_comment_1234567890_text_comment_1234567890_text_comment_1234567890"; - addBook(new BookToAdd(bookId, Instant.now())); + addBook(new BookToAdd(bookName, Instant.now())); HttpTester.Response response = this.executeGet(String.format("/new-page?book-id=%s&page-name=%s&page-start=%s&page-comment=%s", - bookId, pageName, time.toString(), comment)); - Assertions.assertEquals(200, response.getStatus()); + bookName, pageName, time.toString(), comment)); + assertEquals(200, response.getStatus()); this.checkPlainResponse(response.getContent(), true, - String.format("Page created bookId = %s,pageName = %s,pageStart = %s,pageComment = %s", bookId.toLowerCase(), pageName, time, comment)); - Assertions.assertEquals(1, this.storage.getBooksCount()); - BookId bookIdkey = new BookId(bookId); - BookInfo bookIdObj = this.storage.getBook(bookIdkey); - PageInfo page = bookIdObj.getPage(new PageId(bookIdkey, pageName)); - Assertions.assertNotNull(page); - Assertions.assertEquals(time, page.getStarted()); - Assertions.assertNull(page.getEnded()); - Assertions.assertEquals(comment, page.getComment()); + String.format("Page created bookId = %s,pageName = %s,pageStart = %s,pageComment = %s", bookName.toLowerCase(), pageName, time, comment)); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + BookId bookId = new BookId(bookName); + BookInfo bookIdObj = this.storage.getBook(bookId); + PageInfo page = bookIdObj.getPage(new PageId(bookId, time, pageName)); + assertNotNull(page); + assertEquals(time, page.getStarted()); + assertNull(page.getEnded()); + assertEquals(comment, page.getComment()); } @Test public void removePageTest() throws Exception { - - String bookId = "testBook"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "removePageTest"; String old_page = "old_page"; + Instant old_page_start = Instant.now().plus(5, ChronoUnit.MILLIS); String new_page = "new_page"; - addBook(new BookToAdd(bookId, Instant.now().minus(20, ChronoUnit.SECONDS))); - addPage(new BookId(bookId), new PageToAdd(old_page, Instant.now().plus(5, ChronoUnit.MILLIS), "should be deleted in this scenario")); - addPage(new BookId(bookId), new PageToAdd(new_page, Instant.now().plus(3, ChronoUnit.MINUTES), "should not be deleted in this scenario")); + Instant new_page_start = Instant.now().plus(3, ChronoUnit.MINUTES); + addBook(new BookToAdd(bookName, Instant.now().minus(20, ChronoUnit.SECONDS))); + addPage(new BookId(bookName), new PageToAdd(old_page, old_page_start, "should be deleted in this scenario")); + addPage(new BookId(bookName), new PageToAdd(new_page, new_page_start, "should not be deleted in this scenario")); - BookId bookIdkey = new BookId(bookId); - BookInfo bookIdObj = this.storage.getBook(bookIdkey); - Assertions.assertEquals(1, this.storage.getBooksCount()); - Assertions.assertEquals(2, bookIdObj.getPages().size()); + BookId bookId = new BookId(bookName); + BookInfo bookIdObj = this.storage.getBook(bookId); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + assertEquals(2, bookIdObj.getPages().size()); Thread.sleep(30); //to start new page HttpTester.Response response = this.executeGet(String.format("/remove-page?book-id=%s&page-name=%s", - bookId, old_page)); - bookIdObj = this.storage.getBook(bookIdkey); - Assertions.assertEquals(200, response.getStatus()); + bookName, old_page)); + bookIdObj = this.storage.getBook(bookId); + assertEquals(200, response.getStatus()); this.checkPlainResponse(response.getContent(), true, - String.format("Page removed %s:%s", bookId.toLowerCase(), old_page)); - Assertions.assertEquals(1, bookIdObj.getPages().size()); + String.format("Page removed %s:%s:%s", bookName.toLowerCase(), escape(old_page_start.toString()), old_page)); + assertEquals(1, bookIdObj.getPages().size()); - Assertions.assertNotNull(bookIdObj.getPage(new PageId(bookIdkey, new_page))); + assertNotNull(bookIdObj.getPage(new PageId(bookId, new_page_start, new_page))); } -// @Test -// TODO doesn't work currently TH2-3223 + @Test public void pageGapTest() throws Exception { - - String bookId = "testBook"; + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "pageGapTest"; String pageToRemove = "page2"; Instant time = Instant.now(); - BookId bookIdkey = new BookId(bookId); + BookId bookId = new BookId(bookName); - Instant page2Start = time.plus(10, ChronoUnit.MINUTES); - Instant page3Start = time.plus(20, ChronoUnit.MINUTES); + Instant page1Start = time.plus(10, ChronoUnit.MINUTES); + Instant page2Start = time.plus(20, ChronoUnit.MINUTES); + Instant page3Start = time.plus(30, ChronoUnit.MINUTES); - addBook(new BookToAdd(bookId, time.minus(20, ChronoUnit.SECONDS))); - addPage(bookIdkey, new PageToAdd(pageToRemove, page2Start, null)); - addPage(bookIdkey, new PageToAdd("page3", page3Start, null)); + addBook(new BookToAdd(bookName, time.minus(20, ChronoUnit.SECONDS))); + addPage(bookId, new PageToAdd("page1", page1Start, null)); + addPage(bookId, new PageToAdd(pageToRemove, page2Start, null)); + addPage(bookId, new PageToAdd("page3", page3Start, null)); - BookInfo bookIdObj = this.storage.getBook(bookIdkey); - Assertions.assertEquals(1, this.storage.getBooksCount()); - Assertions.assertEquals(3, bookIdObj.getPages().size()); + BookInfo bookInfo = this.storage.getBook(bookId); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + assertEquals(3, bookInfo.getPages().size()); HttpTester.Response response = this.executeGet(String.format("/remove-page?book-id=%s&page-name=%s", - bookId, pageToRemove)); - bookIdObj = this.storage.getBook(bookIdkey); - Assertions.assertEquals(200, response.getStatus()); + bookName, pageToRemove)); + this.storage.refreshPages(bookId); + assertEquals(200, response.getStatus()); this.checkPlainResponseContains(response.getContent(), true, "Page removed"); - Assertions.assertEquals(2, bookIdObj.getPages().size()); - Assertions.assertEquals(page3Start, bookIdObj.getFirstPage().getEnded()); - Assertions.assertEquals(page3Start, bookIdObj.getLastPage().getStarted()); + assertEquals(2, bookInfo.getPages().size()); + + PageInfo firstPage = bookInfo.getFirstPage(); + assertNotNull(firstPage); + PageInfo lastPage = bookInfo.getLastPage(); + assertNotNull(lastPage); + + assertEquals(page2Start, firstPage.getEnded()); + assertEquals(page3Start, lastPage.getStarted()); + } + @Test + public void insertIntoGageGapTest() throws Exception { + int initNumberOfBooks = storage.listBooks().size(); + String bookName = "insertIntoGageGapTest"; + String pageToRemove = "page2"; + String pageToInsert = "page4"; + Instant time = Instant.now(); + BookId bookId = new BookId(bookName); + + Instant page1Start = time.plus(10, ChronoUnit.MINUTES); + Instant page2Start = time.plus(20, ChronoUnit.MINUTES); + Instant page3Start = time.plus(30, ChronoUnit.MINUTES); + + addBook(new BookToAdd(bookName, time.minus(20, ChronoUnit.SECONDS))); + BookInfo bookInfo = this.storage.getBook(bookId); + assertEquals(initNumberOfBooks + 1, storage.listBooks().size()); + + addPage(bookId, new PageToAdd("page1", page1Start, null)); + addPage(bookId, new PageToAdd(pageToRemove, page2Start, null)); + addPage(bookId, new PageToAdd("page3", page3Start, null)); + this.storage.refreshPages(bookId); + assertEquals(3, bookInfo.getPages().size()); + + removePage(new PageId(bookId, page2Start, pageToRemove)); + this.storage.refreshPages(bookId); + assertEquals(2, bookInfo.getPages().size()); + + HttpTester.Response response = this.executeGet(String.format("/new-page?book-id=%s&page-name=%s&page-start=%s", + bookName, pageToInsert, page2Start.toString())); + assertEquals(200, response.getStatus()); + this.checkPlainResponse(response.getContent(), true, + String.format("Page created bookId = %s,pageName = %s,pageStart = %s", bookName.toLowerCase(), pageToInsert, page2Start)); + + this.storage.refreshPages(bookId); + List pages = new ArrayList<>(bookInfo.getPages()); + assertEquals(3, pages.size()); + + assertEquals(page1Start, pages.get(0).getStarted()); + assertEquals(page2Start, pages.get(0).getEnded()); + assertEquals(page2Start, pages.get(1).getStarted()); + assertEquals(page3Start, pages.get(1).getEnded()); + assertEquals(page3Start, pages.get(2).getStarted()); + assertNull(pages.get(2).getEnded()); } } diff --git a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/ViewersTest.java b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/ViewersTest.java index 922859c..c3db019 100644 --- a/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/ViewersTest.java +++ b/cradle-admin-tool-http/src/test/java/com/exactpro/th2/cradle/adm/http/ViewersTest.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,26 +12,38 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.http; import com.exactpro.cradle.BookId; import com.exactpro.cradle.BookToAdd; +import com.exactpro.cradle.CradleManager; +import com.exactpro.cradle.CradleStorage; import com.exactpro.cradle.PageToAdd; +import com.exactpro.cradle.utils.CradleStorageException; import org.eclipse.jetty.http.HttpTester; -import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.io.IOException; import java.time.Instant; +import static java.time.temporal.ChronoUnit.MILLIS; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ViewersTest extends AbstractHttpTest { - public static final BookToAdd BOOK_1 = new BookToAdd("book_1", Instant.now().minusSeconds(60*20)); + public static final BookToAdd BOOK_1; + public static final String DEFAULT_REMOVED_TIME = "+292278994-08-17T07:12:55.807Z"; + static { - BOOK_1.setDesc("book1-description"); - BOOK_1.setFullName("Book1 full name. Test"); - BOOK_1.setFirstPageComment("Comment123"); + BookToAdd book = new BookToAdd("book_1", Instant.now().minusSeconds(60*20)); + book.setDesc("book1-description"); + book.setFullName("Book1 full name. Test"); + book.setFirstPageComment("Comment123"); + + BOOK_1 = book; } public static final BookToAdd BOOK_2 = new BookToAdd("book_2", BOOK_1.getCreated().minusSeconds(60*20)); @@ -40,74 +52,105 @@ public class ViewersTest extends AbstractHttpTest { public static final PageToAdd BOOK_3_PAGE = new PageToAdd("page3/2", Instant.now().plusSeconds(60), "comment"); - - private void createData() throws Exception { - addBook(BOOK_1); - addBook(BOOK_2); - addBook(BOOK_3); - addPage(new BookId(BOOK_3.getName()), BOOK_3_PAGE); - Assertions.assertEquals(3, this.storage.getBooksCount()); + @BeforeAll + public static void createData(CradleManager manager) throws CradleStorageException, IOException { + CradleStorage storage = manager.getStorage(); + storage.addBook(BOOK_1); + storage.addBook(BOOK_2); + storage.addBook(BOOK_3); + storage.addPage(new BookId(BOOK_3.getName()), BOOK_3_PAGE.getName(), BOOK_3_PAGE.getStart(), BOOK_3_PAGE.getComment()); } @Test public void getBookInfoTest() throws Exception { - createData(); HttpTester.Response response = this.executeGet("/get-all-books"); - Assertions.assertEquals(200, response.getStatus()); + assertEquals(200, response.getStatus()); String content = response.getContent().trim(); //TODO books are in incorrect order should be fixed in CradleAPI - String expected = String.format("[{\"bookId\":\"book_2\",\"bookFullName\":null,\"bookDesc\":null," + - "\"bookCreatedTime\":\"%s\"},{\"bookId\":\"book_1\"," + - "\"bookFullName\":\"Book1 full name. Test\",\"bookDesc\":\"book1-description\"," + - "\"bookCreatedTime\":\"%s\"},{\"bookId\":\"book_3\",\"bookFullName\":null," + - "\"bookDesc\":null,\"bookCreatedTime\":\"%s\"}]", BOOK_2.getCreated(), BOOK_1.getCreated(), - BOOK_3.getCreated()); - Assertions.assertEquals(expected, content); + String expected = String.format("[{" + + "\"bookId\":\"book_2\"," + + "\"bookFullName\":null," + + "\"bookDesc\":null," + + "\"bookCreatedTime\":\"%s\"" + + "},{" + + "\"bookId\":\"book_1\"," + + "\"bookFullName\":\"Book1 full name. Test\"," + + "\"bookDesc\":\"book1-description\"," + + "\"bookCreatedTime\":\"%s\"" + + "},{" + + "\"bookId\":\"book_3\"," + + "\"bookFullName\":null," + + "\"bookDesc\":null,\"" + + "bookCreatedTime\":\"%s\"" + + "}]", + BOOK_2.getCreated().truncatedTo(MILLIS), + BOOK_1.getCreated().truncatedTo(MILLIS), + BOOK_3.getCreated().truncatedTo(MILLIS)); + assertEquals(expected, content); } @Test public void getAllBooksTest() throws Exception { - createData(); HttpTester.Response response = this.executeGet("/get-book-info?book-id=" + BOOK_3.getName()); - Assertions.assertEquals(200, response.getStatus()); + assertEquals(200, response.getStatus()); String content = response.getContent().trim(); - String expected = String.format("[{\"bookId\":\"book_3\"," + - "\"bookFullName\":null," + - "\"bookDesc\":null," + - "\"bookCreatedTime\":\"%s\"," + - "\"pages\":" + - "[{\"pageId\":\"page3/2\",\"comment\":\"comment\",\"started\":\"%s\",\"ended\":null,\"updated\":null,\"removed\":null}]}]", - BOOK_3.getCreated(), BOOK_3_PAGE.getStart()); - Assertions.assertEquals(expected, content); + String expected = String.format("[{" + + "\"bookId\":\"book_3\"," + + "\"bookFullName\":null," + + "\"bookDesc\":null," + + "\"bookCreatedTime\":\"%s\"," + + "\"pages\":[{" + + "\"pageId\":\"page3/2\"," + + "\"comment\":\"comment\"," + + "\"started\":\"%s\"," + + "\"ended\":null," + + "\"updated\":\"%s\"," + + "\"removed\":\"%s\"" + + "}]" + + "}]", + BOOK_3.getCreated().truncatedTo(MILLIS), + BOOK_3_PAGE.getStart(), + BOOK_3_PAGE.getStart().truncatedTo(MILLIS), + DEFAULT_REMOVED_TIME + ); + assertEquals(expected, content); } @Test - public void getBookInfoMultistreamNoPagesTest() throws Exception { - createData(); + public void getBookInfoMultiStreamNoPagesTest() throws Exception { HttpTester.Response response = this.executeGet("/get-book-info?with-pages=false&book-id=" + BOOK_3.getName() + "&book-id=" + BOOK_2.getName()); - Assertions.assertEquals(200, response.getStatus()); + assertEquals(200, response.getStatus()); String content = response.getContent().trim(); - String expected = String.format("[{\"bookId\":\"book_2\",\"bookFullName\":null,\"bookDesc\":null," + - "\"bookCreatedTime\":\"%s\",\"pages\":[]},{\"bookId\":\"book_3\"," + - "\"bookFullName\":null,\"bookDesc\":null,\"bookCreatedTime\":\"%s\"," + - "\"pages\":[]}]", BOOK_2.getCreated(), BOOK_3.getCreated()); - Assertions.assertEquals(expected, content); + String expected = String.format("[{" + + "\"bookId\":\"book_2\"," + + "\"bookFullName\":null," + + "\"bookDesc\":null," + + "\"bookCreatedTime\":\"%s\"," + + "\"pages\":[]" + + "},{" + + "\"bookId\":\"book_3\"," + + "\"bookFullName\":null," + + "\"bookDesc\":null," + + "\"bookCreatedTime\":\"%s\"," + + "\"pages\":[]" + + "}]", + BOOK_2.getCreated().truncatedTo(MILLIS), + BOOK_3.getCreated().truncatedTo(MILLIS)); + assertEquals(expected, content); } @Test public void getBookInfoWithPagesTest() throws Exception { - createData(); HttpTester.Response response = this.executeGet("/get-book-info?with-pages=true&book-id=" + BOOK_3.getName() + "&book-id=" + BOOK_2.getName()); - Assertions.assertEquals(200, response.getStatus()); + assertEquals(200, response.getStatus()); } @Test public void getBookInfoWithRemovedPagesTest() throws Exception { - createData(); HttpTester.Response response = this.executeGet("/get-book-info?with-pages=true&load-removed-pages" + "&book-id=" + BOOK_3.getName() + "&book-id=" + BOOK_2.getName()); - Assertions.assertEquals(200, response.getStatus()); + assertEquals(200, response.getStatus()); } } diff --git a/gradle.properties b/gradle.properties index 0863871..6ef0578 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -release_version = 1.8.0 +release_version = 1.9.0 diff --git a/src/main/java/com/exactpro/th2/cradle/adm/modes/RemovePageMode.java b/src/main/java/com/exactpro/th2/cradle/adm/modes/RemovePageMode.java index 90f4b75..896c4af 100644 --- a/src/main/java/com/exactpro/th2/cradle/adm/modes/RemovePageMode.java +++ b/src/main/java/com/exactpro/th2/cradle/adm/modes/RemovePageMode.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022-2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,30 +12,56 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.modes; +import com.exactpro.cradle.PageId; +import com.exactpro.cradle.PageInfo; +import com.exactpro.cradle.counters.Interval; +import com.exactpro.cradle.utils.CradleStorageException; import com.exactpro.th2.cradle.adm.params.RemovePageParams; import com.exactpro.th2.cradle.adm.results.SimpleResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RemovePageMode extends AbstractMode { +import java.time.Instant; +import java.util.Iterator; +import java.util.Objects; - private static final Logger logger = LoggerFactory.getLogger(RemovePageMode.class); +public class RemovePageMode extends AbstractMode { + private static final Logger LOGGER = LoggerFactory.getLogger(RemovePageMode.class); + private static final Interval INTERVAL = new Interval(Instant.MIN, Instant.MAX); @Override public SimpleResult execute() { try { checkInit(); - logger.info("Removing page: pageId({}})", param.getPageId()); - this.cradleStorage.removePage(param.getPageId()); - logger.info("Page is successfully removed"); - return new SimpleResult("Page removed " + param.getPageId()); + LOGGER.info("Search page: {} in book: {}", param.getBookId(), param.getPageName()); + PageId pageId = search(); + if (pageId == null) { + throw new IllegalStateException( + "Book '" + param.getBookId().getName() + "' doesn't contain page '" + param.getPageName() + "'" + ); + } + LOGGER.info("Removing page: pageId({}})", pageId); + this.cradleStorage.removePage(pageId); + LOGGER.info("Page is successfully removed"); + return new SimpleResult("Page removed " + pageId); } catch (Exception e) { - logger.error("Error creating page", e); + LOGGER.error("Error creating page", e); return new SimpleResult(e); } } + + private PageId search() throws CradleStorageException { + Iterator iterator = this.cradleStorage.getPages(param.getBookId(), INTERVAL); + while (iterator.hasNext()) { + PageInfo pageInfo = iterator.next(); + if (Objects.equals(pageInfo.getName(), param.getPageName())) { + return pageInfo.getId(); + } + } + return null; + } } diff --git a/src/main/java/com/exactpro/th2/cradle/adm/params/RemovePageParams.java b/src/main/java/com/exactpro/th2/cradle/adm/params/RemovePageParams.java index a5728ec..bdb1675 100644 --- a/src/main/java/com/exactpro/th2/cradle/adm/params/RemovePageParams.java +++ b/src/main/java/com/exactpro/th2/cradle/adm/params/RemovePageParams.java @@ -1,5 +1,5 @@ -/******************************************************************************* - * Copyright 2022-2022 Exactpro (Exactpro Systems Limited) +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -12,14 +12,11 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - ******************************************************************************/ + */ package com.exactpro.th2.cradle.adm.params; import com.exactpro.cradle.BookId; -import com.exactpro.cradle.PageId; - -import java.time.Instant; public class RemovePageParams { @@ -33,10 +30,6 @@ public BookId getBookId() { return new BookId(bookId); } - public PageId getPageId() { - return new PageId(getBookId(), this.pageName); - } - public String getPageName() { return pageName; } diff --git a/src/test/java/com/exactpro/th2/cradle/adm/TestBookCache.java b/src/test/java/com/exactpro/th2/cradle/adm/TestBookCache.java deleted file mode 100644 index d7d049c..0000000 --- a/src/test/java/com/exactpro/th2/cradle/adm/TestBookCache.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.exactpro.th2.cradle.adm; - -import com.exactpro.cradle.BookCache; -import com.exactpro.cradle.BookId; -import com.exactpro.cradle.BookInfo; -import com.exactpro.cradle.PageInfo; -import com.exactpro.cradle.utils.CradleStorageException; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -class TestBookCache implements BookCache { - - Map books; - - TestBookCache () { - books = new ConcurrentHashMap<>(); - } - - @Override - public BookInfo getBook(BookId bookId) throws CradleStorageException { - if (!books.containsKey(bookId)) { - throw new CradleStorageException(String.format("Book %s is unknown", bookId.getName())); - } - return books.get(bookId); - } - - @Override - public boolean checkBook(BookId bookId) { - return books.containsKey(bookId); - } - - @Override - public Collection loadPageInfo(BookId bookId, boolean loadRemoved) throws CradleStorageException { - throw new CradleStorageException("Method not supported"); - } - - @Override - public BookInfo loadBook(BookId bookId) { - return books.get(bookId); - } - - @Override - public void updateCachedBook(BookInfo bookInfo) { - books.put(bookInfo.getId(), bookInfo); - } - - @Override - public Collection getCachedBooks() { - return Collections.unmodifiableCollection(books.values()); - } -} - diff --git a/src/test/java/com/exactpro/th2/cradle/adm/TestExecutor.java b/src/test/java/com/exactpro/th2/cradle/adm/TestBookPageBuilder.java similarity index 59% rename from src/test/java/com/exactpro/th2/cradle/adm/TestExecutor.java rename to src/test/java/com/exactpro/th2/cradle/adm/TestBookPageBuilder.java index 8b7f26c..d63cc1d 100644 --- a/src/test/java/com/exactpro/th2/cradle/adm/TestExecutor.java +++ b/src/test/java/com/exactpro/th2/cradle/adm/TestBookPageBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,54 +18,49 @@ import com.exactpro.cradle.BookId; import com.exactpro.cradle.BookToAdd; +import com.exactpro.cradle.CradleStorage; import com.exactpro.cradle.PageToAdd; -import com.exactpro.th2.common.schema.factory.CommonFactory; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.mockito.ArgumentMatchers; -import org.mockito.MockedStatic; -import org.mockito.Mockito; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class TestExecutor { - +public class TestBookPageBuilder { public List booksToAdd; public List> pageIds; - public TestExecutor addBookIds(BookToAdd bookToAdd) { + private TestBookPageBuilder() { } + + public TestBookPageBuilder addBookIds(BookToAdd bookToAdd) { if (this.booksToAdd == null) this.booksToAdd = new ArrayList<>(); this.booksToAdd.add(bookToAdd); return this; } - public TestExecutor addBookIds(String name, Instant created) { + public TestBookPageBuilder addBookIds(String name, Instant created) { return this.addBookIds(new BookToAdd(name, created)); } - public TestExecutor addPageIds(BookId bookId, PageToAdd pageToAdd) { + public TestBookPageBuilder addPageIds(BookId bookId, PageToAdd pageToAdd) { if (this.pageIds == null) this.pageIds = new ArrayList<>(); this.pageIds.add(new ImmutablePair<>(bookId, pageToAdd)); return this; } - public TestExecutor addPageIds(BookId bookId, String name, Instant start, String comment) { + public TestBookPageBuilder addPageIds(BookId bookId, String name, Instant start, String comment) { return this.addPageIds(bookId, new PageToAdd(name, start, comment)); } - public TestExecutor addPageIds(String bookId, String name, Instant start, String comment) { + public TestBookPageBuilder addPageIds(String bookId, String name, Instant start, String comment) { return this.addPageIds(new BookId(bookId), name, start, comment); } - public void execTest(TestExec func) throws Exception { - - TestCradleManager testCradleManager = new TestCradleManager(); - TestCradleStorage storage = testCradleManager.getStorage(); + public void exec(CradleStorage storage) throws Exception { if (this.booksToAdd != null) { for (BookToAdd bta : this.booksToAdd) { storage.addBook(bta); @@ -76,18 +71,9 @@ public void execTest(TestExec func) throws Exception { storage.addPages(pta.getKey(), Collections.singletonList(pta.getRight())); } } - - try ( - TestCommonFactory testCommonFactory = new TestCommonFactory(testCradleManager); - MockedStatic commonFactory = Mockito.mockStatic(CommonFactory.class) - ) { - commonFactory.when(() -> CommonFactory.createFromArguments(ArgumentMatchers.any())).then(action -> testCommonFactory); - func.apply(storage); - } } - public interface TestExec { - void apply(TestCradleStorage storage) throws Exception; + public static TestBookPageBuilder builder() { + return new TestBookPageBuilder(); } - } diff --git a/src/test/java/com/exactpro/th2/cradle/adm/TestCommonFactory.java b/src/test/java/com/exactpro/th2/cradle/adm/TestCommonFactory.java deleted file mode 100644 index 9dd3529..0000000 --- a/src/test/java/com/exactpro/th2/cradle/adm/TestCommonFactory.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ - -package com.exactpro.th2.cradle.adm; - -import com.exactpro.cradle.CradleManager; -import com.exactpro.th2.common.schema.factory.CommonFactory; - -public class TestCommonFactory extends CommonFactory { - - private final CradleManager cradleManager; - - public TestCommonFactory(CradleManager cradleManager) { - super(); - this.cradleManager = cradleManager; - } - - @Override - public CradleManager getCradleManager() { - return cradleManager; - } - - @Override - public void close() { - super.close(); - } -} diff --git a/src/test/java/com/exactpro/th2/cradle/adm/TestCradleManager.java b/src/test/java/com/exactpro/th2/cradle/adm/TestCradleManager.java deleted file mode 100644 index c5a5a36..0000000 --- a/src/test/java/com/exactpro/th2/cradle/adm/TestCradleManager.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright 2022 Exactpro (Exactpro Systems Limited) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ - -package com.exactpro.th2.cradle.adm; - -import com.exactpro.cradle.CradleManager; - -public class TestCradleManager implements CradleManager { - - private TestCradleStorage storage; - - @Override - public void close() throws Exception { - storage = null; - } - - @Override - public synchronized TestCradleStorage getStorage() { - if (storage == null) { - try { - storage = new TestCradleStorage(); - storage.init(false); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - return storage; - } -} diff --git a/src/test/java/com/exactpro/th2/cradle/adm/TestCradleStorage.java b/src/test/java/com/exactpro/th2/cradle/adm/TestCradleStorage.java deleted file mode 100644 index 5a38712..0000000 --- a/src/test/java/com/exactpro/th2/cradle/adm/TestCradleStorage.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright 2022-2023 Exactpro (Exactpro Systems Limited) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.exactpro.th2.cradle.adm; - -import com.exactpro.cradle.BookCache; -import com.exactpro.cradle.BookId; -import com.exactpro.cradle.BookInfo; -import com.exactpro.cradle.BookListEntry; -import com.exactpro.cradle.BookToAdd; -import com.exactpro.cradle.CradleStorage; -import com.exactpro.cradle.Direction; -import com.exactpro.cradle.EntityType; -import com.exactpro.cradle.FrameType; -import com.exactpro.cradle.PageId; -import com.exactpro.cradle.PageInfo; -import com.exactpro.cradle.counters.Counter; -import com.exactpro.cradle.counters.CounterSample; -import com.exactpro.cradle.counters.Interval; -import com.exactpro.cradle.intervals.IntervalsWorker; -import com.exactpro.cradle.messages.GroupedMessageBatchToStore; -import com.exactpro.cradle.messages.GroupedMessageFilter; -import com.exactpro.cradle.messages.MessageBatchToStore; -import com.exactpro.cradle.messages.MessageFilter; -import com.exactpro.cradle.messages.StoredGroupedMessageBatch; -import com.exactpro.cradle.messages.StoredMessage; -import com.exactpro.cradle.messages.StoredMessageBatch; -import com.exactpro.cradle.messages.StoredMessageId; -import com.exactpro.cradle.resultset.CradleResultSet; -import com.exactpro.cradle.testevents.StoredTestEvent; -import com.exactpro.cradle.testevents.StoredTestEventId; -import com.exactpro.cradle.testevents.TestEventFilter; -import com.exactpro.cradle.testevents.TestEventToStore; -import com.exactpro.cradle.utils.CradleStorageException; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; - -public class TestCradleStorage extends CradleStorage { - private final BookCache bookCache; - private final List bookList; - private final Map> pages; - private Instant nextRemovedTime; - - public TestCradleStorage() throws CradleStorageException { - super(); - bookCache = new TestBookCache(); - bookList = new ArrayList<>(); - pages = new HashMap<>(); - } - - public void setNextRemovedTime(Instant nextRemovedTime) { - this.nextRemovedTime = nextRemovedTime; - } - - public BookInfo getBook(BookId bookId) throws CradleStorageException { - return bookCache.getBook(bookId); - } - - public BookInfo getBook(String bookId) throws CradleStorageException { - return getBook(new BookId(bookId)); - } - - public int getBooksCount() { - return this.getBooks().size(); - } - - public PageInfo getPage(PageId pageId) throws CradleStorageException { - return getBook(pageId.getBookId()).getPage(pageId); - } - - @Override - protected void doInit(boolean prepareStorage) { - - } - - @Override - protected BookCache getBookCache() { - return bookCache; - } - - @Override - protected void doDispose() { - - } - - @Override - protected Collection doListBooks() { - return bookList; - } - - @Override - protected void doAddBook(BookToAdd newBook, BookId bookId) { - bookList.add(new BookListEntry(bookId.getName(), null)); - } - - @Override - protected void doAddPages(BookId bookId, List pages, PageInfo lastPage) { - this.pages.putIfAbsent(bookId, new ArrayList<>()); - - if (lastPage != null) { - this.pages.get(bookId).removeIf(page -> page.getId().equals(lastPage.getId())); - this.pages.get(bookId).add(lastPage); - } - this.pages.get(bookId).addAll(pages); - } - - @Override - protected Collection doLoadPages(BookId bookId) throws CradleStorageException { - return getBookCache().getBook(bookId).getPages(); - } - - @Override - protected Collection doGetAllPages(BookId bookId) { - List book = new ArrayList<>(); - if(pages.containsKey(bookId)){ - book = pages.get(bookId); - } - return book.stream().sorted(Comparator.comparing(PageInfo::getStarted)).collect(Collectors.toList()); - } - - @Override - protected void doRemovePage(PageInfo page) { - this.pages.get(page.getId().getBookId()).remove(page); - this.pages.get(page.getId().getBookId()).add(new PageInfo( - page.getId(), - page.getStarted(), - page.getEnded(), - page.getComment(), - page.getUpdated(), - nextRemovedTime == null ? Instant.now() : nextRemovedTime - )); - } - - @Override - protected void doStoreMessageBatch(MessageBatchToStore batch, PageInfo page) { - - } - - @Override - protected void doStoreGroupedMessageBatch(GroupedMessageBatchToStore batch, PageInfo page) { - - } - - @Override - protected CompletableFuture doStoreMessageBatchAsync(MessageBatchToStore batch, PageInfo page) { - return null; - } - - @Override - protected CompletableFuture doStoreGroupedMessageBatchAsync(GroupedMessageBatchToStore batch, PageInfo page) { - return null; - } - - @Override - protected void doStoreTestEvent(TestEventToStore event, PageInfo page) { - - } - - @Override - protected CompletableFuture doStoreTestEventAsync(TestEventToStore event, PageInfo page) { - return null; - } - - @Override - protected void doUpdateParentTestEvents(TestEventToStore event) { - - } - - @Override - protected CompletableFuture doUpdateParentTestEventsAsync(TestEventToStore event) { - return null; - } - - @Override - protected void doUpdateEventStatus(StoredTestEvent event, boolean success) { - - } - - @Override - protected CompletableFuture doUpdateEventStatusAsync(StoredTestEvent event, boolean success) { - return null; - } - - @Override - protected StoredMessage doGetMessage(StoredMessageId id, PageId pageId) { - return null; - } - - @Override - protected CompletableFuture doGetMessageAsync(StoredMessageId id, PageId pageId) { - return null; - } - - @Override - protected StoredMessageBatch doGetMessageBatch(StoredMessageId id, PageId pageId) { - return null; - } - - @Override - protected CompletableFuture doGetMessageBatchAsync(StoredMessageId id, PageId pageId) { - return null; - } - - @Override - protected CradleResultSet doGetMessages(MessageFilter filter, BookInfo book) { - return null; - } - - @Override - protected CompletableFuture> doGetMessagesAsync(MessageFilter filter, BookInfo book) { - return null; - } - - @Override - protected CradleResultSet doGetMessageBatches(MessageFilter filter, BookInfo book) { - return null; - } - - @Override - protected CradleResultSet doGetGroupedMessageBatches(GroupedMessageFilter filter, BookInfo book) { - return null; - } - - @Override - protected CompletableFuture> doGetMessageBatchesAsync(MessageFilter filter, BookInfo book) { - return null; - } - - @Override - protected CompletableFuture> doGetGroupedMessageBatchesAsync(GroupedMessageFilter filter, BookInfo book) { - return null; - } - - @Override - protected long doGetLastSequence(String sessionAlias, Direction direction, BookId bookId) { - return 0; - } - - @Override - protected long doGetFirstSequence(String sessionAlias, Direction direction, BookId bookId) { - return 0; - } - - @Override - protected Collection doGetSessionAliases(BookId bookId) { - return null; - } - - @Override - protected Collection doGetGroups(BookId bookId) { - return null; - } - - @Override - protected StoredTestEvent doGetTestEvent(StoredTestEventId id, PageId pageId) { - return null; - } - - @Override - protected CompletableFuture doGetTestEventAsync(StoredTestEventId ids, PageId pageId) { - return null; - } - - @Override - protected CradleResultSet doGetTestEvents(TestEventFilter filter, BookInfo book) { - return null; - } - - @Override - protected CompletableFuture> doGetTestEventsAsync(TestEventFilter filter, BookInfo book) { - return null; - } - - @Override - protected Collection doGetScopes(BookId bookId) { - return null; - } - - @Override - protected CradleResultSet doGetScopes(BookId bookId, Interval interval) { - return null; - } - - @Override - protected CompletableFuture> doGetScopesAsync(BookId bookId, Interval interval) { - return null; - } - - @Override - protected CompletableFuture> doGetMessageCountersAsync(BookId bookId, String sessionAlias, Direction direction, FrameType frameType, Interval interval) { - return null; - } - - @Override - protected CradleResultSet doGetMessageCounters(BookId bookId, String sessionAlias, Direction direction, FrameType frameType, Interval interval) { - return null; - } - - @Override - protected CompletableFuture> doGetCountersAsync(BookId bookId, EntityType entityType, FrameType frameType, Interval interval) { - return null; - } - - @Override - protected CradleResultSet doGetCounters(BookId bookId, EntityType entityType, FrameType frameType, Interval interval) { - return null; - } - - @Override - protected CompletableFuture doGetMessageCountAsync(BookId bookId, String sessionAlias, Direction direction, Interval interval) { - return null; - } - - @Override - protected Counter doGetMessageCount(BookId bookId, String sessionAlias, Direction direction, Interval interval) { - return null; - } - - @Override - protected CompletableFuture doGetCountAsync(BookId bookId, EntityType entityType, Interval interval) { - return null; - } - - @Override - protected Counter doGetCount(BookId bookId, EntityType entityType, Interval interval) { - return null; - } - - @Override - protected CompletableFuture> doGetSessionAliasesAsync(BookId bookId, Interval interval) { - return null; - } - - @Override - protected CradleResultSet doGetSessionAliases(BookId bookId, Interval interval) { - return null; - } - - @Override - protected CompletableFuture> doGetSessionGroupsAsync(BookId bookId, Interval interval) { - return null; - } - - @Override - protected CradleResultSet doGetSessionGroups(BookId bookId, Interval interval) { - return null; - } - - @Override - protected PageInfo doUpdatePageComment(BookId bookId, String pageName, String comment) { - return null; - } - - @Override - protected PageInfo doUpdatePageName(BookId bookId, String pageName, String newPageName) { - return null; - } - - @Override - protected Iterator doGetPages(BookId bookId, Interval interval) { - return null; - } - - @Override - protected CompletableFuture> doGetPagesAsync(BookId bookId, Interval interval) { - return null; - } - - @Override - public IntervalsWorker getIntervalsWorker() { - return null; - } -}