@Test
  public void should_autogenerate_table_from_the_ajax_criterias() {

    request.addParameter("columns[0][data]", "id");
    request.addParameter("columns[1][data]", "firstName");
    request.addParameter("columns[2][data]", "lastName");
    request.addParameter("columns[3][data]", "mail");

    DatatablesCriterias criteria = DatatablesCriterias.getFromRequest(request);

    HtmlTable table =
        new HtmlTableBuilder<Person>()
            .newBuilder("tableId", persons, request, null)
            .auto(criteria)
            .build();

    assertThat(table.getBodyRows()).hasSize(10);
    assertThat(table.getBodyRows().get(0).getColumns()).hasSize(4);
    assertThat(table.getBodyRows().get(0).getColumns().get(0).getContent().toString())
        .isEqualTo("1");
    assertThat(table.getBodyRows().get(0).getColumns().get(1).getContent().toString())
        .isEqualTo("firstName1");
    assertThat(table.getBodyRows().get(0).getColumns().get(2).getContent().toString())
        .isEqualTo("lastName1");
    assertThat(table.getBodyRows().get(0).getColumns().get(3).getContent().toString())
        .isEqualTo("mail1");
    assertThat(table.getBodyRows().get(9).getColumns().get(0).getContent().toString())
        .isEqualTo("10");
    assertThat(table.getBodyRows().get(9).getColumns().get(1).getContent().toString())
        .isEqualTo("firstName10");
    assertThat(table.getBodyRows().get(9).getColumns().get(2).getContent().toString())
        .isEqualTo("lastName10");
    assertThat(table.getBodyRows().get(9).getColumns().get(3).getContent().toString())
        .isEqualTo("mail10");
  }
  @Test
  public void verifyValidServiceTicketWithValidPgtAndProxyHandlerFailing() throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final ServiceTicket sId =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId.getId());
    request.addParameter("pgtUrl", "https://www.github.com");

    this.serviceValidateController.setProxyHandler(
        new ProxyHandler() {
          @Override
          public String handle(
              final Credential credential, final TicketGrantingTicket proxyGrantingTicketId) {
            return null;
          }

          @Override
          public boolean canHandle(final Credential credential) {
            return true;
          }
        });

    final ModelAndView modelAndView =
        this.serviceValidateController.handleRequestInternal(
            request, new MockHttpServletResponse());
    assertEquals(
        ServiceValidateController.DEFAULT_SERVICE_FAILURE_VIEW_NAME, modelAndView.getViewName());
    assertNull(modelAndView.getModel().get("pgtIou"));
  }
  @Test
  public void testParams() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/params");
    Object handler = null;
    try {
      handler = this.handlerMapping.getHandler(request);
    } catch (Exception e) {
      // There is no matching handlers and some default handler
      // See
      // org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping#handleNoMatch
      assertTrue(e instanceof UnsatisfiedServletRequestParameterException);
    }

    request = new MockHttpServletRequest("GET", "/params");
    request.addParameter("param1", "1");
    request.addParameter("param2", "1");

    handler = this.handlerMapping.getHandler(request).getHandler();

    MockHttpServletResponse response = new MockHttpServletResponse();

    this.handlerAdapter.handle(request, response, handler);
    String testResponse = response.getContentAsString();
    assertEquals("User=1;account=1", testResponse);

    request = new MockHttpServletRequest("GET", "/params");
    request.addParameter("param1", "1");
    handler = this.handlerMapping.getHandler(request).getHandler();

    response = new MockHttpServletResponse();

    this.handlerAdapter.handle(request, response, handler);
    testResponse = response.getContentAsString();
    assertEquals("User=1", testResponse);
  }
  public void testRepeatedRequestCatching() throws Exception {
    String event = "theEvent";
    String widgetKey = StandardViewPortWidget.CHILD_KEY;

    adapter = (ServletServiceAdapterComponent) initAdapter("repeatedRequest.xml");
    // lets get reference to the bean doing the heavy-lifting
    // its a singleton, so we're cool
    BeanFactory factory = servlet.getFactory();
    MockViewPortWidget widget = (MockViewPortWidget) factory.getBean("rootWidget");

    req.addParameter(StandardWidget.EVENT_HANDLER_ID_KEY, event);
    req.addParameter(StandardWidgetContainerWidget.EVENT_PATH_KEY, widgetKey);

    // first request, transactionId will get intialized
    adapter.service(req, resp);
    // helper returns true on null transactionId

    MockEventfulStandardWidget child1 =
        (MockEventfulStandardWidget) widget.getChildren().get(widgetKey);
    req.addParameter(
        StandardTransactionFilterWidget.TRANSACTION_ID_KEY, "" + child1.getTransactionId());

    // second request with the valid transactionId
    adapter.service(req, resp);

    assertTrue(child1.getEventProcessed());
    child1.setEventProcessed(false);

    req.addParameter(
        StandardTransactionFilterWidget.TRANSACTION_ID_KEY, "" + child1.getTransactionId());
    adapter.service(req, resp);
    // transactionId used 2nd time, should not process the event
    assertFalse(child1.getEventProcessed());
  }
 @Test
 public void shouldRetireAConceptSource() throws Exception {
   Assert.assertEquals(false, service.getConceptSourceByUuid(getUuid()).isRetired());
   MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid());
   req.addParameter("!purge", "");
   final String reason = "none";
   req.addParameter("reason", reason);
   handle(req);
   Assert.assertEquals(true, service.getConceptSourceByUuid(getUuid()).isRetired());
   Assert.assertEquals(reason, service.getConceptSourceByUuid(getUuid()).getRetireReason());
 }
