+ this.rics.getRic(ricName).setState(Ric.RicState.AVAILABLE);
+ }
+
+ @Test
+ /**
+ * Test that HttpStatus and body from failing REST call to A1 is passed on to the caller.
+ *
+ * @throws ServiceException
+ */
+ void testErrorFromRic() throws ServiceException {
+ putService("service1");
+ addPolicyType("type1", "ric1");
+
+ String url = putPolicyUrl("service1", "ric1", "type1", "id1");
+ MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client("ric1");
+ HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
+ String responseBody = "Refused";
+ byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8);
+
+ WebClientResponseException a1Exception = new WebClientResponseException(httpStatus.value(), "statusText", null,
+ responseBodyBytes, StandardCharsets.UTF_8, null);
+ doReturn(Mono.error(a1Exception)).when(a1Client).putPolicy(any());
+
+ // PUT Policy
+ testErrorCode(restClient().put(url, "{}"), httpStatus, responseBody);
+
+ // DELETE POLICY
+ this.addPolicy("instance1", "type1", "service1", "ric1");
+ doReturn(Mono.error(a1Exception)).when(a1Client).deletePolicy(any());
+ testErrorCode(restClient().delete("/policy?id=instance1"), httpStatus, responseBody);
+
+ // GET STATUS
+ this.addPolicy("instance1", "type1", "service1", "ric1");
+ doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
+ testErrorCode(restClient().get("/policy_status?id=instance1"), httpStatus, responseBody);
+
+ // Check that empty response body is OK
+ a1Exception = new WebClientResponseException(httpStatus.value(), "", null, null, null, null);
+ doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
+ testErrorCode(restClient().get("/policy_status?id=instance1"), httpStatus);
+ }
+
+ @Test
+ void testPutTypelessPolicy() throws Exception {
+ putService("service1");
+ addPolicyType("", "ric1");
+ String url = putPolicyUrl("service1", "ric1", "", "id1");
+ restClient().put(url, jsonString()).block();
+
+ String rsp = restClient().get("/policies").block();
+ List<PolicyInfo> info = parseList(rsp, PolicyInfo.class);
+ assertThat(info).hasSize(1);
+ PolicyInfo policyInfo = info.get(0);
+ assertThat(policyInfo.id).isEqualTo("id1");
+ assertThat(policyInfo.type).isEmpty();