diff options
author | Ravi Mantena <rx908f@att.com> | 2020-11-27 13:34:11 -0500 |
---|---|---|
committer | Ravi Mantena <rx908f@att.com> | 2020-12-08 14:13:43 -0500 |
commit | e3578fcdcd65c9f919c0f7cc16949b79b70d12b4 (patch) | |
tree | e85f8b4048dfc3e7118216894ee36c255cbd6211 /mod2/catalog-service/src/test | |
parent | 437e1f4e621d63cf576caa5de9c5c4804ea455f9 (diff) |
Policy Model Distribution POC Issue-ID: DCAEGEN2-1868
Issue-ID: DCAEGEN2-1868
Change-Id: Ife6421558af59405f3026f66950ff8f2d7aeba17
Signed-off-by: Ravi Mantena <rx908f@att.com>
Diffstat (limited to 'mod2/catalog-service/src/test')
13 files changed, 1162 insertions, 0 deletions
diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/PolicyModelDistributionObjectMother.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/PolicyModelDistributionObjectMother.java new file mode 100644 index 0000000..dfd1bd7 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/PolicyModelDistributionObjectMother.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.objectmothers; + +import org.onap.dcaegen2.platform.mod.util.TestUtil; +import org.springframework.http.ResponseEntity; + +import static org.mockito.ArgumentMatchers.anyString; + +public class PolicyModelDistributionObjectMother { + public static final String PM_DISTRIBUTION_ENV = "DEV"; + public static final String PM_DISTRIBUTION_ENV_ERROR = "DEV1"; + public static final String PM_DISTRIBUTION_MODEL_ID = "5fbfc375f9f1d44e8b0e0ec2"; + public static final String PM_DISTRIBUTION_MODEL_NAME = "onap-policies-naming"; + public static final String PM_DISTRIBUTION_MODEL_ID_ERROR = "5fb896389387ea1087bdb1aa"; + +} diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/PolicyModelObjectMother.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/PolicyModelObjectMother.java new file mode 100644 index 0000000..a868e82 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/objectmothers/PolicyModelObjectMother.java @@ -0,0 +1,57 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.objectmothers; + +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModel; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelCreateRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelUpdateRequest; +import org.onap.dcaegen2.platform.mod.util.TestUtil; + +/** + * Object Mother for Policy Model to generate request for Create, Update and Get Policy Model Response + */ +public class PolicyModelObjectMother { + public static final String PM_CREATE_REQUEST = "src/test/resources/http/requests/policy-model_create_request.json"; + public static final String PM_UPDATE_REQUEST = "src/test/resources/http/requests/policy-model_update_request.json"; + public static final String PM_RESPONSE = "src/test/resources/http/responses/policy-model_create_response.json"; + public static final String POLICY_MODEL_ID = "5fb896389387ea1087bdb1aa"; //"5fae8956cd1bac74e55c9d3a"; + + /** + * Object Mother for Policy Model to generate request for Create + */ + public static PolicyModelCreateRequest getPolicyModelCreateRequest() { + return TestUtil.deserializeJsonFileToModel(PM_CREATE_REQUEST, PolicyModelCreateRequest.class); + } + + /** + * Object Mother for Policy Model to generate request for Get Policy Model Response + */ + public static PolicyModel getPolicyModelResponse() { + return TestUtil.deserializeJsonFileToModel(PM_RESPONSE, PolicyModel.class); + } + + /** + * Object Mother for Policy Model to generate request for Update + */ + public static PolicyModelUpdateRequest getPolicyModelUpdateRequest() { + return TestUtil.deserializeJsonFileToModel(PM_UPDATE_REQUEST, PolicyModelUpdateRequest.class); + } +} diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelControllerTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelControllerTest.java new file mode 100644 index 0000000..e69ba22 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelControllerTest.java @@ -0,0 +1,110 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web; + +import org.hamcrest.Matchers; +import org.junit.Ignore; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModel; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelCreateRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelUpdateRequest; +import org.onap.dcaegen2.platform.mod.web.controller.PolicyModelController; +import org.onap.dcaegen2.platform.mod.web.service.policymodel.PolicyModelService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.Arrays; + +import static org.hamcrest.Matchers.notNullValue; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.dcaegen2.platform.mod.objectmothers.BaseMsObjectMother.USER; +import static org.onap.dcaegen2.platform.mod.objectmothers.BaseMsObjectMother.asJsonString; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.POLICY_MODEL_ID; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.getPolicyModelCreateRequest; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.getPolicyModelResponse; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.getPolicyModelUpdateRequest; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@ExtendWith(SpringExtension.class) +@WebMvcTest(PolicyModelController.class) +public class PolicyModelControllerTest { + + @Autowired + MockMvc mockMvc; + + @MockBean + private PolicyModelService mockPolicyModelService; + + @BeforeEach + void setup() { + } + + @Test + void test_getAllPolicyModels() throws Exception { + PolicyModel policyModel = getPolicyModelResponse(); + + when(mockPolicyModelService.getAll()).thenReturn(Arrays.asList(policyModel)); + + mockMvc.perform(get("/api/policy-model") + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", Matchers.hasSize(1))); + } + + @Test + void test_getPolicyModelById() throws Exception { + PolicyModel policyModel = getPolicyModelResponse(); + + when(mockPolicyModelService.getPolicyModelById(POLICY_MODEL_ID)).thenReturn(policyModel); + + mockMvc.perform(get("/api/policy-model/" + POLICY_MODEL_ID) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id", notNullValue())); + } + + @Test + void test_patchPolicyModel_shouldReturn204AndResponseBody() throws Exception{ + PolicyModelUpdateRequest policyModelpdateRequest = getPolicyModelUpdateRequest(); + PolicyModel policyModel = getPolicyModelResponse(); + + when(mockPolicyModelService.updatePolicyModel(policyModelpdateRequest,POLICY_MODEL_ID, USER)).thenReturn(policyModel); + + mockMvc.perform(patch("/api/policy-model/" + POLICY_MODEL_ID).param("user", USER) + .contentType(MediaType.APPLICATION_JSON) + .content(asJsonString(policyModelpdateRequest)).accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()); + verify(mockPolicyModelService, times(0)).updatePolicyModel(policyModelpdateRequest,POLICY_MODEL_ID, USER); + } + +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelCreateRequestValidationTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelCreateRequestValidationTest.java new file mode 100644 index 0000000..4b34e02 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelCreateRequestValidationTest.java @@ -0,0 +1,95 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelCreateRequest; +import org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import java.util.Set; + +public class PolicyModelCreateRequestValidationTest { + + public Validator validator; + private PolicyModelCreateRequest request; + + @BeforeEach + public void setup(){ + validator = Validation.buildDefaultValidatorFactory().getValidator(); + request = PolicyModelObjectMother.getPolicyModelCreateRequest(); + } + + @Test + void test_pmNameShouldNotBeBlank(){ + request.setName(""); + Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(3); + } + + @Test + void test_pmNameShouldFollowRegex() throws Exception{ + request.setName("pm-1"); + Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(1); + } + + @Test + void test_pmNameSizeValidation() throws Exception { + request.setName("core-name-should-not-exceed-fifty-chars-core-name-should-not-exceed-fifty-chars"); + Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(1); + } + + + @Test + void test_pmVersionShouldNotBeNull(){ + request.setVersion(""); + Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(3); + + } + + @Test + void test_pmVersionShouldFollowRegex() throws Exception{ + request.setContent("1.1.1"); + Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(1); + } + + @Test + void test_pmContentShouldNotBeBlank(){ + request.setContent(""); + Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(2); + } + + @Test + void test_pmOwnerShouldNotBeBlank(){ + request.setOwner(""); + Set<ConstraintViolation<PolicyModelCreateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(2); + } +} diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelDistributionControllerTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelDistributionControllerTest.java new file mode 100644 index 0000000..216d4c8 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelDistributionControllerTest.java @@ -0,0 +1,120 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModel; +import org.onap.dcaegen2.platform.mod.web.controller.PolicyModelDistributionController; +import org.onap.dcaegen2.platform.mod.web.service.policymodel.PolicyModelDistributionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.web.servlet.MockMvc; + +import static org.hamcrest.Matchers.notNullValue; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.dcaegen2.platform.mod.objectmothers.BaseMsObjectMother.USER; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelDistributionObjectMother.PM_DISTRIBUTION_ENV; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelDistributionObjectMother.PM_DISTRIBUTION_MODEL_ID; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelDistributionObjectMother.PM_DISTRIBUTION_MODEL_NAME; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.getPolicyModelResponse; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@ExtendWith(SpringExtension.class) +@WebMvcTest(PolicyModelDistributionController.class) +public class PolicyModelDistributionControllerTest { + + @Autowired + MockMvc mockMvc; + + @MockBean + private PolicyModelDistributionService mockPolicyModelDistributionService; + + @BeforeEach + void setup() { + } + + @Test + void test_getPolicyModelById() throws Exception { + PolicyModel policyModel = getPolicyModelResponse(); + ResponseEntity mockResponseEntity = ResponseEntity.status(200).body(policyModel.getContent()); + + when(mockPolicyModelDistributionService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID)).thenReturn(mockResponseEntity); + + mockMvc.perform(get("/api/policy-type/" + PM_DISTRIBUTION_MODEL_ID) + .param("env",PM_DISTRIBUTION_ENV).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + + verify(mockPolicyModelDistributionService, times(1)).getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + } + + @Test + void test_getPolicyModelById_BadRequest() throws Exception { + PolicyModel policyModel = getPolicyModelResponse(); + ResponseEntity mockResponseEntity = ResponseEntity.status(400).body(policyModel.getContent()); + + when(mockPolicyModelDistributionService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID)).thenReturn(mockResponseEntity); + + mockMvc.perform(get("/api/policy-type/" + PM_DISTRIBUTION_MODEL_ID) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().is4xxClientError()); + + verify(mockPolicyModelDistributionService, times(0)).getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + } + + @Test + void test_distributePolicyModelById_shouldReturn201AndResponseBody() throws Exception { + PolicyModel policyModel = getPolicyModelResponse(); + ResponseEntity mockResponseEntity = ResponseEntity.status(200).body(policyModel.getContent()); + + when(mockPolicyModelDistributionService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID)).thenReturn(mockResponseEntity); + + mockMvc.perform(post("/api/policy-type/" + PM_DISTRIBUTION_MODEL_ID) + .param("env",PM_DISTRIBUTION_ENV).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + verify(mockPolicyModelDistributionService, times(1)).distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + } + + @Test + void test_distributePolicyModelById_BadRequest() throws Exception { + PolicyModel policyModel = getPolicyModelResponse(); + ResponseEntity mockResponseEntity = ResponseEntity.status(400).body(policyModel.getContent()); + + when(mockPolicyModelDistributionService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID)).thenReturn(mockResponseEntity); + + mockMvc.perform(post("/api/policy-type/" + PM_DISTRIBUTION_MODEL_ID) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().is4xxClientError()); + verify(mockPolicyModelDistributionService, times(0)).distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + } + + +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelUpdateRequestValidationTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelUpdateRequestValidationTest.java new file mode 100644 index 0000000..f1945fd --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/PolicyModelUpdateRequestValidationTest.java @@ -0,0 +1,83 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelCreateRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelUpdateRequest; +import org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import java.util.Set; + +public class PolicyModelUpdateRequestValidationTest { + + public Validator validator; + private PolicyModelUpdateRequest request; + + @BeforeEach + public void setup(){ + validator = Validation.buildDefaultValidatorFactory().getValidator(); + request = PolicyModelObjectMother.getPolicyModelUpdateRequest(); + } + + @Test + void test_pmNameShouldNotBeBlank(){ + request.setName(""); + Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(2); + } + + @Test + void test_pmNameShouldFollowRegex() throws Exception{ + request.setName("pm-1"); + Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(1); + } + + @Test + void test_pmNameSizeValidation() throws Exception { + request.setName("core-name-should-not-exceed-fifty-chars-core-name-should-not-exceed-fifty-chars"); + Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(1); + } + + + @Test + void test_pmVersionShouldNotBeNull(){ + request.setVersion("1.1.1"); + Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(1); + + } + + @Test + void test_pmVersionShouldFollowRegex() throws Exception{ + request.setContent("1.1.1"); + Set<ConstraintViolation<PolicyModelUpdateRequest>> violations = validator.validate(request); + Assertions.assertThat(violations.size()).isEqualTo(1); + } + +} diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/PolicyModelDistributionServiceImplTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/PolicyModelDistributionServiceImplTest.java new file mode 100644 index 0000000..a1451c4 --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/PolicyModelDistributionServiceImplTest.java @@ -0,0 +1,329 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModel; +import org.onap.dcaegen2.platform.mod.util.PolicyModelUtils; +import org.onap.dcaegen2.platform.mod.web.service.policymodel.PolicyModelDistributionServiceImpl; +import org.onap.dcaegen2.platform.mod.web.service.policymodel.PolicyModelGateway; +import org.onap.dcaegen2.platform.mod.web.service.policymodel.PolicyModelServiceImpl; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.reactive.function.client.WebClient; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelDistributionObjectMother.PM_DISTRIBUTION_ENV; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelDistributionObjectMother.PM_DISTRIBUTION_MODEL_ID; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelDistributionObjectMother.PM_DISTRIBUTION_MODEL_ID_ERROR; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.getPolicyModelResponse; + +@ExtendWith(MockitoExtension.class) +class PolicyModelDistributionServiceImplTest { + + @Spy + private PolicyModelDistributionServiceImpl pmDistributionImplService = new PolicyModelDistributionServiceImpl(); + + @Mock + private PolicyModelServiceImpl policyModelServiceImpl; + + @Mock + private PolicyModelGateway policyModelGateway; + + @Mock + private PolicyModelUtils policyModelUtils; + + @BeforeEach + void initialize(){ + pmDistributionImplService.setPolicyModelServiceImpl(policyModelServiceImpl); + pmDistributionImplService.setPolicyModelGateway(policyModelGateway); + pmDistributionImplService.setPolicyModelUtils(policyModelUtils); + } + + @Test + void test_getPolicyModelDistributionByIdReturnSucess() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + // Calling the same method twice to resolve the issue of mock server hanging for response + initResponse(mockBackEnd,200,"Operation Successfull"); + initResponse(mockBackEnd,200,"Operation Successfull"); + + ResponseEntity expected = pmDistributionImplService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.OK); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + mockBackEnd.shutdown(); + } + + + @Test + void test_getPolicyModelDistributionByIdReturnUnauthorized() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,401,"Authentication Error"); + + ResponseEntity expected = pmDistributionImplService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + mockBackEnd.shutdown(); + } + + @Test + void test_getPolicyModelDistributionByIdReturnForbidden() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID_ERROR)).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,403,"Authorization Error"); + + ResponseEntity expected = pmDistributionImplService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID_ERROR); + + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID_ERROR); + mockBackEnd.shutdown(); + } + + @Test + void test_getPolicyModelDistributionByIdReturnNotFound() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID_ERROR)).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,404,"Policy Model Not Found"); + + ResponseEntity expected = pmDistributionImplService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID_ERROR); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID_ERROR); + mockBackEnd.shutdown(); + } + + @Test + void test_getPolicyModelDistributionByIdReturnUnsupportedMediaType() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,415,"Unsupported Media Type"); + + ResponseEntity expected = pmDistributionImplService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.UNSUPPORTED_MEDIA_TYPE); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + mockBackEnd.shutdown(); + } + + @Test + void test_getPolicyModelDistributionByIdReturnInternalServerError() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById("test")).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,500,"Internal Server Error"); + + ResponseEntity expected = pmDistributionImplService.getPolicyModelDistributionById(PM_DISTRIBUTION_ENV,"test"); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + verify(policyModelServiceImpl, times(1)).getPolicyModelById("test"); + mockBackEnd.shutdown(); + } + + + @Test + void test_distributePolicyModelReturnSucess() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + // Calling the same method twice to resolve the issue of mock server hanging for response + initResponse(mockBackEnd,200,"Operation Successfull"); + initResponse(mockBackEnd,200,"Operation Successfull"); + + ResponseEntity expected = pmDistributionImplService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.OK); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + verify(policyModelGateway, times(1)).save(any()); + mockBackEnd.shutdown(); + } + + @Test + void test_distributePolicyModelReturnBadRequest() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID_ERROR)).thenReturn(policyModel); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,400,"Invalid Body of Policy Model"); + + ResponseEntity expected = pmDistributionImplService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID_ERROR); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID_ERROR); + verify(policyModelGateway, times(1)).save(any()); + mockBackEnd.shutdown(); + } + + @Test + void test_distributePolicyModelReturnUnauthorized() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,401,"Authentication Error"); + + ResponseEntity expected = pmDistributionImplService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + verify(policyModelGateway, times(1)).save(any()); + } + + @Test + void test_distributePolicyModelReturnForbidden() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,403,"Authorization Error"); + + ResponseEntity expected = pmDistributionImplService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + verify(policyModelGateway, times(1)).save(any()); + } + + @Test + void test_distributePolicyModelReturnNotAcceptable() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,406,"Not Acceptable Policy Model Version"); + + ResponseEntity expected = pmDistributionImplService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.NOT_ACCEPTABLE); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + verify(policyModelGateway, times(1)).save(any()); + } + + @Test + void test_distributePolicyModelReturnUnsupportedMediaType() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById(PM_DISTRIBUTION_MODEL_ID)).thenReturn(policyModel); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,415,"Unsupported Media Type"); + + ResponseEntity expected = pmDistributionImplService.distributePolicyModel(PM_DISTRIBUTION_ENV,PM_DISTRIBUTION_MODEL_ID); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.UNSUPPORTED_MEDIA_TYPE); + verify(policyModelServiceImpl, times(1)).getPolicyModelById(PM_DISTRIBUTION_MODEL_ID); + verify(policyModelGateway, times(1)).save(any()); + } + + @Test + void test_distributePolicyModelReturnInternalServerError() throws IOException { + PolicyModel policyModel = getPolicyModelResponse(); + + when(policyModelServiceImpl.getPolicyModelById("test")).thenReturn(policyModel); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + MockWebServer mockBackEnd = initialize_webServer(); + + initResponse(mockBackEnd,500,"Internal Server Error"); + + ResponseEntity expected = pmDistributionImplService.distributePolicyModel(PM_DISTRIBUTION_ENV,"test"); + + assertThat(expected.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + verify(policyModelServiceImpl, times(1)).getPolicyModelById("test"); + verify(policyModelGateway, times(1)).save(any()); + } + + private MockWebServer initialize_webServer() throws IOException { + MockWebServer mockBackEnd = new MockWebServer(); + mockBackEnd.start(); + + String baseUrl = String.format("http://localhost:%s", mockBackEnd.getPort()); + when(policyModelUtils.getPolicyEngineURL(PM_DISTRIBUTION_ENV)).thenReturn(baseUrl); + when(policyModelUtils.getWebClient(PM_DISTRIBUTION_ENV)).thenReturn(WebClient.create(baseUrl)); + + return mockBackEnd; + } + + private void initResponse(MockWebServer mockBackEnd, int responseCode, String responseBody) { + String webClientResponse = responseBody; + mockBackEnd.enqueue(new MockResponse().setResponseCode(responseCode).setBody(webClientResponse) + .addHeader("Content-Type", "text/plain;charset=ISO-8859-1")); + } + + +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/PolicyModelServiceImplTest.java b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/PolicyModelServiceImplTest.java new file mode 100644 index 0000000..726ed3b --- /dev/null +++ b/mod2/catalog-service/src/test/java/org/onap/dcaegen2/platform/mod/web/service/PolicyModelServiceImplTest.java @@ -0,0 +1,152 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.platform.mod.web.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.platform.mod.model.exceptions.policymodel.PolicyModelConflictException; +import org.onap.dcaegen2.platform.mod.model.exceptions.policymodel.PolicyModelNotFoundException; +import org.onap.dcaegen2.platform.mod.model.policymodel.PolicyModel; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelCreateRequest; +import org.onap.dcaegen2.platform.mod.model.restapi.PolicyModelUpdateRequest; +import org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother; +import org.onap.dcaegen2.platform.mod.web.service.policymodel.PolicyModelGateway; +import org.onap.dcaegen2.platform.mod.web.service.policymodel.PolicyModelServiceImpl; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.onap.dcaegen2.platform.mod.objectmothers.MsInstanceObjectMother.USER; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.POLICY_MODEL_ID; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.getPolicyModelCreateRequest; +import static org.onap.dcaegen2.platform.mod.objectmothers.PolicyModelObjectMother.getPolicyModelUpdateRequest; + +@ExtendWith(MockitoExtension.class) +class PolicyModelServiceImplTest { + + @Spy + private PolicyModelServiceImpl pmImplService = new PolicyModelServiceImpl(); + + @Mock + private PolicyModelGateway policyModelGateway; + + + @BeforeEach + void setUp() { + pmImplService.setPolicyModelGateway(policyModelGateway); + } + + @Test + void getAll() { + PolicyModel instance_1 = PolicyModel.builder().id("123").name("test").owner("user").version("1.0.0").build(); + PolicyModel instance_2 = PolicyModel.builder().id("345").name("test1").owner("user1").version("1.1.0").build(); + + when(policyModelGateway.findAll()).thenReturn(Arrays.asList(instance_1, instance_2)); + + List<PolicyModel> instances = pmImplService.getAll(); + + assertThat(instances.size()).isEqualTo(2); + verify(policyModelGateway, times(1)).findAll(); + } + + @Test + void test_getPolicyModelById() { + PolicyModel expected = PolicyModelObjectMother.getPolicyModelResponse(); + + when(policyModelGateway.findById(POLICY_MODEL_ID)).thenReturn(Optional.of(expected)); + + PolicyModel original = pmImplService.getPolicyModelById(POLICY_MODEL_ID); + + assertThat(original.getId()).isEqualTo(expected.getId()); + verify(policyModelGateway, times(1)).findById(POLICY_MODEL_ID); + } + + @Test + void test_policyModelNotFound_willRaiseException() { + when(policyModelGateway.findById(POLICY_MODEL_ID)).thenReturn(Optional.empty()); + assertThatExceptionOfType(PolicyModelNotFoundException.class).isThrownBy(() -> pmImplService.getPolicyModelById(POLICY_MODEL_ID)); + } + + + @Test + void test_createPolicyModel() { + + PolicyModelCreateRequest policyModelCreateRequest = getPolicyModelCreateRequest(); + PolicyModel policyModel = PolicyModelObjectMother.getPolicyModelResponse(); + + when(policyModelGateway.findByNameAndVersion(policyModelCreateRequest.getName(), policyModelCreateRequest.getVersion())).thenReturn(Optional.empty()); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + pmImplService.createPolicyModel(policyModelCreateRequest,USER); + + assertThat(policyModel.getVersion()).isEqualTo(policyModelCreateRequest.getVersion()); + assertThat(policyModel.getName()).isEqualTo(policyModelCreateRequest.getName()); + + verify(policyModelGateway, times(1)).findByNameAndVersion(policyModelCreateRequest.getName(), policyModelCreateRequest.getVersion()); + verify(policyModelGateway, times(1)).save(any()); + } + + @Test + void test_createPolicyModel_willRaiseException() { + PolicyModelCreateRequest policyModelCreateRequest = getPolicyModelCreateRequest(); + PolicyModel policyModel = PolicyModelObjectMother.getPolicyModelResponse(); + + when(policyModelGateway.findByNameAndVersion(policyModelCreateRequest.getName(), policyModelCreateRequest.getVersion())).thenReturn(Optional.of(policyModel)); + + assertThatExceptionOfType(PolicyModelConflictException.class).isThrownBy(() -> pmImplService.createPolicyModel(policyModelCreateRequest,USER)); + } + + @Test + void test_updatePolicyModel() { + + PolicyModelUpdateRequest policyModelUpdateRequest = getPolicyModelUpdateRequest(); + policyModelUpdateRequest.setName("test1"); + policyModelUpdateRequest.setVersion("1.2.1"); + PolicyModel policyModel = PolicyModelObjectMother.getPolicyModelResponse(); + + when(policyModelGateway.findById(POLICY_MODEL_ID)).thenReturn(Optional.of(policyModel)); + + when(policyModelGateway.findByNameAndVersion(policyModelUpdateRequest.getName(), policyModelUpdateRequest.getVersion())).thenReturn(Optional.empty()); + when(policyModelGateway.save(any())).thenReturn(policyModel); + + pmImplService.updatePolicyModel(policyModelUpdateRequest,POLICY_MODEL_ID, USER); + + assertThat(policyModel.getVersion()).isEqualTo(policyModelUpdateRequest.getVersion()); + assertThat(policyModel.getName()).isEqualTo(policyModelUpdateRequest.getName()); + + verify(policyModelGateway, times(1)).findById(POLICY_MODEL_ID); + verify(policyModelGateway, times(1)).findByNameAndVersion(policyModelUpdateRequest.getName(), policyModelUpdateRequest.getVersion()); + verify(policyModelGateway, times(1)).save(any()); + } + + +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/resources/http/requests/pmdist_sample.json b/mod2/catalog-service/src/test/resources/http/requests/pmdist_sample.json new file mode 100644 index 0000000..16ab65a --- /dev/null +++ b/mod2/catalog-service/src/test/resources/http/requests/pmdist_sample.json @@ -0,0 +1,142 @@ +{ + "self": { + "component_type": "docker", + "description": "Hello World mS for subscribing the data from local DMaaP, DR or MR, processing them and publishing them as PM files to local DMaaP DR", + "name": "dcae-collectors-vcc-helloworld-pm", + "version": "1.0.1" + }, + "services": { + "calls": [], + "provides": [] + }, + "streams": { + "publishes": [ + { + "config_key": "DCAE-HELLO-WORLD-PUB-DR", + "format": "dataformat_Hello_World_PM", + "type": "data_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-PUB-MR", + "format": "dataformat_Hello_World_PM", + "type": "message_router", + "version": "1.0.0" + } + ], + "subscribes": [ + { + "config_key": "DCAE-HELLO-WORLD-SUB-MR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE_HELLO_WORLD_SUB_MR", + "type": "message_router", + "version": "1.0.0" + }, + { + "config_key": "DCAE-HELLO-WORLD-SUB-DR", + "format": "dataformat_Hello_World_PM", + "route": "/DCAE-HELLO-WORLD-SUB-DR", + "type": "data_router", + "version": "1.0.0" + } + ] + }, + "parameters": [ + { + "name": "vcc_hello_name", + "value": "120", + "type": "integer", + "description": "the name entered for specific person", + "sourced_at_deployment": false, + "designer_editable": false, + "policy_editable": false + }, + { + "name": "useDtiConfig", + "value": false, + "type": "boolean", + "description": "component depends on configuration from dti.", + "sourced_at_deployment": false, + "designer_editable": true, + "policy_editable": false, + "required": true + }, + { + "name": "isSelfServeComponent", + "value": false, + "type": "boolean", + "description": "Is this used as self serve component.", + "sourced_at_deployment": false, + "designer_editable": true, + "policy_editable": false, + "required": true + } + ], + "auxilary": { + "healthcheck": { + "interval": "60s", + "initialDelaySeconds": "120s", + "timeout": "20s", + "script": "/opt/app/vcc/bin/common/HealthCheck_HelloWorld.sh", + "type": "docker" + }, + "livehealthcheck": { + "interval": "60s", + "initialDelaySeconds": "120s", + "timeout": "20s", + "script": "/opt/app/vcc/bin/common/HealthCheck_HelloWorld.sh", + "type": "docker" + }, + "reconfigs": { + "app_reconfig": "abc" + }, + "volumes": [ + { + "container": { + "bind": "/opt/app/dcae-certificate" + }, + "host": { + "path": "/opt/app/dcae-certificate" + } + }, + { + "container": { + "bind": "/opt/logs/DCAE/dmd/AGENT" + }, + "host": { + "path": "/opt/logs/DCAE/helloworldpm/dmd/AGENT" + } + }, + { + "container": { + "bind": "/opt/logs/DCAE/dmd/WATCHER" + }, + "host": { + "path": "/opt/logs/DCAE/helloworldpm/dmd/WATCHER" + } + }, + { + "container": { + "bind": "/opt/app/vcc/logs/DCAE" + }, + "host": { + "path": "/opt/logs/DCAE/helloworldpm/vcc-logs" + } + }, + { + "container": { + "bind": "/opt/app/vcc/archive/data" + }, + "host": { + "path": "/opt/data/DCAE/helloworldpm/vcc-archive" + } + } + ] + }, + "artifacts": [ + { + "type": "docker image", + "uri": "dockercentral.it.att.com:5100/com.att.sample/dcae-controller-vcc-helloworld-pm:18.02-001" + } + ] + }
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/resources/http/requests/policy-model_create_request.json b/mod2/catalog-service/src/test/resources/http/requests/policy-model_create_request.json new file mode 100644 index 0000000..ace9181 --- /dev/null +++ b/mod2/catalog-service/src/test/resources/http/requests/policy-model_create_request.json @@ -0,0 +1,6 @@ +{ + "name": "tca_policy_dublin12345", + "content": "tosca_definitions_version: tosca_simple_yaml_1_1_0\r\npolicy_types:\r\n onap.policies.Monitoring:\r\n derived_from: tosca.policies.Root\r\n version: 1.0.0\r\n name: tca_policy_dublin12345\r\n description: a base policy type for all policies that govern monitoring provisioning\r\n onap.policies.monitoring.tcagen2:\r\n derived_from: onap.policies.Monitoring\r\n version: 1.0.0\r\n name: onap.policies.monitoring.tcagen2\r\n properties:\r\n tca.policy:\r\n type: onap.datatypes.monitoring.tca_policy\r\n description: TCA Policy JSON\r\n required: true\r\ndata_types:\r\n onap.datatypes.monitoring.metricsPerEventName:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n controlLoopSchemaType:\r\n type: string\r\n required: true\r\n description: Specifies Control Loop Schema Type for the event Name e.g. VNF, VM\r\n constraints:\r\n - valid_values:\r\n - VM\r\n - VNF\r\n eventName:\r\n type: string\r\n required: true\r\n description: Event name to which thresholds need to be applied\r\n policyName:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope Name\r\n policyScope:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope\r\n policyVersion:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope Version\r\n thresholds:\r\n type: list\r\n required: true\r\n description: Thresholds associated with eventName\r\n entry_schema:\r\n type: onap.datatypes.monitoring.thresholds\r\n onap.datatypes.monitoring.tca_policy:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n domain:\r\n type: string\r\n required: true\r\n description: Domain name to which TCA needs to be applied\r\n default: measurementsForVfScaling\r\n constraints:\r\n - equal: measurementsForVfScaling\r\n metricsPerEventName:\r\n type: list\r\n required: true\r\n description: Contains eventName and threshold details that need to be applied to given eventName\r\n entry_schema:\r\n type: onap.datatypes.monitoring.metricsPerEventName\r\n onap.datatypes.monitoring.thresholds:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n closedLoopControlName:\r\n type: string\r\n required: true\r\n description: Closed Loop Control Name associated with the threshold\r\n closedLoopEventStatus:\r\n type: string\r\n required: true\r\n description: Closed Loop Event Status of the threshold\r\n constraints:\r\n - valid_values:\r\n - ONSET\r\n - ABATED\r\n direction:\r\n type: string\r\n required: true\r\n description: Direction of the threshold\r\n constraints:\r\n - valid_values:\r\n - LESS\r\n - LESS_OR_EQUAL\r\n - GREATER\r\n - GREATER_OR_EQUAL\r\n - EQUAL\r\n fieldPath:\r\n type: string\r\n required: true\r\n description: Json field Path as per CEF message which needs to be analyzed for TCA\r\n constraints:\r\n - valid_values:\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuIdle\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageInterrupt\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageNice\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSoftIrq\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSteal\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSystem\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuWait\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].percentUsage\r\n - $.event.measurementsForVfScalingFields.meanRequestLatency\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryBuffered\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryCached\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryConfigured\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryFree\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryUsed\r\n - $.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\r\n severity:\r\n type: string\r\n required: true\r\n description: Threshold Event Severity\r\n constraints:\r\n - valid_values:\r\n - CRITICAL\r\n - MAJOR\r\n - MINOR\r\n - WARNING\r\n - NORMAL\r\n thresholdValue:\r\n type: integer\r\n required: true\r\n description: Threshold value for the field Path inside CEF message\r\n version:\r\n type: string\r\n required: true\r\n description: Version number associated with the threshold", + "owner": "admin", + "version": "1.0.0" +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/resources/http/requests/policy-model_update_request.json b/mod2/catalog-service/src/test/resources/http/requests/policy-model_update_request.json new file mode 100644 index 0000000..8f2cf5b --- /dev/null +++ b/mod2/catalog-service/src/test/resources/http/requests/policy-model_update_request.json @@ -0,0 +1,5 @@ +{ + "name": "tca_policy_dublin12345", + "owner": "admin123", + "version": "1.0.0" +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/resources/http/responses/policy-model_create_response.json b/mod2/catalog-service/src/test/resources/http/responses/policy-model_create_response.json new file mode 100644 index 0000000..d689dcb --- /dev/null +++ b/mod2/catalog-service/src/test/resources/http/responses/policy-model_create_response.json @@ -0,0 +1,12 @@ +{ + "id": "5fae8956cd1bac74e55c9d3a", + "name": "tca_policy_dublin12345", + "content": "\ttosca_definitions_version: tosca_simple_yaml_1_0_0\r\npolicy_types:\r\n onap.policies.Monitoring:\r\n derived_from: tosca.policies.Root\r\n description: a base policy type for all policies that governs monitoring provisioning\r\n onap.policies.monitoring.cdap.tca.hi.lo.app:\r\n derived_from: onap.policies.Monitoring\r\n version: 1.0.0\r\n properties:\r\n tca_policy:\r\n type: map\r\n description: TCA Policy JSON\r\n entry_schema:\r\n type: onap.datatypes.monitoring.tca_policy\r\ndata_types:\r\n onap.datatypes.monitoring.metricsPerEventName:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n controlLoopSchemaType:\r\n type: string\r\n required: true\r\n description: Specifies Control Loop Schema Type for the event Name e.g. VNF, VM\r\n constraints:\r\n - valid_values:\r\n - VM\r\n - VNF\r\n eventName:\r\n type: string\r\n required: true\r\n description: Event name to which thresholds need to be applied\r\n policyName:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope Name\r\n policyScope:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope\r\n policyVersion:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope Version\r\n thresholds:\r\n type: list\r\n required: true\r\n description: Thresholds associated with eventName\r\n entry_schema:\r\n type: onap.datatypes.monitoring.thresholds\r\n onap.datatypes.monitoring.tca_policy:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n domain:\r\n type: string\r\n required: true\r\n description: Domain name to which TCA needs to be applied\r\n default: measurementsForVfScaling\r\n constraints:\r\n - equal: measurementsForVfScaling\r\n metricsPerEventName:\r\n type: list\r\n required: true\r\n description: Contains eventName and threshold details that need to be applied to given eventName\r\n entry_schema:\r\n type: onap.datatypes.monitoring.metricsPerEventName\r\n onap.datatypes.monitoring.thresholds:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n closedLoopControlName:\r\n type: string\r\n required: true\r\n description: Closed Loop Control Name associated with the threshold\r\n closedLoopEventStatus:\r\n type: string\r\n required: true\r\n description: Closed Loop Event Status of the threshold\r\n constraints:\r\n - valid_values:\r\n - ONSET\r\n - ABATED\r\n direction:\r\n type: string\r\n required: true\r\n description: Direction of the threshold\r\n constraints:\r\n - valid_values:\r\n - LESS\r\n - LESS_OR_EQUAL\r\n - GREATER\r\n - GREATER_OR_EQUAL\r\n - EQUAL\r\n fieldPath:\r\n type: string\r\n required: true\r\n description: Json field Path as per CEF message which needs to be analyzed for TCA\r\n constraints:\r\n - valid_values:\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuIdle\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageInterrupt\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageNice\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSoftIrq\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSteal\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSystem\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuWait\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].percentUsage\r\n - $.event.measurementsForVfScalingFields.meanRequestLatency\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryBuffered\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryCached\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryConfigured\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryFree\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryUsed\r\n - $.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\r\n severity:\r\n type: string\r\n required: true\r\n description: Threshold Event Severity\r\n constraints:\r\n - valid_values:\r\n - CRITICAL\r\n - MAJOR\r\n - MINOR\r\n - WARNING\r\n - NORMAL\r\n thresholdValue:\r\n type: integer\r\n required: true\r\n description: Threshold value for the field Path inside CEF message\r\n version:\r\n type: string\r\n required: true\r\n description: Version number associated with the threshold", + "owner": "admin", + "version": "1.0.0", + "metadata": { + "createdBy": "rx908f", + "createdOn": "2020-11-13T13:25:42.434+0000", + "notes": "" + } +}
\ No newline at end of file diff --git a/mod2/catalog-service/src/test/resources/http/responses/policy-model_create_response1.json b/mod2/catalog-service/src/test/resources/http/responses/policy-model_create_response1.json new file mode 100644 index 0000000..3d3516c --- /dev/null +++ b/mod2/catalog-service/src/test/resources/http/responses/policy-model_create_response1.json @@ -0,0 +1,16 @@ +{ + "id": "5fae8956cd1bac74e55c9d3a", + "name": "tca_policy_dublin12345", + "content": "\tosca_definitions_version: tosca_simple_yaml_1_1_0\r\npolicy_types:\r\n onap.policies.Monitoring:\r\n derived_from: tosca.policies.Root\r\n version: 1.0.0\r\n name: onap.policies.Monitoring\r\n description: a base policy type for all policies that govern monitoring provisioning\r\n onap.policies.monitoring.tcagen2:\r\n derived_from: onap.policies.Monitoring\r\n version: 1.0.0\r\n name: onap.policies.monitoring.tcagen2\r\n properties:\r\n tca.policy:\r\n type: onap.datatypes.monitoring.tca_policy\r\n description: TCA Policy JSON\r\n required: true\r\ndata_types:\r\n onap.datatypes.monitoring.metricsPerEventName:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n controlLoopSchemaType:\r\n type: string\r\n required: true\r\n description: Specifies Control Loop Schema Type for the event Name e.g. VNF, VM\r\n constraints:\r\n - valid_values:\r\n - VM\r\n - VNF\r\n eventName:\r\n type: string\r\n required: true\r\n description: Event name to which thresholds need to be applied\r\n policyName:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope Name\r\n policyScope:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope\r\n policyVersion:\r\n type: string\r\n required: true\r\n description: TCA Policy Scope Version\r\n thresholds:\r\n type: list\r\n required: true\r\n description: Thresholds associated with eventName\r\n entry_schema:\r\n type: onap.datatypes.monitoring.thresholds\r\n onap.datatypes.monitoring.tca_policy:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n domain:\r\n type: string\r\n required: true\r\n description: Domain name to which TCA needs to be applied\r\n default: measurementsForVfScaling\r\n constraints:\r\n - equal: measurementsForVfScaling\r\n metricsPerEventName:\r\n type: list\r\n required: true\r\n description: Contains eventName and threshold details that need to be applied to given eventName\r\n entry_schema:\r\n type: onap.datatypes.monitoring.metricsPerEventName\r\n onap.datatypes.monitoring.thresholds:\r\n derived_from: tosca.datatypes.Root\r\n properties:\r\n closedLoopControlName:\r\n type: string\r\n required: true\r\n description: Closed Loop Control Name associated with the threshold\r\n closedLoopEventStatus:\r\n type: string\r\n required: true\r\n description: Closed Loop Event Status of the threshold\r\n constraints:\r\n - valid_values:\r\n - ONSET\r\n - ABATED\r\n direction:\r\n type: string\r\n required: true\r\n description: Direction of the threshold\r\n constraints:\r\n - valid_values:\r\n - LESS\r\n - LESS_OR_EQUAL\r\n - GREATER\r\n - GREATER_OR_EQUAL\r\n - EQUAL\r\n fieldPath:\r\n type: string\r\n required: true\r\n description: Json field Path as per CEF message which needs to be analyzed for TCA\r\n constraints:\r\n - valid_values:\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsDelta\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsAccumulated\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuIdle\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageInterrupt\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageNice\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSoftIrq\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSteal\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSystem\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuWait\r\n - $.event.measurementsForVfScalingFields.cpuUsageArray[*].percentUsage\r\n - $.event.measurementsForVfScalingFields.meanRequestLatency\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryBuffered\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryCached\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryConfigured\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryFree\r\n - $.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryUsed\r\n - $.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\r\n severity:\r\n type: string\r\n required: true\r\n description: Threshold Event Severity\r\n constraints:\r\n - valid_values:\r\n - CRITICAL\r\n - MAJOR\r\n - MINOR\r\n - WARNING\r\n - NORMAL\r\n thresholdValue:\r\n type: integer\r\n required: true\r\n description: Threshold value for the field Path inside CEF message\r\n version:\r\n type: string\r\n required: true\r\n description: Version number associated with the threshold", + "owner": "admin", + "version": "1.0.0", + "metadata": { + "createdBy": "rx908f", + "createdOn": "2020-11-13T13:25:42.434+0000", + "notes": "" + }, + "distributionInfo": [{ + "url": "https://<policy-api-server>:6969/policy/api/v1/", + "status": "FAILED" + }] +}
\ No newline at end of file |