2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.common.endpoints.http.server.test;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.OutputStream;
26 import java.lang.annotation.Annotation;
27 import java.lang.reflect.Type;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.MultivaluedMap;
30 import lombok.AccessLevel;
32 import org.onap.policy.common.gson.GsonMessageBodyHandler;
35 * GsonMessageBodyHandler that tracks activities.
37 public class MyGsonProvider extends GsonMessageBodyHandler {
39 @Setter(AccessLevel.PRIVATE)
40 private static boolean readSome = false;
42 @Setter(AccessLevel.PRIVATE)
43 private static boolean wroteSome = false;
46 * Constructs the object and resets the variables to indicate that no activity has
49 public MyGsonProvider() {
54 public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
55 MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException {
58 return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
62 public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
63 MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
66 super.writeTo(object, type, genericType, annotations, mediaType, httpHeaders, entityStream);
69 public static boolean hasReadSome() {
73 public static boolean hasWrittenSome() {
77 public static void resetSome() {
78 MyGsonProvider.readSome = false;
79 MyGsonProvider.wroteSome = false;