@Test @RunWithCustomExecutor public void testCheckRulesOnUpdateAU() throws Exception { VitamThreadUtils.getVitamSession().setTenantId(TENANT_ID); when(metaDataClient.selectUnitbyId(any(), any())) .thenReturn(fromStringToJson("{\"$hits" + "\":{\"total\":1,\"size\":1,\"limit\":1,\"time_out\":false},\"$context\":{}," + "\"$results\":[" + SELECT_AU_RESPONSE + "]}")); RequestParserMultiple results; when(adminManagementClient.getRuleByID(eq("STO-00001"))) .thenReturn(new AdminManagementClientMock().getRuleByID("STO-00001")); when(adminManagementClient.getRuleByID(eq("STO-00002"))) .thenReturn(new AdminManagementClientMock().getRuleByID("STO-00002")); when(adminManagementClient.getRuleByID(eq("CLASS-00002"))) .thenReturn(new AdminManagementClientMock().getRuleByID("CLASS-00002")); when(adminManagementClient.getRuleByID(eq("CLASS-00003"))) .thenReturn(new AdminManagementClientMock().getRuleByID("CLASS-00003")); when(adminManagementClient.getRuleByID(eq("REU-00001"))) .thenReturn(new AdminManagementClientMock().getRuleByID("REU-00001")); results = executeCheck(QUERY_STRING); assertEquals(5, results.getRequest().getActions().size()); results = executeCheck(QUERY_MULTIPLE_STRING); assertEquals(1, results.getRequest().getActions().size()); assertEquals(2, results.getRequest().getActions().get(0).getCurrentObject() .get("#management.ClassificationRule.Rules").size()); results = executeCheck(QUERY_CREATE_STRING); assertEquals(1, results.getRequest().getActions().size()); assertEquals(1, results.getRequest().getActions().get(0).getCurrentObject().get("#management.ReuseRule.Rules").size()); try { executeCheck(QUERY_STRING_WITH_END); fail("Should throw exception"); } catch (AccessInternalRuleExecutionException e) { assertEquals(VitamCode.ACCESS_INTERNAL_UPDATE_UNIT_CREATE_RULE_END_DATE.name(), e.getMessage()); } try { executeCheck(QUERY_STRING_WITH_PI_DELETED); fail("Should throw exception"); } catch (AccessInternalRuleExecutionException e) { assertEquals(VitamCode.ACCESS_INTERNAL_UPDATE_UNIT_DELETE_CATEGORY_INHERITANCE.name(), e.getMessage()); } try { executeCheck(QUERY_STRING_WITH_RNRI_DELETED); fail("Should throw exception"); } catch (AccessInternalRuleExecutionException e) { assertEquals(VitamCode.ACCESS_INTERNAL_UPDATE_UNIT_DELETE_CATEGORY_INHERITANCE.name(), e.getMessage()); } try { executeCheck(QUERY_STRING_WITH_WRONG_FINAL_ACTION); fail("Should throw exception"); } catch (AccessInternalRuleExecutionException e) { assertEquals(VitamCode.ACCESS_INTERNAL_UPDATE_UNIT_CREATE_RULE_FINAL_ACTION.name(), e.getMessage()); } try { executeCheck(QUERY_STRING_WITH_WRONG_CATEGORY_FINAL_ACTION); fail("Should throw exception"); } catch (AccessInternalRuleExecutionException e) { assertEquals(VitamCode.ACCESS_INTERNAL_UPDATE_UNIT_CREATE_RULE_FINAL_ACTION.name(), e.getMessage()); } try { executeCheck(QUERY_STRING_WITH_WRONG_CATEGORY); fail("Should throw exception"); } catch (AccessInternalRuleExecutionException e) { assertEquals(VitamCode.ACCESS_INTERNAL_UPDATE_UNIT_CREATE_RULE_CATEGORY.name(), e.getMessage()); } }
@Override public JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit) throws InvalidParseOperationException, AccessInternalExecutionException, MetaDataNotFoundException { final RequestParserMultiple parser = RequestParserHelper.getParser(jsonQuery.deepCopy()); parser.getRequest().reset(); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException(NOT_A_SELECT_OPERATION); } return selectMetadataDocumentById(jsonQuery, idUnit, DataCategory.UNIT); }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit) throws InvalidParseOperationException, AccessInternalExecutionException, MetaDataNotFoundException { final RequestParserMultiple parser = RequestParserHelper.getParser(jsonQuery.deepCopy()); parser.getRequest().reset(); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException(NOT_A_SELECT_OPERATION); } return selectMetadataDocumentById(jsonQuery, idUnit, DataCategory.UNIT); } }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit) throws InvalidParseOperationException, AccessInternalExecutionException, MetaDataNotFoundException { final RequestParserMultiple parser = RequestParserHelper.getParser(jsonQuery.deepCopy()); parser.getRequest().reset(); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException(NOT_A_SELECT_OPERATION); } return selectMetadataDocumentById(jsonQuery, idUnit, DataCategory.UNIT); } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit) throws InvalidParseOperationException, AccessInternalExecutionException, MetaDataNotFoundException { final RequestParserMultiple parser = RequestParserHelper.getParser(jsonQuery.deepCopy()); parser.getRequest().reset(); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException(NOT_A_SELECT_OPERATION); } return selectMetadataDocumentById(jsonQuery, idUnit, DataCategory.UNIT); } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); @Override JsonNode selectUnit(JsonNode jsonQuery); @Override JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit); @Override JsonNode selectObjectGroupById(JsonNode jsonQuery, String idObjectGroup); @Override Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit); @Override Response getAccessLog(JsonNode params); void checkClassificationLevel(JsonNode query); @Override JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId); @Override Response findDIPByOperationId(String id); @Override Response findTransferSIPByOperationId(String id); @Override JsonNode selectObjects(JsonNode jsonQuery); @Override JsonNode selectUnitsWithInheritedRules(JsonNode jsonQuery); }
AccessInternalModuleImpl implements AccessInternalModule { @Override public JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit) throws InvalidParseOperationException, AccessInternalExecutionException, MetaDataNotFoundException { final RequestParserMultiple parser = RequestParserHelper.getParser(jsonQuery.deepCopy()); parser.getRequest().reset(); if (!(parser instanceof SelectParserMultiple)) { throw new InvalidParseOperationException(NOT_A_SELECT_OPERATION); } return selectMetadataDocumentById(jsonQuery, idUnit, DataCategory.UNIT); } AccessInternalModuleImpl(); @VisibleForTesting  AccessInternalModuleImpl(LogbookLifeCyclesClientFactory logbookLifeCyclesClientFactory,
        LogbookOperationsClientFactory logbookOperationsClientFactory, StorageClientFactory storageClientFactory,
        WorkspaceClientFactory workspaceClientFactory, AdminManagementClientFactory adminManagementClientFactory,
        MetaDataClientFactory metaDataClientFactory); @Override JsonNode selectUnit(JsonNode jsonQuery); @Override JsonNode selectUnitbyId(JsonNode jsonQuery, String idUnit); @Override JsonNode selectObjectGroupById(JsonNode jsonQuery, String idObjectGroup); @Override Response getOneObjectFromObjectGroup(String idObjectGroup, String qualifier, int version, String idUnit); @Override Response getAccessLog(JsonNode params); void checkClassificationLevel(JsonNode query); @Override JsonNode updateUnitById(JsonNode queryJson, String idUnit, String requestId); @Override Response findDIPByOperationId(String id); @Override Response findTransferSIPByOperationId(String id); @Override JsonNode selectObjects(JsonNode jsonQuery); @Override JsonNode selectUnitsWithInheritedRules(JsonNode jsonQuery);  }