package org.ovirt.engine.api.restapi.resource;

import static org.easymock.EasyMock.expect;
import static org.ovirt.engine.api.restapi.resource.BackendClustersResourceTest.setUpEntityExpectations;

import java.util.ArrayList;
import java.util.List;

import org.easymock.EasyMock;
import org.junit.Test;
import org.ovirt.engine.core.common.businessentities.VDSGroup;
import org.ovirt.engine.core.common.queries.GetVdsGroupByIdParameters;
import org.ovirt.engine.core.common.queries.VdcQueryType;

public class BackendResourceTest extends AbstractBackendBaseTest {
    BackendClusterResource resource;

    @Test
    public void testQueryWithoutFilter() throws Exception {
        resource.setUriInfo(setUpBasicUriExpectations());
        setUpGetEntityExpectations(false);
        control.replay();
        resource.get();
    }

    @Test
    public void testQueryWithFilter() throws Exception {
        List<String> filterValue = new ArrayList<String>();
        filterValue.add("true");
        EasyMock.reset(httpHeaders);
        expect(httpHeaders.getRequestHeader("filter")).andReturn(filterValue);
        resource.setUriInfo(setUpBasicUriExpectations());
        setUpGetEntityExpectations(true);
        control.replay();
        resource.get();
    }

    @Override
    protected void init() {
        resource = new BackendClusterResource(GUIDS[0].toString());
        resource.setBackend(backend);
        resource.setMappingLocator(mapperLocator);
        resource.setSessionHelper(sessionHelper);
        resource.setMessageBundle(messageBundle);
        resource.setHttpHeaders(httpHeaders);
    }

    protected void setUpGetEntityExpectations(boolean filter) throws Exception {
        setUpGetEntityExpectations(VdcQueryType.GetVdsGroupById,
                GetVdsGroupByIdParameters.class,
                new String[] { "VdsId", "Filtered" },
                new Object[] { GUIDS[0], filter },
                getEntity(0));
    }

    protected VDSGroup getEntity(int index) {
        return setUpEntityExpectations(control.createMock(VDSGroup.class), index);
    }
}

@@ -144,23 +144,20 @@
 .Backend
-Cluster
+Host
 sResourc
@@ -321,45 +321,274 @@
 ine.
-core.common.businessentities.VDSGroup
+api.model.Action;%0Aimport org.ovirt.engine.core.common.action.UpdateVdsActionParameters;%0Aimport org.ovirt.engine.core.common.action.VdcActionType;%0Aimport org.ovirt.engine.core.common.businessentities.VDS;%0Aimport org.ovirt.engine.core.common.businessentities.VdsStatic
 ;%0Aim
@@ -631,31 +631,29 @@
 eries.GetVds
-GroupBy
+ByVds
 IdParameters
@@ -783,39 +783,36 @@
 st %7B%0A    Backend
-Cluster
+Host
 Resource resourc
@@ -1472,24 +1472,828 @@
 t();%0A    %7D%0A%0A
+    @Test%0A    public void testActionWithCorrelationId() throws Exception %7B%0A        setUpGetEntityExpectations(false);%0A        expect(httpHeaders.getRequestHeader(%22Correlation-Id%22)).andReturn(asList(%22Some-Correlation-id%22)).anyTimes();%0A        resource.setUriInfo((setUpActionExpectations(VdcActionType.UpdateVds,%0A                                           UpdateVdsActionParameters.class,%0A                                           new String%5B%5D %7B %22RootPassword%22, %22CorrelationId%22 %7D,%0A                                           new Object%5B%5D %7B NAMES%5B2%5D, %22Some-Correlation-id%22 %7D,%0A                                           true,%0A                                           true)));%0A        Action action = new Action();%0A        action.setRootPassword(NAMES%5B2%5D);        %0A        resource.install(action);%0A    %7D%0A%0A
     @Overrid
@@ -2356,15 +2356,12 @@
 kend
-Cluster
+Host
 Reso
@@ -2384,16 +2384,44 @@
 String()
+, new BackendHostsResource()
 );%0A     
@@ -2792,23 +2792,21 @@
 e.GetVds
-GroupBy
+ByVds
 Id,%0A    
@@ -2827,15 +2827,13 @@
 tVds
-GroupBy
+ByVds
 IdPa
@@ -3008,21 +3008,16 @@
 cted VDS
-Group
  getEnti
@@ -3031,16 +3031,24 @@
 index) %7B
+        
 %0A       
@@ -3052,14 +3052,17 @@
     
-return
+VDS vds =
  set
@@ -3108,13 +3108,8 @@
 (VDS
-Group
 .cla
@@ -3119,16 +3119,238 @@
 , index)
+;%0A        VdsStatic vdsStatic = control.createMock(VdsStatic.class);%0A        expect(vdsStatic.getId()).andReturn(GUIDS%5B2%5D).anyTimes();%0A        expect(vds.getStaticData()).andReturn(vdsStatic).anyTimes();%0A        return vds
 ;%0A    %7D%0A

Add Correlation-Id Tests