Пример #1
0
 private DebtModel loadModelFromPlugin(String pluginKey) {
   Reader xmlFileReader = null;
   try {
     xmlFileReader = debtModelPluginRepository.createReaderForXMLFile(pluginKey);
     return characteristicsXMLImporter.importXML(xmlFileReader);
   } finally {
     IOUtils.closeQuietly(xmlFileReader);
   }
 }
  @Before
  public void setUp() {
    userSessionRule.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);

    when(system2.now()).thenReturn(now.getTime());

    currentId = 10;
    // Associate an id when inserting an object to simulate the db id generator
    doAnswer(
            new Answer() {
              public Object answer(InvocationOnMock invocation) {
                Object[] args = invocation.getArguments();
                CharacteristicDto dto = (CharacteristicDto) args[0];
                dto.setId(currentId++);
                return null;
              }
            })
        .when(dao)
        .insert(any(CharacteristicDto.class), any(DbSession.class));

    when(dbClient.openSession(false)).thenReturn(session);
    when(dbClient.ruleDao()).thenReturn(ruleDao);
    when(dbClient.debtCharacteristicDao()).thenReturn(dao);

    Reader defaultModelReader = mock(Reader.class);
    when(debtModelPluginRepository.createReaderForXMLFile("technical-debt"))
        .thenReturn(defaultModelReader);

    debtModelBackup =
        new DebtModelBackup(
            dbClient,
            debtModelOperations,
            ruleOperations,
            debtModelPluginRepository,
            characteristicsXMLImporter,
            rulesXMLImporter,
            debtModelXMLExporter,
            defLoader,
            system2,
            userSessionRule);
  }