[EAGLE-788] Add unit test for eagle-client-base module

EAGLE-788 Add unit test for eagle-client-base module
- Add unit test for eagle-client-base module.

https://issues.apache.org/jira/browse/EAGLE-788

Author: chitin <chitin1...@gmail.com>

Closes #667 from chitin/EAGLE-788.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/620959bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/620959bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/620959bb

Branch: refs/heads/master
Commit: 620959bbdd334aab15fd43e8312554f5e67b4a75
Parents: b821439
Author: chitin <chitin1...@gmail.com>
Authored: Tue Nov 22 01:35:20 2016 +0800
Committer: Hao Chen <h...@apache.org>
Committed: Tue Nov 22 15:15:08 2016 +0800

----------------------------------------------------------------------
 .../client/impl/TestDeleteRequestBuilder.java   | 67 +++++++++++++
 .../client/impl/TestEagleServiceClient.java     | 98 ++++++++++++++++++++
 .../TestEagleServiceGroupByQueryRequest.java    | 55 +++++++++++
 .../impl/TestEagleServiceQueryBuilder.java      | 39 ++++++++
 .../TestListQueryAPIReponseConvertHelper.java   | 61 ++++++++++++
 .../eagle/service/client/impl/TestQuery.java    | 49 ++++++++++
 ...TestRowkeyQueryAPIResponseConvertHelper.java | 57 ++++++++++++
 7 files changed, 426 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/620959bb/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestDeleteRequestBuilder.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestDeleteRequestBuilder.java
 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestDeleteRequestBuilder.java
