2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdpx.main.rest.serialization;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
26 import com.att.research.xacml.api.Request;
27 import com.att.research.xacml.api.Response;
28 import java.lang.annotation.Annotation;
29 import java.lang.reflect.Type;
30 import javax.ws.rs.core.MediaType;
32 public class CommonSerialization {
34 @SuppressWarnings("rawtypes")
35 private static final Class REQUEST_CLASS = Request.class;
36 @SuppressWarnings("rawtypes")
37 private static final Class RESPONSE_CLASS = Response.class;
38 @SuppressWarnings("rawtypes")
39 private static final Class GENERAL_CLASS = MyObject.class;
41 public static void testIsWritableOrReadable(String primaryType, String subType,
42 MultiArgsFunction<Class<?>, Type, Annotation[], MediaType, Boolean> getter) {
45 assertFalse(getter.apply(null, null, null, null));
47 // valid media type and class type
48 assertTrue("writeable " + subType, getter.apply(
49 REQUEST_CLASS, null, null, new MediaType(primaryType, subType)));
50 assertTrue("writeable " + subType, getter.apply(
51 RESPONSE_CLASS, null, null, new MediaType(primaryType, subType)));
53 // valid media type but invalid class type
54 assertFalse(getter.apply(
55 GENERAL_CLASS, null, null, new MediaType(primaryType, subType)));
57 // null subtype or invalid media type
58 assertFalse(getter.apply(null, null, null, new MediaType(primaryType, null)));
59 assertFalse(getter.apply(null, null, null, MediaType.APPLICATION_JSON_TYPE));
62 public static class MyObject {
69 public MyObject(int id) {
74 public String toString() {
75 return "MyObject [id=" + id + "]";
80 public interface MultiArgsFunction<T, U, V, W, R> {
81 public R apply(T value1, U value2, V value3, W value4);