blob: 0f1de5e7b16b4fbf828f19823196597761f3d38e [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.onosproject.cfm;
17
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 CfmCodecContext implements CodecContext {
29
30 private final ObjectMapper mapper = new ObjectMapper();
31 private final CodecManager codecManager = new CodecManager();
32 private final CfmWebComponent manager = new CfmWebComponent();
33
34 /**
35 * Constructs a new mock codec context.
36 */
37 public CfmCodecContext() {
38 codecManager.activate();
39 manager.codecService = codecManager;
40 manager.activate();
41 }
42
43 @Override
44 public ObjectMapper mapper() {
45 return mapper;
46 }
47
48 @Override
49 public <T> T getService(Class<T> serviceClass) {
50 return null;
51 }
52
53 @Override
54 public <T> JsonCodec<T> codec(Class<T> entityClass) {
55 return codecManager.getCodec(entityClass);
56 }
57
58 /**
59 * Get the codec manager.
60 *
61 * @return instance of codec manager
62 */
63 public CodecService codecManager() {
64 return codecManager;
65 }
66}