-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #527 from jpmorganchase/patch-release-0.7.1
Patch release 0.7.3 branch back to master
- Loading branch information
Showing
67 changed files
with
769 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ | |
</dependencies> | ||
|
||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,4 +103,4 @@ | |
|
||
|
||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,4 +116,4 @@ | |
</plugins> | ||
</build> | ||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,4 +82,4 @@ | |
|
||
</dependencies> | ||
|
||
</project> | ||
</project> |
27 changes: 27 additions & 0 deletions
27
config/src/main/java/com/quorum/tessera/config/constraints/ValidContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.quorum.tessera.config.constraints; | ||
|
||
import java.lang.annotation.Documented; | ||
import static java.lang.annotation.ElementType.*; | ||
import java.lang.annotation.Retention; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
import java.lang.annotation.Target; | ||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
|
||
@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE, TYPE_PARAMETER, TYPE_USE}) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = ValidContentValidator.class) | ||
@Documented | ||
public @interface ValidContent { | ||
|
||
String message() default "{ValidContent.message}"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
int minLines() default 0; | ||
|
||
int maxLines() default Integer.MAX_VALUE; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
config/src/main/java/com/quorum/tessera/config/constraints/ValidContentValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.quorum.tessera.config.constraints; | ||
|
||
import com.quorum.tessera.io.FilesDelegate; | ||
import java.nio.file.Files; | ||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class ValidContentValidator implements ConstraintValidator<ValidContent, Path> { | ||
|
||
private ValidContent config; | ||
|
||
@Override | ||
public void initialize(ValidContent constraintAnnotation) { | ||
this.config = constraintAnnotation; | ||
} | ||
|
||
@Override | ||
public boolean isValid(Path path, ConstraintValidatorContext context) { | ||
|
||
if (Objects.isNull(path)) { | ||
return true; | ||
} | ||
|
||
if (!Files.exists(path)) { | ||
return true; | ||
} | ||
|
||
List<String> lines = FilesDelegate.create().lines(path) | ||
.filter(line -> !Objects.equals("", line)) | ||
.collect(Collectors.toList()); | ||
|
||
return lines.size() >= config.minLines() && lines.size() <= config.maxLines(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
config/src/test/java/com/quorum/tessera/config/constraints/ValidContentValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package com.quorum.tessera.config.constraints; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.UUID; | ||
import javax.validation.ConstraintValidatorContext; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.Test; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class ValidContentValidatorTest { | ||
|
||
@Test | ||
public void ignoreNullPath() { | ||
ValidContentValidator validator = new ValidContentValidator(); | ||
ValidContent validContent = mock(ValidContent.class); | ||
validator.initialize(validContent); | ||
|
||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
assertThat(validator.isValid(null, context)).isTrue(); | ||
|
||
} | ||
|
||
@Test | ||
public void ignoreNonExistPath() { | ||
ValidContentValidator validator = new ValidContentValidator(); | ||
ValidContent validContent = mock(ValidContent.class); | ||
validator.initialize(validContent); | ||
|
||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
Path path = Paths.get(UUID.randomUUID().toString()); | ||
|
||
assertThat(path).doesNotExist(); | ||
|
||
assertThat(validator.isValid(path, context)).isTrue(); | ||
|
||
} | ||
|
||
@Test | ||
public void defaultValuesIgnoreEmptyFile() throws Exception { | ||
ValidContentValidator validator = new ValidContentValidator(); | ||
ValidContent validContent = mock(ValidContent.class); | ||
|
||
validator.initialize(validContent); | ||
|
||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
Path path = Files.createTempFile(UUID.randomUUID().toString(), ""); | ||
|
||
assertThat(path).exists(); | ||
|
||
assertThat(validator.isValid(path, context)).isTrue(); | ||
|
||
} | ||
|
||
@Test | ||
public void expectSingleLineButFileIsEmpty() throws Exception { | ||
ValidContentValidator validator = new ValidContentValidator(); | ||
ValidContent validContent = mock(ValidContent.class); | ||
when(validContent.minLines()).thenReturn(1); | ||
when(validContent.maxLines()).thenReturn(1); | ||
|
||
validator.initialize(validContent); | ||
|
||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
Path path = Files.createTempFile(UUID.randomUUID().toString(), ""); | ||
|
||
assertThat(path).exists(); | ||
|
||
assertThat(validator.isValid(path, context)).isFalse(); | ||
|
||
} | ||
|
||
@Test | ||
public void expectSingleLineFileIsValid() throws Exception { | ||
ValidContentValidator validator = new ValidContentValidator(); | ||
ValidContent validContent = mock(ValidContent.class); | ||
when(validContent.minLines()).thenReturn(1); | ||
when(validContent.maxLines()).thenReturn(1); | ||
|
||
validator.initialize(validContent); | ||
|
||
ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
Path path = Files.createTempFile(UUID.randomUUID().toString(), ""); | ||
Files.write(path, "SOMEDATA".getBytes()); | ||
|
||
assertThat(path).exists(); | ||
|
||
assertThat(validator.isValid(path, context)).isTrue(); | ||
|
||
} | ||
|
||
@Test | ||
public void tooManyLines() throws Exception { | ||
ValidContentValidator validator = new ValidContentValidator(); | ||
ValidContent validContent = mock(ValidContent.class); | ||
when(validContent.minLines()).thenReturn(1); | ||
when(validContent.maxLines()).thenReturn(1); | ||
|
||
validator.initialize(validContent); | ||
|
||
final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
Path path = Files.createTempFile(UUID.randomUUID().toString(), ""); | ||
Files.write(path, Arrays.asList("SOMEDATA","SOMEMOREDATA")); | ||
|
||
assertThat(path).exists(); | ||
|
||
assertThat(validator.isValid(path, context)).isFalse(); | ||
|
||
} | ||
|
||
@Test | ||
public void emptyLine() throws Exception { | ||
ValidContentValidator validator = new ValidContentValidator(); | ||
ValidContent validContent = mock(ValidContent.class); | ||
when(validContent.minLines()).thenReturn(1); | ||
when(validContent.maxLines()).thenReturn(1); | ||
|
||
validator.initialize(validContent); | ||
|
||
final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); | ||
|
||
Path path = Files.createTempFile(UUID.randomUUID().toString(), ""); | ||
Files.write(path, Arrays.asList("")); | ||
|
||
assertThat(path).exists(); | ||
|
||
assertThat(validator.isValid(path, context)).isFalse(); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,4 +115,4 @@ | |
</build> | ||
|
||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
<version>0.8-SNAPSHOT</version> | ||
</parent> | ||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,4 @@ | |
</profile> | ||
</profiles> | ||
|
||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,4 @@ | |
</profile> | ||
</profiles> | ||
|
||
</project> | ||
</project> |
Oops, something went wrong.