Search in sources :

Example 6 with Response

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

the class QueryBuilderTest method generate.

@Test
public void generate() {
    Response response = mock(Response.class);
    component.generate(getSpyMockRequest("queryBuilder", ImmutableMap.of("sql", "select * from testtable limit 1", RestApiConstants.TIMESTAMP_PARAM, "" + new Date().getTime())), response, injector);
    verify(response).sendAsJson(any(JsonApiModel.class));
}
Also used : Response(com.developmentontheedge.be5.api.Response) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel) Date(java.util.Date) Test(org.junit.Test) SqlMockOperationTest(com.developmentontheedge.be5.test.SqlMockOperationTest)

Example 7 with Response

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

the class StaticPageComponentTest method generateFoo.

@Test
public void generateFoo() throws Exception {
    Response response = mock(Response.class);
    String page = "foo.be";
    component.generate(getMockRequest(page), response, injector);
    verify(response).sendErrorAsJson(any(ErrorModel.class), any(Map.class));
}
Also used : Response(com.developmentontheedge.be5.api.Response) ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Example 8 with Response

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

the class ResponseTest method init.

@Before
public void init() throws Exception {
    writer = mock(PrintWriter.class);
    rawResponse = mock(HttpServletResponse.class);
    when(rawResponse.getWriter()).thenReturn(writer);
    response = new ResponseImpl(rawResponse);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) ResponseImpl(com.developmentontheedge.be5.api.impl.ResponseImpl) PrintWriter(java.io.PrintWriter) Before(org.junit.Before)

Example 9 with Response

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

the class HttpRequests method sendGet.

public static String sendGet(String url) {
    try {
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestProperty("User-Agent", USER_AGENT);
        int responseCode = con.getResponseCode();
        if (responseCode != HttpURLConnection.HTTP_OK) {
            return null;
        }
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuilder response = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        return response.toString();
    } catch (Exception e) {
        throw Be5Exception.internal(e);
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) URL(java.net.URL) Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception)

Example 10 with Response

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

the class UserInfoComponentTest method generateSelectRolesAndSendNewStateNotAvailableRole.

@Test
public void generateSelectRolesAndSendNewStateNotAvailableRole() throws Exception {
    Response response = mock(Response.class);
    component.generate(getSpyMockRequest("", ImmutableMap.of("roles", RoleType.ROLE_ADMINISTRATOR)), response, injector);
    verify(response).sendAsRawJson(new UserInfoComponent.State(true, TEST_USER, Collections.singletonList(RoleType.ROLE_ADMINISTRATOR), Collections.singletonList(RoleType.ROLE_ADMINISTRATOR), any(Date.class)));
}
Also used : Response(com.developmentontheedge.be5.api.Response) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

Aggregations

Response (com.developmentontheedge.be5.api.Response)23 Test (org.junit.Test)22 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)20 Request (com.developmentontheedge.be5.api.Request)6 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)5 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)5 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Action (com.developmentontheedge.be5.model.Action)4 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)3 Map (java.util.Map)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)2 UserHelper (com.developmentontheedge.be5.api.helpers.UserHelper)2 ResponseImpl (com.developmentontheedge.be5.api.impl.ResponseImpl)2 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)2 SqlMockOperationTest (com.developmentontheedge.be5.test.SqlMockOperationTest)2 HashUrl (com.developmentontheedge.be5.util.HashUrl)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Date (java.util.Date)2