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
9 package org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl;
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;
23 import java.util.HashSet;
24 import java.util.Optional;
28 * Test for {@link SgtGeneratorImpl}.
30 @RunWith(MockitoJUnitRunner.class)
31 public class SgtGeneratorImplTest {
34 private SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> templateDao;
36 private SgtGeneratorImpl generator;
37 private Set<Sgt> sgts;
40 public void setUp() throws Exception {
41 final SgtGeneratorConfig config = new SgtGeneratorConfigBuilder()
42 .setSgtLow(new Sgt(10))
43 .setSgtHigh(new Sgt(20))
46 sgts = new HashSet<>();
47 Mockito.when(templateDao.keySet()).thenReturn(sgts);
48 generator = new SgtGeneratorImpl(config);
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());
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());
66 public void testGenerateNextSgt_topIsBelowLimit() throws Exception {
68 final Optional<Sgt> sgt = generator.generateNextSgt(templateDao);
70 Assert.assertTrue(sgt.isPresent());
71 Assert.assertEquals(10, sgt.get().getValue().intValue());
75 public void testGenerateNextSgt_withinLimits() throws Exception {
76 sgts.add(new Sgt(10));
77 final Optional<Sgt> sgt = generator.generateNextSgt(templateDao);
79 Assert.assertTrue(sgt.isPresent());
80 Assert.assertEquals(11, sgt.get().getValue().intValue());