diff --git a/.github/workflows/codecov.yaml b/.github/workflows/codecov.yml similarity index 74% rename from .github/workflows/codecov.yaml rename to .github/workflows/codecov.yml index 4c70bc2..df6a405 100644 --- a/.github/workflows/codecov.yaml +++ b/.github/workflows/codecov.yml @@ -1,15 +1,16 @@ ---- name: codecov on: push: - branches: [ "master" ] + branches: + - master pull_request: - branches: [ "master" ] + branches: + - master jobs: codecov: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-java@v3 with: distribution: 'temurin' @@ -20,8 +21,10 @@ jobs: key: maven-${{ hashFiles('**/pom.xml') }} restore-keys: | maven- - - run: mvn clean install + - run: | + mvn clean install - uses: codecov/codecov-action@v3 with: + token: ${{ secrets.CODECOV_TOKEN }} files: ./target/site/jacoco/jacoco.xml fail_ci_if_error: true diff --git a/.github/workflows/mvn.yaml b/.github/workflows/mvn.yaml index 145b232..98ab35e 100644 --- a/.github/workflows/mvn.yaml +++ b/.github/workflows/mvn.yaml @@ -1,4 +1,3 @@ ---- name: mvn on: push: @@ -9,11 +8,11 @@ on: - master jobs: test: - name: Tests + name: Build strategy: matrix: - os: [ubuntu-20.04, macos-12] - java: [11, 17] + os: [ubuntu-20.04, windows-2022, macos-12] + java: [17] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/pdd.yaml b/.github/workflows/pdd.yaml deleted file mode 100644 index cc8c149..0000000 --- a/.github/workflows/pdd.yaml +++ /dev/null @@ -1,10 +0,0 @@ -name: pdd -on: - push: - pull_request: -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: g4s8/pdd-action@master diff --git a/.github/workflows/pdd.yml b/.github/workflows/pdd.yml new file mode 100644 index 0000000..cead8c6 --- /dev/null +++ b/.github/workflows/pdd.yml @@ -0,0 +1,14 @@ +name: pdd +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + pdd: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: g4s8/pdd-action@master diff --git a/.github/workflows/xcop.yaml b/.github/workflows/xcop.yml similarity index 79% rename from .github/workflows/xcop.yaml rename to .github/workflows/xcop.yml index 5682297..9691243 100644 --- a/.github/workflows/xcop.yaml +++ b/.github/workflows/xcop.yml @@ -1,4 +1,3 @@ ---- name: xcop on: push: @@ -8,8 +7,8 @@ on: branches: - master jobs: - xcop: + build: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 - uses: g4s8/xcop-action@master diff --git a/.gitignore b/.gitignore index 629fde0..43e96c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,33 @@ -# Compiled class file -*.class - -# Log file -*.log - -# BlueJ files -*.ctxt - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# for IntelliJidea users +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.params +.springBeans +.sts4-cache + +### IntelliJ IDEA ### .idea - -**/.DS_Store - -target +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/.pdd b/.pdd deleted file mode 100644 index 31683a6..0000000 --- a/.pdd +++ /dev/null @@ -1,4 +0,0 @@ ---source=. ---verbose ---exclude target/** ---rule min-words:10 diff --git a/.rultor.yml b/.rultor.yml index 9f071ac..5b542e2 100644 --- a/.rultor.yml +++ b/.rultor.yml @@ -1,11 +1,20 @@ architect: - - # your GitHub nickname + - h1alexbel +docker: + image: l3r8y/rultor-image:1.0.3 +assets: + settings.xml: eo-cqrs/eo-cqrs-secrets#assets/settings.xml + secring.gpg: eo-cqrs/eo-cqrs-secrets#assets/secring.gpg + pubring.gpg: eo-cqrs/eo-cqrs-secrets#assets/pubring.gpg merge: script: - "mvn clean install --errors --batch-mode" release: pre: false + sensetive: + - settings.xml script: |- [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1 + mvn versions:set "-DnewVersion=${tag}" git commit -am "${tag}" - # add your release pipeline + mvn clean deploy -Prelease --errors --settings ../settings.xml \ No newline at end of file diff --git a/LICENSE b/LICENSE.txt similarity index 88% rename from LICENSE rename to LICENSE.txt index 4821d65..4e7da55 100644 --- a/LICENSE +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Ivan Ivanchuk +Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -14,7 +14,7 @@ copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml new file mode 100644 index 0000000..8e56b64 --- /dev/null +++ b/checkstyle-suppressions.xml @@ -0,0 +1,29 @@ + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..19bc796 --- /dev/null +++ b/pom.xml @@ -0,0 +1,411 @@ + + + + 4.0.0 + + com.jcabi + parent + 0.65.0 + + io.github.eo-cqrs + xfake + 1.0-SNAPSHOT + xfake + + XML In-Memory Storage for your Fake Objects + + 2023 + https://eo-cqrs.github.io/xfake/ + + + 1 + Aliaksei Bialiauski + abialiauski.dev@gmail.com + https://h1alexbel.github.io + https://www.solvd.com + + Architect + Developer + + + + + GitHub + https://github.com/eo-cqrs/xfake/issues + + + GitHub Actions + https://github.com/eo-cqrs/xfake/actions + + + + MIT + https://github.com/eo-cqrs/xfake/blob/master/LICENSE.txt + site + + + + scm:git:git://github.com/eo-cqrs/xfake.git + scm:git:ssh://github.com:eo-cqrs/xfake.git + https://github.com/eo-cqrs/xfake/tree/master + + + 17 + 17 + 17 + UTF-8 + 0.55.0 + 1.18.26 + 5.9.3 + 5.9.3 + 3.24.2 + 0.28.1 + 3.1.0 + 1.1 + 0.1.13 + 1.6.13 + 8.15 + 3.2.2 + 0.1.5 + 3.5.1 + 3.3.0 + 3.1.0 + 5.3.1 + 5.3.1 + + + + org.cactoos + cactoos + ${cactoos.version} + + + com.jcabi + jcabi-xml + + + com.jcabi.incubator + xembly + ${xembly.version} + + + com.jcabi + jcabi-immutable + + + org.projectlombok + lombok + ${lombok.version} + + + org.junit.jupiter + junit-jupiter-api + ${junit-api.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit-params.version} + test + + + org.assertj + assertj-core + ${assert4j-core.version} + test + + + org.hamcrest + hamcrest + test + + + org.mockito + mockito-core + ${mockito-core.version} + test + + + org.mockito + mockito-junit-jupiter + ${mockito-junit-jupiter.version} + test + + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*Spec.* + **/*Test.* + + + + + org.apache.maven.plugins + maven-verifier-plugin + ${maven-verifier-plugin.version} + + + main + package + + verify + + + src/verifier/verifications.xml + + + + + + org.apache.maven.plugins + maven-invoker-plugin + ${maven-invoker-plugin.version} + + + default + none + + + + + org.jacoco + jacoco-maven-plugin + + + jacoco-initialize + + prepare-agent + + + + jacoco-check + test + + check + report + + + + + BUNDLE + + + INSTRUCTION + COVEREDRATIO + 0.55 + + + LINE + COVEREDRATIO + 0.61 + + + BRANCH + COVEREDRATIO + 0.61 + + + COMPLEXITY + COVEREDRATIO + 0.55 + + + METHOD + COVEREDRATIO + 0.55 + + + CLASS + MISSEDCOUNT + 20 + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + javadoc-generate + test + + javadoc + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + com.github.volodya-lombrozo + jtcop-maven-plugin + ${jtcop.version} + + + + check + + + + + + ru.l3r8y + sa-tan + ${sa-tan.version} + + + + search + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + + + + verify-style + process-classes + + check + + + checkstyle.suppressions.file + checkstyle-suppressions.xml + + + + + + + + + release + + false + + gpg.keyname + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + --pinentry-mode + loopback + + + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + + + + diff --git a/src/main/java/io/github/eocqrs/xfake/FkStorage.java b/src/main/java/io/github/eocqrs/xfake/FkStorage.java new file mode 100644 index 0000000..5d599b4 --- /dev/null +++ b/src/main/java/io/github/eocqrs/xfake/FkStorage.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.eocqrs.xfake; + +import com.jcabi.xml.XML; +import org.xembly.Directive; + +/** + * Fake Storage. + * + * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) + * @since 0.0.0 + */ +public interface FkStorage { + + /** + * Full XML. + * + * @return XML + * @throws Exception When something went wrong. + */ + XML xml() throws Exception; + + /** + * Update XML with new directives. + * + * @param dirs Directives + * @throws Exception When something went wrong. + */ + void apply(Iterable dirs) throws Exception; + + /** + * Locks storage to the current thread. + * + *

