2 * Copyright (c) 2014 Contextream, 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.lispflowmapping.implementation;
11 import java.util.HashMap;
13 import java.util.Map.Entry;
15 import junitx.framework.StringAssert;
17 import org.jmock.api.Invocation;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
21 import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
22 import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
23 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
24 import org.opendaylight.lispflowmapping.tools.junit.MockCommandInterpreter;
26 public class LispMappingServiceCliTest extends BaseTestCase {
27 private LispMappingService testedLispMappingService;
29 private Map<Object, Object> visitorExecutions;
30 private MockCommandInterpreter mockCommandInterpreter;
34 public void before() throws Exception {
37 testedLispMappingService = new LispMappingService();
38 dao = context.mock(ILispDAO.class);
39 inject(testedLispMappingService, "lispDao", dao);
40 mockCommandInterpreter = new MockCommandInterpreter();
42 visitorExecutions = new HashMap<Object, Object>();
43 allowing(dao).getAll(wany(IRowVisitor.class));
44 will(new SimpleAction() {
46 public Object invoke(Invocation invocation) throws Throwable {
47 IRowVisitor visitor = (IRowVisitor) invocation.getParameter(0);
48 for (Entry<Object, Object> entry : visitorExecutions.entrySet()) {
49 visitor.visitRow(entry.getKey(), "IP", entry.getValue());
57 public void remove__Basic() throws Exception {
58 mockCommandInterpreter.addArgument("1.2.3.4");
59 oneOf(dao).remove(LispAFIConvertor.asIPAfiAddress("1.2.3.4"));
60 testedLispMappingService._removeEid(mockCommandInterpreter);
64 public void oneEntryInDb() throws Exception {
65 prepareVisitorResult("1.2.3.4", "9.8.7.6");
67 testedLispMappingService._dumpAll(mockCommandInterpreter);
69 String console = mockCommandInterpreter.getPrints().toString();
70 StringAssert.assertStartsWith("EID\tRLOCs\n", console);
71 StringAssert.assertContains("Ipv4", console);
75 public void twoEntriesInDb() throws Exception {
76 prepareVisitorResult("7.2.3.4", "9.8.7.6");
77 prepareVisitorResult("1.2.3.4", "9.8.7.6");
78 testedLispMappingService._dumpAll(mockCommandInterpreter);
80 String console = mockCommandInterpreter.getPrints().toString();
81 StringAssert.assertStartsWith("EID\tRLOCs\n", console);
82 StringAssert.assertContains("Ipv4", console);
83 StringAssert.assertContains("Ipv4", console);
86 private void prepareVisitorResult(final String key, final String value) {
87 visitorExecutions.put(LispAFIConvertor.asIPAfiAddress(key), LispAFIConvertor.asIPAfiAddress(value));