Get types at startup
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / tasks / StartupServiceTest.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 Nordix Foundation
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.oransc.policyagent.tasks;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.anyString;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.verifyNoMoreInteractions;
28 import static org.mockito.Mockito.when;
29
30 import java.util.Vector;
31
32 import org.junit.Test;
33 import org.oransc.policyagent.clients.RicClient;
34 import org.oransc.policyagent.configuration.ApplicationConfig;
35 import org.oransc.policyagent.configuration.ImmutableRicConfig;
36 import org.oransc.policyagent.configuration.RicConfig;
37 import org.oransc.policyagent.exceptions.ServiceException;
38 import org.oransc.policyagent.repository.ImmutablePolicyType;
39 import org.oransc.policyagent.repository.PolicyType;
40 import org.oransc.policyagent.repository.PolicyTypes;
41 import org.oransc.policyagent.repository.Rics;
42
43 public class StartupServiceTest {
44     ApplicationConfig appConfigMock;
45
46     @Test
47     public void startup_allOk() throws ServiceException {
48         ApplicationConfig appConfigMock = mock(ApplicationConfig.class);
49         Vector<RicConfig> ricConfigs = new Vector<>(2);
50         Vector<String> firstNodes = new Vector<String>(1);
51         firstNodes.add("nodeA");
52         ricConfigs.add(ImmutableRicConfig.builder().name("first").managedElementIds(firstNodes).baseUrl("url").build());
53         when(appConfigMock.getRicConfigs()).thenReturn(ricConfigs);
54
55         Rics rics = new Rics();
56         PolicyTypes policyTypes = new PolicyTypes();
57
58         Vector<PolicyType> types = new Vector<>();
59         PolicyType type = ImmutablePolicyType.builder().name("type1").jsonSchema("{}").build();
60         types.add(type);
61         RicClient ricClientMock = mock(RicClient.class);
62         when(ricClientMock.getPolicyTypes(anyString())).thenReturn(types);
63
64         StartupService serviceUnderTest = new StartupService(appConfigMock, rics, policyTypes, ricClientMock);
65
66         serviceUnderTest.startup();
67
68         verify(ricClientMock).deleteAllPolicies("url");
69         verify(ricClientMock).getPolicyTypes("url");
70         verifyNoMoreInteractions(ricClientMock);
71
72         assertEquals("Correct nymber of Rics not added to Rics", 1, rics.size());
73         assertEquals("Not correct Ric added to Rics", "first", rics.getRic("first").name());
74
75         assertEquals("Not correct number of policy types added.", 1, policyTypes.size());
76         assertEquals("Not correct type added.", type, policyTypes.getType(type.name()));
77     }
78 }