Skip to content
Snippets Groups Projects

fix(tests): fix regression on assertions on dates

Merged Nicolas.Rod requested to merge rodn-fix-dates-it into master
2 files
+ 18
18
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -9,12 +9,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
@@ -29,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.HashMap;
@@ -588,9 +587,11 @@ class DepositMetadataValidationV2IT extends PublicationIT {
assertEquals(this.PUBLICATION_SUBTYPE_ARTICLE_SCIENTIFIQUE_NAME, savedPublication.getSubtype().getName());
DepositDoc savedDepositDoc1 = this.createDepositDocFromXml(savedPublication.getMetadata());
assertTrue(savedDepositDoc1.getDates().getDate().stream().anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_PUBLICATION))));
assertTrue(savedDepositDoc1.getDates().getDate().stream()
.anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_PUBLICATION))));
assertTrue(savedDepositDoc1.getDates().getDate().stream().anyMatch(d -> d.getContent().equals(VALID_METADATA_DATE_1)));
assertTrue(savedDepositDoc1.getDates().getDate().stream().anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_FIRST_ONLINE))));
assertTrue(savedDepositDoc1.getDates().getDate().stream()
.anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_FIRST_ONLINE))));
assertTrue(savedDepositDoc1.getDates().getDate().stream().anyMatch(d -> d.getContent().equals(VALID_METADATA_DATE_2)));
// dates formatted for frontend
@@ -615,9 +616,11 @@ class DepositMetadataValidationV2IT extends PublicationIT {
assertEquals(this.PUBLICATION_SUBTYPE_ARTICLE_SCIENTIFIQUE_NAME, savedPublication2.getSubtype().getName());
DepositDoc savedDepositDoc2 = this.createDepositDocFromXml(savedPublication2.getMetadata());
assertTrue(savedDepositDoc2.getDates().getDate().stream().anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_PUBLICATION))));
assertTrue(savedDepositDoc2.getDates().getDate().stream()
.anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_PUBLICATION))));
assertTrue(savedDepositDoc2.getDates().getDate().stream().anyMatch(d -> d.getContent().equals(VALID_METADATA_DATE_1)));
assertTrue(savedDepositDoc2.getDates().getDate().stream().anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_FIRST_ONLINE))));
assertTrue(savedDepositDoc2.getDates().getDate().stream()
.anyMatch(d -> d.getType().equals(DateTypes.fromValue(AouConstants.DATE_TYPE_FIRST_ONLINE))));
assertTrue(savedDepositDoc2.getDates().getDate().stream().anyMatch(d -> d.getContent().equals(VALID_METADATA_DATE_3)));
}
@@ -642,14 +645,11 @@ class DepositMetadataValidationV2IT extends PublicationIT {
Publication publication = new Publication();
publication.setMetadata(xmlMetadata);
publication.setFormStep(Publication.DepositFormStep.DESCRIPTION);
try {
this.publicationService.create(publication);
fail("A BAD REQUEST response should be received");
} catch (final HttpClientErrorException e) {
List<FieldValidationError> validationErrors = this.getValidationErrors(e.getResponseBodyAsString());
assertTrue(this.validationErrorsContain("description.dates.0.date", "This date is not a valid date", validationErrors));
assertTrue(this.validationErrorsContain("description.dates.1.date", "This date is not a valid date", validationErrors));
}
HttpClientErrorException e = assertThrows(HttpClientErrorException.class, () -> this.publicationService.create(publication));
List<FieldValidationError> validationErrors = this.getValidationErrors(e.getResponseBodyAsString());
assertTrue(this.validationErrorsContain("description.dates.publication", "This date is not a valid date", validationErrors));
assertTrue(this.validationErrorsContain("description.dates.first_online", "This date is not a valid date", validationErrors));
}
@Test
@@ -689,8 +689,8 @@ class DepositMetadataValidationV2IT extends PublicationIT {
this.publicationService.create(publication);
});
List<FieldValidationError> validationErrors = this.getValidationErrors(e.getResponseBodyAsString());
assertTrue(this.validationErrorsContain("description.dates.0.date", "At least one date is mandatory", validationErrors));
assertTrue(this.validationErrorsContain("description.dates.1.date", "At least one date is mandatory", validationErrors));
assertTrue(this.validationErrorsContain("description.dates.publication", "At least one date is mandatory", validationErrors));
assertTrue(this.validationErrorsContain("description.dates.first_online", "At least one date is mandatory", validationErrors));
}
@Test
Loading