示例#6
0
    @Test
    public void shouldRequestUpdatesForAllPlayersScreen() throws IOException, ServletException {
        request.addParameter("vasya", "vasya");
        request.addParameter("allPlayersScreen", "true");

        screenController.handleRequest(request, new MockHttpServletResponse());

        verify(screenSender).scheduleUpdate(updateRequestCaptor.capture());
        UpdateRequest updateRequest = updateRequestCaptor.getValue();
        assertTrue(updateRequest.isForAllPlayers());
        assertNull(updateRequest.getPlayersToUpdate());
    }
  private HttpServletRequest getHttpServletRequest() throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());
    final ServiceTicket sId2 =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId2.getId());
    request.addParameter("renew", "true");

    return request;
  }
  /**
   * @see RadiologyObsFormController#saveObs(HttpServletRequest, HttpServletResponse, String,
   *     RadiologyOrder, Obs Obs, BindingResult)
   */
  @Test
  @Verifies(
      value = "should edit obs with edit reason and complex concept",
      method =
          "saveObs(HttpServletRequest, HttpServletResponse, String, RadiologyOrder, Obs Obs, BindingResult)")
  public void saveObs_ShouldEditObsWithEditReasonAndComplexConcept() {

    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.addParameter("saveObs", "saveObs");
    mockRequest.setSession(mockSession);

    when(obsErrors.hasErrors()).thenReturn(false);
    ConceptComplex concept = new ConceptComplex();
    ConceptDatatype cdt = new ConceptDatatype();
    cdt.setHl7Abbreviation("ED");
    concept.setDatatype(cdt);
    mockObs.setConcept(concept);

    ModelAndView modelAndView =
        radiologyObsFormController.saveObs(
            mockRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors);

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR));
    assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR), is("Obs.saved"));
    assertThat(
        modelAndView.getViewName(),
        is(
            "redirect:"
                + RADIOLOGY_OBS_FORM_URL
                + "orderId="
                + mockRadiologyOrder.getId()
                + "&obsId="
                + mockObs.getId()));
  }
  public void testProcess() throws Exception {

    Controller c = (Controller) applicationContext.getBean("peopleController");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("POST");
    HttpServletResponse response = new MockHttpServletResponse();

    request.addParameter("importStudents", "Import Students");

    ModelAndView mav =
        c.handleRequest((HttpServletRequest) request, (HttpServletResponse) response);
    Map m = mav.getModel();
    PeopleBacking p = (PeopleBacking) m.get("peopleBacking");

    MockPageContext ctx = new MockPageContext();
    ctx.setAttribute("peopleBacking", mav.getModel().get("peopleBacking"));
    request.setAttribute("peopleBacking", mav.getModel().get("peopleBacking"));

    List<ProcessErrors> errors =
        (List<ProcessErrors>)
            ExpressionEvaluationUtils.evaluate(
                "test", "${peopleBacking.processStudentsErrors}", List.class, ctx);

    for (ProcessErrors e : errors) {
      ctx.setAttribute("processErrors", e);
      log.debug(
          ExpressionEvaluationUtils.evaluate(
              "test", "${processErrors.message}", String.class, ctx));
    }
  }
 @Test
 public void shouldSearchAConceptSourceIfItMatchesTheQuery() throws Exception {
   MockHttpServletRequest req = request(RequestMethod.GET, getURI());
   req.addParameter("q", "ome");
   SimpleObject result = deserialize(handle(req));
   Assert.assertEquals(2, Util.getResultsSize(result));
 }
  @Test(expected = RuntimeException.class)
  public void testEditTeamNoId() throws Exception {
    MockHttpServletRequest request = getRequest();
    String token = TokenUtil.generateSessionToken();

    // do NOT add the team id, but do add the team name, team description & token
    request.addParameter("team", "Team 1");
    request.addParameter("description", "description");
    request.addParameter("token", token);

    autoWireMock(editTeamController, new Returns(mockTeam), GrouperTeamService.class);
    autoWireMock(editTeamController, new Returns(true), ControllerUtil.class);
    autoWireRemainingResources(editTeamController);

    editTeamController.editTeam(getModelMap(), request, token, token, new SimpleSessionStatus());
  }
  /**
   * @see RadiologyObsFormController#saveObs(HttpServletRequest, HttpServletResponse, String,
   *     RadiologyOrder, Obs Obs, BindingResult)
   */
  @Test
  @Verifies(
      value = "should return redirecting model and view for not authenticated user",
      method =
          "saveObs(HttpServletRequest, HttpServletResponse, String, RadiologyOrder, Obs Obs, BindingResult)")
  public void saveObs_shouldReturnRedirectingModelAndViewForNotAuthenticatedUser() {

    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.addParameter("saveObs", "saveObs");
    mockRequest.setSession(mockSession);

    when(Context.getAuthenticatedUser()).thenReturn(null);

    ModelAndView modelAndView =
        radiologyObsFormController.saveObs(
            mockRequest, null, "Test Edit Reason", mockRadiologyOrder, mockObs, obsErrors);

    assertThat(
        modelAndView.getViewName(),
        is(
            "redirect:"
                + RADIOLOGY_OBS_FORM_URL
                + "orderId="
                + mockRadiologyOrder.getId()
                + "&obsId="
                + mockObs.getId()));
  }
  protected final ModelAndView getModelAndViewUponServiceValidationWithSecurePgtUrl()
      throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final ServiceTicket sId =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId.getId());
    request.addParameter("pgtUrl", "https://www.github.com");

    return this.serviceValidateController.handleRequestInternal(
        request, new MockHttpServletResponse());
  }
  /**
   * @see RadiologyObsFormController#voidObs(HttpServletRequest, HttpServletResponse, Order, Obs,
   *     String, String, Obs, BindingResult)
   */
  @Test
  @Verifies(
      value =
          "should void obs for given request, response, orderId, obsId, voidObs, voidReason, and obs",
      method =
          "voidObs(HttpServletRequest, HttpServletResponse, Order, Obs, String, String, Obs, BindingResult)")
  public void voidObs_ShouldVoidObsForGivenRequestResponseOrderIdObsIdVoidObsVoidReasonAndObs() {

    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.addParameter("voidObs", "voidObs");
    mockRequest.setSession(mockSession);

    when(obsErrors.hasErrors()).thenReturn(false);

    ModelAndView modelAndView =
        radiologyObsFormController.voidObs(
            mockRequest, null, mockRadiologyOrder, mockObs, "Test Void Reason");

    assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR));
    assertThat(
        (String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
        is("Obs.voidedSuccessfully"));
    assertThat(
        (String) modelAndView.getViewName(),
        is(
            "redirect:"
                + RADIOLOGY_OBS_FORM_URL
                + "orderId="
                + mockRadiologyOrder.getId()
                + "&obsId="
                + mockObs.getId()));
  }
  /**
   * @see RadiologyObsFormController#unvoidObs(HttpServletRequest, HttpServletResponse, Obs, String)
   */
  @Test
  @Verifies(
      value = "should unvoid voided obs for given request, response and obs",
      method = "unvoidObs(HttpServletRequest, HttpServletResponse, Obs, String)")
  public void unvoidObs_shouldUnvoidVoidedObsForGivenRequestResponseAndObs() {

    MockHttpSession mockSession = new MockHttpSession();
    mockRequest.addParameter("unvoidObs", "unvoidObs");
    mockRequest.setSession(mockSession);
    when(obsErrors.hasErrors()).thenReturn(false);

    mockObs.setVoided(true);

    ModelAndView modelAndView = radiologyObsFormController.unvoidObs(mockRequest, null, mockObs);
    assertThat(
        modelAndView.getViewName(),
        is(
            "redirect:"
                + RADIOLOGY_OBS_FORM_URL
                + "orderId="
                + mockRadiologyOrder.getId()
                + "&obsId="
                + mockObs.getId()));
    assertThat(
        (String) mockSession.getAttribute(WebConstants.OPENMRS_MSG_ATTR),
        is("Obs.unvoidedSuccessfully"));
  }
  @Test
  public void resolveViewNameWithRequestParameter() throws Exception {
    request.addParameter("format", "xls");

    viewResolver.setFavorParameter(true);
    viewResolver.setMediaTypes(Collections.singletonMap("xls", "application/vnd.ms-excel"));

    ViewResolver viewResolverMock = createMock(ViewResolver.class);
    viewResolver.setViewResolvers(Collections.singletonList(viewResolverMock));

    View viewMock = createMock("application_xls", View.class);

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    expect(viewResolverMock.resolveViewName(viewName, locale)).andReturn(null);
    expect(viewResolverMock.resolveViewName(viewName + ".xls", locale)).andReturn(viewMock);
    expect(viewMock.getContentType()).andReturn("application/vnd.ms-excel").anyTimes();

    replay(viewResolverMock, viewMock);

    View result = viewResolver.resolveViewName(viewName, locale);
    assertSame("Invalid view", viewMock, result);

    verify(viewResolverMock, viewMock);
  }
  @Test
  public void verifyOKWithState() throws Exception {
    final MockHttpServletRequest mockRequest =
        new MockHttpServletRequest("GET", CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockSession.putValue(OAuthConstants.OAUTH20_STATE, STATE);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final ModelAndView modelAndView =
        oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(
        REDIRECT_URI
            + "?"
            + OAuthConstants.CODE
            + "="
            + SERVICE_TICKET
            + "&"
            + OAuthConstants.STATE
            + "="
            + STATE,
        map.get("callbackUrl"));
  }
 /**
  * @see VisitAttributeTypeController#search(String, javax.servlet.http.HttpServletRequest,
  *     HttpServletResponse)
  */
 @Test
 public void search_shouldFindAllMatchingVisitAttributeTypesIfIncludeAllIsSetToTrue()
     throws Exception {
   MockHttpServletRequest request = emptyRequest();
   request.addParameter(RestConstants.REQUEST_PROPERTY_FOR_INCLUDE_ALL, "true");
   Assert.assertEquals(
       3, Util.getResultsSize(controller.search("date", request, emptyResponse())));
 }
 @Test
 public void shouldPurgeAConceptSource() throws Exception {
   Assert.assertNotNull(service.getConceptSourceByUuid(getUuid()));
   MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid());
   req.addParameter("purge", "");
   handle(req);
   Assert.assertNull(service.getConceptSourceByUuid(getUuid()));
 }
