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