Search in sources :

Example 21 with Request

use of com.developmentontheedge.be5.api.Request in project be5 by DevelopmentOnTheEdge.

the class LanguageSelectorTest method generateSelect.

@Test
public void generateSelect() throws Exception {
    Response response = mock(Response.class);
    Request request = getSpyMockRequest("select", ImmutableMap.of("language", "RU"));
    component.generate(request, response, injector);
    verify(response).sendAsRawJson(eq(languageSelectorResponse));
}
Also used : Response(com.developmentontheedge.be5.api.Response) Request(com.developmentontheedge.be5.api.Request) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 22 with Request

use of com.developmentontheedge.be5.api.Request in project be5 by DevelopmentOnTheEdge.

the class StaticPageComponentTest method generate.

@Test
public void generate() throws Exception {
    Response response = mock(Response.class);
    String page = "info.be";
    Request req = getSpyMockRequest(page, ImmutableMap.of(TIMESTAMP_PARAM, "123456789"));
    component.generate(req, response, injector);
    // todo         verify(response).sendAsJson(eq(new ResourceData(STATIC_ACTION,
    // new StaticPagePresentation("", "<h1>Info</h1><p>Test text.</p>"))),
    // eq(ImmutableMap.of(TIMESTAMP_PARAM, "123456789")),
    // eq(Collections.singletonMap(SELF_LINK, "static/" + page)));
    verify(response).sendAsJson(any(ResourceData.class), any(Map.class));
}
Also used : Response(com.developmentontheedge.be5.api.Response) ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) Request(com.developmentontheedge.be5.api.Request) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 23 with Request

use of com.developmentontheedge.be5.api.Request in project be5 by DevelopmentOnTheEdge.

the class TestUtils method getSpyMockRequest.

protected Request getSpyMockRequest(String requestUri, Map<String, String> parameters, Map<String, Object> sessionValues) {
    HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
    when(httpServletRequest.getSession()).thenReturn(mock(HttpSession.class));
    Request request = Mockito.spy(new RequestImpl(httpServletRequest, null, parameters));
    when(request.getRequestUri()).thenReturn(requestUri);
    for (Map.Entry<String, Object> entry : sessionValues.entrySet()) {
        when(request.getAttribute(entry.getKey())).thenReturn(entry.getValue());
    }
    return request;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.developmentontheedge.be5.api.Request) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RequestImpl(com.developmentontheedge.be5.api.impl.RequestImpl)

Aggregations

Request (com.developmentontheedge.be5.api.Request)8 Response (com.developmentontheedge.be5.api.Response)6 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)5 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)5 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)5 Test (org.junit.Test)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)3 Query (com.developmentontheedge.be5.metadata.model.Query)3 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)3 Map (java.util.Map)3 Session (com.developmentontheedge.be5.api.Session)2 UserHelper (com.developmentontheedge.be5.api.helpers.UserHelper)2 RequestImpl (com.developmentontheedge.be5.api.impl.RequestImpl)2 StaticPagePresentation (com.developmentontheedge.be5.model.StaticPagePresentation)2 UserInfo (com.developmentontheedge.be5.model.UserInfo)2 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)2 HashUrl (com.developmentontheedge.be5.util.HashUrl)2