@RunWithCustomExecutor @Test public void testUpdateWithArchiveUnitProfileValidationFailure() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID_0); VitamThreadUtils.getVitamSession().setRequestId(GUIDFactory.newRequestIdGUID(TENANT_ID_0)); String uuid = "aeaqaaaabeghay2jabzuaalbarkww4iaaaba"; List<OntologyModel> ontologyModels = JsonHandler .getFromInputStreamAsTypeReference(OntologyTestHelper.loadOntologies(), new TypeReference<List<OntologyModel>>() { }); final Unit initialUnit = new Unit( JsonHandler.getFromFile(PropertiesUtils.getResourceFile("unitToUpdate.json"))); MetadataCollections.UNIT.getCollection().insertOne(initialUnit); MetadataCollections.UNIT.getEsClient().insertFullDocument(MetadataCollections.UNIT, 0, uuid, initialUnit); String controlSchema = PropertiesUtils.getResourceAsString("unitAUP_KO.json"); CachedArchiveUnitProfileLoader archiveUnitProfileLoader = mock(CachedArchiveUnitProfileLoader.class); doReturn( Optional.of(new ArchiveUnitProfileModel().setStatus(ArchiveUnitProfileStatus.ACTIVE) .setControlSchema(controlSchema))) .when(archiveUnitProfileLoader).loadArchiveUnitProfile("AUP_IDENTIFIER"); final DbRequest dbRequest = new DbRequest(); final UpdateMultiQuery update = new UpdateMultiQuery(); update.addActions(set("Title", "New Title")); update.addActions(set("Boo.Baa", "Illegal string value")); update.addActions(set("ArchiveUnitProfile", "AUP_IDENTIFIER")); final UpdateParserMultiple updateParser = new UpdateParserMultiple(mongoDbVarNameAdapter); updateParser.parse(update.getFinalUpdate()); CachedSchemaValidatorLoader schemaValidatorLoader = new CachedSchemaValidatorLoader(100, 300); OntologyValidator ontologyValidator = new OntologyValidator(() -> ontologyModels); UnitValidator unitValidator = new UnitValidator(archiveUnitProfileLoader, schemaValidatorLoader); assertThatThrownBy(() -> dbRequest.execUpdateRequest(updateParser, uuid, MetadataCollections.UNIT, ontologyValidator, unitValidator, Collections.emptyList()) ).isInstanceOf(MetadataValidationException.class); String expected = BsonHelper.stringify(initialUnit); String after = JsonHandler.unprettyPrint(MetadataCollections.UNIT.getCollection().find(Filters.eq("_id", uuid)).first()); JsonAssert.assertJsonEquals(expected, after); }
public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; }
DbRequest { public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; } }
DbRequest { public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; } @VisibleForTesting  DbRequest(MongoDbMetadataRepository<Unit> mongoDbUnitRepository,
        MongoDbMetadataRepository<ObjectGroup> mongoDbObjectGroupRepository,
        FieldHistoryManager fieldHistoryManager);  DbRequest(); }
DbRequest { public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; } @VisibleForTesting  DbRequest(MongoDbMetadataRepository<Unit> mongoDbUnitRepository,
        MongoDbMetadataRepository<ObjectGroup> mongoDbObjectGroupRepository,
        FieldHistoryManager fieldHistoryManager);  DbRequest(); UpdatedDocument execRuleRequest(final String documentId, final RuleActions ruleActions,
        Map<String, DurationData> bindRuleToDuration, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies); UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId,
        MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); void execInsertUnitRequest(InsertParserMultiple requestParser); void execInsertObjectGroupRequests(List<InsertParserMultiple> requestParsers); void execInsertUnitRequests(BulkUnitInsertRequest request); void deleteUnits(List<String> documentsToDelete); void deleteObjectGroups(List<String> documentsToDelete); }
DbRequest { public UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId, MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator, List<OntologyModel> ontologyModels) throws MetaDataExecutionException, InvalidParseOperationException, MetaDataNotFoundException, MetadataValidationException { final UpdatedDocument result = updateDocumentWithRetries(documentId, requestParser, metadataCollection, ontologyValidator, unitValidator, ontologyModels); LOGGER.debug("Results: {}", result); return result; } @VisibleForTesting  DbRequest(MongoDbMetadataRepository<Unit> mongoDbUnitRepository,
        MongoDbMetadataRepository<ObjectGroup> mongoDbObjectGroupRepository,
        FieldHistoryManager fieldHistoryManager);  DbRequest(); UpdatedDocument execRuleRequest(final String documentId, final RuleActions ruleActions,
        Map<String, DurationData> bindRuleToDuration, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); Result execRequest(final RequestParserMultiple requestParser, List<OntologyModel> ontologies); UpdatedDocument execUpdateRequest(final RequestParserMultiple requestParser, String documentId,
        MetadataCollections metadataCollection, OntologyValidator ontologyValidator, UnitValidator unitValidator,
        List<OntologyModel> ontologyModels); void execInsertUnitRequest(InsertParserMultiple requestParser); void execInsertObjectGroupRequests(List<InsertParserMultiple> requestParsers); void execInsertUnitRequests(BulkUnitInsertRequest request); void deleteUnits(List<String> documentsToDelete); void deleteObjectGroups(List<String> documentsToDelete);  }