2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021,2023 Nordix Foundation.
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.clamp.models.acm.messages.dmaap.participant;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import org.onap.policy.common.utils.coder.CoderException;
26 import org.onap.policy.common.utils.coder.StandardCoder;
29 * Utility class for tests of ParticipantMessage subclasses.
31 public class ParticipantMessageUtils {
33 private ParticipantMessageUtils() {
37 public static String removeVariableFields(String text) {
38 return text.replaceAll("messageId=[^,]*", "messageId=xxx").replaceAll("timestamp=[^,]*", "timestamp=nnn");
42 * Check if object is Serializable.
44 * @param object the Object
45 * @param clazz the class of the Object
46 * @throws CoderException if object is not Serializable
48 public static <T> void assertSerializable(Object object, Class<T> clazz) throws CoderException {
49 var standardCoder = new StandardCoder();
50 var json = standardCoder.encode(object);
51 var other = standardCoder.decode(json, clazz);
53 assertEquals(removeVariableFields(object.toString()), removeVariableFields(other.toString()));