Search in sources :

Example 1 with Builder

use of org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.Builder in project opennms by OpenNMS.

the class BusinessServiceGraphImplTest method canCalculateVertexLevelForDeepHierarchy.

@Test
public void canCalculateVertexLevelForDeepHierarchy() {
    final String[][] BUSINESS_SERVICE_NAMES = new String[][] { { "b1" }, { "b2" }, { "b3", "c21", "c22" }, { "b4", "c31", "c32", "c33" }, { "b5", "c41" }, { "b6", "c51", "c52" }, { "b7", "c61" }, { "b8", "c71", "c72", "c73", "c74" }, { "b9", "c81", "c82" }, { "b10", "c91", "c92", "c93", "c94", "c95", "c96", "c97", "c98", "c99" }, { "b11", "c101" }, { "b12", "c111", "c112" }, { "b13", "c121" }, { "b14" } };
    // Build the hierarchy, linking every level to the left most business service
    // in the line above
    Map<Long, Integer> businessServiceIdToLevel = Maps.newHashMap();
    Builder builder = MockBusinessServiceHierarchy.builder();
    long k = 0;
    for (int level = 0; level < BUSINESS_SERVICE_NAMES.length; level++) {
        String[] servicesAtLevel = BUSINESS_SERVICE_NAMES[level];
        for (int i = servicesAtLevel.length - 1; i >= 0; i--) {
            builder = builder.withBusinessService(k).withName(servicesAtLevel[i]);
            businessServiceIdToLevel.put(k, level);
            k++;
            if (i != 0) {
                builder = builder.commit();
            }
        }
    }
    for (int level = 0; level < BUSINESS_SERVICE_NAMES.length; level++) {
        builder = builder.commit();
    }
    // Create the graph
    MockBusinessServiceHierarchy h = builder.build();
    BusinessServiceGraph graph = new BusinessServiceGraphImpl(h.getBusinessServices());
    // Verify
    for (Entry<Long, Integer> entry : businessServiceIdToLevel.entrySet()) {
        long id = entry.getKey();
        int expectedLevel = entry.getValue();
        assertEquals(expectedLevel, graph.getVertexByBusinessServiceId(id).getLevel());
    }
}
Also used : Builder(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.Builder) MockBusinessServiceHierarchy(org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy) BusinessServiceGraph(org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MockBusinessServiceHierarchy (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy)1 Builder (org.opennms.netmgt.bsm.mock.MockBusinessServiceHierarchy.Builder)1 BusinessServiceGraph (org.opennms.netmgt.bsm.service.model.graph.BusinessServiceGraph)1