Search in sources :

Example 1 with BuildProperties

use of org.apache.asterix.common.config.BuildProperties in project asterixdb by apache.

the class VersionApiServletTest method testGet.

@Test
public void testGet() throws Exception {
    // Configures a test version api servlet.
    VersionApiServlet servlet = new VersionApiServlet(new ConcurrentHashMap<>(), new String[] { "/" });
    Map<String, String> propMap = new HashMap<>();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintWriter outputWriter = new PrintWriter(outputStream);
    // Creates mocks.
    CcApplicationContext mockCtx = mock(CcApplicationContext.class);
    IServletRequest mockRequest = mock(IServletRequest.class);
    IHyracksClientConnection mockHcc = mock(IHyracksClientConnection.class);
    IServletResponse mockResponse = mock(IServletResponse.class);
    BuildProperties mockProperties = mock(BuildProperties.class);
    FullHttpRequest mockHttpRequest = mock(FullHttpRequest.class);
    // Put stuff in let map
    servlet.ctx().put(HYRACKS_CONNECTION_ATTR, mockHcc);
    servlet.ctx().put(ASTERIX_APP_CONTEXT_INFO_ATTR, mockCtx);
    // Sets up mock returns.
    when(mockResponse.writer()).thenReturn(outputWriter);
    when(mockRequest.getHttpRequest()).thenReturn(mockHttpRequest);
    when(mockHttpRequest.method()).thenReturn(HttpMethod.GET);
    when(mockCtx.getBuildProperties()).thenReturn(mockProperties);
    when(mockProperties.getAllProps()).thenReturn(propMap);
    propMap.put("git.build.user.email", "foo@bar.baz");
    propMap.put("git.build.host", "fulliautomatix");
    propMap.put("git.dirty", "true");
    propMap.put("git.remote.origin.url", "git@github.com:apache/incubator-asterixdb.git");
    propMap.put("git.closest.tag.name", "asterix-0.8.7-incubating");
    propMap.put("git.commit.id.describe-short", "asterix-0.8.7-incubating-19-dirty");
    propMap.put("git.commit.user.email", "foo@bar.baz");
    propMap.put("git.commit.time", "21.10.2015 @ 23:36:41 PDT");
    propMap.put("git.commit.message.full", "ASTERIXDB-1045: fix log file reading during recovery\n\nChange-Id: Ic83ee1dd2d7ba88180c25f4ec6c7aa8d0a5a7162\nReviewed-on: https://asterix-gerrit.ics.uci.edu/465\nTested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>");
    propMap.put("git.build.version", "0.8.8-SNAPSHOT");
    propMap.put("git.commit.message.short", "ASTERIXDB-1045: fix log file reading during recovery");
    propMap.put("git.commit.id.abbrev", "e1dad19");
    propMap.put("git.branch", "foo/bar");
    propMap.put("git.build.user.name", "Asterix");
    propMap.put("git.closest.tag.commit.count", "19");
    propMap.put("git.commit.id.describe", "asterix-0.8.7-incubating-19-ge1dad19-dirty");
    propMap.put("git.commit.id", "e1dad1984640517366a7e73e323c9de27b0676f7");
    propMap.put("git.tags", "");
    propMap.put("git.build.time", "22.10.2015 @ 17:11:07 PDT");
    propMap.put("git.commit.user.name", "Obelix");
    // Calls VersionAPIServlet.formResponseObject.
    servlet.handle(mockRequest, mockResponse);
    // Constructs the actual response.
    ObjectMapper om = new ObjectMapper();
    ObjectNode actualResponse = (ObjectNode) om.readTree(outputStream.toByteArray());
    ObjectNode expectedResponse = om.createObjectNode();
    for (Map.Entry<String, String> e : propMap.entrySet()) {
        expectedResponse.put(e.getKey(), e.getValue());
    }
    // Checks the response contains all the expected keys.
    Assert.assertEquals(actualResponse.toString(), expectedResponse.toString());
}
Also used : IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VersionApiServlet(org.apache.asterix.api.http.server.VersionApiServlet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IServletRequest(org.apache.hyracks.http.api.IServletRequest) BuildProperties(org.apache.asterix.common.config.BuildProperties) CcApplicationContext(org.apache.asterix.runtime.utils.CcApplicationContext) IServletResponse(org.apache.hyracks.http.api.IServletResponse) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) SqlppExecutionTest(org.apache.asterix.test.runtime.SqlppExecutionTest)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 VersionApiServlet (org.apache.asterix.api.http.server.VersionApiServlet)1 BuildProperties (org.apache.asterix.common.config.BuildProperties)1 CcApplicationContext (org.apache.asterix.runtime.utils.CcApplicationContext)1 SqlppExecutionTest (org.apache.asterix.test.runtime.SqlppExecutionTest)1 IHyracksClientConnection (org.apache.hyracks.api.client.IHyracksClientConnection)1 IServletRequest (org.apache.hyracks.http.api.IServletRequest)1 IServletResponse (org.apache.hyracks.http.api.IServletResponse)1 Test (org.junit.Test)1