blob: 3c2ae24e0d857d66009d461b97497386d03a06a3 [file] [log] [blame]
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +05303 *
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 */
Priyanka Bb977f562016-07-22 13:02:03 +053016package org.onosproject.pcerest;
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053017
18import org.onosproject.codec.CodecContext;
19import org.onosproject.codec.CodecService;
20import org.onosproject.codec.JsonCodec;
21import org.onosproject.codec.impl.CodecManager;
22
23import com.fasterxml.jackson.databind.ObjectMapper;
24
25/**
26 * Mock codec context for use in codec unit tests.
27 */
28public class MockPceCodecContext implements CodecContext {
29
30 private final ObjectMapper mapper = new ObjectMapper();
31 private final CodecManager codecManager = new CodecManager();
32 private final PceCodecRegistrator manager = new PceCodecRegistrator();
33
34 /**
35 * Constructs a new mock codec context.
36 */
37 public MockPceCodecContext() {
38 codecManager.activate();
39 manager.codecService = codecManager;
40 manager.activate();
41 }
42
43 @Override
44 public ObjectMapper mapper() {
45 return mapper;
46 }
47
48 @SuppressWarnings("unchecked")
49 @Override
50 public <T> T getService(Class<T> serviceClass) {
Mahesh Poojary Sd7a36922016-04-01 16:11:14 +053051 return null;
52 }
53
54 @Override
55 public <T> JsonCodec<T> codec(Class<T> entityClass) {
56 return codecManager.getCodec(entityClass);
57 }
58
59 /**
60 * Get the codec manager.
61 *
62 * @return instance of codec manager
63 */
64 public CodecService codecManager() {
65 return codecManager;
66 }
67}