+ policyTypes.put(type);
+ 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);
+ return p;
+ }
+
+ @Test
+ public void getPolicy() throws Exception {
+ String url = "http://localhost:" + port + "/policy?instance=id";
+ Policy policy = addPolicy("id", "typeName", "service1");
+ {
+ String rsp = this.restTemplate.getForObject(url, String.class);
+ assertThat(rsp).isEqualTo(policy.json());
+ }
+ {
+ this.policies.remove(policy);
+ ResponseEntity<String> rsp = this.restTemplate.getForEntity(url, String.class);
+ assertThat(rsp.getStatusCodeValue()).isEqualTo(HttpStatus.NO_CONTENT.value());
+ }
+ }
+
+ @Test
+ public void getPolicies() throws Exception {
+ String url = "http://localhost:" + port + "/policies";
+ addPolicy("id1", "type1", "service1");
+ addPolicy("id2", "type2", "service2");
+
+ String rsp = this.restTemplate.getForObject(url, String.class);
+ System.out.println(rsp);
+ assertThat(rsp).contains("id1");
+ assertThat(rsp).contains("id2");
+ }
+
+ @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");
+
+ String rsp = this.restTemplate.getForObject(url, String.class);
+ System.out.println(rsp);
+ assertThat(rsp).contains("id1");
+ assertThat(rsp).contains("id2");
+ assertFalse(rsp.contains("id3"));
+
+ url = "http://localhost:" + port + "/policies?type=type1&service=service2";
+ rsp = this.restTemplate.getForObject(url, String.class);
+ System.out.println(rsp);
+ assertFalse(rsp.contains("id1"));
+ assertThat(rsp).contains("id2");
+ assertFalse(rsp.contains("id3"));
+