// Path: src/main/java/com/orange/clara/cloud/servicedbdumper/task/asynctask/CreateDumpTask.java
// public class CreateDumpTask {
//     private Logger logger = LoggerFactory.getLogger(CreateDumpTask.class);
//     @Autowired
//     private Dumper dumper;
// 
//     @Autowired
//     private JobRepo jobRepo;
// 
//     @Autowired
//     private DatabaseRefManager databaseRefManager;
// 
//     @Autowired
//     private DatabaseDumpFileRepo databaseDumpFileRepo;
// 
//     @Async
//     @Transactional(propagation = Propagation.REQUIRES_NEW)
//     public Future<Boolean> runTask(Integer jobId) throws AsyncTaskException {
//         Job job = this.jobRepo.findOne(jobId);
//         DatabaseDumpFile databaseDumpFile = null;
//         try {
//             databaseDumpFile = this.dumper.dump(job.getDbDumperServiceInstance());
//             if (job.getMetadata() != null) {
//                 logger.debug("Adding metadata for dump {}.", databaseDumpFile.getId());
//                 databaseDumpFile.setMetadata(job.getMetadata());
//                 this.databaseDumpFileRepo.save(databaseDumpFile);
//                 logger.debug("Finished adding metadata.");
//             }
//         } catch (DumpException e) {
//             logger.error("Cannot create dump for '{}': {}", job.getDatabaseRefSrc().getName(), e.getMessage());
//             job.setJobEvent(JobEvent.ERRORED);
//             job.setErrorMessage(e.getMessage());
//             this.databaseRefManager.deleteServiceKey(job);
//             jobRepo.save(job);
//             return new AsyncResult<Boolean>(false);
//         }
// 
//         job.setJobEvent(JobEvent.FINISHED);
//         this.databaseRefManager.deleteServiceKey(job);
//         jobRepo.save(job);
//         return new AsyncResult<Boolean>(true);
//     }
// }


import com.google.common.collect.Lists;
import com.orange.clara.cloud.servicedbdumper.exception.AsyncTaskException;
import com.orange.clara.cloud.servicedbdumper.model.Job;
import com.orange.clara.cloud.servicedbdumper.model.JobEvent;
import com.orange.clara.cloud.servicedbdumper.model.JobType;
import com.orange.clara.cloud.servicedbdumper.repo.JobRepo;
import com.orange.clara.cloud.servicedbdumper.task.asynctask.CreateDumpTask;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import java.util.Arrays;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
package com.orange.clara.cloud.servicedbdumper.task;




/**
 * Copyright (C) 2016 Arthur Halet
 * <p>
 * This software is distributed under the terms and conditions of the 'MIT'
 * license which can be found in the file 'LICENSE' in this package distribution
 * or at 'http://opensource.org/licenses/MIT'.
 * <p>
 * Author: Arthur Halet
 * Date: 21/03/2016
 */
public class ScheduledCreateDumpTaskTest extends AbstractScheduledTaskTest {
    @InjectMocks
    ScheduledCreateDumpTask scheduledTask = new ScheduledCreateDumpTask();

    @Mock
// Path: src/main/java/com/orange/clara/cloud/servicedbdumper/task/asynctask/CreateDumpTask.java
// public class CreateDumpTask {
//     private Logger logger = LoggerFactory.getLogger(CreateDumpTask.class);
//     @Autowired
//     private Dumper dumper;
// 
//     @Autowired
//     private JobRepo jobRepo;
// 
//     @Autowired
//     private DatabaseRefManager databaseRefManager;
// 
//     @Autowired
//     private DatabaseDumpFileRepo databaseDumpFileRepo;
// 
//     @Async
//     @Transactional(propagation = Propagation.REQUIRES_NEW)
//     public Future<Boolean> runTask(Integer jobId) throws AsyncTaskException {
//         Job job = this.jobRepo.findOne(jobId);
//         DatabaseDumpFile databaseDumpFile = null;
//         try {
//             databaseDumpFile = this.dumper.dump(job.getDbDumperServiceInstance());
//             if (job.getMetadata() != null) {
//                 logger.debug("Adding metadata for dump {}.", databaseDumpFile.getId());
//                 databaseDumpFile.setMetadata(job.getMetadata());
//                 this.databaseDumpFileRepo.save(databaseDumpFile);
//                 logger.debug("Finished adding metadata.");
//             }
//         } catch (DumpException e) {
//             logger.error("Cannot create dump for '{}': {}", job.getDatabaseRefSrc().getName(), e.getMessage());
//             job.setJobEvent(JobEvent.ERRORED);
//             job.setErrorMessage(e.getMessage());
//             this.databaseRefManager.deleteServiceKey(job);
//             jobRepo.save(job);
//             return new AsyncResult<Boolean>(false);
//         }
// 
//         job.setJobEvent(JobEvent.FINISHED);
//         this.databaseRefManager.deleteServiceKey(job);
//         jobRepo.save(job);
//         return new AsyncResult<Boolean>(true);
//     }
// }


// Path: src/test/java/com/orange/clara/cloud/servicedbdumper/task/ScheduledCreateDumpTaskTest.java
import com.google.common.collect.Lists;
import com.orange.clara.cloud.servicedbdumper.exception.AsyncTaskException;
import com.orange.clara.cloud.servicedbdumper.model.Job;
import com.orange.clara.cloud.servicedbdumper.model.JobEvent;
import com.orange.clara.cloud.servicedbdumper.model.JobType;
import com.orange.clara.cloud.servicedbdumper.repo.JobRepo;
import com.orange.clara.cloud.servicedbdumper.task.asynctask.CreateDumpTask;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import java.util.Arrays;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;

package com.orange.clara.cloud.servicedbdumper.task;




/**
 * Copyright (C) 2016 Arthur Halet
 * <p>
 * This software is distributed under the terms and conditions of the 'MIT'
 * license which can be found in the file 'LICENSE' in this package distribution
 * or at 'http://opensource.org/licenses/MIT'.
 * <p>
 * Author: Arthur Halet
 * Date: 21/03/2016
 */
public class ScheduledCreateDumpTaskTest extends AbstractScheduledTaskTest {
    @InjectMocks
    ScheduledCreateDumpTask scheduledTask = new ScheduledCreateDumpTask();

    @Mock
    CreateDumpTask createDumpTask;