blob: 881544fd8e4baa9c4873c1f67abc802a1b6ae6bf [file] [log] [blame]
kmcpeake4fe18c82015-11-17 20:07:39 +00001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
kmcpeake4fe18c82015-11-17 20:07:39 +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.faultmanagement.web;
17
kmcpeake4fe18c82015-11-17 20:07:39 +000018import org.onosproject.codec.CodecContext;
kmcpeakee4621822015-12-08 14:24:36 +000019import org.onosproject.codec.CodecService;
kmcpeake4fe18c82015-11-17 20:07:39 +000020import org.onosproject.codec.JsonCodec;
kmcpeakee4621822015-12-08 14:24:36 +000021import org.onosproject.codec.impl.CodecManager;
kmcpeake4fe18c82015-11-17 20:07:39 +000022
23import com.fasterxml.jackson.databind.ObjectMapper;
kmcpeake4fe18c82015-11-17 20:07:39 +000024
25/**
26 * Mock codec context for use in codec unit tests.
27 */
kmcpeakeb172d5f2015-12-10 11:30:43 +000028public final class AlarmCodecContext implements CodecContext {
kmcpeake4fe18c82015-11-17 20:07:39 +000029
30 private final ObjectMapper mapper = new ObjectMapper();
kmcpeakee4621822015-12-08 14:24:36 +000031 private final CodecManager codecManager = new CodecManager();
32 private final AlarmCodecRegistrator manager = new AlarmCodecRegistrator();
kmcpeake4fe18c82015-11-17 20:07:39 +000033
34 /**
35 * Constructs a new mock codec context.
36 */
37 public AlarmCodecContext() {
kmcpeakee4621822015-12-08 14:24:36 +000038 codecManager.activate();
39 manager.codecService = codecManager;
40 manager.activate();
kmcpeake4fe18c82015-11-17 20:07:39 +000041 }
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) {
kmcpeake4fe18c82015-11-17 20:07:39 +000051 return null;
52 }
53
kmcpeake4fe18c82015-11-17 20:07:39 +000054 @Override
55 public <T> JsonCodec<T> codec(Class<T> entityClass) {
kmcpeakee4621822015-12-08 14:24:36 +000056 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;
kmcpeake4fe18c82015-11-17 20:07:39 +000066 }
67}