@Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetDataLinksOnNode() throws SQLException {
    List<LinkInterface> dlis =
        NetworkElementFactory.getInstance(m_appContext)
            .getDataLinksOnNode(m_dbPopulator.getNode1().getId());
    assertEquals(5, dlis.size());

    List<LinkInterface> dlis2 =
        NetworkElementFactory.getInstance(m_appContext).getDataLinksOnNode(100);
    assertEquals(0, dlis2.size());
  }
  @Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetAtInterfaces() throws Exception {
    AtInterface atif =
        NetworkElementFactory.getInstance(m_appContext)
            .getAtInterface(m_dbPopulator.getNode2().getId(), "192.168.2.1");
    assertEquals("AA:BB:CC:DD:EE:FF", atif.get_physaddr());

    List<OnmsNode> nodes =
        NetworkElementFactory.getInstance(m_appContext).getNodesFromPhysaddr("AA:BB:CC:DD:EE:FF");
    assertEquals(1, nodes.size());
  }
  @Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetNodeLabel() throws SQLException {
    String nodeLabel = NetworkElementFactory.getInstance(m_appContext).getNodeLabel(1);

    assertEquals(nodeLabel, "node1");
  }
 @Test
 @JUnitTemporaryDatabase
 public void testGetServicesOnInterface() {
   m_jdbcTemplate.update("UPDATE ifservices SET status='A' WHERE id=2;");
   Service[] svc =
       NetworkElementFactory.getInstance(m_appContext).getServicesOnInterface(1, "192.168.1.1");
   assertEquals(1, svc.length);
 }
 @Test
 @Transactional
 @JUnitTemporaryDatabase
 public void testGetActiveInterfacesOnNode() {
   Interface[] intfs =
       NetworkElementFactory.getInstance(m_appContext)
           .getActiveInterfacesOnNode(m_dbPopulator.getNode1().getId());
   assertEquals("active interfaces", 4, intfs.length);
 }
  @Test
  @JUnitTemporaryDatabase
  public void testGetIpPrimaryAddress() throws SQLException {
    m_jdbcTemplate.update(
        "INSERT INTO node (nodeId, nodeCreateTime, nodeType, nodeLabel) VALUES (12, now(), 'A', 'nodeLabel')");
    m_jdbcTemplate.update(
        "INSERT INTO ipinterface (nodeid, ipaddr, iplastcapsdpoll, issnmpprimary) VALUES (12, '172.168.1.1', now(), 'P')");

    String ipAddr = NetworkElementFactory.getInstance(m_appContext).getIpPrimaryAddress(12);

    assertEquals(ipAddr, "172.168.1.1");
  }
  @Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetInterfacesWithIpAddress() throws Exception {
    Interface[] interfaces =
        NetworkElementFactory.getInstance(m_appContext)
            .getInterfacesWithIpAddress("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%5");
    assertEquals("interface count", 1, interfaces.length);
    assertEquals("node ID", m_dbPopulator.getNode1().getId().intValue(), interfaces[0].getNodeId());
    assertEquals("ifIndex", 4, interfaces[0].getIfIndex());

    interfaces =
        NetworkElementFactory.getInstance(m_appContext)
            .getInterfacesWithIpAddress("fe80:0000:0000:0000:aaaa:bbbb:cccc:0001%5");
    assertEquals("interface count", 0, interfaces.length);

    interfaces =
        NetworkElementFactory.getInstance(m_appContext)
            .getInterfacesWithIpAddress("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%4");
    assertEquals("interface count", 0, interfaces.length);
  }
  @Test
  @Transactional
  @JUnitTemporaryDatabase
  public void testGetNodesWithIpLikeOneInterface() throws Exception {
    // setUp() creates nodes by default, start with a clean slate
    for (final OnmsNode node : m_nodeDao.findAll()) {
      m_nodeDao.delete(node);
    }
    m_nodeDao.flush();

    m_jdbcTemplate.update(
        "INSERT INTO node (nodeId, nodeCreateTime, nodeType) VALUES (12, now(), 'A')");
    m_jdbcTemplate.update(
        "INSERT INTO ipInterface (nodeId, ipAddr, isManaged) VALUES (12, '1.1.1.1', 'M')");

    final List<OnmsNode> nodes =
        NetworkElementFactory.getInstance(m_appContext).getNodesWithIpLike("*.*.*.*");
    assertEquals("node count", 1, nodes.size());
  }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    javax.servlet.jsp.PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;

    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html;charset=ISO-8859-1");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\n\n");
      out.write("\n\n");

      // Get required parameter(s)
      String nodeIdStr = request.getParameter("node");
      if (nodeIdStr == null) throw new org.opennms.web.MissingParameterException("node");
      int nodeId = Integer.parseInt(nodeIdStr);
      String nodeLabel = org.opennms.web.element.NetworkElementFactory.getNodeLabel(nodeId);
      Node node_db = NetworkElementFactory.getNode(nodeId);
      String orgName = node_db.getOrganizationName();
      Asset asset = this.model.getAsset(nodeId);
      boolean isNew = false;

      if (asset == null) {
        asset = new Asset();
        isNew = true;
      }

      Vector vCategories = WTProperties.getList("AssetCategories.list");

      out.write("\n\n");
      out.write("<html>\n");
      out.write("<head>\n\t");
      out.write("<title>WebTelemetry - Node Assets | System Info for ");
      out.print(node_db.getLabel());
      out.write("</title>\n\t");
      out.write("<base HREF=\"");
      out.print(org.opennms.web.Util.calculateUrlBase(request));
      out.write("\" />\n\t");
      out.write(
          "<link rel=\"stylesheet\" type=\"text/css\" href=\"/wt-portal/css/default.css\" />\n\t");
      out.write("<script type=\"text/javascript\" src=\"/wt-portal/javascript/WTtools.js\">");
      out.write("</script>\n");
      out.write("</head>\n\n");
      out.write("<body>\n\t");
      out.write("<!-- Header -->\n\t");
      String title = "Asset - Vendor Info for Node: " + node_db.getLabel() + " (" + orgName + ")";
      out.write("\n\t");
      JspRuntimeLibrary.include(
          request,
          response,
          "/includes/tabheader.jsp"
              + "?"
              + "title="
              + java.net.URLEncoder.encode("" + title)
              + "&"
              + "refresh="
              + "1"
              + "&"
              + "helpURL="
              + "assetmanager%2FWTHelp_AssetManager.html"
              + "&"
              + "tabgroup="
              + "asset"
              + "&"
              + "tabselected="
              + "vendor"
              + "&"
              + "node="
              + java.net.URLEncoder.encode("" + nodeIdStr),
          out,
          false);
      out.write("\n\n");
      out.write("<!-- BEGIN FRAMING TABLE:open tags, keep at 100%-->\n");
      out.write("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t");
      out.write("<tr>\n\t\t");
      out.write("<td width=\"10\">");
      out.write(
          "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"1\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">");
      out.write("</td>\n\t\t");
      out.write("<td>\n\n");
      out.write("<!-- USER-DEFINED ATTRIBUTES TABLE: was Identification -->\n      ");
      out.write("<form action=\"asset/modifyAsset\" method=\"POST\" name=\"sysInfo\">\n        ");
      out.write("<input type=\"hidden\" name=\"node\" value=\"");
      out.print(nodeId);
      out.write("\" />\n        ");
      out.write("<input type=\"hidden\" name=\"isnew\" value=\"");
      out.print(isNew);
      out.write("\" />\n        ");
      out.write("<input type=\"hidden\" name=\"view\" value=\"asset-tab-vendor\" />\n\n        ");
      if (!isNew) {
        out.write("\n        ");
        out.write("<!-- asset-tab-system -->\n        ");
        out.write("<input type=\"hidden\" name=\"category\" value=\"");
        out.print(asset.getCategory());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"serialnumber\" value=\"");
        out.print(asset.getSerialNumber());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"manufacturer\" value=\"");
        out.print(asset.getManufacturer());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"operatingsystem\" value=\"");
        out.print(asset.getOperatingSystem());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"modelnumber\" value=\"");
        out.print(asset.getModelNumber());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"assetnumber\" value=\"");
        out.print(asset.getAssetNumber());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"dateinstalled\" value=\"");
        out.print(asset.getDateInstalled());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"description\" value=\"");
        out.print(asset.getDescription());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"comments\" value=\"");
        out.print(asset.getComments());
        out.write("\" />\n\n        ");
        out.write("<!-- asset-tab-location -->\n        ");
        out.write("<input type=\"hidden\" name=\"region\" value=\"");
        out.print(asset.getRegion());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"division\" value=\"");
        out.print(asset.getDivision());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"department\" value=\"");
        out.print(asset.getDepartment());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"address1\" value=\"");
        out.print(asset.getAddress1());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"address2\" value=\"");
        out.print(asset.getAddress2());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"city\" value=\"");
        out.print(asset.getCity());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"state\" value=\"");
        out.print(asset.getState());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"zip\" value=\"");
        out.print(asset.getZip());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"building\" value=\"");
        out.print(asset.getBuilding());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"floor\" value=\"");
        out.print(asset.getFloor());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"room\" value=\"");
        out.print(asset.getRoom());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"rack\" value=\"");
        out.print(asset.getRack());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"slot\" value=\"");
        out.print(asset.getSlot());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"port\" value=\"");
        out.print(asset.getPort());
        out.write("\" />\n        ");
        out.write("<input type=\"hidden\" name=\"circuitid\" value=\"");
        out.print(asset.getCircuitId());
        out.write("\" />\n        ");
      }
      out.write("\n\n");
      out.write("<!-- END FRAMING TABLE:open tags, keep at 100%-->\n\t");
      out.write("<table width=\"98%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n\t  ");
      out.write("<tr class=\"tableHeader\">\n\t    ");
      out.write("<td colspan=\"6\" class=\"tableHeader\">Vendor");
      out.write("</td>\n\t  ");
      out.write("</tr>\n\t  ");
      out.write("<tr class=\"tableRowLight\">\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Name:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"vendor\" value=\"");
      out.print(asset.getVendor());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Phone:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"vendorphone\" value=\"");
      out.print(asset.getVendorPhone());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Fax:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"vendorfax\"  value=\"");
      out.print(asset.getVendorFax());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t  ");
      out.write("</tr>\n\t  ");
      out.write("<tr class=\"tableRowLight\">\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Lease:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"lease\" value=\"");
      out.print(asset.getLease());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Lease Expires:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"leaseexpires\" value=\"");
      out.print(asset.getLeaseExpires());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Vendor Asset:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"vendorassetnumber\" value=\"");
      out.print(asset.getVendorAssetNumber());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t  ");
      out.write("</tr>\n\t  ");
      out.write("<tr class=\"tableRowLight\">\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Maint Contract:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"maintcontract\" value=\"");
      out.print(asset.getMaintContract());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Contract Expires:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"maintcontractexpires\" value=\"");
      out.print(asset.getMaintContractExpires());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<span class=\"formText\">Maint Phone:");
      out.write("</span>");
      out.write("</td>\n\t    ");
      out.write("<td class=\"tableText\">");
      out.write("<input type=\"text\" name=\"supportphone\" value=\"");
      out.print(asset.getSupportPhone());
      out.write("\" size=\"20\" maxlength=\"64\"/>");
      out.write("</td>\n\t  ");
      out.write("</tr>\n\t  ");
      out.write("<tr class=\"tableRowLight\">\n\t    ");
      out.write("<td class=\"tableText\" colspan=\"6\">");
      out.write(
          "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"4\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">");
      out.write("</td>\n\t  ");
      out.write("</tr>\n\t");
      out.write("</table>");
      out.write("<br />\n\n\t");
      out.write("<table width=\"98%\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n\t  ");
      out.write("<tr>\n\t\t");
      out.write("<td colspan=\"3\">");
      out.write("<br />\n\t\t\t");
      out.write("<INPUT type=\"hidden\" name=\"button\" value=\"\">\n\t\t\t");
      out.write(
          "<INPUT type=\"image\" src=\"/wt-portal/images/buttons/btn_save_changes.gif\" onClick=\"document.sysInfo.button.value='Save Changes';\">\n\t\t\t&nbsp;&nbsp;&nbsp;\n\t\t\t");
      out.write(
          "<a href=\"javascript:document.sysInfo.reset()\" onClick=\"javascript:document.sysInfo.reset();\">");
      out.write("<img src=\"/wt-portal/images/buttons/btn_reset.gif\" border=\"0\" alt=\"Reset\">");
      out.write("</a>");
      out.write("<br />&nbsp;\n\t\t\t");
      out.write("<!-- ");
      out.write("<input type=\"submit\" value=\"Save Changes\"/>\n\t\t\t");
      out.write("<input type=\"reset\" /> -->\n\t\t");
      out.write("</td>\n\t\t");
      out.write("<td colspan=\"3\" align=\"right\" class=\"message\">");
      out.write("<br />\n\t\t\t");
      if (isNew) {
        out.write("\n\t\t\t\tNew Record\n\t\t\t");
      } else {
        out.write("\n\t\t\t\tLast Modified: ");
        out.print(WTTools.formatLocalDateToString(asset.getLastModifiedDate()));
        out.write(" by ");
        out.print(asset.getUserLastModified());
        out.write("\n\t\t\t");
      }
      out.write("\n\t\t");
      out.write("</td>\n\t  ");
      out.write("</tr>\n\t");
      out.write("</table>\n\t");
      out.write("</form>\n\n");
      out.write("<!-- BEGIN FRAMING TABLE:close tags-->\n\t\t");
      out.write("</td>\n\t");
      out.write("</tr>\n");
      out.write("</table>\n");
      out.write("<!-- END FRAMING TABLE:close tags-->\n\n");
      out.write("<br>\n");
      JspRuntimeLibrary.include(request, response, "/includes/footer.jsp", out, false);
      out.write("\n\n");
      out.write("</body>\n");
      out.write("</html>\n");
    } catch (Throwable t) {
      out = _jspx_out;
      if (out != null && out.getBufferSize() != 0) out.clearBuffer();
      if (pageContext != null) pageContext.handlePageException(t);
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
    }
  }