Package gobo.controller.dump

Source Code of gobo.controller.dump.IndexControllerTest

package gobo.controller.dump;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpSession;

import org.junit.Test;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;

import gobo.ControllerTester;
import gobo.TestBase;

public class IndexControllerTest extends TestBase {

  ResourceBundle bundle = ResourceBundle.getBundle("authSub");
  final String authSubToken = bundle.getString("token");

  @SuppressWarnings("unchecked")
  @Test
  public void runTest() throws Exception {

    ControllerTester tester = new ControllerTester();
    String run = tester.start("/dump/index");
    assertNotNull(run);
    List<Map<String, Object>> list = (List) tester.request.getAttribute("list");
    assertNull(list);
  }

  @SuppressWarnings("unchecked")
  @Test
  public void runAuthWithoutDataTest() throws Exception {

    ControllerTester tester = new ControllerTester();
    HttpSession session = tester.request.getSession(true);
    session.setAttribute("token", authSubToken);

    String run = tester.start("/dump/index");
    assertNotNull(run);
    List<Map<String, Object>> list = (List) tester.request.getAttribute("list");
    assertThat(list.size(), is(0));

  }

  @SuppressWarnings("unchecked")
  @Test
  public void runAuthWithDataTest() throws Exception {

    ControllerTester tester = new ControllerTester();
    HttpSession session = tester.request.getSession(true);
    session.setAttribute("token", authSubToken);

    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    Entity entity = new Entity(KeyFactory.createKey("TestKind", 1));
    ds.put(entity);

    String run = tester.start("/dump/index");
    assertNotNull(run);
    List<Map<String, Object>> list = (List) tester.request.getAttribute("list");
    assertThat(list.size(), is(1));

    Map row = list.get(0);
    assertThat(row.get("name").toString(), equalTo("TestKind"));
    assertThat(row.get("count").toString(), equalTo("1"));
  }
}
TOP

Related Classes of gobo.controller.dump.IndexControllerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.