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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pdp.xacml.application.common.std;
25 import static org.assertj.core.api.Assertions.assertThatThrownBy;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
30 import java.util.HashMap;
32 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
33 import org.junit.Test;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
35 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
37 public class StdBaseTranslatorTest {
41 StdBaseTranslator translator = new StdBaseTranslator();
42 assertNotNull(translator);
43 assertThatThrownBy(() -> translator.convertPolicy(null)).isInstanceOf(ToscaPolicyConversionException.class);
44 assertNull(translator.convertRequest(null));
48 public void testBadData() throws ToscaPolicyConversionException {
49 TestTranslator translator = new TestTranslator();
51 assertThatThrownBy(() -> translator.convertPolicy(
52 new ToscaPolicy())).isInstanceOf(ToscaPolicyConversionException.class)
53 .hasMessageContaining("missing metadata");
55 translator.metadata.put(StdBaseTranslator.POLICY_ID, "random.policy.id");
57 assertThatThrownBy(() -> translator.convertPolicy(
58 new ToscaPolicy())).isInstanceOf(ToscaPolicyConversionException.class)
59 .hasMessageContaining("missing metadata");
61 translator.metadata.put(StdBaseTranslator.POLICY_VERSION, "1.0.0");
63 ToscaPolicy policy = new ToscaPolicy();
64 assertEquals("1.0.0", translator.convertPolicy(policy).getVersion());
68 public class TestTranslator extends StdBaseTranslator {
69 public Map<String, String> metadata = new HashMap<>();
72 public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
73 PolicyType xacmlPolicy = new PolicyType();
74 this.fillMetadataSection(xacmlPolicy, metadata);