- verify(ricClientMock).deleteAllPolicies(FIRST_RIC_URL);
- verify(ricClientMock).getPolicyTypes(FIRST_RIC_URL);
- verify(ricClientMock).deleteAllPolicies(SECOND_RIC_URL);
- verify(ricClientMock).getPolicyTypes(SECOND_RIC_URL);
- verifyNoMoreInteractions(ricClientMock);
-
- assertEquals("Not correct number of policy types added.", 2, policyTypes.size());
- assertEquals("Not correct type added.", type1, policyTypes.getType(POLICY_TYPE_1_NAME));
- assertEquals("Not correct type added.", type2, policyTypes.getType(POLICY_TYPE_2_NAME));
- assertEquals("Correct nymber of Rics not added to Rics", 2, rics.size());
-
- Ric firstRic = rics.getRic(FIRST_RIC_NAME);
- assertNotNull("Ric \"" + FIRST_RIC_NAME + "\" not added to repositpry", firstRic);
- assertEquals("Not correct Ric \"" + FIRST_RIC_NAME + "\" added to Rics", FIRST_RIC_NAME, firstRic.name());
- assertEquals("Not correct state for \"" + FIRST_RIC_NAME + "\"", ACTIVE, firstRic.state());
- assertEquals("Not correct no of types supported", 1, firstRic.getSupportedPolicyTypes().size());
- assertTrue("Not correct type supported", firstRic.isSupportingType(type1));
- assertEquals("Not correct no of managed nodes", 1, firstRic.getManagedNodes().size());
- assertTrue("Not managed by node", firstRic.isManaging(MANAGED_NODE_A));
-
- Ric secondRic = rics.getRic(SECOND_RIC_NAME);
- assertNotNull("Ric \"" + SECOND_RIC_NAME + "\" not added to repositpry", secondRic);
- assertEquals("Not correct Ric \"" + SECOND_RIC_NAME + "\" added to Rics", SECOND_RIC_NAME, secondRic.name());
- assertEquals("Not correct state for \"" + SECOND_RIC_NAME + "\"", ACTIVE, secondRic.state());
- assertEquals("Not correct no of types supported", 2, secondRic.getSupportedPolicyTypes().size());
- assertTrue("Not correct type supported", secondRic.isSupportingType(type1));
- assertTrue("Not correct type supported", secondRic.isSupportingType(type2));
- assertEquals("Not correct no of managed nodes", 2, secondRic.getManagedNodes().size());
- assertTrue("Not correct managed node", secondRic.isManaging(MANAGED_NODE_B));
- assertTrue("Not correct managed node", secondRic.isManaging(MANAGED_NODE_C));
+ await().untilAsserted(() -> assertThat(policyTypes.size()).isEqualTo(2));
+
+ 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).getPolicyTypeIdentities(SECOND_RIC_URL);
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_1);
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_2);
+
+ 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.get(FIRST_RIC_NAME);
+ 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.get(SECOND_RIC_NAME);
+ assertNotNull(secondRic, "Ric " + SECOND_RIC_NAME + " not added to repository");
+ 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);
+ }
+
+ @Test
+ public void startup_unableToConnectToGetTypes() {
+ Vector<RicConfig> ricConfigs = new Vector<>(2);
+ ricConfigs.add(getRicConfig(FIRST_RIC_NAME, FIRST_RIC_URL, MANAGED_NODE_A));
+ ricConfigs.add(getRicConfig(SECOND_RIC_NAME, SECOND_RIC_URL, MANAGED_NODE_B, MANAGED_NODE_C));
+ when(appConfigMock.getRicConfigs()).thenReturn(ricConfigs);
+
+ Flux<String> fluxType1 = Flux.just(POLICY_TYPE_1_NAME);
+ doReturn(Flux.error(new Exception("Unable to contact ric.")), fluxType1).when(a1ClientMock)
+ .getPolicyTypeIdentities(anyString());
+
+ Flux<String> policies = Flux.just(new String[] {POLICY_ID_1, POLICY_ID_2});
+ doReturn(policies).when(a1ClientMock).getPolicyIdentities(anyString());
+ when(a1ClientMock.getPolicyType(anyString(), anyString())).thenReturn(Mono.just("Schema"));
+ when(a1ClientMock.deletePolicy(anyString(), anyString())).thenReturn(Mono.just("OK"));
+
+ Rics rics = new Rics();
+ PolicyTypes policyTypes = new PolicyTypes();
+ StartupService serviceUnderTest = new StartupService(appConfigMock, rics, policyTypes, a1ClientMock);
+
+ serviceUnderTest.startup();
+
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_1);
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_2);
+
+ assertEquals(NOT_REACHABLE, rics.get(FIRST_RIC_NAME).state(), "Not correct state for " + FIRST_RIC_NAME);
+
+ assertEquals(ACTIVE, rics.get(SECOND_RIC_NAME).state(), "Not correct state for " + SECOND_RIC_NAME);
+ }
+
+ @Test
+ public void startup_unableToConnectToGetPolicies() {
+ Vector<RicConfig> ricConfigs = new Vector<>(2);
+ ricConfigs.add(getRicConfig(FIRST_RIC_NAME, FIRST_RIC_URL, MANAGED_NODE_A));
+ ricConfigs.add(getRicConfig(SECOND_RIC_NAME, SECOND_RIC_URL, MANAGED_NODE_B, MANAGED_NODE_C));
+ when(appConfigMock.getRicConfigs()).thenReturn(ricConfigs);
+
+ 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));
+ when(a1ClientMock.getPolicyType(anyString(), anyString())).thenReturn(Mono.just("Schema"));
+ Flux<String> policies = Flux.just(new String[] {POLICY_ID_1, POLICY_ID_2});
+ doReturn(Flux.error(new Exception("Unable to contact ric.")), policies).when(a1ClientMock)
+ .getPolicyIdentities(anyString());
+ when(a1ClientMock.deletePolicy(anyString(), anyString())).thenReturn(Mono.just("OK"));
+
+ Rics rics = new Rics();
+ PolicyTypes policyTypes = new PolicyTypes();
+ StartupService serviceUnderTest = new StartupService(appConfigMock, rics, policyTypes, a1ClientMock);
+
+ serviceUnderTest.startup();
+
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_1);
+ verify(a1ClientMock).deletePolicy(SECOND_RIC_URL, POLICY_ID_2);
+
+ assertEquals(NOT_REACHABLE, rics.get(FIRST_RIC_NAME).state(), "Not correct state for " + FIRST_RIC_NAME);
+
+ assertEquals(ACTIVE, rics.get(SECOND_RIC_NAME).state(), "Not correct state for " + SECOND_RIC_NAME);