Operational policy modification
[clamp.git] / src / test / java / org / onap / clamp / policy / downloader / PolicyEngineControllerTestItCase.java
1 package org.onap.clamp.policy.downloader;
2 /*-
3  * ============LICENSE_START=======================================================
4  * ONAP CLAMP
5  * ================================================================================
6  * Copyright (C) 2020 AT&T Intellectual Property. All rights
7  *                             reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END============================================
21  * ===================================================================
22  *
23  */
24
25 import static org.assertj.core.api.Assertions.assertThat;
26
27 import com.google.gson.JsonSyntaxException;
28 import java.io.IOException;
29 import java.time.Instant;
30 import java.util.List;
31 import javax.transaction.Transactional;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.clamp.clds.Application;
35 import org.onap.clamp.loop.template.PolicyModel;
36 import org.onap.clamp.loop.template.PolicyModelsRepository;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.test.context.ActiveProfiles;
40 import org.springframework.test.context.junit4.SpringRunner;
41
42 @RunWith(SpringRunner.class)
43 @SpringBootTest(classes = Application.class)
44 @ActiveProfiles(profiles = "clamp-default,clamp-policy-controller")
45 public class PolicyEngineControllerTestItCase {
46
47     @Autowired
48     PolicyEngineController policyController;
49
50     @Autowired
51     PolicyModelsRepository policyModelsRepository;
52
53     /**
54      * This method tests a fake synchronization with the emulator.
55      *
56      * @throws JsonSyntaxException  In case of issues
57      * @throws IOException          In case of issues
58      * @throws InterruptedException In case of issues
59      */
60     @Test
61     @Transactional
62     public void synchronizeAllPoliciesTest() throws JsonSyntaxException, IOException, InterruptedException {
63         policyController.synchronizeAllPolicies();
64         Instant firstExecution = policyController.getLastInstantExecuted();
65         assertThat(firstExecution).isNotNull();
66         List<PolicyModel> policyModelsList = policyModelsRepository.findAll();
67         assertThat(policyModelsList.size()).isGreaterThanOrEqualTo(8);
68         assertThat(policyModelsList).contains(new PolicyModel("onap.policies.Monitoring", null, "1.0.0"));
69         assertThat(policyModelsList).contains(new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0"));
70
71         // Re-do it to check that there is no issue with duplicate key
72         policyController.synchronizeAllPolicies();
73         Instant secondExecution = policyController.getLastInstantExecuted();
74         assertThat(secondExecution).isNotNull();
75
76         assertThat(firstExecution).isBefore(secondExecution);
77     }
78
79 }