00b9ad186c7b51da52364b2b4c56bc6dea9b9b14
[unimgr.git] / cli / src / test / java / org / opendaylight / unimgr / cli / UnimgrConsoleProviderTest.java
1 /*
2  * Copyright (c) 2016 CableLabs 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 package org.opendaylight.unimgr.cli;
9
10 import static org.mockito.Mockito.mock;
11 import static org.mockito.Mockito.when;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Evc;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 public class UnimgrConsoleProviderTest implements IUnimgrConsoleProvider {
29
30     private final List<UniAugmentation> listUni = new ArrayList<UniAugmentation>();
31     private final List<EvcAugmentation> listEvc = new ArrayList<EvcAugmentation>();
32     private boolean firstTest = true;
33
34     @Override
35     public boolean addUni(UniAugmentation uni) {
36         return (listUni.contains(uni)) ? false : listUni.add(uni);
37     }
38
39     @Override
40     public boolean removeUni(IpAddress ipAddress) {
41         firstTest = !firstTest;
42         return !firstTest;
43     }
44
45     @Override
46     public List<UniAugmentation> listUnis(LogicalDatastoreType dataStoreType) {
47         return listUni;
48     }
49
50     public void setListUnis(int amount, String ipAddress) {
51         for(int i=0; i<amount; i++){
52             final UniAugmentation uniAug = mock(UniAugmentation.class);
53             final IpAddress ipAddr = mock(IpAddress.class);
54             final Ipv4Address ip4 = mock(Ipv4Address.class);
55             when(uniAug.getIpAddress()).thenReturn(ipAddr);
56             when(ipAddr.getIpv4Address()).thenReturn(ip4);
57             when(ip4.getValue()).thenReturn(ipAddress);
58             listUni.add(uniAug);
59         }
60     }
61
62     @Override
63     public UniAugmentation getUni(IpAddress ipAddress) {
64         return (listUni.isEmpty()) ? null : listUni.get(0);
65     }
66
67     @Override
68     public boolean addEvc(EvcAugmentation evc) {
69         return (listEvc.contains(evc)) ? false : listEvc.add(evc);
70     }
71
72     @Override
73     public Evc getEvc(String uuid) {
74         return (listEvc.isEmpty()) ? null : listEvc.get(0);
75     }
76
77     @Override
78     public boolean removeEvc(String uuid) {
79         firstTest = !firstTest;
80         return !firstTest;
81     }
82
83     @Override
84     public void close() throws Exception { }
85
86     @Override
87     public boolean updateUni(UniAugmentation uni) {
88         // TODO Auto-generated method stub
89         return false;
90     }
91
92     @Override
93     public boolean updateEvc(InstanceIdentifier<Link> evcKey, EvcAugmentation evc, UniSource uniSource,
94             UniDest uniDest) {
95         // TODO Auto-generated method stub
96         return false;
97     }
98
99 }