use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class EsDaoPaginatedSearchTest method saveDataToES.
private void saveDataToES() throws IOException, IndexingServiceException {
testDataList.clear();
Path path = Paths.get("src/test/resources/nodetypes-faceted-search-result.json");
FacetedSearchResult res = jsonMapper.readValue(path.toFile(), FacetedSearchResult.class);
Object[] data = res.getData();
for (Object element : data) {
String serializeDatum = jsonMapper.writeValueAsString(element);
NodeType indexedNodeType = jsonMapper.readValue(serializeDatum, NodeType.class);
indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
String typeName = MappingBuilder.indexTypeFromClass(NodeType.class);
dao.save(indexedNodeType);
assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName, indexedNodeType.getId(), true);
testDataList.add(indexedNodeType);
for (CapabilityDefinition capaDef : indexedNodeType.getCapabilities()) {
if (capaDef.getType().equals("jndi")) {
jndiTestDataList.add(indexedNodeType);
}
}
}
refresh();
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class EsDaoPaginatedSearchTest method facetedSearchPaginatedTest.
// @Ignore
@Test
public void facetedSearchPaginatedTest() throws IndexingServiceException, IOException, InterruptedException {
String searchText = "jndi";
int maxElement = getCount(QueryBuilders.matchPhrasePrefixQuery("_all", searchText).maxExpansions(10));
int size = 7;
// simple faceted pagination
assertTrue(maxElement > 0);
testFacetedSearchWellPaginated(maxElement, size, searchText, null, null);
// faceted search with filters
FilterBuilder filter = FilterBuilders.termFilter("capabilities.type", "jndi");
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
queryBuilder = QueryBuilders.filteredQuery(queryBuilder, filter);
maxElement = getCount(queryBuilder);
Map<String, String[]> filters = new HashMap<String, String[]>();
filters.put("capabilities.type", new String[] { "jndi" });
assertTrue(maxElement > 0);
testFacetedSearchWellPaginated(maxElement, size, searchText, filters, FetchContext.SUMMARY);
// test nothing found
// test when nothing found
searchText = "pacpac";
maxElement = getCount(QueryBuilders.matchPhrasePrefixQuery("_all", searchText).maxExpansions(10));
assertEquals(0, maxElement);
GetMultipleDataResult<NodeType> searchResp = dao.facetedSearch(NodeType.class, searchText, null, null, 0, size);
assertNotNull(searchResp);
assertNotNull(searchResp.getData());
assertNotNull(searchResp.getTypes());
assertEquals(0, searchResp.getData().length);
assertEquals(0, searchResp.getTypes().length);
}
use of org.alien4cloud.tosca.model.types.NodeType 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 org.alien4cloud.tosca.model.types.NodeType 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 org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class EsDaoSuggestionTest method saveDataToES.
private void saveDataToES(boolean refresh) throws JsonProcessingException {
for (NodeType datum : dataTest) {
String json = jsonMapper.writeValueAsString(datum);
String typeName = MappingBuilder.indexTypeFromClass(datum.getClass());
nodeClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(json).setRefresh(refresh).execute().actionGet();
assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName, datum.getId(), true);
}
refresh();
}
Aggregations