Code Review
/
nonrtric.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Integrate Config Binding Service client
[nonrtric.git]
/
policy-agent
/
src
/
test
/
java
/
org
/
oransc
/
policyagent
/
ApplicationTest.java
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
d8ff2e1
..
18ea22b
100644
(file)
--- a/
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
+++ b/
policy-agent/src/test/java/org/oransc/policyagent/ApplicationTest.java
@@
-21,9
+21,7
@@
package org.oransc.policyagent;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
-
import java.net.URL;
import java.net.URL;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.oransc.policyagent.configuration.ApplicationConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.oransc.policyagent.configuration.ApplicationConfig;
@@
-34,6
+32,7
@@
import org.oransc.policyagent.repository.Policies;
import org.oransc.policyagent.repository.Policy;
import org.oransc.policyagent.repository.PolicyType;
import org.oransc.policyagent.repository.PolicyTypes;
import org.oransc.policyagent.repository.Policy;
import org.oransc.policyagent.repository.PolicyType;
import org.oransc.policyagent.repository.PolicyTypes;
+import org.oransc.policyagent.repository.Rics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@
-45,40
+44,42
@@
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
+
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ApplicationTest {
@Autowired
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ApplicationTest {
@Autowired
- private Policies policies;
-
- @Autowired
- private PolicyTypes policyTypes;
-
- @Autowired
- ApplicationConfig appConfig;
+ private Beans beans;
static class MockApplicationConfig extends ApplicationConfig {
static class MockApplicationConfig extends ApplicationConfig {
+ @Override
public void initialize() {
URL url = MockApplicationConfig.class.getClassLoader().getResource("test_application_configuration.json");
loadConfigurationFromFile(url.getFile());
}
}
public void initialize() {
URL url = MockApplicationConfig.class.getClassLoader().getResource("test_application_configuration.json");
loadConfigurationFromFile(url.getFile());
}
}
+
@TestConfiguration
static class Beans {
@Bean
@TestConfiguration
static class Beans {
@Bean
- Policies getPolicies() {
+ public Rics getRics() {
+ return new Rics();
+ }
+
+ @Bean
+ public Policies getPolicies() {
return new Policies();
}
@Bean
return new Policies();
}
@Bean
- PolicyTypes getPolicyTypes() {
+
public
PolicyTypes getPolicyTypes() {
return new PolicyTypes();
}
@Bean
return new PolicyTypes();
}
@Bean
- ApplicationConfig getApplicationConfig() {
+
public
ApplicationConfig getApplicationConfig() {
return new MockApplicationConfig();
}
}
return new MockApplicationConfig();
}
}
@@
-111,7
+112,8
@@
public class ApplicationTest {
addPolicyType("type1");
this.restTemplate.put(url, json);
addPolicyType("type1");
this.restTemplate.put(url, json);
- Policy policy = this.policies.get("instance1");
+
+ Policy policy = beans.getPolicies().get("instance1");
assertThat(policy).isNotNull();
assertThat(policy.id()).isEqualTo("instance1");
assertThat(policy).isNotNull();
assertThat(policy.id()).isEqualTo("instance1");
@@
-120,22
+122,22
@@
public class ApplicationTest {
private PolicyType addPolicyType(String name) {
PolicyType type = ImmutablePolicyType.builder() //
private PolicyType addPolicyType(String name) {
PolicyType type = ImmutablePolicyType.builder() //
- .jsonSchema("") //
- .name(name) //
- .build();
+
.jsonSchema("") //
+
.name(name) //
+
.build();
-
policyTypes
.put(type);
+
beans.getPolicyTypes()
.put(type);
return type;
}
private Policy addPolicy(String id, String typeName, String service) throws ServiceException {
Policy p = ImmutablePolicy.builder().id(id) //
return type;
}
private Policy addPolicy(String id, String typeName, String service) throws ServiceException {
Policy p = ImmutablePolicy.builder().id(id) //
- .json("{}") //
- .ownerServiceName(service) //
-
.ric(appConfig
.getRic("ric1")) //
- .type(addPolicyType(typeName)) //
- .build();
-
this.policies
.put(p);
+
.json("{}") //
+
.ownerServiceName(service) //
+
.ric(beans.getRics()
.getRic("ric1")) //
+
.type(addPolicyType(typeName)) //
+
.build();
+
beans.getPolicies()
.put(p);
return p;
}
return p;
}
@@
-148,7
+150,7
@@
public class ApplicationTest {
assertThat(rsp).isEqualTo(policy.json());
}
{
assertThat(rsp).isEqualTo(policy.json());
}
{
-
this.policies
.remove(policy);
+
beans.getPolicies()
.remove(policy);
ResponseEntity<String> rsp = this.restTemplate.getForEntity(url, String.class);
assertThat(rsp.getStatusCodeValue()).isEqualTo(HttpStatus.NO_CONTENT.value());
}
ResponseEntity<String> rsp = this.restTemplate.getForEntity(url, String.class);
assertThat(rsp.getStatusCodeValue()).isEqualTo(HttpStatus.NO_CONTENT.value());
}
@@
-168,11
+170,11
@@
public class ApplicationTest {
@Test
public void getPoliciesFilter() throws Exception {
@Test
public void getPoliciesFilter() throws Exception {
- String url = "http://localhost:" + port + "/policies?type=type1";
addPolicy("id1", "type1", "service1");
addPolicy("id2", "type1", "service2");
addPolicy("id3", "type2", "service1");
addPolicy("id1", "type1", "service1");
addPolicy("id2", "type1", "service2");
addPolicy("id3", "type2", "service1");
+ String url = "http://localhost:" + port + "/policies?type=type1";
String rsp = this.restTemplate.getForObject(url, String.class);
System.out.println(rsp);
assertThat(rsp).contains("id1");
String rsp = this.restTemplate.getForObject(url, String.class);
System.out.println(rsp);
assertThat(rsp).contains("id1");