Search in sources :

Example 6 with FacetedSearchResult

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;
}
Also used : FilteredSearchRequest(alien4cloud.rest.model.FilteredSearchRequest) AuditTrace(alien4cloud.audit.model.AuditTrace) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Example 7 with FacetedSearchResult

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);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Test(org.junit.Test)

Example 8 with FacetedSearchResult

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);
}
Also used : User(alien4cloud.security.model.User) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Example 9 with FacetedSearchResult

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);
        }
    }
}
Also used : Map(java.util.Map) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Then(cucumber.api.java.en.Then)

Example 10 with FacetedSearchResult

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);
}
Also used : FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Then(cucumber.api.java.en.Then)

Aggregations

FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)22 Then (cucumber.api.java.en.Then)6 FilteredSearchRequest (alien4cloud.rest.model.FilteredSearchRequest)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 Application (alien4cloud.model.application.Application)3 HashMap (java.util.HashMap)3 SneakyThrows (lombok.SneakyThrows)3 FacetedSearchFacet (alien4cloud.dao.model.FacetedSearchFacet)2 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)2 TestUtils.nullAsString (alien4cloud.it.utils.TestUtils.nullAsString)2 Deployment (alien4cloud.model.deployment.Deployment)2 Given (cucumber.api.java.en.Given)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Function (java.util.function.Function)2 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)2