use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class CategoryRestServiceIT method testUpdateCategory.
@Test
@JUnitTemporaryDatabase
public void testUpdateCategory() throws Exception {
// create
OnmsCategory createMe = new OnmsCategory();
createMe.setDescription("This is a description");
createMe.setName("myName");
createCategory(createMe);
// verify creation
String url = "/categories";
String xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("<description>This is a description</description>"));
assertTrue(xml.contains("name=\"myName\""));
// change
url += "/myName";
sendPut(url, "description=My Equipment&name=NewCategory", 204);
xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("<description>My Equipment</description>"));
assertTrue(xml.contains("name=\"NewCategory\""));
xml = sendRequest(DELETE, url, 204);
assertFalse(xml.contains("<description>My Equipment</description>"));
assertFalse(xml.contains("name=\"NewCategory\""));
assertFalse(xml.contains("name=\"myName\""));
assertFalse(xml.contains("<description>This is a description</description>"));
sendRequest(GET, url, 200);
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class SnmpAssetProvisioningAdapterIT method testAdd.
@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
@JUnitSnmpAgent(resource = "snmpAssetTestData.properties")
public void testAdd() throws Exception {
AdapterOperationChecker verifyOperations = new AdapterOperationChecker(1);
m_adapter.getOperationQueue().addListener(verifyOperations);
OnmsNode n = m_nodeDao.findByForeignId("rancid", "1");
assertNotNull(n);
m_adapter.addNode(n.getId());
assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(n.getId()).size());
// TODO: Add assertions to check that the addNode() adapter call updated the asset record
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class SnmpAssetProvisioningAdapterFullIT method testAddSameOperationTwice.
@Test
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testAddSameOperationTwice() throws InterruptedException {
AdapterOperationChecker verifyOperations = new AdapterOperationChecker(2);
m_adapter.getOperationQueue().addListener(verifyOperations);
try {
OnmsNode node = m_nodeDao.get(NODE_ID);
assertNotNull(node);
int firstNodeId = node.getId();
m_adapter.addNode(firstNodeId);
// should get deduplicated
m_adapter.addNode(firstNodeId);
m_adapter.updateNode(firstNodeId);
assertTrue(verifyOperations.enqueueLatch.await(4, TimeUnit.SECONDS));
assertTrue(verifyOperations.dequeueLatch.await(4, TimeUnit.SECONDS));
assertTrue(verifyOperations.executeLatch.await(4, TimeUnit.SECONDS));
assertEquals(0, m_adapter.getOperationQueue().getOperationQueueForNode(firstNodeId).size());
node = m_nodeDao.get(firstNodeId);
assertNotNull(node);
System.out.println("ID: " + node.getAssetRecord().getId());
System.out.println("Comment: " + node.getAssetRecord().getComment());
assertNotNull("AssetRecord comment is null", node.getAssetRecord().getComment());
assertEquals(EXPECTED_COMMENT_FIELD, node.getAssetRecord().getComment());
} finally {
m_adapter.getOperationQueue().removeListener(verifyOperations);
}
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class MigratorIT method testUpdate.
@Test
@JUnitTemporaryDatabase(createSchema = false)
public void testUpdate() throws Exception {
// Make sure there is no databasechangelog table
assertFalse(changelogExists());
Resource aResource = null;
for (final Resource resource : getTestResources()) {
URI uri = resource.getURI();
if (uri.getScheme().equals("file") && uri.toString().contains("test-api/schema/a")) {
aResource = resource;
}
if (uri.getScheme().equals("jar") && uri.toString().contains("test-api.schema.a")) {
aResource = resource;
}
}
assertNotNull("aResource must not be null", aResource);
Set<String> tables = getTables();
assertFalse("must not contain table 'schematest'", tables.contains("schematest"));
final Migration migration = new Migration();
migration.setAdminUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setAdminPassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setDatabaseUser(System.getProperty(TemporaryDatabase.ADMIN_USER_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_USER));
migration.setDatabasePassword(System.getProperty(TemporaryDatabase.ADMIN_PASSWORD_PROPERTY, TemporaryDatabase.DEFAULT_ADMIN_PASSWORD));
migration.setChangeLog("changelog.xml");
migration.setAccessor(new ExistingResourceAccessor(aResource));
LOG.info("Running migration on database: {}", migration);
final Migrator m = new Migrator();
m.setDataSource(m_dataSource);
m.setAdminDataSource(m_dataSource);
m.setValidateDatabaseVersion(false);
m.setCreateUser(false);
m.setCreateDatabase(false);
m.prepareDatabase(migration);
m.migrate(migration);
LOG.info("Migration complete: {}", migration);
tables = getTables();
assertTrue("must contain table 'schematest'", tables.contains("schematest"));
}
use of org.opennms.core.test.db.annotations.JUnitTemporaryDatabase in project opennms by OpenNMS.
the class NodeRestServiceIT method testLimits.
@Test
@JUnitTemporaryDatabase
public void testLimits() throws Exception {
JAXBContext context = JAXBContext.newInstance(OnmsNodeList.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
// Testing POST
for (m_nodeCounter = 0; m_nodeCounter < 20; m_nodeCounter++) {
createNode();
}
String url = "/nodes";
// Testing GET Collection
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("limit", "10");
parameters.put("orderBy", "id");
String xml = sendRequest(GET, url, parameters, 200);
assertTrue(xml, xml.contains("Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0"));
Pattern p = Pattern.compile("<node [^>]*\\s*id=", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE);
Matcher m = p.matcher(xml);
int count = 0;
while (m.find()) {
count++;
}
assertEquals("should get 10 nodes back", 10, count);
// Validate object by unmarshalling
OnmsNodeList list = (OnmsNodeList) unmarshaller.unmarshal(new StringReader(xml));
assertEquals(Integer.valueOf(10), list.getCount());
assertEquals(10, list.size());
assertEquals(Integer.valueOf(20), list.getTotalCount());
int i = 0;
Set<OnmsNode> sortedNodes = new TreeSet<OnmsNode>(new Comparator<OnmsNode>() {
@Override
public int compare(OnmsNode o1, OnmsNode o2) {
if (o1 == null && o2 == null) {
return 0;
} else if (o1 == null) {
return 1;
} else if (o2 == null) {
return -1;
} else {
if (o1.getId() == null) {
throw new IllegalStateException("Null ID on node: " + o1.toString());
}
return o1.getId().compareTo(o2.getId());
}
}
});
// Sort the nodes by ID
sortedNodes.addAll(list.getObjects());
for (OnmsNode node : sortedNodes) {
assertEquals(node.toString(), "TestMachine" + i++, node.getLabel());
}
}
Aggregations