package com.ifeng.at.testagent.driver.methodImpl;

import android.view.View;

import com.ifeng.at.testagent.driver.MethodExecute;
import com.ifeng.at.testagent.rpc.Request;
import com.ifeng.at.testagent.rpc.Response;
import com.robotium.solo.Solo;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lr on 2016/7/22.
 */
public class GetView implements MethodExecute{

    @Override
    public Response execute(Request request, Solo solo, Map varCache) {

        Response response = new Response();
        Map entity = new HashMap();

        response.setId(request.getId());
        response.setVersion(request.getVersion());
        if (request.getArgs().length != 1){
            response.setEntity(null);
            response.setResult(0);
            response.setError("Wrong number of params, need one.");
            return response;
        }

        View view = solo.getView(request.getArgs()[0]);
        if (request.getVar() != null){
            varCache.put(request.getVar(), view);
        }

        entity.put("v", view);

        response.setError(null);
        response.setEntity(entity);
        response.setResult(1);

        return response;
    }

    @Override
    public String getMethodName() {
        return "getView";
    }
}

@@ -1023,40 +1023,8 @@
  %7D%0A%0A
-        entity.put(%22v%22, view);%0A%0A
     
@@ -1079,22 +1079,20 @@
 tEntity(
-entity
+null
 );%0A     

fix getView setEntity