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 OptimizationConfigPolicyTest {
38 public ExpectedException thrown = ExpectedException.none();
41 public void testConstructor1() {
42 thrown.expect(NullPointerException.class);
43 OptimizationConfigPolicy policy = new OptimizationConfigPolicy();
44 policy.getCorrectPolicyDataObject();
45 fail("Expected an exception");
49 public void testConstructor2() {
50 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
51 OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
52 assertNull(policy.getCorrectPolicyDataObject());
56 public void testSave() throws PAPException {
57 PolicyType policyType = new PolicyType();
58 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
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 OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
67 assertThatThrownBy(() -> policy.savePolicies()).isInstanceOf(Exception.class);
71 public void testAdvice() {
72 PolicyType policyType = new PolicyType();
73 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
74 policyAdapter.setPolicyID("id");
75 policyAdapter.setHighestVersion(1);
76 policyAdapter.setPolicyType("Config");
77 policyAdapter.setNewFileName("newfile");
78 policyAdapter.setData(policyType);
79 policyAdapter.setJsonBody("{\"key\":\"value\"}");
80 policyAdapter.setServiceType("svcType");
82 OptimizationConfigPolicy policy = new OptimizationConfigPolicy(policyAdapter);
83 assertThatThrownBy(() -> policy.savePolicies()).isInstanceOf(Exception.class);
85 AdviceExpressionsType expType = policy.getAdviceExpressions(1, "filename");
86 assertEquals(1, expType.getAdviceExpression().size());