new file mode 100644
index 0000000..993305a
--- /dev/null
+++ 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestDeleteRequestBuilder.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.eagle.service.client.impl;
+
+import junit.framework.Assert;
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.eagle.service.client.EagleServiceConnector;
+import org.apache.eagle.service.client.EagleServiceSingleEntityQueryRequest;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * @Since 11/17/16.
+ */
+public class TestDeleteRequestBuilder {
+
+    @Test
+    public void testDeleteRequestByIds() throws Exception {
+        EagleServiceConnector connector = mock(EagleServiceConnector.class);
+        IEagleServiceClient client = new EagleServiceClientImpl(connector);
+        List<String> ids = new ArrayList<>();
+        ids.add("id1");
+        ids.add("id2");
+        ids.add("id3");
+        DeleteRequestBuilder deleteRequestBuilder = 
client.delete().startRowkey("rowkey").startTime(1479369296000L).endTime(1479369296000L
 + DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).filterIfMissing(true).
+            metricName("metric").treeAgg(false).byId(ids);
+        Field deleteRequestField = 
DeleteRequestBuilder.class.getDeclaredField("request");
+        Field idsField = 
DeleteRequestBuilder.class.getDeclaredField("deleteIds");
+        deleteRequestField.setAccessible(true);
+        idsField.setAccessible(true);
+        EagleServiceSingleEntityQueryRequest request = 
(EagleServiceSingleEntityQueryRequest)deleteRequestField.get(deleteRequestBuilder);
+        List<String> deleteIds = 
(List<String>)idsField.get(deleteRequestBuilder);
+        
Assert.assertEquals("query=null&startRowkey=rowkey&pageSize=2147483647&startTime=2016-11-17%2007:54:56&endTime=2016-11-18%2007:54:56&treeAgg=false&metricName=metric&filterIfMissing=true",
 request.getQueryParameterString());
+        Assert.assertEquals("[id1, id2, id3]", deleteIds.toString());
+    }
+
+    @Test
+    public void testDeleteRequestByQuery() throws Exception {
+        EagleServiceConnector connector = mock(EagleServiceConnector.class);
+        IEagleServiceClient client = new EagleServiceClientImpl(connector);
+        DeleteRequestBuilder deleteRequestBuilder = 
client.delete().byQuery("AuditService");
+        Field deleteRequestField = 
DeleteRequestBuilder.class.getDeclaredField("request");
+        deleteRequestField.setAccessible(true);
+        EagleServiceSingleEntityQueryRequest request = 
(EagleServiceSingleEntityQueryRequest)deleteRequestField.get(deleteRequestBuilder);
+        Assert.assertEquals("query=AuditService&pageSize=0&treeAgg=false", 
request.getQueryParameterString());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/620959bb/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceClient.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceClient.java
 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceClient.java
new file mode 100644
index 0000000..8dc7d3c
--- /dev/null
+++ 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceClient.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.eagle.service.client.impl;
+
+import junit.framework.Assert;
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.test.TestEntity;
+import org.apache.eagle.log.entity.test.TestTimeSeriesAPIEntity;
+import org.apache.eagle.service.client.EagleServiceClientException;
+import org.apache.eagle.service.client.EagleServiceConnector;
+import org.junit.Test;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * @Since 11/16/16.
+ */
+public class TestEagleServiceClient {
+
+    @Test
+    public void testBuildBathPath() {
+        EagleServiceBaseClient eagleServiceBaseClient = new 
EagleServiceClientImpl("localhost", 9090, "admin", "secret");
+        String expectedPath = "http://localhost:9090/rest";;
+        Assert.assertEquals(expectedPath, 
eagleServiceBaseClient.buildBathPath().toString());
+    }
+
+    @Test
+    public void testMarshall() throws IOException {
+        List<String> ids = new ArrayList<>();
+        ids.add("eagle001");
+        ids.add("eagle002");
+        ids.add("eagle003");
+        String expectedJson = "[\"eagle001\",\"eagle002\",\"eagle003\"]";
+        Assert.assertEquals(expectedJson, 
EagleServiceBaseClient.marshall(ids));
+        System.out.println(EagleServiceBaseClient.marshall(ids));
+    }
+
+    @Test(expected = EagleServiceClientException.class)
+    public void testGroupEntitiesByServiceException() throws 
EagleServiceClientException {
+        List<TaggedLogAPIEntity> entities = new ArrayList<>();
+        TaggedLogAPIEntity testEntity1 = null;
+        TaggedLogAPIEntity testEntity2 = new TestEntity();
+        entities.add(testEntity1);
+        entities.add(testEntity2);
+        EagleServiceBaseClient eagleServiceBaseClient = new 
EagleServiceClientImpl("localhost", 9090, "admin", "secret");
+        eagleServiceBaseClient.groupEntitiesByService(entities);
+    }
+
+    @Test
+    public void testGroupEntitiesByService() throws 
EagleServiceClientException {
+        List<TaggedLogAPIEntity> entities = new ArrayList<>();
+        TaggedLogAPIEntity testEntity1 = new TestTimeSeriesAPIEntity();
+        entities.add(testEntity1);
+        EagleServiceBaseClient eagleServiceBaseClient = new 
EagleServiceClientImpl("localhost", 9090, "admin", "secret");
+        Map<String,List<TaggedLogAPIEntity>> serviceEntityMap = 
eagleServiceBaseClient.groupEntitiesByService(entities);
+        System.out.println(serviceEntityMap);
+        Set<String> keySet = serviceEntityMap.keySet();
+        for(Map.Entry<String, List<TaggedLogAPIEntity>> entry : 
serviceEntityMap.entrySet()) {
+            Assert.assertEquals("TestTimeSeriesAPIEntity", entry.getKey());
+            Assert.assertEquals(1, entry.getValue().size());
+        }
+    }
+
+    @Test
+    public void testGetServiceNameByService() throws 
EagleServiceClientException {
+        EagleServiceConnector connector = mock(EagleServiceConnector.class);
+        EagleServiceBaseClient client = new EagleServiceClientImpl(connector);
+        String serviceName = 
client.getServiceNameByClass(TestTimeSeriesAPIEntity.class);
+        Assert.assertEquals("TestTimeSeriesAPIEntity", serviceName);
+    }
+
+    @Test(expected = EagleServiceClientException.class)
+    public void testGetServiceNameByServiceException() throws 
EagleServiceClientException {
+        EagleServiceConnector connector = mock(EagleServiceConnector.class);
+        EagleServiceBaseClient client = new EagleServiceClientImpl(connector);
+        String serviceName = client.getServiceNameByClass(TestEntity.class);
+        System.out.println(serviceName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/620959bb/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceGroupByQueryRequest.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceGroupByQueryRequest.java
 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceGroupByQueryRequest.java
new file mode 100644
index 0000000..d229fb6
--- /dev/null
+++ 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceGroupByQueryRequest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.eagle.service.client.impl;
+
+import junit.framework.Assert;
+import org.apache.eagle.service.client.EagleServiceClientException;
+import org.apache.eagle.service.client.EagleServiceGroupByQueryRequest;
+import org.junit.Test;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Since 11/18/16.
+ */
+public class TestEagleServiceGroupByQueryRequest {
+
+    @Test
+    public void testGetQueryString() throws EagleServiceClientException {
+        EagleServiceGroupByQueryRequest request = new 
EagleServiceGroupByQueryRequest();
+        request.setStartRowkey("rowkey");
+        request.setStartTime("2016-11-18 00:00:00 000");
+        request.setEndTime("2016-11-18 11:11:11 000");
+        request.setMetricName("metric");
+        request.setFilter("filter");
+        request.setPageSize(Integer.MAX_VALUE);
+        request.setIntervalMin(10);
+        List<String> groupBys = new ArrayList<>();
+        groupBys.add("field1");
+        groupBys.add("field2");
+        request.setGroupBys(groupBys);
+        List<String> orderBys = new ArrayList<>();
+        orderBys.add("field3");
+        orderBys.add("field3");
+        request.setOrderBys(orderBys);
+        List<String> returns = new ArrayList<>();
+        returns.add("field5");
+        returns.add("field6");
+        request.setReturns(returns);
+        
Assert.assertEquals("query=AuditService%5Bfilter%5D%3C%40field1%2C%40field2%3E%7Bfield5%2Cfield6%7D.%7Bfield3%2Cfield3%7D&startRowkey=rowkey&pageSize=2147483647&startTime=2016-11-18+00%3A00%3A00+000&endTime=2016-11-18+11%3A11%3A11+000&metricName=metric&timeSeries=true&intervalmin=10",
 request.getQueryParameterString("AuditService"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/620959bb/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceQueryBuilder.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceQueryBuilder.java
 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceQueryBuilder.java
new file mode 100644
index 0000000..8da2537
--- /dev/null
+++ 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestEagleServiceQueryBuilder.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.eagle.service.client.impl;
+
+import junit.framework.Assert;
+import org.apache.commons.lang3.time.DateUtils;
+import org.apache.eagle.service.client.EagleServiceQueryBuilder;
+import org.apache.eagle.service.client.EagleServiceQueryRequest;
+import org.junit.Test;
+
+/**
+ * @Since 11/17/16.
+ */
+public class TestEagleServiceQueryBuilder {
+
+    @Test
+    public void testEagleQuery() throws Exception {
+        EagleServiceQueryBuilder builder = new EagleServiceQueryBuilder();
+        
builder.setStartTime(0).setEndTime(DateUtils.MILLIS_PER_DAY).setPageSize(Integer.MAX_VALUE).addReturnField("field1").addReturnField("field2")
+            .addReturnTag("tag1").addSearchTag("tagKey", "tagValue");
+        EagleServiceQueryRequest request = builder.buildRequest();
+        
Assert.assertEquals("pageSize=2147483647&startTime=1970-01-01%2000:00:00&endTime=1970-01-02%2000:00:00&tagNameValue=tagKey%3DtagValue&outputTag=tag1&outputField=field1&outputField=field2",
 request.getQueryParameterString());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/620959bb/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestListQueryAPIReponseConvertHelper.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestListQueryAPIReponseConvertHelper.java
 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestListQueryAPIReponseConvertHelper.java
new file mode 100644
index 0000000..0fc5d2c
--- /dev/null
+++ 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestListQueryAPIReponseConvertHelper.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.eagle.service.client.impl;
+
+import junit.framework.Assert;
+import org.apache.eagle.log.entity.ListQueryAPIResponseEntity;
+import org.apache.eagle.log.entity.test.TestEntity;
+import org.apache.eagle.service.client.ListQueryAPIResponseConvertHelper;
+import org.junit.Test;
+
+import java.util.*;
+
+/**
+ * @Since 11/16/16.
+ */
+public class TestListQueryAPIReponseConvertHelper {
+
+    @Test
+    public void testConvert() throws Exception {
+        Map<String, Object> objectMap = new HashMap<>();
+        objectMap.put("prefix", "eagle");
+        objectMap.put("timestamp", 1479264382L);
+        objectMap.put("encodedRowkey", "rowkey");
+        Map<String, String> tags = new HashMap<>();
+        tags.put("field1", "value1");
+        objectMap.put("tags", tags);
+        objectMap.put("remediationID", "ID");
+        objectMap.put("remediationStatus", "status");
+        objectMap.put("count", 123456789L);
+        objectMap.put("numHosts", 9);
+        objectMap.put("numClusters", 123456789L);
+        List<Map<String, Object>> mapCollection = new ArrayList<Map<String, 
Object>>();
+        mapCollection.add(objectMap);
+        ListQueryAPIResponseEntity listQueryAPIResponseEntity = new 
ListQueryAPIResponseEntity();
+        listQueryAPIResponseEntity.setObj(mapCollection);
+        ListQueryAPIResponseConvertHelper listQueryAPIResponseConvertHelper = 
new ListQueryAPIResponseConvertHelper();
+        listQueryAPIResponseEntity = 
listQueryAPIResponseConvertHelper.convert(TestEntity.class, 
listQueryAPIResponseEntity);
+        List<TestEntity> objs = (List<TestEntity>) 
listQueryAPIResponseEntity.getObj();
+        TestEntity entity = objs.get(0);
+        Assert.assertEquals("eagle", entity.getPrefix());
+        Assert.assertEquals(1479264382L, entity.getTimestamp());
+        Assert.assertEquals("rowkey", entity.getEncodedRowkey());
+        Assert.assertEquals("ID", entity.getRemediationID());
+        Assert.assertEquals("status", entity.getRemediationStatus());
+        Assert.assertEquals(1, entity.getTags().size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/620959bb/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestQuery.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestQuery.java
 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestQuery.java
new file mode 100644
index 0000000..6365494
--- /dev/null
+++ 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestQuery.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.eagle.service.client.impl;
+
+import junit.framework.Assert;
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.eagle.service.client.EagleServiceConnector;
+import org.apache.eagle.service.client.EagleServiceSingleEntityQueryRequest;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.junit.Test;
+import static org.mockito.Mockito.*;
+
+import java.lang.reflect.Field;
+
+/**
+ * @Since 11/15/16.
+ */
+public class TestQuery {
+
+    @Test
+    public void testQuery() throws Exception {
+        EagleServiceConnector connector = mock(EagleServiceConnector.class);
+        IEagleServiceClient client = new EagleServiceClientImpl(connector);
+        String site = "sandbox";
+        String query = "AuditService" + 
"[@serviceName=\"AlertDataSourceService\" AND @site=\"" + site + "\"]{*}";
+        SearchRequestBuilder searchRequestBuilder = 
client.search().startRowkey("rowkey").startTime(0).endTime(10 * 
DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).filterIfMissing(true).metricName("metric").query(query);
+        Field requestField = 
SearchRequestBuilder.class.getDeclaredField("request");
+        requestField.setAccessible(true);
+        EagleServiceSingleEntityQueryRequest request = 
(EagleServiceSingleEntityQueryRequest) requestField.get(searchRequestBuilder);
+        String expected = 
"query=AuditService%5B%40serviceName%3D%22AlertDataSourceService%22+AND+%40site%3D%22sandbox%22%5D%7B*%7D&startRowkey=rowkey&pageSize=2147483647&startTime=1970-01-01%2000:00:00&endTime=1970-01-11%2000:00:00&treeAgg=false&metricName=metric&filterIfMissing=true";
+        Assert.assertEquals(expected, request.getQueryParameterString());
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/620959bb/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestRowkeyQueryAPIResponseConvertHelper.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestRowkeyQueryAPIResponseConvertHelper.java
 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestRowkeyQueryAPIResponseConvertHelper.java
new file mode 100644
index 0000000..9511181
--- /dev/null
+++ 
b/eagle-core/eagle-query/eagle-client-base/src/test/java/org/apache/eagle/service/client/impl/TestRowkeyQueryAPIResponseConvertHelper.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.eagle.service.client.impl;
+
+import junit.framework.Assert;
+import org.apache.eagle.log.entity.RowkeyQueryAPIResponseEntity;
+import org.apache.eagle.log.entity.test.TestEntity;
+import org.apache.eagle.service.client.RowkeyQueryAPIResponseConvertHelper;
+import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Since 11/17/16.
+ */
+public class TestRowkeyQueryAPIResponseConvertHelper {
+    @Test
+    public void testConvert() throws Exception {
+        Map<String, Object> objectMap = new HashMap<>();
+        objectMap.put("prefix", "eagle");
+        objectMap.put("timestamp", 1479264382L);
+        objectMap.put("encodedRowkey", "rowkey");
+        Map<String, String> tags = new HashMap<>();
+        tags.put("field1", "value1");
+        objectMap.put("tags", tags);
+        objectMap.put("remediationID", "ID");
+        objectMap.put("remediationStatus", "status");
+        objectMap.put("count", 123456789L);
+        objectMap.put("numHosts", 9);
+        objectMap.put("numClusters", 123456789L);
+        RowkeyQueryAPIResponseEntity rowkeyQueryAPIResponseEntity = new 
RowkeyQueryAPIResponseEntity();
+        rowkeyQueryAPIResponseEntity.setObj(objectMap);
+        RowkeyQueryAPIResponseConvertHelper 
rowkeyQueryAPIResponseConvertHelper = new RowkeyQueryAPIResponseConvertHelper();
+        rowkeyQueryAPIResponseEntity = 
rowkeyQueryAPIResponseConvertHelper.convert(TestEntity.class, 
rowkeyQueryAPIResponseEntity);
+        TestEntity entity = (TestEntity)rowkeyQueryAPIResponseEntity.getObj();
+        Assert.assertEquals("eagle", entity.getPrefix());
+        Assert.assertEquals(1479264382L, entity.getTimestamp());
+        Assert.assertEquals("rowkey", entity.getEncodedRowkey());
+        Assert.assertEquals("ID", entity.getRemediationID());
+        Assert.assertEquals("status", entity.getRemediationStatus());
+        Assert.assertEquals(1, entity.getTags().size());
+    }
+}

Reply via email to