2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-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.pap.xacml.rest.components;
23 import static org.assertj.core.api.Assertions.assertThatThrownBy;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.fail;
28 import com.att.research.xacml.api.pap.PAPException;
29 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
30 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
31 import org.junit.Rule;
32 import org.junit.Test;
33 import org.junit.rules.ExpectedException;
34 import org.onap.policy.rest.adapter.PolicyRestAdapter;
36 public class MicroServicePolicyTest {
38 public ExpectedException thrown = ExpectedException.none();
41 public void testConstructor1() {
42 thrown.expect(NullPointerException.class);
43 MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy();
44 policy.getCorrectPolicyDataObject();
45 fail("Expected an exception");
49 public void testConstructor2() {
50 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
51 MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
52 assertNull(policy.getCorrectPolicyDataObject());
55 @Test(expected = NullPointerException.class)
56 public void testSave() throws PAPException {
57 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
58 PolicyType policyType = new PolicyType();
59 policyAdapter.setPolicyID("id");
60 policyAdapter.setHighestVersion(1);
61 policyAdapter.setPolicyType("Config");
62 policyAdapter.setNewFileName("newfile");
63 policyAdapter.setData(policyType);
64 policyAdapter.setJsonBody("{\"key\":\"value\"}");
65 policyAdapter.setServiceType("svcType");
66 MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
68 policy.savePolicies();
72 public void testAdvice() {
73 PolicyType policyType = new PolicyType();
74 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
75 policyAdapter.setPolicyID("id");
76 policyAdapter.setHighestVersion(1);
77 policyAdapter.setPolicyType("Config");
78 policyAdapter.setNewFileName("newfile");
79 policyAdapter.setData(policyType);
80 policyAdapter.setJsonBody("{\"key\":\"value\"}");
81 policyAdapter.setServiceType("svcType");
83 MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
84 assertThatThrownBy(() -> policy.savePolicies()).isInstanceOf(NullPointerException.class);
86 AdviceExpressionsType expType = policy.getAdviceExpressions(1, "filename");
87 assertEquals(1, expType.getAdviceExpression().size());