Search in sources :

Example 1 with HistoryAwareSearchProvider

use of org.opennms.features.topology.api.support.HistoryAwareSearchProvider 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, GraphContainer)} 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), graphContainerMock);
    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), graphContainerMock);
    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), graphContainerMock);
    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()));
}
Also used : CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) HistoryAwareSearchProvider(org.opennms.features.topology.api.support.HistoryAwareSearchProvider) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 HistoryAwareSearchProvider (org.opennms.features.topology.api.support.HistoryAwareSearchProvider)1 Criteria (org.opennms.features.topology.api.topo.Criteria)1 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)1 AlarmHopCriteria (org.opennms.features.topology.app.internal.support.AlarmHopCriteria)1 CategoryHopCriteria (org.opennms.features.topology.app.internal.support.CategoryHopCriteria)1 IpLikeHopCriteria (org.opennms.features.topology.app.internal.support.IpLikeHopCriteria)1