mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
This commit is contained in:
parent
9c98d6470d
commit
7a8635eba2
4 changed files with 77 additions and 17 deletions
|
|
@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
## Unreleased
|
## Unreleased
|
||||||
### Fixed
|
### Fixed
|
||||||
- date conversion when using [ConfigurationBuilder#date(Date)](https://github.com/itplr-kosit/validator/blob/d7beb1040418ae5cbeb9427532fd87482f55756c/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java#L109)
|
- date conversion when using [ConfigurationBuilder#date(Date)](https://github.com/itplr-kosit/validator/blob/d7beb1040418ae5cbeb9427532fd87482f55756c/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java#L109)
|
||||||
|
### Fixed
|
||||||
|
- [#51](https://github.com/itplr-kosit/validator/issues/51) Suffix of report xml is missing
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- read saxon XdmNode with InputFactory
|
- read saxon XdmNode with InputFactory
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
package de.kosit.validationtool.cmd;
|
package de.kosit.validationtool.cmd;
|
||||||
|
|
||||||
|
import static org.apache.commons.io.FilenameUtils.isExtension;
|
||||||
|
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -18,27 +21,25 @@ public class DefaultNamingStrategy implements NamingStrategy {
|
||||||
|
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
private String postfix = "report";
|
private String postfix;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createName(final String base) {
|
public String createName(final String name) {
|
||||||
if (StringUtils.isEmpty(base)) {
|
if (StringUtils.isEmpty(name)) {
|
||||||
throw new IllegalArgumentException("Can not generate name based on null input");
|
throw new IllegalArgumentException("Can not generate name based on null input");
|
||||||
}
|
}
|
||||||
final int index = base.lastIndexOf('.');
|
final String base = isExtension(name.toLowerCase(), "xml") ? FilenameUtils.getBaseName(name) : name;
|
||||||
final StringBuilder result = new StringBuilder();
|
final StringBuilder result = new StringBuilder();
|
||||||
if (isNotEmpty(this.prefix)) {
|
if (isNotEmpty(this.prefix)) {
|
||||||
result.append(this.prefix).append("-");
|
result.append(this.prefix).append("-");
|
||||||
}
|
}
|
||||||
result.append(base, 0, index > 0 ? index : base.length());
|
result.append(base);
|
||||||
if (isNotEmpty(this.postfix)) {
|
if (isNotEmpty(this.postfix)) {
|
||||||
result.append("-").append(this.postfix);
|
result.append("-").append(this.postfix);
|
||||||
|
} else if (isEmpty(this.prefix)) {
|
||||||
|
result.append("-").append("report");
|
||||||
}
|
}
|
||||||
if (index > 0) {
|
|
||||||
result.append(base.substring(index));
|
|
||||||
} else {
|
|
||||||
result.append(".xml");
|
result.append(".xml");
|
||||||
}
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ package de.kosit.validationtool.impl.tasks;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -113,11 +113,7 @@ public interface CheckAction {
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
final String fileName = getInput().getName().replaceAll(".*/|.*\\\\", "");
|
final String fileName = getInput().getName().replaceAll(".*/|.*\\\\", "");
|
||||||
final Matcher matcher = Pattern.compile("(.*)\\..+").matcher(fileName);
|
return FilenameUtils.getBaseName(fileName);
|
||||||
if (matcher.matches()) {
|
|
||||||
return matcher.group(1);
|
|
||||||
}
|
|
||||||
return fileName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
package de.kosit.validationtool.cmd;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests {@link DefaultNamingStrategy}
|
||||||
|
*
|
||||||
|
* @author Andreas Penski
|
||||||
|
*/
|
||||||
|
public class DefaultNamingStrategyTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSimple() {
|
||||||
|
final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
|
||||||
|
assertThat(strategy.createName("test")).isEqualTo("test-report.xml");
|
||||||
|
strategy.setPrefix("prefix");
|
||||||
|
assertThat(strategy.createName("test")).isEqualTo("prefix-test.xml");
|
||||||
|
strategy.setPostfix("postfix");
|
||||||
|
assertThat(strategy.createName("test")).isEqualTo("prefix-test-postfix.xml");
|
||||||
|
strategy.setPrefix(null);
|
||||||
|
assertThat(strategy.createName("test")).isEqualTo("test-postfix.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDotted() {
|
||||||
|
final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
|
||||||
|
assertThat(strategy.createName("test.xml")).isEqualTo("test-report.xml");
|
||||||
|
strategy.setPrefix("prefix");
|
||||||
|
assertThat(strategy.createName("test.xml")).isEqualTo("prefix-test.xml");
|
||||||
|
strategy.setPostfix("postfix");
|
||||||
|
assertThat(strategy.createName("test.xml")).isEqualTo("prefix-test-postfix.xml");
|
||||||
|
strategy.setPrefix(null);
|
||||||
|
assertThat(strategy.createName("test.xml")).isEqualTo("test-postfix.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDoubleDotted() {
|
||||||
|
final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
|
||||||
|
assertThat(strategy.createName("test.second.xml")).isEqualTo("test.second-report.xml");
|
||||||
|
strategy.setPrefix("prefix");
|
||||||
|
assertThat(strategy.createName("test.second.xml")).isEqualTo("prefix-test.second.xml");
|
||||||
|
strategy.setPostfix("postfix");
|
||||||
|
assertThat(strategy.createName("test.second.xml")).isEqualTo("prefix-test.second-postfix.xml");
|
||||||
|
strategy.setPrefix(null);
|
||||||
|
assertThat(strategy.createName("test.second.xml")).isEqualTo("test.second-postfix.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnknownExtenson() {
|
||||||
|
final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
|
||||||
|
assertThat(strategy.createName("test.ext")).isEqualTo("test.ext-report.xml");
|
||||||
|
strategy.setPrefix("prefix");
|
||||||
|
assertThat(strategy.createName("test.ext")).isEqualTo("prefix-test.ext.xml");
|
||||||
|
strategy.setPostfix("postfix");
|
||||||
|
assertThat(strategy.createName("test.ext")).isEqualTo("prefix-test.ext-postfix.xml");
|
||||||
|
strategy.setPrefix(null);
|
||||||
|
assertThat(strategy.createName("test.ext")).isEqualTo("test.ext-postfix.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue