Consolidate PolicyRestAdapter setup
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / components / ClosedLoopPolicyTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.components;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.fail;
26
27 import com.att.research.xacml.api.pap.PAPException;
28
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.onap.policy.rest.adapter.PolicyRestAdapter;
36
37 public class ClosedLoopPolicyTest {
38     @Rule
39     public ExpectedException thrown = ExpectedException.none();
40
41     @Test
42     public void testConstructor1() {
43         thrown.expect(NullPointerException.class);
44         ClosedLoopPolicy policy = new ClosedLoopPolicy();
45         policy.getCorrectPolicyDataObject();
46     }
47
48     @Test
49     public void testConstructor2() {
50         PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
51         ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
52         assertNull(policy.getCorrectPolicyDataObject());
53     }
54
55     @Test
56     public void testReadFile() throws IOException {
57         thrown.expect(IOException.class);
58         ClosedLoopPolicy.readFile("/foo",  StandardCharsets.UTF_8);
59         fail("Expecting an exception.");
60     }
61
62     @Test
63     public void testPrepareToSave() throws PAPException {
64         PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
65         ClosedLoopPolicy policy = new ClosedLoopPolicy(policyAdapter);
66         policyAdapter.setHighestVersion(1);
67         policyAdapter.setPolicyType("Config");
68         policyAdapter.setNewFileName("foo.xml");
69         policy.prepareToSave();
70         assertEquals(policy.isPreparedToSave(), true);
71     }
72 }