|
18 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | 19 | import org.springframework.security.test.context.support.WithMockUser; |
20 | 20 |
|
| 21 | +import java.util.UUID; |
21 | 22 | import java.util.stream.Stream; |
22 | 23 |
|
23 | | -import static org.junit.Assert.assertFalse; |
24 | | -import static org.junit.Assert.assertTrue; |
| 24 | +import static org.junit.Assert.*; |
25 | 25 |
|
26 | 26 | /** |
27 | 27 | * Created by katzelda on 7/20/18. |
@@ -199,4 +199,36 @@ public void mixtureMustAtLeast2OneOfComponents() throws Exception{ |
199 | 199 |
|
200 | 200 |
|
201 | 201 | } |
| 202 | + |
| 203 | + @Test |
| 204 | + public void mixtureComponentsTypeMustHaveNoTrailingBlanks() throws Exception{ |
| 205 | + |
| 206 | + String inputComponentType = "MAY_BE_PRESENT_ONE_OF "; |
| 207 | + String componentTypeTrimmed =inputComponentType.trim(); |
| 208 | + String inputComponentType2 = " MUST_BE_PRESENT"; |
| 209 | + String componentType2Trimmed = inputComponentType2.trim(); |
| 210 | + JsonNode toSubmit = new MixtureSubstanceBuilder() |
| 211 | + .addName("foo " + UUID.randomUUID()) |
| 212 | + .addComponents(inputComponentType, s1) |
| 213 | + .addComponents(inputComponentType2, s2) |
| 214 | + .addComponents(componentTypeTrimmed, s3) |
| 215 | + .buildJson(); |
| 216 | + |
| 217 | + GsrsEntityService.CreationResult<Substance> result = substanceEntityService.createEntity(toSubmit); |
| 218 | + |
| 219 | + ValidationResponse response = result.getValidationResponse(); |
| 220 | + assertTrue(response.isValid()); |
| 221 | + //this is split up and stored as a variable for java 8 type inference to work... |
| 222 | + Stream<ValidationMessage>s1 = response.getValidationMessages().stream(); |
| 223 | + |
| 224 | + assertEquals(2, s1 |
| 225 | + .filter(m->m.getMessageType() == ValidationMessage.MESSAGE_TYPE.WARNING) |
| 226 | + .map(ValidationMessage::getMessage) |
| 227 | + .filter(m-> m.contains(MixtureValidator.NO_LEAD_TRAIL_SPACES_IN_TYPE)) |
| 228 | + .count()); |
| 229 | + MixtureSubstance completed = (MixtureSubstance) result.getCreatedEntity(); |
| 230 | + assertEquals(2, completed.mixture.components.stream().map(component -> component.type).filter(t->t.equals(componentTypeTrimmed)).count()); |
| 231 | + assertEquals(1, completed.mixture.components.stream().map(component -> component.type).filter(t->t.equals(componentType2Trimmed)).count()); |
| 232 | + } |
| 233 | + |
202 | 234 | } |
0 commit comments