use of org.opennms.web.svclayer.model.AggregateStatus in project opennms by OpenNMS.
the class DefaultSiteStatusServiceTest method testCreateAggregateStatusUsingNodeId.
@Test
public void testCreateAggregateStatusUsingNodeId() {
Collection<AggregateStatus> aggrStati;
Collection<AggregateStatusDefinition> defs = new HashSet<>();
OnmsCategory catRouters = new OnmsCategory("routers");
OnmsCategory catSwitches = new OnmsCategory("switches");
AggregateStatusDefinition definition = new AggregateStatusDefinition("Routers/Switches", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { catRouters, catSwitches })));
defs.add(definition);
OnmsCategory catServers = new OnmsCategory("servers");
definition = new AggregateStatusDefinition("Servers", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { catServers })));
defs.add(definition);
DefaultSiteStatusViewService aggregateSvc = new DefaultSiteStatusViewService();
aggregateSvc.setNodeDao(m_nodeDao);
aggregateSvc.setCategoryDao(m_categoryDao);
aggregateSvc.setSiteStatusViewConfigDao(m_siteStatusViewConfigDao);
OnmsNode node = new OnmsNode();
node.setId(1);
node.getAssetRecord().setBuilding("HQ");
List<OnmsNode> nodes = new ArrayList<>();
nodes.add(node);
for (AggregateStatusDefinition def : defs) {
expect(m_nodeDao.findAllByVarCharAssetColumnCategoryList("building", "HQ", def.getCategories())).andReturn(nodes);
}
for (OnmsNode n : nodes) {
expect(m_nodeDao.load(n.getId())).andReturn(n);
}
replay(m_nodeDao);
expect(m_categoryDao.findByName("switches")).andReturn(catSwitches);
expect(m_categoryDao.findByName("routers")).andReturn(catRouters);
expect(m_categoryDao.findByName("servers")).andReturn(catServers);
replay(m_categoryDao);
List<RowDef> rows = new ArrayList<>();
RowDef rowDef = new RowDef();
Category category = new Category();
category.setName("servers");
rowDef.addCategory(category);
rows.add(rowDef);
rowDef = new RowDef();
category = new Category();
category.setName("switches");
rowDef.addCategory(category);
category = new Category();
category.setName("routers");
rowDef.addCategory(category);
rows.add(rowDef);
View view = new View();
view.setRows(rows);
expect(m_siteStatusViewConfigDao.getView("building")).andReturn(view);
replay(m_siteStatusViewConfigDao);
aggrStati = aggregateSvc.createAggregateStatusesUsingNodeId(node.getId(), "building");
verify(m_nodeDao);
verify(m_categoryDao);
verify(m_siteStatusViewConfigDao);
assertNotNull(aggrStati);
}
use of org.opennms.web.svclayer.model.AggregateStatus in project opennms by OpenNMS.
the class DefaultSiteStatusServiceTest method testCreateAggregateStatusUsingBuilding.
@Test
public void testCreateAggregateStatusUsingBuilding() {
Collection<AggregateStatus> aggrStati;
Collection<AggregateStatusDefinition> defs = new HashSet<>();
AggregateStatusDefinition definition = new AggregateStatusDefinition("Routers/Switches", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { new OnmsCategory("routers"), new OnmsCategory("switches") })));
defs.add(definition);
definition = new AggregateStatusDefinition("Servers", new HashSet<OnmsCategory>(Arrays.asList(new OnmsCategory[] { new OnmsCategory("servers") })));
defs.add(definition);
DefaultSiteStatusViewService aggregateSvc = new DefaultSiteStatusViewService();
aggregateSvc.setNodeDao(m_nodeDao);
OnmsNode node = new OnmsNode();
List<OnmsNode> nodes = new ArrayList<>();
nodes.add(node);
for (AggregateStatusDefinition def : defs) {
expect(m_nodeDao.findAllByVarCharAssetColumnCategoryList("building", "HQ", def.getCategories())).andReturn(nodes);
}
replay(m_nodeDao);
AggregateStatusView view = new AggregateStatusView();
view.setColumnName("building");
view.setColumnValue("HQ");
view.setTableName("assets");
view.setStatusDefinitions(new LinkedHashSet<AggregateStatusDefinition>(defs));
aggrStati = aggregateSvc.createAggregateStatusUsingAssetColumn(view);
verify(m_nodeDao);
assertNotNull(aggrStati);
}
use of org.opennms.web.svclayer.model.AggregateStatus in project opennms by OpenNMS.
the class NetworkElementFactory method getNodesWithCategories.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getNodesWithCategories(java.lang.String[], boolean)
*/
@Override
public List<OnmsNode> getNodesWithCategories(String[] categories, boolean onlyNodesWithDownAggregateStatus) {
List<OnmsNode> ourNodes = getNodesInCategories(categories);
if (onlyNodesWithDownAggregateStatus) {
AggregateStatus as = new AggregateStatus(new HashSet<OnmsNode>(ourNodes));
ourNodes = as.getDownNodes();
}
return ourNodes;
}
Aggregations