package _VisualDVM.Passes.All;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.Passes.Server.TestingServerPass;
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.ServerObjectsCache.VisualCaches;

import java.io.Serializable;
//заменить текущий тест на текущий проект.
public class ReplaceTestProject extends CreateTestFromProject {
    @Override
    public String getIconPath() {
        return "/icons/Menu/Undo.png";
    }
    @Override
    protected void performDone() throws Exception {
        new TestingServerPass() {
            @Override
            public String getDescription() {
                return "";
            }
            @Override
            protected boolean canStart(Object... args) throws Exception {
                target = args[0];
                return SendRequest(ServerCode.ReplaceTestCode, null, (Serializable) target);
            }
        }.Do(target);
        Global.mainModule.getPass(PassCode.SynchronizeTests).Do();
    }
    @Override
    protected void showDone() throws Exception {
        super.showFinish();
        VisualCaches.RefreshCache(target);
        Global.testingServer.db.tests.getUI().Show(target.getPK());
    }
    @Override
    protected boolean initTarget() throws Exception {
        if (Global.testingServer.db.tests.getUI().CheckCurrent(Log)) {
            target = Global.testingServer.db.tests.getUI().getCurrent();
            return true;
        }
        return false;
    }
}
