Search in sources :

Example 1 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class EsDaoPaginatedSearchTest method testTextBasedSearchWellPaginated.

private void testTextBasedSearchWellPaginated(int maxElement, int size, String searchText, Map<String, String[]> filters) throws IOException {
    List<NodeType> expectedDataList = new ArrayList<>(jndiTestDataList);
    GetMultipleDataResult searchResp;
    int expectedSize;
    for (int from = 0; from < maxElement; from += size) {
        expectedSize = (maxElement - from) > size ? size : maxElement - from;
        searchResp = dao.search(NodeType.class, searchText, filters, from, size);
        assertNotNull(searchResp);
        assertNotNull(searchResp.getTypes());
        assertNotNull(searchResp.getData());
        assertEquals(expectedSize, searchResp.getTypes().length);
        assertEquals(expectedSize, searchResp.getData().length);
        // testing the pertinence of returned data
        Object[] data = searchResp.getData();
        for (Object element : data) {
            NodeType nt = jsonMapper.readValue(jsonMapper.writeValueAsString(element), NodeType.class);
            assertTrue(expectedDataList.contains(nt));
            expectedDataList.remove(nt);
        }
    }
    // assert the list is empty at the end.
    assertTrue(expectedDataList.isEmpty());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) ArrayList(java.util.ArrayList) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult)

Example 2 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class EsDaoSearchTest method textBasedSearch.

@Test
public void textBasedSearch() throws IndexingServiceException, JsonParseException, JsonMappingException, IOException, InterruptedException {
    // text search based
    String searchText = "positive";
    GetMultipleDataResult searchResp = dao.search(NodeType.class, searchText, null, 10);
    assertNotNull(searchResp);
    assertEquals(2, searchResp.getTypes().length);
    assertEquals(2, searchResp.getData().length);
    String[] ids = new String[] { indexedNodeTypeTest.getId(), indexedNodeTypeTest4.getId() };
    for (int i = 0; i < searchResp.getData().length; i++) {
        NodeType idnt = (NodeType) searchResp.getData()[i];
        assertElementIn(idnt.getId(), ids);
    }
    // text search based with filters
    Map<String, String[]> filters = new HashMap<String, String[]>();
    filters.put("capabilities.type", new String[] { "container" });
    searchResp = dao.search(NodeType.class, searchText, filters, 10);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getTypes());
    assertNotNull(searchResp.getData());
    assertEquals(1, searchResp.getTypes().length);
    assertEquals(1, searchResp.getData().length);
    NodeType idnt = (NodeType) searchResp.getData()[0];
    assertElementIn(idnt.getElementId(), new String[] { "1" });
    // test nothing found
    searchText = "pacpac";
    searchResp = dao.search(NodeType.class, searchText, null, 10);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getData());
    assertNotNull(searchResp.getTypes());
    assertEquals(0, searchResp.getData().length);
    assertEquals(0, searchResp.getTypes().length);
}
Also used : HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 3 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class EsDaoSearchTest method searchInTagsTest.

@Test
public void searchInTagsTest() throws IndexingServiceException, InterruptedException, IOException {
    // test simple find all search
    GetMultipleDataResult searchResp = dao.find(NodeType.class, null, 10);
    assertNotNull(searchResp);
    assertEquals(4, searchResp.getTypes().length);
    assertEquals(4, searchResp.getData().length);
    // test simple find with filters
    Map<String, String[]> filters = new HashMap<String, String[]>();
    filters.put("tags", new String[] { "My" });
    searchResp = dao.find(NodeType.class, filters, 10);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getTypes());
    assertNotNull(searchResp.getData());
    assertEquals(4, searchResp.getTypes().length);
    assertEquals(4, searchResp.getData().length);
}
Also used : HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 4 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class EsDaoSuggestionTest method simpleSearchTest.

@Test
public void simpleSearchTest() throws IndexingServiceException, InterruptedException, IOException {
    String searchText = "ver";
    GetMultipleDataResult searchResp = dao.suggestSearch(new String[] { APPLICATION_INDEX, ElasticSearchDAO.TOSCA_ELEMENT_INDEX }, new Class<?>[] { Application.class, NodeType.class, ArtifactType.class, CapabilityType.class, RelationshipType.class }, TAG_NAME_PATH, searchText, FetchContext.TAG_SUGGESTION, 0, 10);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getTypes());
    assertNotNull(searchResp.getData());
    assertEquals(2, searchResp.getTypes().length);
    assertEquals(2, searchResp.getData().length);
    assertElementIn("nodetype", searchResp.getTypes());
}
Also used : GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 5 with GetMultipleDataResult

