use of org.opennms.features.topology.app.internal.support.CategoryHopCriteria in project opennms by OpenNMS.
the class CategorySearchProvider method addVertexHopCriteria.
@Override
public void addVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
CategoryHopCriteria criteria = createCriteria(searchResult);
container.addCriteria(criteria);
}
use of org.opennms.features.topology.app.internal.support.CategoryHopCriteria in project opennms by OpenNMS.
the class BundleContextHistoryManagerTest method initProvidersAndCriteria.
/**
* In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
*/
private void initProvidersAndCriteria() {
// Preparing SearchProviders
CategoryProvider vertexProvider = new CategoryProvider() {
@Override
public Collection<OnmsCategory> getAllCategories() {
return Lists.newArrayList(findCategoryByName("somename"));
}
@Override
public OnmsCategory findCategoryByName(String m_categoryName) {
OnmsCategory cat = new OnmsCategory("test", "test");
cat.setId(Integer.valueOf(idCategory));
return cat;
}
@Override
public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
return new ArrayList<>();
}
};
IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {
@Override
public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
OnmsNode node = new OnmsNode();
node.setId(Integer.valueOf(idIpLike));
String ipAddr = "127.0.0.1";
OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
return Lists.newArrayList(ipInterface);
}
};
AlarmProvider alarmProvider = new AlarmProvider() {
@Override
public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
Date eventTime = new Date();
OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
OnmsEvent event = new OnmsEvent();
OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
return Lists.newArrayList(alarm);
}
};
// Creating SearchResults to be used in testing
SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
// Initializing available (initial) SearchProviders
this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(vertexProvider));
this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
// Initializing available (initial) Criteria
this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider));
this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
use of org.opennms.features.topology.app.internal.support.CategoryHopCriteria in project opennms by OpenNMS.
the class BundleContextHistoryManagerTest method verifySearchCriteriaPersistence.
/**
* <p>This method tests the correctness of {@link org.opennms.features.topology.api.support.HistoryAwareSearchProvider#buildCriteriaFromQuery(SearchResult)} method.
* The {@link SearchCriteria} objects, generated by this method, are compared to those created directly, with the use of a corresponding constructor</p>
* <p>
* Additionally, it checks whether the {@link SavedHistory} objects are saved / loaded correctly and whether there is any data loss / distortion
* </p>
*/
@Test
public void verifySearchCriteriaPersistence() {
// Test 1 - checking whether method buildCriteriaFromQuery is working correctly
// Testing for CategoryHopCriteria & CategorySearchProvider
Criteria criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.category)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.category));
Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.category), criterionNew);
// Testing for IpLikeHopCriteria & IpLikeSearchProvider
criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.ipLike)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.ipLike));
Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.ipLike), criterionNew);
// Testing for AlarmHopCriteria & AlarmSearchProvider
criterionNew = ((HistoryAwareSearchProvider) this.startingProviders.get(CriteriaTypes.alarm)).buildCriteriaFromQuery(this.startingSearchResults.get(CriteriaTypes.alarm));
Assert.assertEquals(this.startingCriteria.get(CriteriaTypes.alarm), criterionNew);
// Step 1 - providing GraphContainer with a starting Criteria set
for (Criteria criteria : this.startingCriteria.values()) {
graphContainerMock.addCriteria(criteria);
}
// Saving and then loading history
String fragment = historyManager.saveOrUpdateHistory("admin", graphContainerMock);
historyManager.applyHistory(fragment, graphContainerMock);
Assert.assertNotNull(capturedCriteria);
Assert.assertThat(startingCriteria.values(), containsInAnyOrder(capturedCriteria.toArray()));
}
use of org.opennms.features.topology.app.internal.support.CategoryHopCriteria in project opennms by OpenNMS.
the class CategorySearchProvider method removeVertexHopCriteria.
@Override
public void removeVertexHopCriteria(SearchResult searchResult, GraphContainer container) {
CategoryHopCriteria criteria = createCriteria(searchResult);
container.removeCriteria(criteria);
}
Aggregations