Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.sdxl2; |
| 18 | |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.onosproject.net.intent.Intent; |
| 21 | import org.onosproject.net.intent.IntentServiceAdapter; |
| 22 | import org.onosproject.net.intent.Key; |
| 23 | |
| 24 | import 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 | */ |
| 30 | public 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 | } |