import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.oransc.policyagent.repository.Ric.RicState.ACTIVE;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
import java.util.Vector;
import org.junit.jupiter.api.Test;
import org.oransc.policyagent.configuration.ImmutableRicConfig;
import org.oransc.policyagent.configuration.RicConfig;
import org.oransc.policyagent.exceptions.ServiceException;
-import org.oransc.policyagent.repository.ImmutablePolicyType;
-import org.oransc.policyagent.repository.PolicyType;
import org.oransc.policyagent.repository.PolicyTypes;
import org.oransc.policyagent.repository.Ric;
import org.oransc.policyagent.repository.Rics;
@Mock
A1Client a1ClientMock;
- private static Gson gson = new GsonBuilder() //
- .serializeNulls() //
- .create(); //
-
@Test
public void startup_allOk() throws ServiceException {
Vector<RicConfig> ricConfigs = new Vector<>(2);
ricConfigs.add(getRicConfig(SECOND_RIC_NAME, SECOND_RIC_URL, MANAGED_NODE_B, MANAGED_NODE_C));
when(appConfigMock.getRicConfigs()).thenReturn(ricConfigs);
- PolicyType type1 = ImmutablePolicyType.builder().name(POLICY_TYPE_1_NAME).jsonSchema("{}").build();
- Flux<String> fluxType1 = Flux.just(gson.toJson(type1));
- PolicyType type2 = ImmutablePolicyType.builder().name(POLICY_TYPE_2_NAME).jsonSchema("{}").build();
- Flux<String> fluxType2 = Flux.just(gson.toJson(type2));
- when(a1ClientMock.getAllPolicyTypes(anyString())).thenReturn(fluxType1)
+ Flux<String> fluxType1 = Flux.just(POLICY_TYPE_1_NAME);
+ Flux<String> fluxType2 = Flux.just(POLICY_TYPE_2_NAME);
+ when(a1ClientMock.getPolicyTypeIdentities(anyString())).thenReturn(fluxType1)
.thenReturn(fluxType1.concatWith(fluxType2));
Flux<String> policies = Flux.just(new String[] {POLICY_ID_1, POLICY_ID_2});
- when(a1ClientMock.getPoliciesForType(anyString(), anyString())).thenReturn(policies);
+ when(a1ClientMock.getPolicyIdentities(anyString())).thenReturn(policies);
when(a1ClientMock.deletePolicy(anyString(), anyString())).thenReturn(Mono.empty());
Rics rics = new Rics();
await().untilAsserted(() -> assertThat(policyTypes.size()).isEqualTo(2));
- verify(a1ClientMock).getAllPolicyTypes(FIRST_RIC_URL);
+ verify(a1ClientMock).getPolicyTypeIdentities(FIRST_RIC_URL);
verify(a1ClientMock).deletePolicy(FIRST_RIC_URL, POLICY_ID_1);
verify(a1ClientMock).deletePolicy(FIRST_RIC_URL, POLICY_ID_2);
- verify(a1ClientMock).getAllPolicyTypes(SECOND_RIC_URL);
- verify(a1ClientMock, times(2)).deletePolicy(SECOND_RIC_URL, POLICY_ID_1);
- verify(a1ClientMock, times(2)).deletePolicy(SECOND_RIC_URL, POLICY_ID_2);
+ verify(a1ClientMock).getPolicyTypeIdentities(SECOND_RIC_URL);
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_1);
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_2);
- assertEquals(type1, policyTypes.getType(POLICY_TYPE_1_NAME), "Not correct type added.");
- assertEquals(type2, policyTypes.getType(POLICY_TYPE_2_NAME), "Not correct type added.");
+ assertTrue(policyTypes.contains(POLICY_TYPE_1_NAME), POLICY_TYPE_1_NAME + " not added to PolicyTypes.");
+ assertTrue(policyTypes.contains(POLICY_TYPE_2_NAME), POLICY_TYPE_2_NAME + " not added to PolicyTypes.");
assertEquals(2, rics.size(), "Correct number of Rics not added to Rics");
Ric firstRic = rics.getRic(FIRST_RIC_NAME);
- assertNotNull(firstRic, "Ric \"" + FIRST_RIC_NAME + "\" not added to repositpry");
- assertEquals(FIRST_RIC_NAME, firstRic.name(), "Not correct Ric \"" + FIRST_RIC_NAME + "\" added to Rics");
- assertEquals(ACTIVE, firstRic.state(), "Not correct state for \"" + FIRST_RIC_NAME + "\"");
- assertEquals(1, firstRic.getSupportedPolicyTypes().size(), "Not correct no of types supported");
- assertTrue(firstRic.isSupportingType(type1.name()), "Not correct type supported");
- assertEquals(1, firstRic.getManagedNodes().size(), "Not correct no of managed nodes");
- assertTrue(firstRic.isManaging(MANAGED_NODE_A), "Not managed by node");
+ assertNotNull(firstRic, "Ric " + FIRST_RIC_NAME + " not added to repository");
+ assertEquals(FIRST_RIC_NAME, firstRic.name(), FIRST_RIC_NAME + " not added to Rics");
+ assertEquals(ACTIVE, firstRic.state(), "Not correct state for ric " + FIRST_RIC_NAME);
+ assertEquals(1, firstRic.getSupportedPolicyTypes().size(),
+ "Not correct no of types supported for ric " + FIRST_RIC_NAME);
+ assertTrue(firstRic.isSupportingType(POLICY_TYPE_1_NAME),
+ POLICY_TYPE_1_NAME + " not supported by ric " + FIRST_RIC_NAME);
+ assertEquals(1, firstRic.getManagedNodes().size(), "Not correct no of managed nodes for ric " + FIRST_RIC_NAME);
+ assertTrue(firstRic.isManaging(MANAGED_NODE_A), MANAGED_NODE_A + " not managed by ric " + FIRST_RIC_NAME);
Ric secondRic = rics.getRic(SECOND_RIC_NAME);
- assertNotNull(secondRic, "Ric \"" + SECOND_RIC_NAME + "\" not added to repositpry");
- assertEquals(SECOND_RIC_NAME, secondRic.name(), "Not correct Ric \"" + SECOND_RIC_NAME + "\" added to Rics");
- assertEquals(ACTIVE, secondRic.state(), "Not correct state for \"" + SECOND_RIC_NAME + "\"");
- assertEquals(2, secondRic.getSupportedPolicyTypes().size(), "Not correct no of types supported");
- assertTrue(secondRic.isSupportingType(type1.name()), "Not correct type supported");
- assertTrue(secondRic.isSupportingType(type2.name()), "Not correct type supported");
- assertEquals(2, secondRic.getManagedNodes().size(), "Not correct no of managed nodes");
- assertTrue(secondRic.isManaging(MANAGED_NODE_B), "Not correct managed node");
- assertTrue(secondRic.isManaging(MANAGED_NODE_C), "Not correct managed node");
+ assertNotNull(secondRic, "Ric " + SECOND_RIC_NAME + " not added to repositpry");
+ assertEquals(SECOND_RIC_NAME, secondRic.name(), SECOND_RIC_NAME + " not added to Rics");
+ assertEquals(ACTIVE, secondRic.state(), "Not correct state for " + SECOND_RIC_NAME);
+ assertEquals(2, secondRic.getSupportedPolicyTypes().size(),
+ "Not correct no of types supported for ric " + SECOND_RIC_NAME);
+ assertTrue(secondRic.isSupportingType(POLICY_TYPE_1_NAME),
+ POLICY_TYPE_1_NAME + " not supported by ric " + SECOND_RIC_NAME);
+ assertTrue(secondRic.isSupportingType(POLICY_TYPE_2_NAME),
+ POLICY_TYPE_2_NAME + " not supported by ric " + SECOND_RIC_NAME);
+ assertEquals(2, secondRic.getManagedNodes().size(),
+ "Not correct no of managed nodes for ric " + SECOND_RIC_NAME);
+ assertTrue(secondRic.isManaging(MANAGED_NODE_B), MANAGED_NODE_B + " not managed by ric " + SECOND_RIC_NAME);
+ assertTrue(secondRic.isManaging(MANAGED_NODE_C), MANAGED_NODE_C + " not managed by ric " + SECOND_RIC_NAME);
}
private RicConfig getRicConfig(String name, String baseUrl, String... nodeNames) {