If the lock is available, grant it + * to the calling thread and block all operations from other threads. + * If not available, wait for the holder of the lock to release it with + * {@link #unlock()} before any other operations can be performed. + * + *

Locking behavior is reentrant, which means a thread can invoke + * multiple times, where a hold count is maintained. + */ + void lock(); + + /** + * Unlock storage. + * + *

Locking behavior is reentrant, thus if the thread invoked + * {@link #lock()} multiple times, the hold count is decremented. If the + * hold count reaches 0, the lock is released. + * + *

If the current thread does not hold the lock, an + * {@link IllegalMonitorStateException} will be thrown. + */ + void unlock(); +} diff --git a/src/main/java/io/github/eocqrs/xfake/ImmutableReentrantLock.java b/src/main/java/io/github/eocqrs/xfake/ImmutableReentrantLock.java new file mode 100644 index 0000000..7fb8baa --- /dev/null +++ b/src/main/java/io/github/eocqrs/xfake/ImmutableReentrantLock.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.eocqrs.xfake; + +import java.io.Serial; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Immutable Lock. + * + * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) + * @since 0.0.0 + */ +final class ImmutableReentrantLock extends ReentrantLock { + + /** + * Serialization id. + */ + @Serial + private static final long serialVersionUID = -3003135962114984635L; +} diff --git a/src/main/java/io/github/eocqrs/xfake/InFile.java b/src/main/java/io/github/eocqrs/xfake/InFile.java new file mode 100644 index 0000000..1676d8a --- /dev/null +++ b/src/main/java/io/github/eocqrs/xfake/InFile.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.eocqrs.xfake; + +import com.jcabi.xml.XML; +import com.jcabi.xml.XMLDocument; +import org.cactoos.io.TeeInput; +import org.cactoos.scalar.LengthOf; +import org.cactoos.text.TextOf; +import org.xembly.Directive; +import org.xembly.Xembler; + +import java.io.File; +import java.nio.charset.StandardCharsets; + +/** + * Storage in file. + * + * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) + * @since 0.0.0 + */ +public final class InFile implements FkStorage { + + /** + * File name. + */ + private final transient String name; + /** + * Lock. + */ + private final transient ImmutableReentrantLock lock = + new ImmutableReentrantLock(); + + /** + * Ctor. + * + * @param nm File name to create + * @param root root XML node + * @throws Exception When something went wrong. + */ + public InFile(final String nm, final String root) throws Exception { + this(File.createTempFile(nm, ".xml"), root); + new File(this.name).deleteOnExit(); + } + + /** + * Ctor. + * + * @param file File + * @param root root XML node + * @throws Exception When something went wrong. + */ + public InFile(final File file, final String root) throws Exception { + new LengthOf( + new TeeInput( + root, + file, + StandardCharsets.UTF_8 + ) + ).value(); + this.name = file.getAbsolutePath(); + } + + @Override + public XML xml() throws Exception { + synchronized (this.name) { + return new XMLDocument( + new TextOf( + new File( + this.name + ) + ).asString() + ); + } + } + + @Override + public void apply(final Iterable dirs) throws Exception { + synchronized (this.name) { + new LengthOf( + new TeeInput( + new XMLDocument( + new Xembler( + dirs + ).applyQuietly(this.xml().node()) + ).toString(), + new File( + this.name + ), + StandardCharsets.UTF_8 + ) + ).value(); + } + } + + @Override + public void lock() { + this.lock.lock(); + } + + @Override + public void unlock() { + this.lock.unlock(); + } +} diff --git a/src/main/java/io/github/eocqrs/xfake/package-info.java b/src/main/java/io/github/eocqrs/xfake/package-info.java new file mode 100644 index 0000000..760f08d --- /dev/null +++ b/src/main/java/io/github/eocqrs/xfake/package-info.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Xfake. + * + * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) + * @since 0.0.0 + */ +package io.github.eocqrs.xfake; diff --git a/src/test/java/io/github/eocqrs/xfake/ImmutableReentrantLockTest.java b/src/test/java/io/github/eocqrs/xfake/ImmutableReentrantLockTest.java new file mode 100644 index 0000000..4877932 --- /dev/null +++ b/src/test/java/io/github/eocqrs/xfake/ImmutableReentrantLockTest.java @@ -0,0 +1,24 @@ +package io.github.eocqrs.xfake; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link ImmutableReentrantLock} + * + * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) + * @since 0.0.0 + */ +final class ImmutableReentrantLockTest { + + @Test + void locksAndUnlocksWithoutException() { + final ImmutableReentrantLock lock = new ImmutableReentrantLock(); + Assertions.assertDoesNotThrow( + lock::lock + ); + Assertions.assertDoesNotThrow( + lock::unlock + ); + } +} diff --git a/src/test/java/io/github/eocqrs/xfake/InFileTest.java b/src/test/java/io/github/eocqrs/xfake/InFileTest.java new file mode 100644 index 0000000..b0c27a2 --- /dev/null +++ b/src/test/java/io/github/eocqrs/xfake/InFileTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package io.github.eocqrs.xfake; + +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.xembly.Directives; + +/** + * Test case for {@link InFile} + * + * @author Aliaksei Bialiauski (abialiauski.dev@gmail.com) + * @since 0.0.0 + */ +final class InFileTest { + + @Test + void createsStorageInXmlFile() throws Exception { + final FkStorage storage = new InFile("fake-test", ""); + MatcherAssert.assertThat( + "Storage has root node", + storage.xml().nodes("broker").isEmpty(), + Matchers.equalTo(false) + ); + } + + @Test + void appliesDirectives() throws Exception { + final FkStorage storage = new InFile("fake-test", ""); + storage.apply( + new Directives() + .xpath("/broker") + .addIf("servers") + ); + MatcherAssert.assertThat( + "XML has right format", + storage.xml().nodes("broker/servers").isEmpty(), + Matchers.equalTo(false) + ); + } + + @Test + void locksAndUnlocks() throws Exception { + final FkStorage storage = new InFile("fake", ""); + Assertions.assertDoesNotThrow( + storage::lock + ); + Assertions.assertDoesNotThrow( + storage::unlock + ); + } +} + diff --git a/src/verifier/verifications.xml b/src/verifier/verifications.xml new file mode 100644 index 0000000..6704167 --- /dev/null +++ b/src/verifier/verifications.xml @@ -0,0 +1,33 @@ + + + + + + true + LICENSE.txt + 2023 + + +