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.models.pdp.concepts;
23 import org.onap.policy.common.utils.coder.Coder;
24 import org.onap.policy.common.utils.coder.CoderException;
25 import org.onap.policy.common.utils.coder.StandardCoder;
28 * Super class to test identity keys.
30 * @param <T> type of key being tested
32 public class IdentTestBase<T> {
34 private static final Coder coder = new StandardCoder();
36 private final Class<T> clazz;
40 * Constructs the object.
41 * @param clazz the type of class being tested
43 public IdentTestBase(Class<T> clazz) {
48 * Makes an identifier. Uses JSON which does no error checking.
50 * @param name name to put into the identifier
51 * @param version version to put into the identifier
52 * @return a new identifier
53 * @throws CoderException if the JSON cannot be decoded
55 public T makeIdent(String name, String version) throws CoderException {
56 StringBuilder bldr = new StringBuilder();
60 bldr.append("'name':'");
65 if (version != null) {
70 bldr.append("'version':'");
77 String json = bldr.toString().replace('\'', '"');
79 return coder.decode(json, clazz);