blob: c18359706f946da13c937f5f00f7ea0aa0b25e6a [file] [log] [blame]
Ray Milkeydb358082015-01-13 16:34:38 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeydb358082015-01-13 16:34:38 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
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 implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.codec.impl;
17
18import org.hamcrest.Description;
19import org.hamcrest.TypeSafeDiagnosingMatcher;
20import org.onosproject.net.ConnectPoint;
21
22import com.fasterxml.jackson.databind.JsonNode;
23
24/**
25 * Hamcrest matcher for connect points.
26 */
27
28public final class ConnectPointJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
29
30 private final ConnectPoint connectPoint;
31
32 private ConnectPointJsonMatcher(ConnectPoint connectPointValue) {
33 connectPoint = connectPointValue;
34 }
35
36 @Override
37 public boolean matchesSafely(JsonNode jsonConnectPoint, Description description) {
38 // check device
39 final String jsonDevice = jsonConnectPoint.get("device").asText();
40 final String device = connectPoint.deviceId().toString();
41 if (!jsonDevice.equals(device)) {
42 description.appendText("device was " + jsonDevice);
43 return false;
44 }
45
46 // check port
47 final String jsonPort = jsonConnectPoint.get("port").asText();
48 final String port = connectPoint.port().toString();
49 if (!jsonPort.equals(port)) {
50 description.appendText("port was " + jsonPort);
51 return false;
52 }
53
54 return true;
55 }
56
57 @Override
58 public void describeTo(Description description) {
59 description.appendText(connectPoint.toString());
60 }
61
62 /**
63 * Factory to allocate an connect point matcher.
64 *
65 * @param connectPoint connect point object we are looking for
66 * @return matcher
67 */
68 public static ConnectPointJsonMatcher matchesConnectPoint(ConnectPoint connectPoint) {
69 return new ConnectPointJsonMatcher(connectPoint);
70 }
71}