Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / hosttracker_new / implementation / src / test / java / org / opendaylight / controller / hosttracker / test / MockEntityClassifierMac.java
1 /*
2  * Copyright (c) 2013 Big Switch Networks, Inc.
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the
5  * "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13  * implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 package org.opendaylight.controller.hosttracker.test;
18
19 import static org.opendaylight.controller.hosttracker.IDeviceService.DeviceField.MAC;
20 import static org.opendaylight.controller.hosttracker.IDeviceService.DeviceField.SWITCHPORT;
21 import static org.opendaylight.controller.hosttracker.IDeviceService.DeviceField.VLAN;
22
23 import java.util.EnumSet;
24
25 import org.opendaylight.controller.hosttracker.Entity;
26 import org.opendaylight.controller.hosttracker.IDeviceService;
27 import org.opendaylight.controller.hosttracker.IDeviceService.DeviceField;
28 import org.opendaylight.controller.hosttracker.IEntityClass;
29 import org.opendaylight.controller.hosttracker.internal.DefaultEntityClassifier;
30
31 /**
32  * A simple IEntityClassifier. Useful for tests that need an IEntityClassifier
33  * with switch/port as key fields.
34  */
35 public class MockEntityClassifierMac extends DefaultEntityClassifier {
36     public static class TestEntityClassMac implements IEntityClass {
37         protected String name;
38
39         public TestEntityClassMac(String name) {
40             this.name = name;
41         }
42
43         @Override
44         public EnumSet<DeviceField> getKeyFields() {
45             return EnumSet.of(MAC, VLAN);
46         }
47
48         @Override
49         public String getName() {
50             return name;
51         }
52     }
53
54     public static IEntityClass testECMac1 = new MockEntityClassifierMac.TestEntityClassMac(
55             "testECMac1");
56     public static IEntityClass testECMac2 = new MockEntityClassifierMac.TestEntityClassMac(
57             "testECMac2");
58
59     @Override
60     public IEntityClass classifyEntity(Entity entity) {
61         if (((Long) entity.getPort().getNode().getID()) == null) {
62             throw new IllegalArgumentException("Not all key fields specified."
63                     + " Required fields: " + getKeyFields());
64         } else if (((Long) entity.getPort().getNode().getID()) == 1L) {
65             return testECMac1;
66         } else if (((Long) entity.getPort().getNode().getID()) == 2L) {
67             return testECMac2;
68         } else if (((Long) entity.getPort().getNode().getID()) == -1L) {
69             return null;
70         }
71         return DefaultEntityClassifier.entityClass;
72     }
73
74     @Override
75     public EnumSet<IDeviceService.DeviceField> getKeyFields() {
76         return EnumSet.of(MAC, VLAN, SWITCHPORT);
77     }
78 }