package org.ovirt.engine.core.bll;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import org.junit.Test;

import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
import org.ovirt.engine.core.common.users.VdcUser;
import org.ovirt.engine.core.compat.Guid;

public class ValidateSessionQueryTest extends AbstractQueryTest<VdcQueryParametersBase, ValidateSessionQuery<VdcQueryParametersBase>> {

    @Test
    public void testSuccessfulSessionId() {
        VdcQueryParametersBase params = new VdcQueryParametersBase();;
        params.setSessionId("good_session_id");

        ValidateSessionQuery<VdcQueryParametersBase> query = spy(new ValidateSessionQuery<VdcQueryParametersBase>(params));
        when(query.getSessionUser("good_session_id")).thenReturn(new VdcUser(Guid.NewGuid(), "myUser", "myDomain"));
        query.Execute();
        assertTrue(query.getQueryReturnValue().getSucceeded());
        assertTrue(query.getQueryReturnValue().getReturnValue() instanceof VdcUser);
        VdcUser user = (VdcUser) query.getQueryReturnValue().getReturnValue();
        assertTrue(user.getDomainControler().equals("myDomain"));
        assertTrue(user.getUserName().equals("myUser"));
    }

    @Test
    public void testUnsuccessfulSessionId() {
        VdcQueryParametersBase params = new VdcQueryParametersBase();
        params.setSessionId("bad_session_id");

        ValidateSessionQuery<VdcQueryParametersBase> query = new ValidateSessionQuery<VdcQueryParametersBase>(params);
        query.Execute();
        assertFalse(query.getQueryReturnValue().getSucceeded());
    }

}

@@ -120,47 +120,8 @@
 ue;%0A
-import static org.mockito.Mockito.spy;%0A
 impo
@@ -180,17 +180,16 @@
 t.Test;%0A
-%0A
 import o
@@ -396,16 +396,20 @@
 Abstract
+User
 QueryTes
@@ -549,87 +549,21 @@
     
-VdcQueryParametersBase params = new VdcQueryParametersBase();;%0A        
+when(
 params.
-s
+g
 etSe
@@ -570,16 +570,30 @@
 ssionId(
+)).thenReturn(
 %22good_se
@@ -617,142 +617,23 @@
     
-ValidateSessionQuery%3CVdcQueryParametersBase%3E query = spy(new ValidateSessionQuery%3CVdcQueryParametersBase%3E(params));%0A        when(query
+when(getQuery()
 .get
@@ -727,37 +727,42 @@
 ain%22));%0A        
-q
+getQ
 uery
+()
 .Execute();%0A    
@@ -768,37 +768,42 @@
      assertTrue(
-q
+getQ
 uery
+()
 .getQueryReturnV
@@ -845,21 +845,26 @@
 ertTrue(
-q
+getQ
 uery
+()
 .getQuer
@@ -949,21 +949,26 @@
 dcUser) 
-q
+getQ
 uery
+()
 .getQuer
@@ -1198,86 +1198,21 @@
     
-VdcQueryParametersBase params = new VdcQueryParametersBase();%0A        
+when(
 params.
-s
+g
 etSe
@@ -1219,16 +1219,30 @@
 ssionId(
+)).thenReturn(
 %22bad_ses
@@ -1265,132 +1265,18 @@
     
-ValidateSessionQuery%3CVdcQueryParametersBase%3E query = new ValidateSessionQuery%3CVdcQueryParametersBase%3E(params);%0A        query
+getQuery()
 .Exe
@@ -1307,13 +1307,18 @@
 lse(
-q
+getQ
 uery
+()
 .get

Fix broken ValidateSessionQueryTest