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());
}
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);
}
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);
}
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());
}
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());
}
Aggregations