From c90c720200ffda9f2dc2888d08eceeac8bc66ed9 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Tue, 30 Jan 2024 16:06:51 +0200 Subject: [PATCH 1/6] test: Add unit test for addPolicyService to cover the basic fail and success scenarios. --- .../tfs/policy/model/PolicyRuleBasic.java | 2 +- .../tfs/policy/model/PolicyRuleService.java | 2 +- .../tfs/policy/PolicyGrpcServiceTest.java | 382 +++++++++++++++ .../etsi/tfs/policy/PolicyServiceTest.java | 443 ++++++------------ src/policy/target/kubernetes/kubernetes.yml | 108 ----- 5 files changed, 515 insertions(+), 422 deletions(-) create mode 100644 src/policy/src/test/java/org/etsi/tfs/policy/PolicyGrpcServiceTest.java delete mode 100644 src/policy/target/kubernetes/kubernetes.yml diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleBasic.java b/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleBasic.java index ea00ea3fc..7df894abd 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleBasic.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleBasic.java @@ -64,7 +64,7 @@ public class PolicyRuleBasic { this.booleanOperator = BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_UNDEFINED; this.policyRuleActions = new ArrayList(); this.isValid = false; - this.exceptionMessage = e.toString(); + this.exceptionMessage = e.getMessage(); } } diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleService.java b/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleService.java index 1f507ebc9..db25dc9bf 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleService.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleService.java @@ -50,7 +50,7 @@ public class PolicyRuleService { this.serviceId = new ServiceId("", ""); this.deviceIds = new ArrayList(); this.isValid = false; - this.exceptionMessage = e.toString(); + this.exceptionMessage = e.getMessage(); } } diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyGrpcServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyGrpcServiceTest.java new file mode 100644 index 000000000..2461bcee6 --- /dev/null +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyGrpcServiceTest.java @@ -0,0 +1,382 @@ +/* +* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +* +* 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. +*/ + +package org.etsi.tfs.policy; + +import static org.assertj.core.api.Assertions.assertThat; + +import context.ContextOuterClass; +import context.ContextOuterClass.Uuid; +import io.quarkus.grpc.GrpcClient; +import io.quarkus.test.junit.QuarkusTest; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.inject.Inject; +import monitoring.Monitoring.KpiId; +import org.etsi.tfs.policy.monitoring.model.FloatKpiValue; +import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; +import org.jboss.logging.Logger; +import org.junit.jupiter.api.Test; +import policy.Policy; +import policy.Policy.PolicyRuleBasic; +import policy.Policy.PolicyRuleStateEnum; +import policy.PolicyAction; +import policy.PolicyAction.PolicyRuleActionEnum; +import policy.PolicyCondition; +import policy.PolicyCondition.BooleanOperator; +import policy.PolicyCondition.NumericalOperator; +import policy.PolicyCondition.PolicyRuleCondition; +import policy.PolicyService; + +@QuarkusTest +class PolicyGrpcServiceTest { + private static final Logger LOGGER = Logger.getLogger(PolicyGrpcServiceTest.class); + + @GrpcClient PolicyService client; + private final Serializer serializer; + + @Inject + PolicyGrpcServiceTest(Serializer serializer) { + this.serializer = serializer; + } + + private context.ContextOuterClass.ServiceId createContextServiceId() { + final var contextIdUuid = serializer.serializeUuid("571eabc1-0f59-48da-b608-c45876c3fa8a"); + + final var serviceIdUuid = serializer.serializeUuid("123456789"); + + context.ContextOuterClass.ContextId contextId = + context.ContextOuterClass.ContextId.newBuilder().setContextUuid(contextIdUuid).build(); + + return context.ContextOuterClass.ServiceId.newBuilder() + .setContextId(contextId) + .setServiceUuid(serviceIdUuid) + .build(); + } + + private PolicyRuleBasic createPolicyRuleBasic() { + final var expectedPolicyRuleIdUuid = + serializer.serializeUuid("571eabc1-0f59-48da-b608-c45876c3fa8a"); + + final var expectedPolicyRuleId = + Policy.PolicyRuleId.newBuilder().setUuid(expectedPolicyRuleIdUuid).build(); + + final var expectedPolicyRuleState = + Policy.PolicyRuleState.newBuilder() + .setPolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED) + .build(); + + final var expectedFirstKpiValue = new IntegerKpiValue(22); + final var expectedSecondKpiValue = new FloatKpiValue(69.1f); + + final var serializedExpectedFirstKpiValue = serializer.serialize(expectedFirstKpiValue); + final var serializedExpectedSecondKpiValue = serializer.serialize(expectedSecondKpiValue); + + final var firstExpectedPolicyRuleCondition = + PolicyRuleCondition.newBuilder() + .setKpiId( + KpiId.newBuilder() + .setKpiId( + Uuid.newBuilder().setUuid("79e49ba3-a7b4-4b4b-8aaa-28b05c6f888e").build())) + .setNumericalOperator(NumericalOperator.POLICYRULE_CONDITION_NUMERICAL_EQUAL) + .setKpiValue(serializedExpectedFirstKpiValue) + .build(); + + final var secondExpectedPolicyRuleCondition = + PolicyCondition.PolicyRuleCondition.newBuilder() + .setKpiId( + KpiId.newBuilder() + .setKpiId( + Uuid.newBuilder().setUuid("eae900e5-2703-467d-82f2-97aae8b55c15").build())) + .setNumericalOperator(NumericalOperator.POLICYRULE_CONDITION_NUMERICAL_GREATER_THAN) + .setKpiValue(serializedExpectedSecondKpiValue) + .build(); + + final var expectedPolicyRuleConditions = + List.of(firstExpectedPolicyRuleCondition, secondExpectedPolicyRuleCondition); + + org.etsi.tfs.policy.model.PolicyRuleActionConfig policyRuleActionConfig_1 = + new org.etsi.tfs.policy.model.PolicyRuleActionConfig("paramater1", "parameter2"); + final var serializedPolicyRuleActionConfigList_1 = + serializer.serialize(policyRuleActionConfig_1); + + org.etsi.tfs.policy.model.PolicyRuleActionConfig policyRuleActionConfig_2 = + new org.etsi.tfs.policy.model.PolicyRuleActionConfig("paramater3", "parameter4"); + final var serializedPolicyRuleActionConfigList_2 = + serializer.serialize(policyRuleActionConfig_2); + + final var firstExpectedPolicyRuleAction = + PolicyAction.PolicyRuleAction.newBuilder() + .setAction(PolicyAction.PolicyRuleActionEnum.POLICYRULE_ACTION_ADD_SERVICE_CONFIGRULE) + .addActionConfig(serializedPolicyRuleActionConfigList_1) + .build(); + + final var secondExpectedPolicyRuleAction = + PolicyAction.PolicyRuleAction.newBuilder() + .setAction(PolicyRuleActionEnum.POLICYRULE_ACTION_ADD_SERVICE_CONSTRAINT) + .addActionConfig(serializedPolicyRuleActionConfigList_2) + .build(); + + final var expectedPolicyRuleActions = + List.of(firstExpectedPolicyRuleAction, secondExpectedPolicyRuleAction); + + return PolicyRuleBasic.newBuilder() + .setPolicyRuleId(expectedPolicyRuleId) + .setPolicyRuleState(expectedPolicyRuleState) + .addAllConditionList(expectedPolicyRuleConditions) + .setBooleanOperator(BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR) + .addAllActionList(expectedPolicyRuleActions) + .build(); + } + + // @Test + // void shouldAddPolicyService() throws ExecutionException, InterruptedException, TimeoutException + // { + // CompletableFuture message = new CompletableFuture<>(); + + // final var policyRuleBasic = createPolicyRuleBasic(); + + // final var expectedPolicyRuleState = policyRuleBasic.getPolicyRuleState(); + + // final var serviceId = createContextServiceId(); + + // final var expectedDeviceIdUuid1 = + // serializer.serializeUuid("20db867c-772d-4872-9179-244ecafb3257"); + + // final var expectedDeviceId1 = + // + // ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid1).build(); + + // final var deviceIds = List.of(expectedDeviceId1); + // final var policyRuleService = + // Policy.PolicyRuleService.newBuilder() + // .setPolicyRuleBasic(policyRuleBasic) + // .setServiceId(serviceId) + // .addAllDeviceList(deviceIds) + // .build(); + + // client + // .policyAddService(policyRuleService) + // .subscribe() + // .with(policyRuleState -> + // message.complete(policyRuleState.getPolicyRuleState().toString())); + + // assertThat(message.get(5, TimeUnit.SECONDS)) + // .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); + // } + + // @Test + // void shouldAddPolicyDevice() throws ExecutionException, InterruptedException, TimeoutException + // { + // CompletableFuture message = new CompletableFuture<>(); + + // final var expectedDeviceIdUuid1 = + // serializer.serializeUuid("20db867c-772d-4872-9179-244ecafb3257"); + // final var expectedDeviceIdUuid2 = + // serializer.serializeUuid("095974ac-d757-412d-b317-bcf355220aa9"); + + // final var expectedDeviceId1 = + // + // ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid1).build(); + // final var expectedDeviceId2 = + // + // ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid2).build(); + + // final var policyRuleBasic = createPolicyRuleBasic(); + // final var deviceIds = List.of(expectedDeviceId1, expectedDeviceId2); + + // final var expectedPolicyRuleState = policyRuleBasic.getPolicyRuleState(); + + // final var policyRuleDevice = + // Policy.PolicyRuleDevice.newBuilder() + // .setPolicyRuleBasic(policyRuleBasic) + // .addAllDeviceList(deviceIds) + // .build(); + + // client + // .policyAddDevice(policyRuleDevice) + // .subscribe() + // .with(policyRuleState -> + // message.complete(policyRuleState.getPolicyRuleState().toString())); + + // assertThat(message.get(5, TimeUnit.SECONDS)) + // .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); + // } + + @Test + void shouldUpdatePolicyServiceReturnFailedState() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + final var expectedPolicyRuleState = + Policy.PolicyRuleState.newBuilder() + .setPolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED) + .build(); + + final var policyRuleBasic = + PolicyRuleBasic.newBuilder().setPolicyRuleState(expectedPolicyRuleState).build(); + final var policyRuleService = + Policy.PolicyRuleService.newBuilder().setPolicyRuleBasic(policyRuleBasic).build(); + + client + .policyUpdateService(policyRuleService) + .subscribe() + .with(policyRuleState -> message.complete(policyRuleState.getPolicyRuleState().toString())); + + assertThat(message.get(5, TimeUnit.SECONDS)) + .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); + } + + @Test + void shouldUpdatePolicyDeviceReturnFailedState() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + final var expectedDeviceIdUuid = + serializer.serializeUuid("20db867c-772d-4872-9179-244ecafb3257"); + + final var expectedDeviceId = + ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid).build(); + + final var expectedPolicyRuleState = + Policy.PolicyRuleState.newBuilder() + .setPolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED) + .build(); + + final var policyRuleBasic = + PolicyRuleBasic.newBuilder().setPolicyRuleState(expectedPolicyRuleState).build(); + final var deviceIds = List.of(expectedDeviceId); + final var policyRuleDevice = + Policy.PolicyRuleDevice.newBuilder() + .setPolicyRuleBasic(policyRuleBasic) + .addAllDeviceList(deviceIds) + .build(); + + client + .policyUpdateDevice(policyRuleDevice) + .subscribe() + .with(policyRuleState -> message.complete(policyRuleState.getPolicyRuleState().toString())); + + assertThat(message.get(5, TimeUnit.SECONDS)) + .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); + } + + // TODO: Disable shouldDeletePolicy test until mock context service + // @Test + // void shouldDeletePolicy() throws ExecutionException, InterruptedException, TimeoutException + // { + // CompletableFuture message = new CompletableFuture<>(); + + // final var uuid = + // ContextOuterClass.Uuid.newBuilder() + // + // .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) + // .build(); + // final var policyRuleId = Policy.PolicyRuleId.newBuilder().setUuid(uuid).build(); + + // final var expectedPolicyRuleState = + // Policy.PolicyRuleState.newBuilder() + // .setPolicyRuleState(PolicyRuleStateEnum.POLICY_REMOVED) + // .build(); + + // client + // .policyDelete(policyRuleId) + // .subscribe() + // .with(policyRuleState -> + // message.complete(policyRuleState.getPolicyRuleState().toString())); + + // assertThat(message.get(5, TimeUnit.SECONDS)) + // .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); + // } + + @Test + void shouldGetPolicyService() throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + final var uuid = + ContextOuterClass.Uuid.newBuilder() + .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) + .build(); + final var policyRuleId = Policy.PolicyRuleId.newBuilder().setUuid(uuid).build(); + + client + .getPolicyService(policyRuleId) + .subscribe() + .with( + policyRuleService -> { + LOGGER.infof( + "Getting policy with ID: %s", + policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid()); + message.complete( + policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid().getUuid()); + }); + + assertThat(message.get(5, TimeUnit.SECONDS)).isEqualTo(policyRuleId.getUuid().getUuid()); + } + + @Test + void shouldGetPolicyDevice() throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + final var uuid = + ContextOuterClass.Uuid.newBuilder() + .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) + .build(); + final var policyRuleId = Policy.PolicyRuleId.newBuilder().setUuid(uuid).build(); + + client + .getPolicyDevice(policyRuleId) + .subscribe() + .with( + policyRuleService -> { + LOGGER.infof( + "Getting policy with ID: %s", + policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid()); + message.complete( + policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid().getUuid()); + }); + + assertThat(message.get(5, TimeUnit.SECONDS)).isEqualTo(policyRuleId.getUuid().getUuid()); + } + + @Test + void shouldGetPolicyByServiceId() + throws ExecutionException, InterruptedException, TimeoutException { + + CompletableFuture message = new CompletableFuture<>(); + + final var uuid = + ContextOuterClass.Uuid.newBuilder() + .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) + .build(); + final var serviceId = ContextOuterClass.ServiceId.newBuilder().setServiceUuid(uuid).build(); + + client + .getPolicyByServiceId(serviceId) + .subscribe() + .with( + policyRuleList -> { + LOGGER.infof("Getting policyRuleList with ID: %s", policyRuleList); + message.complete(policyRuleList.toString()); + }); + + assertThat(message.get(5, TimeUnit.SECONDS)).isEmpty(); + } +} diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyServiceTest.java index 2d1a425a8..b09cdeea0 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyServiceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyServiceTest.java @@ -1,382 +1,201 @@ -/* -* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) -* -* 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. -*/ - package org.etsi.tfs.policy; import static org.assertj.core.api.Assertions.assertThat; -import context.ContextOuterClass; -import context.ContextOuterClass.Uuid; -import io.quarkus.grpc.GrpcClient; import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import io.smallrye.mutiny.Uni; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import javax.inject.Inject; -import monitoring.Monitoring.KpiId; -import org.etsi.tfs.policy.monitoring.model.FloatKpiValue; +import org.etsi.tfs.policy.context.ContextService; +import org.etsi.tfs.policy.context.model.Service; +import org.etsi.tfs.policy.context.model.ServiceId; +import org.etsi.tfs.policy.context.model.ServiceTypeEnum; +import org.etsi.tfs.policy.model.BooleanOperator; +import org.etsi.tfs.policy.model.NumericalOperator; +import org.etsi.tfs.policy.model.PolicyRule; +import org.etsi.tfs.policy.model.PolicyRuleAction; +import org.etsi.tfs.policy.model.PolicyRuleActionConfig; +import org.etsi.tfs.policy.model.PolicyRuleActionEnum; +import org.etsi.tfs.policy.model.PolicyRuleBasic; +import org.etsi.tfs.policy.model.PolicyRuleCondition; +import org.etsi.tfs.policy.model.PolicyRuleService; +import org.etsi.tfs.policy.model.PolicyRuleState; +import org.etsi.tfs.policy.model.PolicyRuleStateEnum; +import org.etsi.tfs.policy.monitoring.MonitoringService; import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; -import org.jboss.logging.Logger; +import org.etsi.tfs.policy.monitoring.model.KpiValue; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import policy.Policy; -import policy.Policy.PolicyRuleBasic; -import policy.Policy.PolicyRuleStateEnum; -import policy.PolicyAction; -import policy.PolicyAction.PolicyRuleActionEnum; -import policy.PolicyCondition; -import policy.PolicyCondition.BooleanOperator; -import policy.PolicyCondition.NumericalOperator; -import policy.PolicyCondition.PolicyRuleCondition; -import policy.PolicyService; +import org.mockito.Mockito; @QuarkusTest -class PolicyServiceTest { - private static final Logger LOGGER = Logger.getLogger(PolicyServiceTest.class); - - @GrpcClient PolicyService client; - private final Serializer serializer; - - @Inject - PolicyServiceTest(Serializer serializer) { - this.serializer = serializer; - } +public class PolicyServiceTest { - private context.ContextOuterClass.ServiceId createContextServiceId() { - final var contextIdUuid = serializer.serializeUuid("571eabc1-0f59-48da-b608-c45876c3fa8a"); + @Inject PolicyServiceImpl policyService; - final var serviceIdUuid = serializer.serializeUuid("123456789"); + @InjectMock PolicyRuleConditionValidator policyRuleConditionValidator; - context.ContextOuterClass.ContextId contextId = - context.ContextOuterClass.ContextId.newBuilder().setContextUuid(contextIdUuid).build(); + @InjectMock ContextService contextService; - return context.ContextOuterClass.ServiceId.newBuilder() - .setContextId(contextId) - .setServiceUuid(serviceIdUuid) - .build(); - } - - private PolicyRuleBasic createPolicyRuleBasic() { - final var expectedPolicyRuleIdUuid = - serializer.serializeUuid("571eabc1-0f59-48da-b608-c45876c3fa8a"); - - final var expectedPolicyRuleId = - Policy.PolicyRuleId.newBuilder().setUuid(expectedPolicyRuleIdUuid).build(); - - final var expectedPolicyRuleState = - Policy.PolicyRuleState.newBuilder() - .setPolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED) - .build(); - - final var expectedFirstKpiValue = new IntegerKpiValue(22); - final var expectedSecondKpiValue = new FloatKpiValue(69.1f); - - final var serializedExpectedFirstKpiValue = serializer.serialize(expectedFirstKpiValue); - final var serializedExpectedSecondKpiValue = serializer.serialize(expectedSecondKpiValue); - - final var firstExpectedPolicyRuleCondition = - PolicyRuleCondition.newBuilder() - .setKpiId( - KpiId.newBuilder() - .setKpiId( - Uuid.newBuilder().setUuid("79e49ba3-a7b4-4b4b-8aaa-28b05c6f888e").build())) - .setNumericalOperator(NumericalOperator.POLICYRULE_CONDITION_NUMERICAL_EQUAL) - .setKpiValue(serializedExpectedFirstKpiValue) - .build(); - - final var secondExpectedPolicyRuleCondition = - PolicyCondition.PolicyRuleCondition.newBuilder() - .setKpiId( - KpiId.newBuilder() - .setKpiId( - Uuid.newBuilder().setUuid("eae900e5-2703-467d-82f2-97aae8b55c15").build())) - .setNumericalOperator(NumericalOperator.POLICYRULE_CONDITION_NUMERICAL_GREATER_THAN) - .setKpiValue(serializedExpectedSecondKpiValue) - .build(); - - final var expectedPolicyRuleConditions = - List.of(firstExpectedPolicyRuleCondition, secondExpectedPolicyRuleCondition); - - org.etsi.tfs.policy.model.PolicyRuleActionConfig policyRuleActionConfig_1 = - new org.etsi.tfs.policy.model.PolicyRuleActionConfig("paramater1", "parameter2"); - final var serializedPolicyRuleActionConfigList_1 = - serializer.serialize(policyRuleActionConfig_1); - - org.etsi.tfs.policy.model.PolicyRuleActionConfig policyRuleActionConfig_2 = - new org.etsi.tfs.policy.model.PolicyRuleActionConfig("paramater3", "parameter4"); - final var serializedPolicyRuleActionConfigList_2 = - serializer.serialize(policyRuleActionConfig_2); - - final var firstExpectedPolicyRuleAction = - PolicyAction.PolicyRuleAction.newBuilder() - .setAction(PolicyAction.PolicyRuleActionEnum.POLICYRULE_ACTION_ADD_SERVICE_CONFIGRULE) - .addActionConfig(serializedPolicyRuleActionConfigList_1) - .build(); - - final var secondExpectedPolicyRuleAction = - PolicyAction.PolicyRuleAction.newBuilder() - .setAction(PolicyRuleActionEnum.POLICYRULE_ACTION_ADD_SERVICE_CONSTRAINT) - .addActionConfig(serializedPolicyRuleActionConfigList_2) - .build(); - - final var expectedPolicyRuleActions = - List.of(firstExpectedPolicyRuleAction, secondExpectedPolicyRuleAction); - - return PolicyRuleBasic.newBuilder() - .setPolicyRuleId(expectedPolicyRuleId) - .setPolicyRuleState(expectedPolicyRuleState) - .addAllConditionList(expectedPolicyRuleConditions) - .setBooleanOperator(BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR) - .addAllActionList(expectedPolicyRuleActions) - .build(); - } + @InjectMock MonitoringService monitoringService; - // @Test - // void shouldAddPolicyService() throws ExecutionException, InterruptedException, TimeoutException - // { - // CompletableFuture message = new CompletableFuture<>(); + static PolicyRuleBasic policyRuleBasic; + static PolicyRuleService policyRuleService; - // final var policyRuleBasic = createPolicyRuleBasic(); + @BeforeAll + static void init() { - // final var expectedPolicyRuleState = policyRuleBasic.getPolicyRuleState(); + String policyId = "policyRuleId"; + KpiValue kpiValue = new IntegerKpiValue(100); - // final var serviceId = createContextServiceId(); + PolicyRuleCondition policyRuleCondition = + new PolicyRuleCondition( + "kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue); - // final var expectedDeviceIdUuid1 = - // serializer.serializeUuid("20db867c-772d-4872-9179-244ecafb3257"); + PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value"); - // final var expectedDeviceId1 = - // - // ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid1).build(); + PolicyRuleAction policyRuleAction = + new PolicyRuleAction( + PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION, + Arrays.asList(policyRuleActionConfig)); - // final var deviceIds = List.of(expectedDeviceId1); - // final var policyRuleService = - // Policy.PolicyRuleService.newBuilder() - // .setPolicyRuleBasic(policyRuleBasic) - // .setServiceId(serviceId) - // .addAllDeviceList(deviceIds) - // .build(); + policyRuleBasic = + new PolicyRuleBasic( + policyId, + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 1, + Arrays.asList(policyRuleCondition), + BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR, + Arrays.asList(policyRuleAction)); - // client - // .policyAddService(policyRuleService) - // .subscribe() - // .with(policyRuleState -> - // message.complete(policyRuleState.getPolicyRuleState().toString())); + ServiceId serviceId = new ServiceId("contextId", "serviceId"); - // assertThat(message.get(5, TimeUnit.SECONDS)) - // .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); - // } + Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0); - // @Test - // void shouldAddPolicyDevice() throws ExecutionException, InterruptedException, TimeoutException - // { - // CompletableFuture message = new CompletableFuture<>(); + List deviceIds = Arrays.asList("device1", "device2"); - // final var expectedDeviceIdUuid1 = - // serializer.serializeUuid("20db867c-772d-4872-9179-244ecafb3257"); - // final var expectedDeviceIdUuid2 = - // serializer.serializeUuid("095974ac-d757-412d-b317-bcf355220aa9"); + policyRuleService = new PolicyRuleService(policyRuleBasic, serviceId, deviceIds); + } - // final var expectedDeviceId1 = - // - // ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid1).build(); - // final var expectedDeviceId2 = - // - // ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid2).build(); + @Test + void contextOrServiceIdMustNotBeEmpty() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); - // final var policyRuleBasic = createPolicyRuleBasic(); - // final var deviceIds = List.of(expectedDeviceId1, expectedDeviceId2); + ServiceId serviceId = new ServiceId("", ""); + List deviceIds = Arrays.asList("device1", "device2"); - // final var expectedPolicyRuleState = policyRuleBasic.getPolicyRuleState(); + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, deviceIds); - // final var policyRuleDevice = - // Policy.PolicyRuleDevice.newBuilder() - // .setPolicyRuleBasic(policyRuleBasic) - // .addAllDeviceList(deviceIds) - // .build(); + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, "Context Id of Service Id must not be empty."); - // client - // .policyAddDevice(policyRuleDevice) - // .subscribe() - // .with(policyRuleState -> - // message.complete(policyRuleState.getPolicyRuleState().toString())); + policyService + .addPolicyService(policyRuleService) + .subscribe() + .with( + item -> { + message.complete(item); + }); - // assertThat(message.get(5, TimeUnit.SECONDS)) - // .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); - // } + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } @Test - void shouldUpdatePolicyServiceReturnFailedState() - throws ExecutionException, InterruptedException, TimeoutException { - CompletableFuture message = new CompletableFuture<>(); + void serviceIdMustNotBeEmpty() throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + ServiceId serviceId = new ServiceId("sdf", ""); + List deviceIds = Arrays.asList("device1", "device2"); - final var expectedPolicyRuleState = - Policy.PolicyRuleState.newBuilder() - .setPolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED) - .build(); + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, deviceIds); - final var policyRuleBasic = - PolicyRuleBasic.newBuilder().setPolicyRuleState(expectedPolicyRuleState).build(); - final var policyRuleService = - Policy.PolicyRuleService.newBuilder().setPolicyRuleBasic(policyRuleBasic).build(); + PolicyRuleState expectedResult = + new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Service Id must not be empty."); - client - .policyUpdateService(policyRuleService) + policyService + .addPolicyService(policyRuleService) .subscribe() - .with(policyRuleState -> message.complete(policyRuleState.getPolicyRuleState().toString())); + .with(item -> message.complete(item)); - assertThat(message.get(5, TimeUnit.SECONDS)) - .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); } @Test - void shouldUpdatePolicyDeviceReturnFailedState() + void policyRuleIdMustNotBeEmpty() throws ExecutionException, InterruptedException, TimeoutException { - CompletableFuture message = new CompletableFuture<>(); - - final var expectedDeviceIdUuid = - serializer.serializeUuid("20db867c-772d-4872-9179-244ecafb3257"); - - final var expectedDeviceId = - ContextOuterClass.DeviceId.newBuilder().setDeviceUuid(expectedDeviceIdUuid).build(); - - final var expectedPolicyRuleState = - Policy.PolicyRuleState.newBuilder() - .setPolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED) - .build(); - - final var policyRuleBasic = - PolicyRuleBasic.newBuilder().setPolicyRuleState(expectedPolicyRuleState).build(); - final var deviceIds = List.of(expectedDeviceId); - final var policyRuleDevice = - Policy.PolicyRuleDevice.newBuilder() - .setPolicyRuleBasic(policyRuleBasic) - .addAllDeviceList(deviceIds) - .build(); - - client - .policyUpdateDevice(policyRuleDevice) - .subscribe() - .with(policyRuleState -> message.complete(policyRuleState.getPolicyRuleState().toString())); + CompletableFuture message = new CompletableFuture<>(); - assertThat(message.get(5, TimeUnit.SECONDS)) - .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); - } - - // TODO: Disable shouldDeletePolicy test until mock context service - // @Test - // void shouldDeletePolicy() throws ExecutionException, InterruptedException, TimeoutException - // { - // CompletableFuture message = new CompletableFuture<>(); - - // final var uuid = - // ContextOuterClass.Uuid.newBuilder() - // - // .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) - // .build(); - // final var policyRuleId = Policy.PolicyRuleId.newBuilder().setUuid(uuid).build(); - - // final var expectedPolicyRuleState = - // Policy.PolicyRuleState.newBuilder() - // .setPolicyRuleState(PolicyRuleStateEnum.POLICY_REMOVED) - // .build(); - - // client - // .policyDelete(policyRuleId) - // .subscribe() - // .with(policyRuleState -> - // message.complete(policyRuleState.getPolicyRuleState().toString())); - - // assertThat(message.get(5, TimeUnit.SECONDS)) - // .isEqualTo(expectedPolicyRuleState.getPolicyRuleState().toString()); - // } - - @Test - void shouldGetPolicyService() throws ExecutionException, InterruptedException, TimeoutException { - CompletableFuture message = new CompletableFuture<>(); + String policyId = ""; - final var uuid = - ContextOuterClass.Uuid.newBuilder() - .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) - .build(); - final var policyRuleId = Policy.PolicyRuleId.newBuilder().setUuid(uuid).build(); + PolicyRuleBasic policyRuleBasic = + new PolicyRuleBasic( + policyId, + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 1, + new ArrayList<>(), + null, + new ArrayList<>()); - client - .getPolicyService(policyRuleId) - .subscribe() - .with( - policyRuleService -> { - LOGGER.infof( - "Getting policy with ID: %s", - policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid()); - message.complete( - policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid().getUuid()); - }); + ServiceId serviceId = new ServiceId("contextId", "serviceId"); - assertThat(message.get(5, TimeUnit.SECONDS)).isEqualTo(policyRuleId.getUuid().getUuid()); - } + Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0); - @Test - void shouldGetPolicyDevice() throws ExecutionException, InterruptedException, TimeoutException { - CompletableFuture message = new CompletableFuture<>(); + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>()); - final var uuid = - ContextOuterClass.Uuid.newBuilder() - .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) - .build(); - final var policyRuleId = Policy.PolicyRuleId.newBuilder().setUuid(uuid).build(); + PolicyRuleState expectedResult = + new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Policy rule ID must not be empty."); - client - .getPolicyDevice(policyRuleId) + policyService + .addPolicyService(policyRuleService) .subscribe() .with( - policyRuleService -> { - LOGGER.infof( - "Getting policy with ID: %s", - policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid()); - message.complete( - policyRuleService.getPolicyRuleBasic().getPolicyRuleId().getUuid().getUuid()); + item -> { + message.complete(item); }); - assertThat(message.get(5, TimeUnit.SECONDS)).isEqualTo(policyRuleId.getUuid().getUuid()); + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); } @Test - void shouldGetPolicyByServiceId() - throws ExecutionException, InterruptedException, TimeoutException { + void policyServiceSuccess() throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_VALIDATED, "Successfully transitioned to VALIDATED state"); - CompletableFuture message = new CompletableFuture<>(); + Mockito.when( + policyRuleConditionValidator.isServiceIdValid( + Mockito.any(ServiceId.class), Mockito.anyList())) + .thenReturn(Uni.createFrom().item(Boolean.TRUE)); - final var uuid = - ContextOuterClass.Uuid.newBuilder() - .setUuid(UUID.fromString("0f14d0ab-9608-7862-a9e4-5ed26688389b").toString()) - .build(); - final var serviceId = ContextOuterClass.ServiceId.newBuilder().setServiceUuid(uuid).build(); + Mockito.when(contextService.setPolicyRule(Mockito.any(PolicyRule.class))) + .thenReturn(Uni.createFrom().item("policyRuleId")); - client - .getPolicyByServiceId(serviceId) + policyService + .addPolicyService(policyRuleService) .subscribe() .with( - policyRuleList -> { - LOGGER.infof("Getting policyRuleList with ID: %s", policyRuleList); - message.complete(policyRuleList.toString()); + item -> { + message.complete(item); }); - assertThat(message.get(5, TimeUnit.SECONDS)).isEmpty(); + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); } } diff --git a/src/policy/target/kubernetes/kubernetes.yml b/src/policy/target/kubernetes/kubernetes.yml deleted file mode 100644 index 55847f89e..000000000 --- a/src/policy/target/kubernetes/kubernetes.yml +++ /dev/null @@ -1,108 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - app.quarkus.io/commit-id: 5f8866be9cb91871607627819258b0b375410467 - app.quarkus.io/build-timestamp: 2024-01-26 - 16:40:15 +0000 - prometheus.io/scrape: "true" - prometheus.io/path: /q/metrics - prometheus.io/port: "8080" - prometheus.io/scheme: http - labels: - app.kubernetes.io/name: policyservice - app: policyservice - name: policyservice -spec: - ports: - - name: http - port: 9192 - targetPort: 8080 - - name: grpc-server - port: 6060 - targetPort: 6060 - selector: - app.kubernetes.io/name: policyservice - type: ClusterIP ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - annotations: - app.quarkus.io/commit-id: 5f8866be9cb91871607627819258b0b375410467 - app.quarkus.io/build-timestamp: 2024-01-26 - 16:40:15 +0000 - prometheus.io/scrape: "true" - prometheus.io/path: /q/metrics - prometheus.io/port: "8080" - prometheus.io/scheme: http - labels: - app: policyservice - app.kubernetes.io/name: policyservice - name: policyservice -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/name: policyservice - template: - metadata: - annotations: - app.quarkus.io/commit-id: 5f8866be9cb91871607627819258b0b375410467 - app.quarkus.io/build-timestamp: 2024-01-26 - 16:40:15 +0000 - prometheus.io/scrape: "true" - prometheus.io/path: /q/metrics - prometheus.io/port: "8080" - prometheus.io/scheme: http - labels: - app: policyservice - app.kubernetes.io/name: policyservice - spec: - containers: - - env: - - name: KUBERNETES_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace - - name: SERVICE_SERVICE_HOST - value: serviceservice - - name: MONITORING_SERVICE_HOST - value: monitoringservice - - name: CONTEXT_SERVICE_HOST - value: contextservice - image: labs.etsi.org:5050/tfs/controller/policy:0.1.0 - imagePullPolicy: Always - livenessProbe: - failureThreshold: 3 - httpGet: - path: /q/health/live - port: 8080 - scheme: HTTP - initialDelaySeconds: 2 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 10 - name: policyservice - ports: - - containerPort: 8080 - name: http - protocol: TCP - - containerPort: 6060 - name: grpc-server - protocol: TCP - readinessProbe: - failureThreshold: 3 - httpGet: - path: /q/health/ready - port: 8080 - scheme: HTTP - initialDelaySeconds: 2 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 10 - resources: - limits: - cpu: 500m - memory: 2048Mi - requests: - cpu: 50m - memory: 512Mi -- GitLab From bfdfbb1c7768003967156e8730a4f5dbe1d08138 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Wed, 31 Jan 2024 13:20:19 +0200 Subject: [PATCH 2/6] test: Change PolicyServiceTest to PolicyAddServiceTest --- .../policy/common/ApplicationProperties.java | 43 ++++ .../etsi/tfs/policy/PolicyAddServiceTest.java | 235 ++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java create mode 100644 src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java b/src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java new file mode 100644 index 000000000..b24ecd4a5 --- /dev/null +++ b/src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java @@ -0,0 +1,43 @@ +package org.etsi.tfs.policy.common; + +import org.etsi.tfs.policy.model.PolicyRuleState; +import org.etsi.tfs.policy.model.PolicyRuleStateEnum; + +public class ApplicationProperties { + + public static final String INVALID_MESSAGE = "%s is invalid."; + public static final String VALID_MESSAGE = "%s is valid."; + + public static final PolicyRuleState INSERTED_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_INSERTED, "Successfully entered to INSERTED state"); + public static final PolicyRuleState VALIDATED_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_VALIDATED, "Successfully transitioned to VALIDATED state"); + public static final PolicyRuleState PROVISIONED_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_PROVISIONED, + "Successfully transitioned from VALIDATED to PROVISIONED state"); + public static final PolicyRuleState ACTIVE_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_ACTIVE, + "Successfully transitioned from PROVISIONED to ACTIVE state"); + public static final PolicyRuleState ENFORCED_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_ENFORCED, + "Successfully transitioned from ACTIVE to ENFORCED state"); + public static final PolicyRuleState INEFFECTIVE_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_INEFFECTIVE, + "Transitioned from ENFORCED to INEFFECTIVE state"); + public static final PolicyRuleState EFFECTIVE_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_EFFECTIVE, + "Successfully transitioned from ENFORCED to EFFECTIVE state"); + public static final PolicyRuleState UPDATED_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_UPDATED, "Successfully entered to UPDATED state"); + public static final PolicyRuleState REMOVED_POLICYRULE_STATE = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_REMOVED, "Successfully entered to REMOVED state"); +} diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java new file mode 100644 index 000000000..657422071 --- /dev/null +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java @@ -0,0 +1,235 @@ +package org.etsi.tfs.policy; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.etsi.tfs.policy.common.ApplicationProperties.*; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import io.smallrye.mutiny.Uni; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.inject.Inject; +import org.etsi.tfs.policy.context.ContextService; +import org.etsi.tfs.policy.context.model.Service; +import org.etsi.tfs.policy.context.model.ServiceId; +import org.etsi.tfs.policy.context.model.ServiceTypeEnum; +import org.etsi.tfs.policy.model.BooleanOperator; +import org.etsi.tfs.policy.model.NumericalOperator; +import org.etsi.tfs.policy.model.PolicyRule; +import org.etsi.tfs.policy.model.PolicyRuleAction; +import org.etsi.tfs.policy.model.PolicyRuleActionConfig; +import org.etsi.tfs.policy.model.PolicyRuleActionEnum; +import org.etsi.tfs.policy.model.PolicyRuleBasic; +import org.etsi.tfs.policy.model.PolicyRuleCondition; +import org.etsi.tfs.policy.model.PolicyRuleService; +import org.etsi.tfs.policy.model.PolicyRuleState; +import org.etsi.tfs.policy.model.PolicyRuleStateEnum; +import org.etsi.tfs.policy.monitoring.MonitoringService; +import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; +import org.etsi.tfs.policy.monitoring.model.KpiValue; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +@QuarkusTest +public class PolicyAddServiceTest { + + @Inject PolicyServiceImpl policyService; + + @InjectMock PolicyRuleConditionValidator policyRuleConditionValidator; + + @InjectMock ContextService contextService; + + @InjectMock MonitoringService monitoringService; + + static PolicyRuleBasic policyRuleBasic; + static PolicyRuleService policyRuleService; + + @BeforeAll + static void init() { + + String policyId = "policyRuleId"; + KpiValue kpiValue = new IntegerKpiValue(100); + + PolicyRuleCondition policyRuleCondition = + new PolicyRuleCondition( + "kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue); + + PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value"); + + PolicyRuleAction policyRuleAction = + new PolicyRuleAction( + PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION, + Arrays.asList(policyRuleActionConfig)); + + policyRuleBasic = + new PolicyRuleBasic( + policyId, + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 1, + Arrays.asList(policyRuleCondition), + BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR, + Arrays.asList(policyRuleAction)); + + ServiceId serviceId = new ServiceId("contextId", "serviceId"); + + Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0); + + List deviceIds = Arrays.asList("device1", "device2"); + + policyRuleService = new PolicyRuleService(policyRuleBasic, serviceId, deviceIds); + } + + @Test + void contextOrServiceIdMustNotBeEmpty() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + ServiceId serviceId = new ServiceId("", ""); + List deviceIds = Arrays.asList("device1", "device2"); + + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, deviceIds); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, "Context Id of Service Id must not be empty."); + + policyService + .addPolicyService(policyRuleService) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void serviceIdMustNotBeEmpty() throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + ServiceId serviceId = new ServiceId("sdf", ""); + List deviceIds = Arrays.asList("device1", "device2"); + + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, deviceIds); + + PolicyRuleState expectedResult = + new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Service Id must not be empty."); + + policyService + .addPolicyService(policyRuleService) + .subscribe() + .with(item -> message.complete(item)); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void policyRuleIdMustNotBeEmpty() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + String policyId = ""; + + PolicyRuleBasic policyRuleBasic = + new PolicyRuleBasic( + policyId, + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 1, + new ArrayList<>(), + null, + new ArrayList<>()); + + ServiceId serviceId = new ServiceId("contextId", "serviceId"); + + Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0); + + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>()); + + PolicyRuleState expectedResult = + new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Policy rule ID must not be empty."); + + policyService + .addPolicyService(policyRuleService) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void checkMessageIfServiceIsNotValid() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + ServiceId serviceId = new ServiceId("contextId", "serviceId"); + + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>()); + + PolicyRuleState expectedResult = + new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, serviceId + " is invalid."); + + Mockito.when( + policyRuleConditionValidator.isServiceIdValid( + Mockito.any(ServiceId.class), Mockito.anyList())) + .thenReturn(Uni.createFrom().item(Boolean.FALSE)); + + policyService + .addPolicyService(policyRuleService) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void policyServiceSuccess() + throws ExecutionException, InterruptedException, TimeoutException, IOException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_VALIDATED, + VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage()); + + Mockito.when( + policyRuleConditionValidator.isServiceIdValid( + Mockito.any(ServiceId.class), Mockito.anyList())) + .thenReturn(Uni.createFrom().item(Boolean.TRUE)); + + Mockito.when(contextService.setPolicyRule(Mockito.any(PolicyRule.class))) + .thenReturn(Uni.createFrom().item("policyRuleId")); + + policyService + .addPolicyService(policyRuleService) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } +} -- GitLab From 7a31182d3b78dacfa0773867f059d3b045ff9516 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Wed, 31 Jan 2024 13:44:05 +0200 Subject: [PATCH 3/6] test: Create tests for addDevice , updateDevice , updateService , deleteService --- .../etsi/tfs/policy/PolicyServiceImpl.java | 42 +--- .../tfs/policy/model/PolicyRuleDevice.java | 2 +- .../etsi/tfs/policy/PolicyAddDeviceTest.java | 188 ++++++++++++++++++ .../tfs/policy/PolicyDeleteServiceTest.java | 112 +++++++++++ .../tfs/policy/PolicyUpdateDeviceTest.java | 185 +++++++++++++++++ ...Test.java => PolicyUpdateServiceTest.java} | 54 +++-- 6 files changed, 518 insertions(+), 65 deletions(-) create mode 100644 src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java create mode 100644 src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java create mode 100644 src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java rename src/policy/src/test/java/org/etsi/tfs/policy/{PolicyServiceTest.java => PolicyUpdateServiceTest.java} (81%) diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java index b5f1d85eb..c2f98e31e 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/PolicyServiceImpl.java @@ -16,6 +16,8 @@ package org.etsi.tfs.policy; +import static org.etsi.tfs.policy.common.ApplicationProperties.*; + import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.groups.UniJoin; @@ -64,8 +66,7 @@ import org.jboss.logging.Logger; public class PolicyServiceImpl implements PolicyService { private static final Logger LOGGER = Logger.getLogger(PolicyServiceImpl.class); - private static final String INVALID_MESSAGE = "%s is invalid."; - private static final String VALID_MESSAGE = "%s is valid."; + private static final int POLICY_EVALUATION_TIMEOUT = 5; private static final int ACCEPTABLE_NUMBER_OF_ALARMS = 3; private static final int MONITORING_WINDOW_IN_SECONDS = 5; @@ -74,39 +75,6 @@ public class PolicyServiceImpl implements PolicyService { // Temporary solution for not calling the same rpc more than it's needed private static int noAlarms = 0; - private static final PolicyRuleState INSERTED_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_INSERTED, "Successfully entered to INSERTED state"); - private static final PolicyRuleState VALIDATED_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_VALIDATED, "Successfully transitioned to VALIDATED state"); - private static final PolicyRuleState PROVISIONED_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_PROVISIONED, - "Successfully transitioned from VALIDATED to PROVISIONED state"); - private static final PolicyRuleState ACTIVE_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_ACTIVE, - "Successfully transitioned from PROVISIONED to ACTIVE state"); - private static final PolicyRuleState ENFORCED_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_ENFORCED, - "Successfully transitioned from ACTIVE to ENFORCED state"); - private static final PolicyRuleState INEFFECTIVE_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_INEFFECTIVE, - "Transitioned from ENFORCED to INEFFECTIVE state"); - private static final PolicyRuleState EFFECTIVE_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_EFFECTIVE, - "Successfully transitioned from ENFORCED to EFFECTIVE state"); - private static final PolicyRuleState UPDATED_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_UPDATED, "Successfully entered to UPDATED state"); - private static final PolicyRuleState REMOVED_POLICYRULE_STATE = - new PolicyRuleState( - PolicyRuleStateEnum.POLICY_REMOVED, "Successfully entered to REMOVED state"); - private final ContextService contextService; private final MonitoringService monitoringService; private final ServiceService serviceService; @@ -457,7 +425,9 @@ public class PolicyServiceImpl implements PolicyService { policyRuleBasic.getPolicyRuleId())); contextService.removePolicyRule(policyId).subscribe().with(x -> {}); - subscriptionList.get(policyId).cancel(); + + // TODO: When the Map doesn't contains the policyId we should throw an exception? + if (subscriptionList.contains(policyId)) subscriptionList.get(policyId).cancel(); return policyRuleBasic.getPolicyRuleState(); }); diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleDevice.java b/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleDevice.java index 9c23692a1..f46635e87 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleDevice.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/model/PolicyRuleDevice.java @@ -40,7 +40,7 @@ public class PolicyRuleDevice { this.policyRuleBasic = policyRuleBasic; this.deviceIds = new ArrayList(); this.isValid = false; - this.exceptionMessage = e.toString(); + this.exceptionMessage = e.getMessage(); } } diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java new file mode 100644 index 000000000..1b00248e1 --- /dev/null +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java @@ -0,0 +1,188 @@ +package org.etsi.tfs.policy; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.etsi.tfs.policy.common.ApplicationProperties.INVALID_MESSAGE; +import static org.etsi.tfs.policy.common.ApplicationProperties.VALIDATED_POLICYRULE_STATE; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import io.smallrye.mutiny.Uni; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.inject.Inject; +import org.etsi.tfs.policy.context.ContextService; +import org.etsi.tfs.policy.model.BooleanOperator; +import org.etsi.tfs.policy.model.NumericalOperator; +import org.etsi.tfs.policy.model.PolicyRuleAction; +import org.etsi.tfs.policy.model.PolicyRuleActionConfig; +import org.etsi.tfs.policy.model.PolicyRuleActionEnum; +import org.etsi.tfs.policy.model.PolicyRuleBasic; +import org.etsi.tfs.policy.model.PolicyRuleCondition; +import org.etsi.tfs.policy.model.PolicyRuleDevice; +import org.etsi.tfs.policy.model.PolicyRuleState; +import org.etsi.tfs.policy.model.PolicyRuleStateEnum; +import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; +import org.etsi.tfs.policy.monitoring.model.KpiValue; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +@QuarkusTest +class PolicyAddDeviceTest { + + @Inject PolicyServiceImpl policyService; + + @InjectMock PolicyRuleConditionValidator policyRuleConditionValidator; + + @InjectMock ContextService contextService; + + static PolicyRuleBasic policyRuleBasic; + static PolicyRuleDevice policyRuleDevice; + + @BeforeAll + static void init() { + + String policyId = "policyRuleId"; + KpiValue kpiValue = new IntegerKpiValue(100); + + PolicyRuleCondition policyRuleCondition = + new PolicyRuleCondition( + "kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue); + + PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value"); + + PolicyRuleAction policyRuleAction = + new PolicyRuleAction( + PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION, + Arrays.asList(policyRuleActionConfig)); + + policyRuleBasic = + new PolicyRuleBasic( + policyId, + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 1, + Arrays.asList(policyRuleCondition), + BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR, + Arrays.asList(policyRuleAction)); + + List deviceIds = Arrays.asList("device1", "device2"); + + policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, deviceIds); + } + + @Test + void deviceListMustNotBeEmpty() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleDevice policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, new ArrayList<>()); + + PolicyRuleState expectedResult = + new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Device Ids must not be empty."); + + policyService + .updatePolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void isPolicyRuleBasicValid() throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleBasic policyRuleBasic = + new PolicyRuleBasic( + "policyId", + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 0, + new ArrayList<>(), + BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR, + new ArrayList<>()); + + PolicyRuleDevice policyRuleDevice = + new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2")); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, "Policy Rule conditions cannot be empty."); + + policyService + .updatePolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void isUpdatedPolicyRuleIdValid() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleDevice policyRuleDevice = + new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2")); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, + String.format( + INVALID_MESSAGE, policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId())); + + Mockito.when(policyRuleConditionValidator.isUpdatedPolicyRuleIdValid(Mockito.anyString())) + .thenReturn(Uni.createFrom().item(Boolean.FALSE)); + + policyService + .updatePolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void successUpdatePolicyService() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleDevice policyRuleDevice = + new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2")); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_VALIDATED, + VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage()); + + Mockito.when(policyRuleConditionValidator.isDeviceIdValid(Mockito.anyString())) + .thenReturn(Uni.createFrom().item(Boolean.TRUE)); + + policyService + .addPolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } +} diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java new file mode 100644 index 000000000..9609bf11b --- /dev/null +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java @@ -0,0 +1,112 @@ +package org.etsi.tfs.policy; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.etsi.tfs.policy.common.ApplicationProperties.REMOVED_POLICYRULE_STATE; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import io.smallrye.mutiny.Uni; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.inject.Inject; +import org.etsi.tfs.policy.context.ContextService; +import org.etsi.tfs.policy.context.model.Service; +import org.etsi.tfs.policy.context.model.ServiceId; +import org.etsi.tfs.policy.context.model.ServiceTypeEnum; +import org.etsi.tfs.policy.model.BooleanOperator; +import org.etsi.tfs.policy.model.NumericalOperator; +import org.etsi.tfs.policy.model.PolicyRule; +import org.etsi.tfs.policy.model.PolicyRuleAction; +import org.etsi.tfs.policy.model.PolicyRuleActionConfig; +import org.etsi.tfs.policy.model.PolicyRuleActionEnum; +import org.etsi.tfs.policy.model.PolicyRuleBasic; +import org.etsi.tfs.policy.model.PolicyRuleCondition; +import org.etsi.tfs.policy.model.PolicyRuleService; +import org.etsi.tfs.policy.model.PolicyRuleState; +import org.etsi.tfs.policy.model.PolicyRuleStateEnum; +import org.etsi.tfs.policy.model.PolicyRuleType; +import org.etsi.tfs.policy.model.PolicyRuleTypeService; +import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; +import org.etsi.tfs.policy.monitoring.model.KpiValue; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +@QuarkusTest +class PolicyDeleteServiceTest { + + @Inject PolicyServiceImpl policyService; + @InjectMock ContextService contextService; + + static PolicyRuleBasic policyRuleBasic; + static PolicyRuleService policyRuleService; + + @BeforeAll + static void init() { + + String policyId = "policyRuleId"; + KpiValue kpiValue = new IntegerKpiValue(100); + + PolicyRuleCondition policyRuleCondition = + new PolicyRuleCondition( + "kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue); + + PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value"); + + PolicyRuleAction policyRuleAction = + new PolicyRuleAction( + PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION, + Arrays.asList(policyRuleActionConfig)); + + policyRuleBasic = + new PolicyRuleBasic( + policyId, + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 1, + Arrays.asList(policyRuleCondition), + BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR, + Arrays.asList(policyRuleAction)); + + ServiceId serviceId = new ServiceId("contextId", "serviceId"); + + Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0); + + List deviceIds = Arrays.asList("device1", "device2"); + + policyRuleService = new PolicyRuleService(policyRuleBasic, serviceId, deviceIds); + } + + @Test + void contextOrServiceIdMustNotBeEmpty() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + String policyRuleId = ""; + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_REMOVED, + REMOVED_POLICYRULE_STATE.getPolicyRuleStateMessage()); + + PolicyRuleType policyRuleType = new PolicyRuleTypeService(policyRuleService); + + PolicyRule policyRule = new PolicyRule(policyRuleType); + + Mockito.when(contextService.getPolicyRule(Mockito.anyString())) + .thenReturn(Uni.createFrom().item(policyRule)); + + policyService + .deletePolicy(policyRuleId) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } +} diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java new file mode 100644 index 000000000..0e8e2e3d0 --- /dev/null +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java @@ -0,0 +1,185 @@ +package org.etsi.tfs.policy; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.etsi.tfs.policy.common.ApplicationProperties.INVALID_MESSAGE; +import static org.etsi.tfs.policy.common.ApplicationProperties.VALIDATED_POLICYRULE_STATE; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import io.smallrye.mutiny.Uni; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.inject.Inject; +import org.etsi.tfs.policy.model.BooleanOperator; +import org.etsi.tfs.policy.model.NumericalOperator; +import org.etsi.tfs.policy.model.PolicyRuleAction; +import org.etsi.tfs.policy.model.PolicyRuleActionConfig; +import org.etsi.tfs.policy.model.PolicyRuleActionEnum; +import org.etsi.tfs.policy.model.PolicyRuleBasic; +import org.etsi.tfs.policy.model.PolicyRuleCondition; +import org.etsi.tfs.policy.model.PolicyRuleDevice; +import org.etsi.tfs.policy.model.PolicyRuleState; +import org.etsi.tfs.policy.model.PolicyRuleStateEnum; +import org.etsi.tfs.policy.monitoring.model.IntegerKpiValue; +import org.etsi.tfs.policy.monitoring.model.KpiValue; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +@QuarkusTest +class PolicyUpdateDeviceTest { + + @Inject PolicyServiceImpl policyService; + + @InjectMock PolicyRuleConditionValidator policyRuleConditionValidator; + + static PolicyRuleBasic policyRuleBasic; + static PolicyRuleDevice policyRuleDevice; + + @BeforeAll + static void init() { + + String policyId = "policyRuleId"; + KpiValue kpiValue = new IntegerKpiValue(100); + + PolicyRuleCondition policyRuleCondition = + new PolicyRuleCondition( + "kpiId", NumericalOperator.POLICY_RULE_CONDITION_NUMERICAL_GREATER_THAN, kpiValue); + + PolicyRuleActionConfig policyRuleActionConfig = new PolicyRuleActionConfig("key", "value"); + + PolicyRuleAction policyRuleAction = + new PolicyRuleAction( + PolicyRuleActionEnum.POLICY_RULE_ACTION_NO_ACTION, + Arrays.asList(policyRuleActionConfig)); + + policyRuleBasic = + new PolicyRuleBasic( + policyId, + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 1, + Arrays.asList(policyRuleCondition), + BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR, + Arrays.asList(policyRuleAction)); + + List deviceIds = Arrays.asList("device1", "device2"); + + policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, deviceIds); + } + + @Test + void deviceListMustNotBeEmpty() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleDevice policyRuleDevice = new PolicyRuleDevice(policyRuleBasic, new ArrayList<>()); + + PolicyRuleState expectedResult = + new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Device Ids must not be empty."); + + policyService + .updatePolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void isPolicyRuleBasicValid() throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleBasic policyRuleBasic = + new PolicyRuleBasic( + "policyId", + new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), + 0, + new ArrayList<>(), + BooleanOperator.POLICYRULE_CONDITION_BOOLEAN_OR, + new ArrayList<>()); + + PolicyRuleDevice policyRuleDevice = + new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2")); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, "Policy Rule conditions cannot be empty."); + + policyService + .updatePolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void isUpdatedPolicyRuleIdValid() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleDevice policyRuleDevice = + new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1", "device2")); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, + String.format( + INVALID_MESSAGE, policyRuleDevice.getPolicyRuleBasic().getPolicyRuleId())); + + Mockito.when(policyRuleConditionValidator.isUpdatedPolicyRuleIdValid(Mockito.anyString())) + .thenReturn(Uni.createFrom().item(Boolean.FALSE)); + + policyService + .updatePolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } + + @Test + void successUpdatePolicyService() + throws ExecutionException, InterruptedException, TimeoutException { + CompletableFuture message = new CompletableFuture<>(); + + PolicyRuleDevice policyRuleDevice = + new PolicyRuleDevice(policyRuleBasic, Arrays.asList("device1")); + + PolicyRuleState expectedResult = + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_VALIDATED, + VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage()); + + Mockito.when(policyRuleConditionValidator.isUpdatedPolicyRuleIdValid(Mockito.anyString())) + .thenReturn(Uni.createFrom().item(Boolean.TRUE)); + + policyService + .updatePolicyDevice(policyRuleDevice) + .subscribe() + .with( + item -> { + message.complete(item); + }); + + assertThat(message.get(5, TimeUnit.SECONDS).getPolicyRuleStateMessage()) + .isEqualTo(expectedResult.getPolicyRuleStateMessage().toString()); + } +} diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateServiceTest.java similarity index 81% rename from src/policy/src/test/java/org/etsi/tfs/policy/PolicyServiceTest.java rename to src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateServiceTest.java index b09cdeea0..3acab688b 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyServiceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateServiceTest.java @@ -1,6 +1,8 @@ package org.etsi.tfs.policy; import static org.assertj.core.api.Assertions.assertThat; +import static org.etsi.tfs.policy.common.ApplicationProperties.INVALID_MESSAGE; +import static org.etsi.tfs.policy.common.ApplicationProperties.VALIDATED_POLICYRULE_STATE; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.mockito.InjectMock; @@ -19,7 +21,6 @@ import org.etsi.tfs.policy.context.model.ServiceId; import org.etsi.tfs.policy.context.model.ServiceTypeEnum; import org.etsi.tfs.policy.model.BooleanOperator; import org.etsi.tfs.policy.model.NumericalOperator; -import org.etsi.tfs.policy.model.PolicyRule; import org.etsi.tfs.policy.model.PolicyRuleAction; import org.etsi.tfs.policy.model.PolicyRuleActionConfig; import org.etsi.tfs.policy.model.PolicyRuleActionEnum; @@ -36,7 +37,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; @QuarkusTest -public class PolicyServiceTest { +class PolicyUpdateServiceTest { @Inject PolicyServiceImpl policyService; @@ -100,7 +101,7 @@ public class PolicyServiceTest { PolicyRuleStateEnum.POLICY_FAILED, "Context Id of Service Id must not be empty."); policyService - .addPolicyService(policyRuleService) + .updatePolicyService(policyRuleService) .subscribe() .with( item -> { @@ -125,7 +126,7 @@ public class PolicyServiceTest { new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Service Id must not be empty."); policyService - .addPolicyService(policyRuleService) + .updatePolicyService(policyRuleService) .subscribe() .with(item -> message.complete(item)); @@ -134,33 +135,26 @@ public class PolicyServiceTest { } @Test - void policyRuleIdMustNotBeEmpty() + void checkMessageIfServiceIsNotValid() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture message = new CompletableFuture<>(); - String policyId = ""; - - PolicyRuleBasic policyRuleBasic = - new PolicyRuleBasic( - policyId, - new PolicyRuleState(PolicyRuleStateEnum.POLICY_INSERTED, "Failed due to some errors"), - 1, - new ArrayList<>(), - null, - new ArrayList<>()); - ServiceId serviceId = new ServiceId("contextId", "serviceId"); - Service service = new Service(serviceId, ServiceTypeEnum.UNKNOWN, null, null, null, null, 0.0); - PolicyRuleService policyRuleService = new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>()); PolicyRuleState expectedResult = - new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Policy rule ID must not be empty."); + new PolicyRuleState( + PolicyRuleStateEnum.POLICY_FAILED, String.format(INVALID_MESSAGE, serviceId)); + + Mockito.when( + policyRuleConditionValidator.isPolicyRuleServiceValid( + Mockito.anyString(), Mockito.any(ServiceId.class))) + .thenReturn(Uni.createFrom().item(Boolean.FALSE)); policyService - .addPolicyService(policyRuleService) + .updatePolicyService(policyRuleService) .subscribe() .with( item -> { @@ -172,23 +166,27 @@ public class PolicyServiceTest { } @Test - void policyServiceSuccess() throws ExecutionException, InterruptedException, TimeoutException { + void successUpdatePolicyService() + throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture message = new CompletableFuture<>(); + ServiceId serviceId = new ServiceId("contextId", "serviceId"); + + PolicyRuleService policyRuleService = + new PolicyRuleService(policyRuleBasic, serviceId, new ArrayList<>()); + PolicyRuleState expectedResult = new PolicyRuleState( - PolicyRuleStateEnum.POLICY_VALIDATED, "Successfully transitioned to VALIDATED state"); + PolicyRuleStateEnum.POLICY_VALIDATED, + VALIDATED_POLICYRULE_STATE.getPolicyRuleStateMessage()); Mockito.when( - policyRuleConditionValidator.isServiceIdValid( - Mockito.any(ServiceId.class), Mockito.anyList())) + policyRuleConditionValidator.isPolicyRuleServiceValid( + Mockito.anyString(), Mockito.any(ServiceId.class))) .thenReturn(Uni.createFrom().item(Boolean.TRUE)); - Mockito.when(contextService.setPolicyRule(Mockito.any(PolicyRule.class))) - .thenReturn(Uni.createFrom().item("policyRuleId")); - policyService - .addPolicyService(policyRuleService) + .updatePolicyService(policyRuleService) .subscribe() .with( item -> { -- GitLab From 92e777f41b9ee116dc309d4e78149053e572b0b3 Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Thu, 8 Feb 2024 16:42:45 +0200 Subject: [PATCH 4/6] test: make some minor fixes. --- .../tfs/policy/common/ApplicationProperties.java | 16 ++++++++++++++++ .../org/etsi/tfs/policy/PolicyAddDeviceTest.java | 12 +++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java b/src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java index b24ecd4a5..f01fcd9cc 100644 --- a/src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java +++ b/src/policy/src/main/java/org/etsi/tfs/policy/common/ApplicationProperties.java @@ -1,3 +1,19 @@ +/* +* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +* +* 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. +*/ + package org.etsi.tfs.policy.common; import org.etsi.tfs.policy.model.PolicyRuleState; diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java index 1b00248e1..68daec087 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java @@ -86,7 +86,7 @@ class PolicyAddDeviceTest { new PolicyRuleState(PolicyRuleStateEnum.POLICY_FAILED, "Device Ids must not be empty."); policyService - .updatePolicyDevice(policyRuleDevice) + .addPolicyDevice(policyRuleDevice) .subscribe() .with( item -> { @@ -118,7 +118,7 @@ class PolicyAddDeviceTest { PolicyRuleStateEnum.POLICY_FAILED, "Policy Rule conditions cannot be empty."); policyService - .updatePolicyDevice(policyRuleDevice) + .addPolicyDevice(policyRuleDevice) .subscribe() .with( item -> { @@ -130,8 +130,7 @@ class PolicyAddDeviceTest { } @Test - void isUpdatedPolicyRuleIdValid() - throws ExecutionException, InterruptedException, TimeoutException { + void isPolicyRuleIdValid() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture message = new CompletableFuture<>(); PolicyRuleDevice policyRuleDevice = @@ -147,7 +146,7 @@ class PolicyAddDeviceTest { .thenReturn(Uni.createFrom().item(Boolean.FALSE)); policyService - .updatePolicyDevice(policyRuleDevice) + .addPolicyDevice(policyRuleDevice) .subscribe() .with( item -> { @@ -159,8 +158,7 @@ class PolicyAddDeviceTest { } @Test - void successUpdatePolicyService() - throws ExecutionException, InterruptedException, TimeoutException { + void successPolicyDevice() throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture message = new CompletableFuture<>(); PolicyRuleDevice policyRuleDevice = -- GitLab From 4bb1439493aba78e94b06649c007316d7835cffe Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Fri, 9 Feb 2024 16:54:29 +0200 Subject: [PATCH 5/6] tests: add kubernetes.yml file --- src/policy/target/kubernetes/kubernetes.yml | 108 ++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/policy/target/kubernetes/kubernetes.yml diff --git a/src/policy/target/kubernetes/kubernetes.yml b/src/policy/target/kubernetes/kubernetes.yml new file mode 100644 index 000000000..2737f8546 --- /dev/null +++ b/src/policy/target/kubernetes/kubernetes.yml @@ -0,0 +1,108 @@ +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + app.quarkus.io/commit-id: 47e6691312515be37e2d9ffa85a1ee165a66c9db + app.quarkus.io/build-timestamp: 2024-02-09 - 14:52:23 +0000 + prometheus.io/scrape: "true" + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + labels: + app.kubernetes.io/name: policyservice + app: policyservice + name: policyservice +spec: + ports: + - name: http + port: 9192 + targetPort: 8080 + - name: grpc-server + port: 6060 + targetPort: 6060 + selector: + app.kubernetes.io/name: policyservice + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + app.quarkus.io/commit-id: 47e6691312515be37e2d9ffa85a1ee165a66c9db + app.quarkus.io/build-timestamp: 2024-02-09 - 14:52:23 +0000 + prometheus.io/scrape: "true" + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + labels: + app: policyservice + app.kubernetes.io/name: policyservice + name: policyservice +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: policyservice + template: + metadata: + annotations: + app.quarkus.io/commit-id: 47e6691312515be37e2d9ffa85a1ee165a66c9db + app.quarkus.io/build-timestamp: 2024-02-09 - 14:52:23 +0000 + prometheus.io/scrape: "true" + prometheus.io/path: /q/metrics + prometheus.io/port: "8080" + prometheus.io/scheme: http + labels: + app: policyservice + app.kubernetes.io/name: policyservice + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: CONTEXT_SERVICE_HOST + value: contextservice + - name: SERVICE_SERVICE_HOST + value: serviceservice + - name: MONITORING_SERVICE_HOST + value: monitoringservice + image: labs.etsi.org:5050/tfs/controller/policy:0.1.0 + imagePullPolicy: Always + livenessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/live + port: 8080 + scheme: HTTP + initialDelaySeconds: 2 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 10 + name: policyservice + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 6060 + name: grpc-server + protocol: TCP + readinessProbe: + failureThreshold: 3 + httpGet: + path: /q/health/ready + port: 8080 + scheme: HTTP + initialDelaySeconds: 2 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 10 + resources: + limits: + cpu: 500m + memory: 2048Mi + requests: + cpu: 50m + memory: 512Mi -- GitLab From f4e3f0804d83f22218f3281527ad4ae9156f015b Mon Sep 17 00:00:00 2001 From: kpoulakakis Date: Mon, 12 Feb 2024 11:40:18 +0200 Subject: [PATCH 6/6] tests: add license header. --- .../org/etsi/tfs/policy/PolicyAddDeviceTest.java | 16 ++++++++++++++++ .../etsi/tfs/policy/PolicyAddServiceTest.java | 16 ++++++++++++++++ .../etsi/tfs/policy/PolicyDeleteServiceTest.java | 16 ++++++++++++++++ .../etsi/tfs/policy/PolicyUpdateDeviceTest.java | 16 ++++++++++++++++ .../etsi/tfs/policy/PolicyUpdateServiceTest.java | 16 ++++++++++++++++ 5 files changed, 80 insertions(+) diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java index 68daec087..3c4a1577b 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddDeviceTest.java @@ -1,3 +1,19 @@ +/* +* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +* +* 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. +*/ + package org.etsi.tfs.policy; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java index 657422071..773187f07 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyAddServiceTest.java @@ -1,3 +1,19 @@ +/* +* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +* +* 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. +*/ + package org.etsi.tfs.policy; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java index 9609bf11b..a62c5dd3d 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyDeleteServiceTest.java @@ -1,3 +1,19 @@ +/* +* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +* +* 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. +*/ + package org.etsi.tfs.policy; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java index 0e8e2e3d0..0cc2d5a70 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateDeviceTest.java @@ -1,3 +1,19 @@ +/* +* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +* +* 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. +*/ + package org.etsi.tfs.policy; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateServiceTest.java b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateServiceTest.java index 3acab688b..e65f2d459 100644 --- a/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateServiceTest.java +++ b/src/policy/src/test/java/org/etsi/tfs/policy/PolicyUpdateServiceTest.java @@ -1,3 +1,19 @@ +/* +* Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +* +* 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. +*/ + package org.etsi.tfs.policy; import static org.assertj.core.api.Assertions.assertThat; -- GitLab