blob: a9711d374bcdf577014ca5a2cd3a03f79db1b158 [file] [log] [blame]
Carolina Fernandezad893432016-07-18 11:11:34 +02001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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 */
16
17package org.onosproject.sdxl2;
18
19import com.google.common.collect.Sets;
20import org.onosproject.net.intent.Intent;
21import org.onosproject.net.intent.IntentServiceAdapter;
22import org.onosproject.net.intent.Key;
23
24import java.util.Set;
25
26/**
27 * Represents a fake IntentService class that easily allows to store and
28 * retrieve intents without implementing the IntentService logic.
29 */
30public class IntentServiceTest extends IntentServiceAdapter {
31
32 private Set<Intent> intents;
33
34 /**
35 * Defines a set of intents.
36 */
37 public IntentServiceTest() {
38 intents = Sets.newHashSet();
39 }
40
41 @Override
42 public void submit(Intent intent) {
43 intents.add(intent);
44 }
45
46 @Override
47 public long getIntentCount() {
48 return intents.size();
49 }
50
51 @Override
52 public Iterable<Intent> getIntents() {
53 return Sets.newHashSet(intents.iterator());
54 }
55
56 @Override
57 public Intent getIntent(Key intentKey) {
58 for (Intent intent : intents) {
59 if (intent.key().equals(intentKey)) {
60 return intent;
61 }
62 }
63 return null;
64 }
65
66 @Override
67 public void withdraw(Intent intent) {
68 intents.remove(intent);
69 }
70
71}