Skip to content

Commit

Permalink
#303 seen dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Jun 27, 2023
1 parent b94a78d commit 862526b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/fake/SeenDirs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.kafka.fake;

import org.cactoos.Scalar;
import org.xembly.Directives;

/**
* Seen Directives.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.3.5
*/
public final class SeenDirs implements Scalar<Directives> {

private final String topic;
private final String fetched;

public SeenDirs(final String tpc, final String ftcd) {
this.topic = tpc;
this.fetched = ftcd;
}

@Override
public Directives value() throws Exception {
return new Directives()
.xpath(
("broker/topics/topic[name = '%s']/datasets/dataset[value = '%s'"
+ " and seen = 'false']/seen/text()")
.formatted(
this.topic,
this.fetched
)
)
.set("true");
}
}
54 changes: 54 additions & 0 deletions src/test/java/io/github/eocqrs/kafka/fake/SeenDirsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.kafka.fake;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

/**
* Test case for {@link SeenDirs}.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.3.5
*/
final class SeenDirsTest {

@Test
void dirsInRightFormat() throws Exception {
final String directives = "XPATH \"broker/topics/topic[name = &apos;test&apos;]"
+ "/datasets/dataset[value = &apos;test&apos;"
+ " and seen = &apos;false&apos;]/seen/text()\";\n"
+ "1:SET \"true\";";
MatcherAssert.assertThat(
"Directives in the right format",
new SeenDirs(
"test",
"test"
).value().toString(),
Matchers.equalTo(
directives
)
);
}
}

0 comments on commit 862526b

Please sign in to comment.