cleanup of Deprecated classes for config subsystem
[groupbasedpolicy.git] / sxp-integration / sxp-ep-provider / src / test / java / org / opendaylight / groupbasedpolicy / sxp / ep / provider / impl / SgtGeneratorImplTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl;
10
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.runners.MockitoJUnitRunner;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.integration.sxp.ep.provider.model.rev160302.sxp.ep.mapper.EndpointPolicyTemplateBySgt;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.integration.sxp.ep.provider.model.rev160302.SgtGeneratorConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.integration.sxp.ep.provider.model.rev160302.SgtGeneratorConfigBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.sxp.database.rev160308.Sgt;
22
23 import java.util.HashSet;
24 import java.util.Optional;
25 import java.util.Set;
26
27 /**
28  * Test for {@link SgtGeneratorImpl}.
29  */
30 @RunWith(MockitoJUnitRunner.class)
31 public class SgtGeneratorImplTest {
32
33     @Mock
34     private SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> templateDao;
35
36     private SgtGeneratorImpl generator;
37     private Set<Sgt> sgts;
38
39     @Before
40     public void setUp() throws Exception {
41         final SgtGeneratorConfig config = new SgtGeneratorConfigBuilder()
42                 .setSgtLow(new Sgt(10))
43                 .setSgtHigh(new Sgt(20))
44                 .build();
45
46         sgts = new HashSet<>();
47         Mockito.when(templateDao.keySet()).thenReturn(sgts);
48         generator = new SgtGeneratorImpl(config);
49     }
50
51     @Test
52     public void testGenerateNextSgt_noData() throws Exception {
53         final Optional<Sgt> sgt = generator.generateNextSgt(templateDao);
54         Assert.assertTrue(sgt.isPresent());
55         Assert.assertEquals(10, sgt.get().getValue().intValue());
56     }
57
58     @Test
59     public void testGenerateNextSgt_topIsAboveLimit() throws Exception {
60         sgts.add(new Sgt(20));
61         final Optional<Sgt> sgt = generator.generateNextSgt(templateDao);
62         Assert.assertFalse(sgt.isPresent());
63     }
64
65     @Test
66     public void testGenerateNextSgt_topIsBelowLimit() throws Exception {
67         sgts.add(new Sgt(9));
68         final Optional<Sgt> sgt = generator.generateNextSgt(templateDao);
69
70         Assert.assertTrue(sgt.isPresent());
71         Assert.assertEquals(10, sgt.get().getValue().intValue());
72     }
73
74     @Test
75     public void testGenerateNextSgt_withinLimits() throws Exception {
76         sgts.add(new Sgt(10));
77         final Optional<Sgt> sgt = generator.generateNextSgt(templateDao);
78
79         Assert.assertTrue(sgt.isPresent());
80         Assert.assertEquals(11, sgt.get().getValue().intValue());
81     }
82 }