示例#20
0
  public LockQuery buildMockLockQuery() throws UnsupportedEncodingException {
    MockHttpServletRequest httpReq = new MockHttpServletRequest("GET", "/search_video/");
    httpReq.addParameter("keyword", readRandomLine(encoding));
    Parameter p = new Parameter(httpReq);
    SearchContext<Video> context = new SearchContext<Video>(p, 48);

    return (LockQuery) context.lockQuery;
  }
  @Test
  public void should_generate_table_by_extracting_property_from_the_ajax_criterias() {

    request.addParameter("columns[0][data]", "id");
    request.addParameter("columns[1][data]", "firstName");
    request.addParameter("columns[2][data]", "lastName");
    request.addParameter("columns[3][data]", "mail");

    DatatablesCriterias criteria = DatatablesCriterias.getFromRequest(request);

    HtmlTable table =
        new HtmlTableBuilder<Person>()
            .newBuilder("tableId", persons, request, null)
            .column()
            .fillFromCriteria(criteria)
            .title("Id")
            .column()
            .fillFromCriteria(criteria)
            .title("Firtname")
            .column()
            .fillFromCriteria(criteria)
            .title("Lastname")
            .column()
            .fillFromCriteria(criteria, "formatted-{0}")
            .title("Mail")
            .build();

    assertThat(table.getBodyRows()).hasSize(10);
    assertThat(table.getBodyRows().get(0).getColumns()).hasSize(4);
    assertThat(table.getBodyRows().get(0).getColumns().get(0).getContent().toString())
        .isEqualTo("1");
    assertThat(table.getBodyRows().get(0).getColumns().get(1).getContent().toString())
        .isEqualTo("firstName1");
    assertThat(table.getBodyRows().get(0).getColumns().get(2).getContent().toString())
        .isEqualTo("lastName1");
    assertThat(table.getBodyRows().get(0).getColumns().get(3).getContent().toString())
        .isEqualTo("formatted-mail1");
    assertThat(table.getBodyRows().get(9).getColumns().get(0).getContent().toString())
        .isEqualTo("10");
    assertThat(table.getBodyRows().get(9).getColumns().get(1).getContent().toString())
        .isEqualTo("firstName10");
    assertThat(table.getBodyRows().get(9).getColumns().get(2).getContent().toString())
        .isEqualTo("lastName10");
    assertThat(table.getBodyRows().get(9).getColumns().get(3).getContent().toString())
        .isEqualTo("formatted-mail10");
  }
  @Test
  public void testEchoingParametersWithMultipleValues() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.addParameter("param1", "param1value1");
    request.addParameter("param2", "param2value2");
    request.addParameter("param3", "param3value3");
    request.addParameter("param4", "param4value4");

    new EchoServlet().doGet(request, response);
    String[] lines = response.getContentAsString().split("\n");
    assertEquals("Except as many lines as we have parameter values", 4, lines.length);
    assertEquals("param1=param1value1", lines[0]);
    assertEquals("param2=param2value2", lines[1]);
    assertEquals("param3=param3value3", lines[2]);
    assertEquals("param4=param4value4", lines[3]);
  }
 public MockHttpServletRequest newRequest(
     RequestMethod method, String requestURI, Parameter... parameters) {
   MockHttpServletRequest request = request(method, requestURI);
   for (Parameter parameter : parameters) {
     request.addParameter(parameter.name, parameter.value);
   }
   return request;
 }
  public void testRequestWithParameter() throws Exception {
    filter.setPattern(Pattern.compile("d-\\d+-e"));
    request.addParameter("any", "thing");
    request.addParameter("d-16544-e", "2");
    request.addParameter("other", "foo");

    assertNull(
        "FILTER_APPLIED initially set", request.getAttribute(RequestConstants.FILTER_APPLIED));

    filter.doFilter(request, response, filterChain);
    verifyMocks();

    assertEquals(
        "FILTER_APPLIED not set",
        Boolean.TRUE,
        request.getAttribute(RequestConstants.FILTER_APPLIED));
  }
  @Test
  public void shouldGetFullByUuid() throws Exception {
    MockHttpServletRequest request = request(RequestMethod.GET, getURI() + "/" + getUuid());
    request.addParameter("v", "full");
    SimpleObject result = deserialize(handle(request));

    Assert.assertNotNull(result);
    Assert.assertEquals(getUuid(), PropertyUtils.getProperty(result, "uuid"));
  }
  @Test
  public void verifyValidServiceTicket() throws Exception {
    final TicketGrantingTicket tId =
        getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final ServiceTicket sId =
        getCentralAuthenticationService().grantServiceTicket(tId.getId(), TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId.getId());

    assertEquals(
        ServiceValidateController.DEFAULT_SERVICE_SUCCESS_VIEW_NAME,
        this.serviceValidateController
            .handleRequestInternal(request, new MockHttpServletResponse())
            .getViewName());
  }
  @Test
  public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid());
    req.addParameter(
        RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    SimpleObject result = deserialize(handle(req));

    Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
  }
 protected RequestContext buildRequestContext(String... paramNamesAndValues) {
   MockHttpServletRequest request = new MockHttpServletRequest();
   for (int i = 0; i < paramNamesAndValues.length; i += 2) {
     request.addParameter(paramNamesAndValues[i], paramNamesAndValues[i + 1]);
   }
   RequestContext context = new RequestContext();
   context.setRequest(request);
   return context;
 }
