use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class JtiTelemetryIT method sendnewSuspectEvent.
public static OnmsNode sendnewSuspectEvent(Executor executor, InetSocketAddress opennmsHttp, TestEnvironment m_testEnvironment, boolean isMinion, Date startOfTest) throws ClientProtocolException, IOException {
Event minionEvent = new Event();
minionEvent.setUei("uei.opennms.org/internal/discovery/newSuspect");
minionEvent.setHost(SENDER_IP);
minionEvent.setInterface(SENDER_IP);
minionEvent.setInterfaceAddress(Inet4Address.getByName(SENDER_IP));
minionEvent.setSource("system-test");
minionEvent.setSeverity("4");
if (isMinion) {
Parm parm = new Parm();
parm.setParmName("location");
Value minion = new Value("MINION");
parm.setValue(minion);
List<Parm> parms = new ArrayList<>();
parms.add(parm);
minionEvent.setParmCollection(parms);
}
String xmlString = JaxbUtils.marshal(minionEvent);
executor.execute(Request.Post(String.format("http://%s:%d/opennms/rest/events", opennmsHttp.getAddress().getHostAddress(), opennmsHttp.getPort())).bodyString(xmlString, ContentType.APPLICATION_XML)).returnContent();
InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
EventDao eventDao = daoFactory.getDao(EventDaoHibernate.class);
NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
Criteria criteria = new CriteriaBuilder(OnmsEvent.class).eq("eventUei", EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI).ge("eventTime", startOfTest).eq("ipAddr", Inet4Address.getByName(SENDER_IP)).toCriteria();
await().atMost(1, MINUTES).pollInterval(10, SECONDS).until(DaoUtils.countMatchingCallable(eventDao, criteria), greaterThan(0));
final OnmsNode onmsNode = await().atMost(1, MINUTES).pollInterval(5, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).eq("label", SENDER_IP).ge("createTime", startOfTest).toCriteria()), notNullValue());
assertNotNull(onmsNode);
if (isMinion) {
assertThat(onmsNode.getLocation().getLocationName(), is("MINION"));
}
LOG.info(" New suspect event has been sent and node has been created for IP : {}", SENDER_IP);
return onmsNode;
}
use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class NxosTelemetryIT method addRequisition.
public static OnmsNode addRequisition(InetSocketAddress opennmsHttp, boolean isMinion, Date startOfTest) {
RestClient client = new RestClient(opennmsHttp);
Requisition requisition = new Requisition("telemetry");
List<RequisitionInterface> interfaces = new ArrayList<>();
RequisitionInterface requisitionInterface = new RequisitionInterface();
requisitionInterface.setIpAddr("192.168.0.1");
requisitionInterface.setManaged(true);
requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
interfaces.add(requisitionInterface);
RequisitionNode node = new RequisitionNode();
String label = "nexus9k";
node.setNodeLabel(label);
node.setForeignId("nxos");
node.setInterfaces(interfaces);
if (isMinion) {
// For a requisition, foreignId needs to be unique, change foreignId
node.setLocation("MINION");
node.setForeignId("nexus9k");
// Change label so that node matches with foreignId
label = "nxos";
node.setNodeLabel(label);
}
requisition.insertNode(node);
client.addOrReplaceRequisition(requisition);
client.importRequisition("telemetry");
InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
final OnmsNode onmsNode = await().atMost(3, MINUTES).pollInterval(30, SECONDS).until(DaoUtils.findMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).ge("createTime", startOfTest).eq("label", label).toCriteria()), notNullValue());
assertNotNull(onmsNode);
return onmsNode;
}
use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class MinionHeartbeatOutageIT method getDaoFactory.
protected HibernateDaoFactory getDaoFactory() {
if (m_daoFactory == null) {
// Connect to the postgresql container
final InetSocketAddress pgsql = testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
m_daoFactory = new HibernateDaoFactory(pgsql);
}
return m_daoFactory;
}
use of org.opennms.smoketest.utils.HibernateDaoFactory in project opennms by OpenNMS.
the class AbstractNodeRestServiceTest method verifyCreationWithAssetRecord.
// See NMS-9855
@Test
public void verifyCreationWithAssetRecord() {
final String node = "<node type=\"A\" label=\"TestMachine1\" foreignSource=\"SmokeTests\" foreignId=\"TestMachine1\">" + "<assetRecord>" + "<description>Right here, right now</description>" + "</assetRecord>" + "<labelSource>H</labelSource>" + "<sysContact>The Owner</sysContact>" + "<sysDescription>" + "Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun 9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386" + "</sysDescription>" + "<sysLocation>DevJam</sysLocation>" + "<sysName>TestMachine1</sysName>" + "<sysObjectId>.1.3.6.1.4.1.8072.3.2.255</sysObjectId>" + "<createTime>2011-09-24T07:12:46.421-04:00</createTime>" + "<lastCapsdPoll>2011-09-24T07:12:46.421-04:00</lastCapsdPoll>" + "</node>";
given().body(node).contentType(ContentType.XML).post().then().assertThat().statusCode(201);
// Verify that only one asset record has been created
final HibernateDaoFactory daoFactory = new HibernateDaoFactory(getPostgresService());
final AssetRecordDao dao = daoFactory.getDao(AssetRecordDaoHibernate.class);
assertThat(dao.countAll(), is(1));
// Ensure we can get nodes with asset records attached
given().get().then().log().all().and().assertThat().statusCode(200);
}
Aggregations