blob: 45c5646b935cd7c74f25188cd5b70325b5762357 [file] [log] [blame]
Sean Condonfae8e662016-12-15 10:25:13 +00001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Sean Condonfae8e662016-12-15 10:25:13 +00003 *
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.drivers.netconf;
17
David K. Bainbridge1a10d622018-05-07 12:32:27 -070018import java.util.HashSet;
19import java.util.Set;
20
Sean Condonfae8e662016-12-15 10:25:13 +000021import org.onosproject.core.ApplicationId;
22import org.onosproject.core.CoreService;
23import org.onosproject.core.DefaultApplicationId;
24import org.onosproject.core.IdGenerator;
25import org.onosproject.core.Version;
26import org.onosproject.net.intent.MockIdGenerator;
27
28public class MockCoreService implements CoreService {
29
30 private HashSet<ApplicationId> appIds;
31 private Version version;
David K. Bainbridge1a10d622018-05-07 12:32:27 -070032 private int nextAppId = 101;
33
34 public MockCoreService(int baseId, String... apps) {
35 nextAppId = baseId;
36 appIds = new HashSet<ApplicationId>();
37 for (String app : apps) {
38 appIds.add(new DefaultApplicationId(nextAppId, app));
39 nextAppId += 1;
40 }
41 version = Version.version(1, 1, "1", "1");
42 }
Sean Condonfae8e662016-12-15 10:25:13 +000043
44 public MockCoreService() {
David K. Bainbridge1a10d622018-05-07 12:32:27 -070045 this(101, "org.onosproject.drivers.netconf");
Sean Condonfae8e662016-12-15 10:25:13 +000046 appIds = new HashSet<ApplicationId>();
Sean Condonfae8e662016-12-15 10:25:13 +000047 }
48
49 @Override
50 public Version version() {
51 return version;
52 }
53
54 @Override
55 public Set<ApplicationId> getAppIds() {
56 return appIds;
57 }
58
59 @Override
60 public ApplicationId getAppId(Short id) {
David K. Bainbridge1a10d622018-05-07 12:32:27 -070061 for (ApplicationId appId : appIds) {
Sean Condonfae8e662016-12-15 10:25:13 +000062 if (appId.id() == id.shortValue()) {
63 return appId;
64 }
65 }
66 return null;
67 }
68
69 @Override
70 public ApplicationId getAppId(String name) {
David K. Bainbridge1a10d622018-05-07 12:32:27 -070071 for (ApplicationId appId : appIds) {
Sean Condonfae8e662016-12-15 10:25:13 +000072 if (appId.name().equalsIgnoreCase(name)) {
73 return appId;
74 }
75 }
76 return null;
77 }
78
79 @Override
80 public ApplicationId registerApplication(String name) {
David K. Bainbridge1a10d622018-05-07 12:32:27 -070081 // Check if the app already exists
82 ApplicationId appId = getAppId(name);
83 if (appId == null) {
84 appId = new DefaultApplicationId(nextAppId, name);
85 nextAppId += 1;
86 appIds.add(appId);
87 }
Sean Condonfae8e662016-12-15 10:25:13 +000088 return appId;
89 }
90
91 @Override
92 public ApplicationId registerApplication(String name, Runnable preDeactivate) {
93 // TODO Auto-generated method stub
94 return null;
95 }
96
97 @Override
98 public IdGenerator getIdGenerator(String topic) {
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070099 return MockIdGenerator.INSTANCE;
Sean Condonfae8e662016-12-15 10:25:13 +0000100 }
101
102}