blob: 257d9a78f826d1d0a8c91bd6e69c421559cac84c [file] [log] [blame]
Jian Li8bcef8b2016-01-06 11:35:53 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Li8bcef8b2016-01-06 11:35:53 -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 com.fasterxml.jackson.databind.JsonNode;
19import org.onosproject.net.flowobjective.Objective;
20
21/**
22 * Hamcrest matcher for instructions.
23 */
24public final class ObjectiveJsonMatcher {
25
26 final Objective objective;
27
28 private ObjectiveJsonMatcher(Objective objective) {
29 this.objective = objective;
30 }
31
32 protected boolean matchesSafely(JsonNode jsonObjective) {
33
34 // check operation
35 String jsonOp = jsonObjective.get("operation").asText();
36 String op = objective.op().toString();
37 if (!jsonOp.equals(op)) {
38 return false;
39 }
40
41 // check permanent
42 boolean jsonPermanent = jsonObjective.get("isPermanent").asBoolean();
43 boolean permanent = objective.permanent();
44 if (jsonPermanent != permanent) {
45 return false;
46 }
47
48 // check priority
49 int jsonPriority = jsonObjective.get("priority").asInt();
50 int priority = objective.priority();
51 if (jsonPriority != priority) {
52 return false;
53 }
54
55 // check timeout
56 int jsonTimeout = jsonObjective.get("timeout").asInt();
57 int timeout = objective.timeout();
58 if (jsonTimeout != timeout) {
59 return false;
60 }
61
62 return true;
63 }
64
65 /**
66 * Factory to allocate a ObjectiveJsonMatcher.
67 *
68 * @param objective objective object we are looking for
69 * @return matcher
70 */
71 public static ObjectiveJsonMatcher matchesObjective(Objective objective) {
72 return new ObjectiveJsonMatcher(objective);
73 }
74}