@Test
public void testCacheTemplateRecord() throws Exception {

    // Build template record cache
    long obsvDomain = 4335L;
    String hostname = "deviceA";
    IpfixTemplateRecord expected = generateTemplateRecord("01030002000800048008000500000E91");
    IpfixTemplateRecord tr = generateTemplateRecord("01010002000800048008000500000E91");
    HashMap<Integer, AbstractTemplateRecord> templateByIdCache = new HashMap<>();
    templateByIdCache.put(259, expected);
    templateByIdCache.put(257, tr);
    m_ipfixfeCachingService.cacheTemplateRecord(obsvDomain, hostname, templateByIdCache);
    IpfixTemplateRecord tmplRecord11 = generateTemplateRecord("01030002000800048008000500000E91");
    IpfixTemplateRecord tmplRecord12 = generateTemplateRecord("01010002000800048008000500000E91");
    HashMap<Integer, AbstractTemplateRecord> tmplRecordByIdCache1 = new HashMap<>();
    templateByIdCache.put(259, tmplRecord11);
    templateByIdCache.put(257, tmplRecord12);
    m_ipfixfeCachingService.cacheTemplateRecord(obsvDomain, "ANV1.ONT2", tmplRecordByIdCache1);
    IpfixTemplateRecord tmplRecord21 = generateTemplateRecord("01030002000800048008000500000E91");
    IpfixTemplateRecord tmplRecord22 = generateTemplateRecord("01010002000800048008000500000E91");
    HashMap<Integer, AbstractTemplateRecord> tmplRecordByIdCache2 = new HashMap<>();
    templateByIdCache.put(259, tmplRecord21);
    templateByIdCache.put(257, tmplRecord22);
    m_ipfixfeCachingService.cacheTemplateRecord(obsvDomain, "ANV1.ONT3", tmplRecordByIdCache2);
    // Verify cache data
    IpfixTemplateRecord template = (IpfixTemplateRecord) m_ipfixfeCachingService.getTemplateRecord(obsvDomain, hostname, 259);
    assertTemplateRecord(expected, template);
    template = (IpfixTemplateRecord) m_ipfixfeCachingService.getTemplateRecord(obsvDomain, hostname, 257);
    assertTemplateRecord(tr, template);
    Set<String> allCacheKeys = m_ipfixfeCachingService.getAllCacheKeys();
    assertEquals(2, allCacheKeys.size());
    assertTrue(allCacheKeys.contains("4335_deviceA_259"));
    assertTrue(allCacheKeys.contains("4335_deviceA_257"));
    // Test for updateHostname
    String newHostname = "deviceA.New";
    m_ipfixfeCachingService.updateHostName(obsvDomain, hostname, newHostname);
    template = (IpfixTemplateRecord) m_ipfixfeCachingService.getTemplateRecord(obsvDomain, newHostname, 257);
    assertTemplateRecord(tr, template);
    allCacheKeys = m_ipfixfeCachingService.getAllCacheKeys();
    assertEquals(2, allCacheKeys.size());
    assertTrue(allCacheKeys.contains("4335_deviceA.New_259"));
    assertTrue(allCacheKeys.contains("4335_deviceA.New_257"));
}