aboutsummaryrefslogtreecommitdiffstats
path: root/evc/evcbase/src/test/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRepositoryTest.java
blob: b8c43621b661a1b8d0bb9e71cd6d6cb327b2ba32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
* Copyright (c) 2015 CableLabs Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution, and is available at
* http://www.apache.org/licenses/LICENSE-2.0
*******************************************************************************/

package com.cablelabs.vcpe.evc.evcbase.repository;

import com.cablelabs.vcpe.cos.cosbase.model.CoS;
import com.cablelabs.vcpe.evc.evcbase.model.Evc;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

/**
 * Created by steve on 5/25/15.
 */
public class EvcRepositoryTest
{

    @Test
    public void test() {

        // First, create a couple of CoS's to reference
        CoS gold   = new CoS();
        CoS silver = new CoS();
        CoS bronze = new CoS();

        //            id        CIR/MBS  avail  delay   jitter  frameloss
        gold.setAllProps("gold", 100, 0.99, 17.43, 2.43, 0.01);
        silver.setAllProps("silver", 50, 0.95, 27.43, 2.43, 0.02);
        bronze.setAllProps("bronze", 25,      0.90,  37.43,  2.43,   0.03);

        Evc evc_1   = new Evc();
        Evc evc_2 = new Evc();
        Evc evc_3 = new Evc();

        List<String> uniIdList = new ArrayList<String>();
        uniIdList.add("UNI-1");
        uniIdList.add("UNI-2");

        List<String> uniMacList = new ArrayList<String>();
        uniMacList.add("11:11:11:11:11:11");
        uniMacList.add("22:22:22:22:22:22");

        List<String> uniIpList = new ArrayList<String>();
        uniIpList.add("192.168.1.1");
        uniIpList.add("192.168.1.2");

        evc_1.setAllNonPerfProps("evc_1",
                Evc.EvcType.POINT_TO_POINT, 2, uniIdList, uniMacList, uniIpList,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                true, true, 1600, gold.getId());
        evc_2.setAllNonPerfProps("evc_2",
                Evc.EvcType.POINT_TO_POINT, 2, uniIdList, uniMacList, uniIpList,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                true, true, 1500, silver.getId());
        evc_3.setAllNonPerfProps("evc_3",
                Evc.EvcType.POINT_TO_POINT, 2, uniIdList, uniMacList, uniIpList,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                true, true, 1400, bronze.getId());

        evc_1.dump();
        evc_2.dump();
        evc_3.dump();

        EvcRespository repo = EvcRespositoryInMem.INSTANCE;

        assertNotNull(repo.add(evc_1));
        assertNotNull(repo.add(evc_2));
        assertNotNull(repo.add(evc_3));
        assertNull(repo.add(evc_3)); // duplicate
        assertEquals(repo.count(), 3);

        assertNotNull(repo.get(evc_1.getId()));
        assertNotNull(repo.get(evc_2.getId()));
        assertNotNull(repo.get(evc_3.getId()));

        assertNotNull(repo.delete(evc_2.getId()));
        assertNull(repo.delete(evc_2.getId()));
        assertNull(repo.delete("not-in-repo"));
        assertEquals(repo.count(), 2);

        assertEquals(repo.get(evc_1.getId()).getEvcMaxSvcFrameSize(), 1600);
        assertNotEquals(repo.get(evc_3.getId()).getEvcMaxSvcFrameSize(), 1600);

        Evc evc_4  = new Evc();
        evc_4.setAllNonPerfProps("evc_4",
                Evc.EvcType.POINT_TO_POINT, 2, uniIdList, uniMacList, uniIpList,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                true, true, 1200, bronze.getId());

        assertNull(repo.update(evc_4));    // update non-existent cos
        assertEquals(repo.count(), 3);
        assertEquals(repo.get("evc_4").getEvcMaxSvcFrameSize(), 1200);

        evc_4.setEvcMaxSvcFrameSize(1250);
        assertNotNull(repo.update(evc_4)); // update existing evc, same object
        assertEquals(repo.get(evc_4.getId()).getEvcMaxSvcFrameSize(), 1250);

        evc_4.dump();

        Evc evc_4_2  = new Evc();
        evc_4_2.setAllNonPerfProps("evc_4",
                Evc.EvcType.POINT_TO_POINT, 2, uniIdList, uniMacList,  uniIpList,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                Evc.FrameDelivery.UNCONDITIONAL,
                true, true, 500, bronze.getId());

        assertNotNull(repo.update(evc_4_2)); // update evc, new object
        assertEquals(repo.get(evc_4_2.getId()).getEvcMaxSvcFrameSize(), 500);
    }
}