2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.groupbasedpolicy.sxp.mapper.impl.dao;
10 import com.google.common.collect.Iterables;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointForwardingTemplateBySubnet;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointForwardingTemplateBySubnetBuilder;
20 * Test for {@link SimpleCachedDaoEPForwardingTemplateImpl}.
22 public class SimpleCachedDaoEPForwardingTemplateImplTest {
24 private static final IpPrefix IP_PREFIX_1 = buildIpPrefix("1.2.3.0/24");
27 private static final IpPrefix IP_PREFIX_2 = buildIpPrefix("1.2.3.4/32");
29 private SimpleCachedDaoEPForwardingTemplateImpl dao;
32 public void setUp() throws Exception {
33 dao = new SimpleCachedDaoEPForwardingTemplateImpl();
34 Assert.assertTrue(dao.isEmpty());
38 public void testUpdate() throws Exception {
39 dao.update(IP_PREFIX_1, buildValue(IP_PREFIX_1));
40 dao.update(IP_PREFIX_2, buildValue(IP_PREFIX_2));
42 Assert.assertEquals(2, Iterables.size(dao.values()));
45 private EndpointForwardingTemplateBySubnet buildValue(final IpPrefix ipPrefix) {
46 return new EndpointForwardingTemplateBySubnetBuilder()
47 .setIpPrefix(ipPrefix)
52 public void testFind() throws Exception {
53 final EndpointForwardingTemplateBySubnet value1 = buildValue(IP_PREFIX_1);
54 final EndpointForwardingTemplateBySubnet value2 = buildValue(IP_PREFIX_2);
55 dao.update(IP_PREFIX_1, value1);
56 dao.update(IP_PREFIX_2, value2);
57 Assert.assertFalse(dao.isEmpty());
59 Assert.assertTrue(dao.find(IP_PREFIX_1).isPresent());
60 Assert.assertEquals(value1, dao.find(IP_PREFIX_1).get());
61 Assert.assertTrue(dao.find(IP_PREFIX_2).isPresent());
62 Assert.assertEquals(value2, dao.find(IP_PREFIX_2).get());
64 final IpPrefix key = buildIpPrefix("1.2.3.1/32");
65 Assert.assertTrue(dao.find(key).isPresent());
66 Assert.assertEquals(value1, dao.find(key).get());
69 private static IpPrefix buildIpPrefix(final String ipv4PrefixValue) {
70 return new IpPrefix(new Ipv4Prefix(ipv4PrefixValue));
74 public void testInvalidateCache() throws Exception {
75 dao.update(IP_PREFIX_1, buildValue(IP_PREFIX_1));
76 dao.update(IP_PREFIX_2, buildValue(IP_PREFIX_2));
78 Assert.assertEquals(2, Iterables.size(dao.values()));
79 dao.invalidateCache();
80 Assert.assertTrue(dao.isEmpty());