diff options
Diffstat (limited to 'context/context-management/src/test/java')
2 files changed, 58 insertions, 3 deletions
diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java index 611eb7f25..65b2ed6ff 100644 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -72,6 +73,10 @@ public class JavaSchemaHelperParametersTest { jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportJsonAdapter"); assertTrue(pars.validate().isValid()); + jsonPars.setAdaptedClass("java.lang.String"); + jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportJsonAdapter2"); + assertTrue(pars.validate().isValid()); + Map<String, JavaSchemaHelperJsonAdapterParameters> adapterMap = new LinkedHashMap<>(); pars.setJsonAdapters(adapterMap); diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonAdapter2.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonAdapter2.java new file mode 100644 index 000000000..627cde4c4 --- /dev/null +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonAdapter2.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.context.impl.schema.java; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import java.io.IOException; + +public class SupportJsonAdapter2 extends TypeAdapter<String> { + + @Override + public void write(JsonWriter out, String value) throws IOException { + if (value == null) { + out.nullValue(); + + } else { + out.value(value); + } + } + + @Override + public String read(JsonReader in) throws IOException { + if (in.peek() == JsonToken.NULL) { + in.nextNull(); + return null; + } else { + return in.nextString(); + } + } +} |