use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class AuditLogStepsDefinitions method searchAuditLogs.
private List<AuditTrace> searchAuditLogs(String query, Integer from, int numberOfResult, Map<String, String[]> filters, boolean checkResultSize) throws IOException {
FilteredSearchRequest req = new FilteredSearchRequest(query, from, 10, filters);
String jSon = JsonUtil.toString(req);
String restResponse = Context.getRestClientInstance().postJSon("/rest/v1/audit/search", jSon);
FacetedSearchResult searchResult = JsonUtil.read(restResponse, FacetedSearchResult.class).getData();
if (checkResultSize) {
Assert.assertEquals(numberOfResult, searchResult.getTotalResults());
}
Object[] searchData = searchResult.getData();
List<AuditTrace> actualTraces = Lists.newArrayList();
for (Object jsonData : searchData) {
actualTraces.add(JsonUtil.readObject(JsonUtil.toString(jsonData), AuditTrace.class));
}
return actualTraces;
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class SearchTest method searchPostTest.
@Test
public void searchPostTest() {
String query = "positive";
RestResponse<FacetedSearchResult<? extends AbstractToscaType>> response;
ComponentSearchRequest req;
FacetedSearchResult data;
String[] ids;
// without filters
req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, null);
response = componentController.search(req);
assertNotNull(response);
assertNotNull(response.getData());
assertNull(response.getError());
data = response.getData();
assertEquals(2, data.getTotalResults());
assertEquals(2, data.getTypes().length);
assertEquals(2, data.getData().length);
ids = new String[] { indexedNodeTypeTest.getId(), indexedNodeTypeTest4.getId() };
for (int i = 0; i < data.getData().length; i++) {
NodeType idnt = (NodeType) data.getData()[i];
assertElementIn(idnt.getId(), ids);
}
// filter based test
Map<String, String[]> filters = new HashMap<String, String[]>();
filters.put("capabilities.type", new String[] { "container", "banana" });
req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, filters);
response = componentController.search(req);
assertNotNull(response);
assertNotNull(response.getData());
assertNull(response.getError());
data = response.getData();
assertEquals(1, data.getTotalResults());
assertEquals(1, data.getTypes().length);
assertEquals(1, data.getData().length);
NodeType idnt = (NodeType) data.getData()[0];
assertElementIn(idnt.getId(), new String[] { indexedNodeTypeTest.getId() });
// test nothing found
query = "pacpac";
req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, null);
response = componentController.search(req);
assertNotNull(response);
assertNotNull(response.getData());
assertNull(response.getError());
data = response.getData();
assertNotNull(data.getTypes());
assertEquals(0, data.getTotalResults());
assertEquals(0, data.getData().length);
assertEquals(0, data.getTypes().length);
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class InMemoryUserDao method search.
@Override
public FacetedSearchResult search(String searchQuery, String group, int from, int size) {
List<User> userList = Lists.newArrayList();
for (User user : userMap.values()) {
if (user.getUsername().startsWith(searchQuery)) {
userList.add(user);
}
}
User[] users = userList.toArray(new User[userList.size()]);
String[] types = new String[users.length];
for (int i = 0; i < types.length; i++) {
types[i] = User.class.getName();
}
Map<String, FacetedSearchFacet[]> facets = Maps.newHashMap();
return new FacetedSearchResult(0, users.length, 0, users.length, types, users, facets);
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class MixingComponentVersionsDefinitionsSteps method The_response_should_contains_elements_from_various_types_of_version_and_older_versions_are.
@Then("^The response should contains (\\d+) elements from various types of version \"([^\"]*)\" and older versions are$")
public void The_response_should_contains_elements_from_various_types_of_version_and_older_versions_are(int expectedElementSize, String expectedVersion, List<String> expectedOlderVersions) throws Throwable {
Set<String> expectedOlderVersionsSet = (expectedOlderVersions == null) ? null : Sets.newHashSet(expectedOlderVersions);
SearchDefinitionSteps searchDefinitionSteps = new SearchDefinitionSteps();
searchDefinitionSteps.The_response_should_contains_elements_from_various_types(expectedElementSize);
RestResponse<FacetedSearchResult> restResponse = JsonUtil.read(Context.getInstance().getRestResponse(), FacetedSearchResult.class);
FacetedSearchResult searchResp = restResponse.getData();
Object[] elements = searchResp.getData();
for (int i = 0; i < expectedElementSize; i++) {
Map<String, Object> element = (Map<String, Object>) elements[i];
Assert.assertEquals(expectedVersion, element.get("archiveVersion"));
Set<String> actualOlderVersions = getComponentVersions((String) element.get("elementId"));
actualOlderVersions.remove(expectedVersion);
if (CollectionUtils.isEmpty(expectedOlderVersions)) {
Assert.assertTrue(actualOlderVersions.isEmpty());
} else {
Assert.assertEquals(expectedOlderVersionsSet, actualOlderVersions);
}
}
}
use of alien4cloud.dao.model.FacetedSearchResult in project alien4cloud by alien4cloud.
the class SearchDefinitionSteps method The_response_should_contains_.
@Then("^The response should contains (\\d+) \"([^\"]*)\".$")
public void The_response_should_contains_(int expectedSize, String searchedComponentType) throws Throwable {
RestResponse<FacetedSearchResult> restResponse = JsonUtil.read(Context.getInstance().getRestResponse(), FacetedSearchResult.class);
FacetedSearchResult searchResp = restResponse.getData();
assertNotNull(searchResp);
assertNotNull(searchResp.getTypes());
assertNotNull(searchResp.getData());
assertTrue(searchResp.getTypes().length >= expectedSize);
assertTrue(searchResp.getData().length >= expectedSize);
// check result types
List<String> resultTypes = Lists.newArrayList(searchResp.getTypes());
int count = 0;
for (String type : resultTypes) {
count = type.equals(indexedComponentTypes.get(searchedComponentType)) ? count += 1 : count;
}
assertEquals("There should be " + expectedSize + " " + searchedComponentType + " in result.", expectedSize, count);
}
Aggregations