package org.ovirt.engine.core.bll;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.ovirt.engine.core.common.businessentities.VmDevice;
import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
import org.ovirt.engine.core.common.businessentities.VmDeviceId;
import org.ovirt.engine.core.common.businessentities.VmWatchdog;
import org.ovirt.engine.core.common.queries.IdQueryParameters;
import org.ovirt.engine.core.common.utils.VmDeviceType;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.VmDeviceDAO;

@RunWith(MockitoJUnitRunner.class)
public class GetWatchdogQueryTest extends AbstractQueryTest<IdQueryParameters, GetWatchdogQuery<IdQueryParameters>> {

    @Mock
    VmDeviceDAO vmDeviceDAO;

    @Test
    public void executeQueryCommandWithNull() {
        Mockito.when(getDbFacadeMockInstance().getVmDeviceDao()).thenReturn(vmDeviceDAO);
        Mockito.when(getQueryParameters().getId()).thenReturn(new Guid("ee655a4d-effc-4aab-be2b-2f80ff40cd1c"));
        getQuery().executeQueryCommand();
        Assert.assertTrue(((List<?>) getQuery().getQueryReturnValue().getReturnValue()).isEmpty());
    }

    @Test
    @Ignore
    public void executeQueryCommandWithWatchdog() {
        final Guid vmId = new Guid("ee655a4d-effc-4aab-be2b-2f80ff40cd1c");
        VmDeviceDAO vmDeviceDaoMock = Mockito.mock(VmDeviceDAO.class);
        HashMap<String, Object> watchdogSpecParams = new HashMap<String, Object>();
        watchdogSpecParams.put("model", "i6300esb");
        watchdogSpecParams.put("action", "reset");
        VmDevice vmDevice = new VmDevice(new VmDeviceId(new Guid("6f86b8a4-e721-4149-b2df-056eb621b16a"),
                vmId), VmDeviceGeneralType.WATCHDOG, VmDeviceType.WATCHDOG.getName(), "", 1, watchdogSpecParams, true,
                true, true, "", null, null);
        Mockito.when(vmDeviceDaoMock.getVmDeviceByVmIdAndType(vmId, VmDeviceGeneralType.WATCHDOG))
                .thenReturn(Arrays.asList(vmDevice));
        GetWatchdogQuery<IdQueryParameters> query =
                new GetWatchdogQuery<IdQueryParameters>(new IdQueryParameters(vmId));
        query = Mockito.spy(query);
        Mockito.when(query.getVmDeviceDAO()).thenReturn(vmDeviceDaoMock);
        IdQueryParameters params = new IdQueryParameters(vmId);
        Mockito.when(query.getParameters())
                .thenReturn(params);
        Mockito.doCallRealMethod().when(query).executeQueryCommand();
        Mockito.doCallRealMethod().when(query).getReturnValue();
        Mockito.doCallRealMethod().when(query).setReturnValue(Mockito.any(Object.class));

        query.executeQueryCommand();
        Assert.assertNotNull(query.getReturnValue());
        Assert.assertEquals((((VmWatchdog)query.getReturnValue()).getAction()).name().toLowerCase(), "reset");
        Assert.assertEquals((((VmWatchdog)query.getReturnValue()).getModel()).name().toLowerCase(), "i6300esb");
    }

}

@@ -133,33 +133,8 @@
 rt;%0A
-import org.junit.Ignore;%0A
 impo
@@ -955,28 +955,32 @@
 eDAO;%0A%0A    @
-Test
+Override
 %0A    public 
@@ -988,39 +988,57 @@
 oid 
-executeQueryCommandWithNull() %7B
+setUp() throws Exception %7B%0A        super.setUp();
 %0A   
@@ -1124,16 +1124,81 @@
 ceDAO);%0A
+    %7D%0A%0A    @Test%0A    public void executeQueryCommandWithNull() %7B%0A
         
@@ -1465,20 +1465,8 @@
 est%0A
-    @Ignore%0A
     
@@ -1593,79 +1593,8 @@
 %22);%0A
-        VmDeviceDAO vmDeviceDaoMock = Mockito.mock(VmDeviceDAO.class);%0A
     
@@ -2077,22 +2077,18 @@
 mDeviceD
-aoMock
+AO
 .getVmDe
@@ -2208,372 +2208,50 @@
     
-GetWatchdogQuery%3CIdQueryParameters%3E query =%0A                new GetWatchdogQuery%3CIdQueryParameters%3E(new IdQueryParameters(vmId));%0A        query = Mockito.spy(query);%0A        Mockito.when(query.getVmDeviceDAO()).thenReturn(vmDeviceDaoMock);%0A        IdQueryParameters params = new IdQueryParameters(vmId);%0A        Mockito.when(query.getParameters())%0A                
+Mockito.when(getQueryParameters().getId())
 .the
@@ -2262,25 +2262,24 @@
 urn(
-params
+vmId
 );%0A
+%0A
         
 Mock
@@ -2278,45 +2278,17 @@
     
-Mockito.doCallRealMethod().when(q
+getQ
 uery
+(
 ).ex
@@ -2304,32 +2304,33 @@
 yCommand();%0A
+%0A
         
 Mockito.doCa
@@ -2321,50 +2321,53 @@
     
-Mockito.doCallRealMethod().when(q
+List%3CVmWatchdog%3E result = getQ
 uery
+(
 ).get
+Query
 Retu
@@ -2379,109 +2379,35 @@
 ue()
-;%0A        Mockito.doCallRealMethod().when(query).setReturnValue(Mockito.any(Object.class)
+.getReturnValue(
 );%0A
-%0A
         
 quer
@@ -2406,88 +2406,126 @@
     
-query.executeQueryCommand();%0A        Assert.assertNotNull(query.getReturnValue()
+Assert.assertNotNull(result);%0A        Assert.assertFalse(result.isEmpty());%0A        VmWatchdog watchdog = result.get(0
 );%0A 
@@ -2555,45 +2555,16 @@
 als(
-(((VmW
+w
 atchdog
-)query.getReturnValue())
 .get
@@ -2571,17 +2571,16 @@
 Action()
-)
 .name().
@@ -2636,45 +2636,16 @@
 als(
-(((VmW
+w
 atchdog
-)query.getReturnValue())
 .get
@@ -2651,17 +2651,16 @@
 tModel()
-)
 .name().

Fix and enable GetWatchdogQuery ignored test