use of alien4cloud.dao.model.GetMultipleDataResult in project alien4cloud by alien4cloud.

the class NodeTypeScoreServiceTest method testScoreService.

@Test
public void testScoreService() throws InterruptedException {
    // Initialize test data
    NodeType indexedNodeType = new NodeType();
    indexedNodeType.setElementId("mordor");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("very_evil"));
    dao.save(indexedNodeType);
    String mordor100Id = indexedNodeType.getId();
    indexedNodeType.setArchiveVersion("1.0.1");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("deprecated_evil"));
    dao.save(indexedNodeType);
    String mordor101Id = indexedNodeType.getId();
    indexedNodeType.setElementId("isengard");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(null);
    dao.save(indexedNodeType);
    String isengard100Id = indexedNodeType.getId();
    indexedNodeType.setElementId("isengard");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.1");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(Lists.newArrayList("evil"));
    dao.save(indexedNodeType);
    String isengard101Id = indexedNodeType.getId();
    Topology topology = new Topology();
    topology.setId("topology");
    topology.setArchiveName("test-archive");
    topology.setArchiveVersion("1.0.0");
    topology.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
    topology.setDependencies(Sets.newHashSet(new CSARDependency("middleEarth", "1.0.1")));
    topology.setNodeTemplates(MapUtil.newHashMap(new String[] { "isengard" }, new NodeTemplate[] { new NodeTemplate(indexedNodeType.getElementId(), null, null, null, null, null, null, null) }));
    dao.save(topology);
    indexedNodeType.setElementId("osgiliath");
    indexedNodeType.setArchiveName("middleEarth");
    indexedNodeType.setArchiveVersion("1.0.0");
    indexedNodeType.setCreationDate(new Date());
    indexedNodeType.setLastUpdateDate(new Date());
    indexedNodeType.setDefaultCapabilities(null);
    dao.save(indexedNodeType);
    String osgiliath100Id = indexedNodeType.getId();
    // perform scoring
    scoreService.run();
    // check that order on query is correct
    GetMultipleDataResult data = dao.search(NodeType.class, "", null, AlienConstants.DEFAULT_ES_SEARCH_SIZE);
    Assert.assertEquals(5, data.getData().length);
    Assert.assertEquals(isengard101Id, ((NodeType) data.getData()[0]).getId());
    Assert.assertEquals(1011, ((NodeType) data.getData()[0]).getAlienScore());
    Assert.assertEquals(mordor101Id, ((NodeType) data.getData()[1]).getId());
    Assert.assertEquals(1010, ((NodeType) data.getData()[1]).getAlienScore());
    Assert.assertEquals(osgiliath100Id, ((NodeType) data.getData()[2]).getId());
    Assert.assertEquals(1000, ((NodeType) data.getData()[2]).getAlienScore());
    Assert.assertEquals(mordor100Id, ((NodeType) data.getData()[3]).getId());
    Assert.assertEquals(10, ((NodeType) data.getData()[3]).getAlienScore());
    Assert.assertEquals(isengard100Id, ((NodeType) data.getData()[4]).getId());
    Assert.assertEquals(0, ((NodeType) data.getData()[4]).getAlienScore());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Date(java.util.Date) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Aggregations

GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)32 Test (org.junit.Test)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ApiOperation (io.swagger.annotations.ApiOperation)7 HashMap (java.util.HashMap)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 Application (alien4cloud.model.application.Application)4 User (alien4cloud.security.model.User)4 Then (cucumber.api.java.en.Then)4 Location (alien4cloud.model.orchestrators.locations.Location)3 IdsFilterBuilder (org.elasticsearch.index.query.IdsFilterBuilder)3 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)2 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)2 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)2 FilteredSearchRequest (alien4cloud.rest.model.FilteredSearchRequest)2 Group (alien4cloud.security.model.Group)2 Arrays (java.util.Arrays)2 Resource (javax.annotation.Resource)2