public static final String API_NAME = "A1 Policy Management";
public static final String API_DESCRIPTION = "";
+ public static final String RIC_NOT_FOUND_MSG = "Near-RT RIC not found";
public static class RejectionException extends Exception {
private static final long serialVersionUID = 1L;
return policyInfo.flatMap(policyInfoValue -> {
String jsonString = gson.toJson(policyInfoValue.getPolicyData());
return Mono.zip(Mono.justOrEmpty(rics.get(policyInfoValue.getRicId()))
- .switchIfEmpty(Mono.error(new EntityNotFoundException("Near-RT RIC not found"))),
+ .switchIfEmpty(Mono.error(new EntityNotFoundException(RIC_NOT_FOUND_MSG))),
Mono.justOrEmpty(policyTypes.get(policyInfoValue.getPolicytypeId()))
.switchIfEmpty(Mono.error(new EntityNotFoundException("policy type not found"))))
.flatMap(tuple -> {
throw new EntityNotFoundException("Policy type identity not found");
}
if ((ricId != null && this.rics.get(ricId) == null)) {
- throw new EntityNotFoundException("Near-RT RIC not found");
+ throw new EntityNotFoundException(RIC_NOT_FOUND_MSG);
}
Collection<Policy> filtered = policies.filterPolicies(policyTypeId, ricId, serviceId, typeName);
throw new EntityNotFoundException("Policy type not found");
}
if ((ricId != null && this.rics.get(ricId) == null)) {
- throw new EntityNotFoundException("Near-RT RIC not found");
+ throw new EntityNotFoundException(RIC_NOT_FOUND_MSG);
}
Collection<Policy> filtered = policies.filterPolicies(policyTypeId, ricId, serviceId, typeName);
private PolicyInfo toPolicyInfo(Policy policy) {
try {
- PolicyInfo policyInfo = new PolicyInfo()
- .policyId(policy.getId())
- .policyData(objectMapper.readTree(policy.getJson()))
- .ricId(policy.getRic().id())
- .policytypeId(policy.getType().getId())
+ PolicyInfo policyInfo = new PolicyInfo(policy.getRic().id(), policy.getId(),
+ objectMapper.readTree(policy.getJson()), policy.getType().getId())
.serviceId(policy.getOwnerServiceId())
._transient(policy.isTransient());
if (!policy.getStatusNotificationUri().isEmpty()) {
public Mono<ResponseEntity<PolicyObjectInformation>> createPolicyService
(PolicyObjectInformation policyObjectInfo, ServerWebExchange serverWebExchange) {
try {
- if (!helper.jsonSchemaValidation(gson.toJson(policyObjectInfo.getPolicyObject(), Map.class)))
+ if (Boolean.FALSE.equals(helper.jsonSchemaValidation(gson.toJson(policyObjectInfo.getPolicyObject(), Map.class))))
return Mono.error(new ServiceException("Schema validation failed", HttpStatus.BAD_REQUEST));
Ric ric = rics.getRic(policyObjectInfo.getNearRtRicId());
PolicyType policyType = policyTypes.getType(policyObjectInfo.getPolicyTypeId());
}
public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypesService(String nearRtRicId, String typeName,
- String compatibleWithVersion,
- ServerWebExchange webExchange) throws Exception {
+ String compatibleWithVersion) throws ServiceException {
if (compatibleWithVersion != null && typeName == null) {
throw new ServiceException("Parameter " + Consts.COMPATIBLE_WITH_VERSION_PARAM + " can only be used when "
+ Consts.TYPE_NAME_PARAM + " is given", HttpStatus.BAD_REQUEST);
Collection<PolicyTypeInformation> listOfPolicyTypes = new ArrayList<>();
if (nearRtRicId == null || nearRtRicId.isEmpty() || nearRtRicId.isBlank()) {
for(Ric ric : rics.getRics()) {
- Collection<PolicyType> policyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
+ Collection<PolicyType> filteredPolicyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
compatibleWithVersion);
- listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(policyTypes, ric));
+ listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(filteredPolicyTypes, ric));
}
} else {
Ric ric = rics.get(nearRtRicId);
if (ric == null)
throw new EntityNotFoundException("Near-RT RIC not Found using ID: " +nearRtRicId);
- Collection<PolicyType> policyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
+ Collection<PolicyType> filteredPolicyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
compatibleWithVersion);
- listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(policyTypes, ric));
+ listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(filteredPolicyTypes, ric));
}
return Mono.just(new ResponseEntity<>(Flux.fromIterable(listOfPolicyTypes), HttpStatus.OK));
}
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import org.junit.jupiter.api.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mockito;
import org.onap.ccsdk.oran.a1policymanagementservice.config.TestConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EntityNotFoundException;
@TestPropertySource(properties = { //
"app.vardata-directory=/tmp/pmstestv3", //
})
-public class PolicyServiceTest {
+class PolicyServiceTest {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
}
@Test
- public void testPolicyAlreadyCreatedTrue() throws Exception{
+ void testPolicyAlreadyCreatedTrue() throws Exception{
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
}
@Test
- public void testPolicyNotAuthorizedFail() throws IOException {
+ void testPolicyNotAuthorizedFail() throws IOException {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
}
@Test
- public void testDeletePolicySuccess() throws Exception {
+ void testDeletePolicySuccess() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
}
@Test
- public void testDeletePolicyThrowsException() throws Exception {
+ void testDeletePolicyThrowsException() {
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
assertThrows(EntityNotFoundException.class, () -> policyService.deletePolicyService("dummyPolicyID", serverWebExchange));
}
@Test
- public void testPutPolicy() throws Exception {
+ void testPutPolicy() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
});
}
- @Test
- public void testGetPolicyTypes() throws Exception {
+ @ParameterizedTest
+ @CsvSource({
+ ", , ",
+ ", uri_type, ",
+ "Ric_347, uri_type,"
+ })
+ @DisplayName("testGetPolicyTypes & testGetPolicyTypesMatchedTypeName & testGetPolicyTypesMatchedTypeNameWithRic")
+ void testGetPolicyTypes(String nearRtRicID, String typeName, String compatibleWithVersion) throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
- ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
- Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, null,null, serverWebExchange);
+ Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono =
+ policyService.getPolicyTypesService(nearRtRicID, typeName, compatibleWithVersion);
testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1);
}
@Test
- public void testGetPolicyTypesEmpty() throws Exception {
- ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
+ void testGetPolicyTypesEmpty() throws Exception {
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
- Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, null, null, serverWebExchange);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 0);
+ Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, null, null);
+ testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
}
@Test
- public void testGetPolicyTypesNoRic() {
- ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
- assertThrows(EntityNotFoundException.class, () -> policyService.getPolicyTypesService("NoRic", "","", serverWebExchange));
+ void testGetPolicyTypesNoRic() {
+ assertThrows(EntityNotFoundException.class, () -> policyService.getPolicyTypesService("NoRic", "",""));
}
@Test
- public void testGetPolicyTypesNoMatchedTypeName() throws Exception {
+ void testGetPolicyTypesNoMatchedTypeName() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
- ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
- Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("", "noTypeName", null, serverWebExchange);
+ Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("", "noTypeName", null);
testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
}
@Test
- public void testGetPolicyTypesNoMatchedTypeNameWithRic() throws Exception {
+ void testGetPolicyTypesNoMatchedTypeNameWithRic() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
- ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
- Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("Ric_347", "noTypeName", null, serverWebExchange);
+ Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("Ric_347", "noTypeName", null);
testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty());
}
@Test
- public void testGetPolicyTypesMatchedTypeName() throws Exception {
- String policyTypeName = "uri_type_123";
- String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
- ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
- Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, "uri_type", null, serverWebExchange);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1);
- }
-
- @Test
- public void testGetPolicyTypesMatchedTypeNameWithRic() throws Exception {
- String policyTypeName = "uri_type_123";
- String nonRtRicId = "Ric_347";
- testHelper.addPolicyType(policyTypeName, nonRtRicId);
- ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
- when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod();
- Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService
- .getPolicyTypesService("Ric_347", "uri_type", null, serverWebExchange);
- testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1);
- }
-
- @Test
- public void testGetPolicyIds() throws Exception {
+ void testGetPolicyIds() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
}
@Test
- public void testGetPolicyIdsNoRic() throws Exception {
+ void testGetPolicyIdsNoRic() throws Exception {
testHelper.addPolicyType("uri_type_123", "Ric_347");
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService
}
@Test
- public void testGetPolicyIdsNoPolicyType() {
+ void testGetPolicyIdsNoPolicyType() {
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService
.getPolicyIdsService("noPolicyType", "noRic", "", "", serverWebExchange));
}
@Test
- public void testGetPolicyService() throws Exception {
+ void testGetPolicyService() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
}
@Test
- public void testGetPolicyServiceNoPolicy() throws Exception {
+ void testGetPolicyServiceNoPolicy() {
ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class);
EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService
.getPolicyService("NoPolicy", serverWebExchange));
}
@Test
- public void testGetPolicyTypeService() throws Exception {
+ void testGetPolicyTypeService() throws Exception {
String policyTypeName = "uri_type_123";
String nonRtRicId = "Ric_347";
PolicyType addedPolicyType = testHelper.addPolicyType(policyTypeName, nonRtRicId);
}
@Test
- public void testGetPolicyTypeServiceNoPolicyType() {
+ void testGetPolicyTypeServiceNoPolicyType() {
EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService
.getPolicyTypeDefinitionService("NoPolicyType"));
assertEquals("PolicyType not found with ID: NoPolicyType", exception.getMessage());