X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2FApplicationTest.java;h=091915415d299eb663b0cfc5dcfe8f21c046b13f;hb=eec4647d457ca8c2ebecc86485127bd529919533;hp=8a6523c4ca0b923251434b53e25c90d807d43bfc;hpb=ffe0c150f08205d73ee362f58f492aeb2703f295;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java index 8a6523c4..09191541 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java @@ -34,6 +34,7 @@ import java.util.Vector; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.oransc.policyagent.clients.A1Client; import org.oransc.policyagent.configuration.ApplicationConfig; import org.oransc.policyagent.configuration.ImmutableRicConfig; import org.oransc.policyagent.configuration.RicConfig; @@ -50,6 +51,8 @@ import org.oransc.policyagent.repository.PolicyType; import org.oransc.policyagent.repository.PolicyTypes; import org.oransc.policyagent.repository.Ric; import org.oransc.policyagent.repository.Rics; +import org.oransc.policyagent.tasks.RepositorySupervision; +import org.oransc.policyagent.utils.MockA1Client; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -77,15 +80,21 @@ public class ApplicationTest { @Autowired private PolicyTypes policyTypes; + @Autowired + MockA1Client a1Client; + + @Autowired + RepositorySupervision supervision; + private static Gson gson = new GsonBuilder() // .serializeNulls() // .create(); // public static class MockApplicationConfig extends ApplicationConfig { @Override - public void initialize() { + public String getLocalConfigurationFilePath() { URL url = MockApplicationConfig.class.getClassLoader().getResource("test_application_configuration.json"); - loadConfigurationFromFile(url.getFile()); + return url.getFile(); } } @@ -94,20 +103,31 @@ public class ApplicationTest { */ @TestConfiguration static class TestBeanFactory { + private final PolicyTypes policyTypes = new PolicyTypes(); @Bean public ApplicationConfig getApplicationConfig() { return new MockApplicationConfig(); } + @Bean + A1Client getA1Client() { + return new MockA1Client(this.policyTypes); + } + + @Bean + public Policies getPolicies() { + return new Policies(); + } + + @Bean + public PolicyTypes getPolicyTypes() { + return this.policyTypes; + } + @Bean public Rics getRics() { - Rics rics = new Rics(); - rics.put(new Ric(ImmutableRicConfig.builder().name("kista_1").baseUrl("kista_url") - .managedElementIds(new Vector<>()).build())); - rics.put(new Ric(ImmutableRicConfig.builder().name("ric1").baseUrl("ric_url") - .managedElementIds(new Vector<>()).build())); - return rics; + return new Rics(); } } @@ -137,6 +157,22 @@ public class ApplicationTest { assertThat(rsp).isEqualTo("[]"); } + @Test + public void testRecovery() throws Exception { + reset(); + Policy policy = addPolicy("policyId", "typeName", "service", "ric"); // This should be created in the RIC + + Policy policy2 = addPolicy("policyId2", "typeName", "service", "ric"); + a1Client.putPolicy("ric", policy2); // put it in the RIC + policies.remove(policy2); // Remove it from the repo -> should be deleted in the RIC + + supervision.checkAllRics(); // The created policy should be put in the RIC + Policies ricPolicies = a1Client.getPolicies("ric"); + assertThat(ricPolicies.size()).isEqualTo(1); + Policy ricPolicy = ricPolicies.get("policyId"); + assertThat(ricPolicy.json()).isEqualTo(policy.json()); + } + @Test public void testGetRic() throws Exception { reset(); @@ -146,8 +182,6 @@ public class ApplicationTest { assertThat(rsp).isEqualTo("ric1"); } - // managedElmentId -> nodeName - @Test public void testPutPolicy() throws Exception { putService("service1"); @@ -155,6 +189,7 @@ public class ApplicationTest { String url = baseUrl() + "/policy?type=type1&instance=instance1&ric=ric1&service=service1"; String json = "{}"; addPolicyType("type1", "ric1"); + this.rics.getRic("ric1").setState(Ric.RicState.IDLE); this.restTemplate.put(url, json); @@ -187,7 +222,7 @@ public class ApplicationTest { Vector mes = new Vector<>(); RicConfig conf = ImmutableRicConfig.builder() // .name(ricName) // - .baseUrl("baseUrl") // + .baseUrl(ricName) // .managedElementIds(mes) // .build(); Ric ric = new Ric(conf); @@ -234,7 +269,8 @@ public class ApplicationTest { public void testDeletePolicy() throws Exception { reset(); String url = baseUrl() + "/policy?instance=id"; - addPolicy("id", "typeName", "service1", "ric1"); + Policy policy = addPolicy("id", "typeName", "service1", "ric1"); + policy.ric().setState(Ric.RicState.IDLE); assertThat(policies.size()).isEqualTo(1); this.restTemplate.delete(url); @@ -338,6 +374,7 @@ public class ApplicationTest { ServiceRegistrationInfo service = ImmutableServiceRegistrationInfo.builder() // .keepAliveInterval(1) // .name(name) // + .callbackUrl("callbackUrl") // .build(); String json = gson.toJson(service); return json;