Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.server;
import static io.airlift.http.client.Request.Builder.preparePost;
import static io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator;
import static io.airlift.http.client.StringResponseHandler.StringResponse;
import static io.airlift.http.client.StringResponseHandler.createStringResponseHandler;
import static org.testng.Assert.assertEquals;
@Test(singleThreaded = true)
public class TestExecuteResource
    private TestingPrestoServer server;
    private HttpClient client;
    public void setup()
            throws Exception
    {
         = new TestingPrestoServer();
         = new JettyHttpClient();
    }
    @SuppressWarnings("deprecation")
    @AfterMethod
    public void teardown()
    {
        Closeables.closeQuietly();
        Closeables.closeQuietly();
    }
    @Test
    public void testExecute()
            throws Exception
    {
        String expected = "{\"columns\":[" +
                "{\"name\":\"foo\",\"type\":\"bigint\"}," +
                "{\"name\":\"bar\",\"type\":\"varchar\"}]," +
                "\"data\":[[123,\"abc\"]]}\n";
        StringResponse response = executeQuery("SELECT 123 foo, 'abc' bar FROM dual");
        assertEquals(response.getStatusCode(), ..code());
        assertEquals(response.getHeader(.), "application/json");
        assertEquals(response.getBody(), expected);
    }
    private StringResponse executeQuery(String query)
    {
        Request request = preparePost()
                .setUri(.resolve("/v1/execute"))
                .setHeader(."test")
                .setHeader(..)
                .setHeader(..)
                .setBodyGenerator(createStaticBodyGenerator(query.))
                .build();
        return .execute(requestcreateStringResponseHandler());
    }
New to GrepCode? Check out our FAQ X