MRI version bumpup for Aluminium
[netvirt.git] / cloud-servicechain / impl / src / test / java / org / opendaylight / netvirt / cloudservicechain / matchers / NodeIIdMatcher.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.netvirt.cloudservicechain.matchers;
9
10 import java.util.List;
11 import org.mockito.ArgumentMatcher;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
15
16 public class NodeIIdMatcher extends ArgumentMatcher<InstanceIdentifier<Node>> {
17
18     InstanceIdentifier<Node> expectedNodeIId;
19
20     public NodeIIdMatcher(InstanceIdentifier<Node> expectedNodeIId) {
21         this.expectedNodeIId = expectedNodeIId;
22     }
23
24     @Override
25     public boolean matches(Object nodeIId) {
26
27         if (! (nodeIId instanceof InstanceIdentifier<?>)) {
28             return false;
29         }
30         boolean result = false;
31         try {
32             InstanceIdentifier<Node> actualNodeIId = (InstanceIdentifier<Node>) nodeIId;
33             List<PathArgument> expectedNodeIIdPath = this.expectedNodeIId.getPath();
34             List<PathArgument> actualNodeIIdPath = actualNodeIId.getPath();
35             if (expectedNodeIIdPath.size() != actualNodeIIdPath.size()) {
36                 return false;
37             }
38
39             for (int i = 0; i < expectedNodeIIdPath.size(); i++) {
40                 if (expectedNodeIIdPath.get(i).compareTo(actualNodeIIdPath.get(i)) != 0) {
41                     result = false;
42                     break;
43                 }
44             }
45
46         } catch (ClassCastException e) {
47             return false;
48         }
49
50
51         return result;
52     }
53
54 }