示例#29
0
    @Test
    public void shouldRequestUpdatesForPlayers() throws IOException, ServletException {
        request.addParameter("vasya", "vasya");

        screenController.handleRequest(request, new MockHttpServletResponse());

        verify(screenSender).scheduleUpdate(updateRequestCaptor.capture());
        assertUpdateRequestContainsPlayer("vasya");
    }
  @Test(expected = RuntimeException.class)
  public void testEditTeamNoMember() throws Exception {
    MockHttpServletRequest request = getRequest();
    String token = TokenUtil.generateSessionToken();
    // Add the teamId, team name, description & token
    request.addParameter("teamName", "Team 1");
    request.addParameter("team", "team-1");
    request.addParameter("description", "description");
    request.addParameter("token", token);

    GrouperTeamService grouperTeamService = mock(GrouperTeamService.class);
    when(grouperTeamService.findTeamById("team-1")).thenReturn(null);
    when(grouperTeamService.findMember("team-1", "member-1")).thenReturn(mockAdminMember);
    autoWireMock(editTeamController, grouperTeamService, GrouperTeamService.class);
    autoWireMock(editTeamController, new Returns(true), ControllerUtil.class);
    autoWireRemainingResources(editTeamController);

    editTeamController.editTeam(getModelMap(), request, token, token, new SimpleSessionStatus());
  }