+ @Test
+ public void startupAndUnableToConnectToGetTypes_thenRicStateSetToUndefined() {
+ Mono<?> error = Mono.error(new Exception("Unable to contact ric."));
+ doReturn(error, error).when(a1ClientMock).getPolicyTypeIdentities();
+
+ Rics rics = new Rics();
+ PolicyTypes policyTypes = new PolicyTypes();
+ StartupService serviceUnderTest = new StartupService(appConfigMock, refreshTaskMock, rics, policyTypes,
+ a1ClientFactory, new Policies(), new Services());
+
+ serviceUnderTest.startup();
+ serviceUnderTest.onRicConfigUpdate(getRicConfig(FIRST_RIC_NAME, FIRST_RIC_URL, MANAGED_NODE_A),
+ ApplicationConfig.RicConfigUpdate.ADDED);
+
+ assertEquals(RicState.UNDEFINED, rics.get(FIRST_RIC_NAME).getState(),
+ "Not correct state for " + FIRST_RIC_NAME);
+ }
+
+ @Test
+ public void startupAndUnableToConnectToDeleteAllPolicies_thenRicStateSetToUndefined() {
+
+ Mono<List<String>> policyTypes = Mono.just(Arrays.asList(POLICY_TYPE_1_NAME));
+ when(a1ClientMock.getPolicyTypeIdentities()).thenReturn(policyTypes);
+ when(a1ClientMock.getPolicyTypeSchema(anyString())).thenReturn(Mono.just("Schema"));
+ Flux<?> error = Flux.error(new Exception("Unable to contact ric."));
+ doReturn(error).when(a1ClientMock).deleteAllPolicies();
+
+ RicConfig ricConfig = mock(RicConfig.class);
+ when(ricConfig.name()).thenReturn(FIRST_RIC_NAME);
+ when(ricConfig.managedElementIds()).thenReturn(ImmutableList.copyOf(Collections.emptyList()));
+ Ric ric = new Ric(ricConfig);
+
+ PolicyType policyType = mock(PolicyType.class);
+ when(policyType.name()).thenReturn(POLICY_TYPE_1_NAME);
+
+ Policy policy = mock(Policy.class);
+ when(policy.ric()).thenReturn(ric);
+ when(policy.type()).thenReturn(policyType);
+ Policies policies = new Policies();
+ policies.put(policy);
+
+ StartupService serviceUnderTest = new StartupService(appConfigMock, refreshTaskMock, new Rics(),
+ new PolicyTypes(), a1ClientFactory, policies, new Services());
+
+ serviceUnderTest.startup();
+ serviceUnderTest.onRicConfigUpdate(getRicConfig(FIRST_RIC_NAME, FIRST_RIC_URL, MANAGED_NODE_A),
+ ApplicationConfig.RicConfigUpdate.ADDED);
+
+ assertEquals(RicState.UNDEFINED, ric.getState(), "Not correct state for " + FIRST_RIC_NAME);
+ }
+
+ @SafeVarargs
+ private <T> Vector<T> toVector(T... objs) {
+ Vector<T> result = new Vector<>();
+ for (T o : objs) {
+ result.add(o);