diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2024-07-24 21:09:09 +0100 |
---|---|---|
committer | adheli.tavares <adheli.tavares@est.tech> | 2024-07-24 21:09:54 +0100 |
commit | 257358ffc369e0813bca5fa92b83710e3d97cfee (patch) | |
tree | 3bc494df192dc38fadc2e225cd8b09c88dd4884d /applications/guard/src | |
parent | 66b1f3ead4f08893da0ea50aad25cd4831367b3c (diff) |
Convert unit tests from junit4 to junit5
Issue-ID: POLICY-5094
Change-Id: Id727408a5fd553aa08623a6ede1a56607b760e3f
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'applications/guard/src')
6 files changed, 182 insertions, 237 deletions
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java index 184db863..4cea61c6 100644 --- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java +++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020, 2023 Nordix Foundation. + * Modifications Copyright (C) 2020, 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,19 +75,10 @@ public class GuardTranslator implements ToscaPolicyTranslator { // // common guard property fields // - public static final String FIELD_ACTOR = "actor"; - public static final String FIELD_OPERATION = "operation"; public static final String FIELD_CONTROLLOOP = "id"; public static final String FIELD_TIMERANGE = "timeRange"; // - // frequency property fields - // - public static final String FIELD_TIMEWINDOW = "timeWindow"; - public static final String FIELD_TIMEUNITS = "timeUnits"; - public static final String FIELD_LIMIT = "limit"; - - // // minmax property fields // public static final String FIELD_TARGET = "target"; @@ -99,17 +90,6 @@ public class GuardTranslator implements ToscaPolicyTranslator { // public static final String FIELD_BLACKLIST = "blacklist"; - // - // filter property fields - // - public static final String FIELD_FILTER_WHITELIST = "whitelist"; - public static final String FIELD_FILTER_ALGORITHM = "algorithm"; - public static final String FIELD_FILTER_FILTERS = "filters"; - public static final String FIELD_FILTER_FIELD = "field"; - public static final String FIELD_FILTER_FUNCTION = "function"; - public static final String FIELD_FILTER_FILTER = "filter"; - public static final String FIELD_FILTER_BLACKLIST = "blacklist"; - public static final String POLICYTYPE_FREQUENCY = "onap.policies.controlloop.guard.common.FrequencyLimiter"; public static final String POLICYTYPE_MINMAX = "onap.policies.controlloop.guard.common.MinMax"; public static final String POLICYTYPE_BLACKLIST = "onap.policies.controlloop.guard.common.Blacklist"; @@ -286,7 +266,7 @@ public class GuardTranslator implements ToscaPolicyTranslator { } /** - * Generate the targetType for the policy. Optional to add MatchType for the target. eg. the + * Generate the targetType for the policy. Optional to add MatchType for the target. e.g. the * blacklist policy type uses the target in a different manner. * * @param properties TOSCA properties object @@ -327,7 +307,6 @@ public class GuardTranslator implements ToscaPolicyTranslator { return target; } - @SuppressWarnings("unchecked") protected AllOfType addMatch(AllOfType allOf, Object value, Identifier attributeId) { if (value instanceof String) { if (".*".equals(value.toString())) { @@ -350,8 +329,8 @@ public class GuardTranslator implements ToscaPolicyTranslator { } return allOf; } - if (value instanceof Collection) { - ((Collection<String>) value).forEach(val -> { + if (value instanceof Collection<?> collection) { + collection.forEach(val -> { var match = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( XACML3.ID_FUNCTION_STRING_EQUAL, val, @@ -365,27 +344,6 @@ public class GuardTranslator implements ToscaPolicyTranslator { return allOf; } - protected void addTimeRangeMatch(AllOfType allOf, TimeRange timeRange) { - - var matchStart = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( - XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL, - timeRange.getStartTime(), - XACML3.ID_DATATYPE_TIME, - XACML3.ID_ENVIRONMENT_CURRENT_TIME, - XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT); - - allOf.getMatch().add(matchStart); - - var matchEnd = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( - XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL, - timeRange.getEndTime(), - XACML3.ID_DATATYPE_TIME, - XACML3.ID_ENVIRONMENT_CURRENT_TIME, - XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT); - - allOf.getMatch().add(matchEnd); - } - protected VariableReferenceType createTimeRangeVariable(Map<String, Object> properties, PolicyType newPolicyType) throws ToscaPolicyConversionException { // @@ -456,7 +414,7 @@ public class GuardTranslator implements ToscaPolicyTranslator { FrequencyDefinition frequencyDef = ToscaPolicyTranslatorUtils.decodeProperties(toscaPolicy.getProperties(), FrequencyDefinition.class); // - // See if its possible to generate a count + // See if it's possible to generate a count // String timeWindow = null; if (frequencyDef.getTimeWindow() != null) { diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslatorTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslatorTest.java index d0541e2a..c1c072db 100644 --- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslatorTest.java +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslatorTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,30 +26,30 @@ package org.onap.policy.xacml.pdp.application.guard; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException; -public class CoordinationGuardTranslatorTest { +class CoordinationGuardTranslatorTest { @Test - public void testUnsupportedMethods() { + void testUnsupportedMethods() { CoordinationGuardTranslator translator = new CoordinationGuardTranslator(); assertThatExceptionOfType(ToscaPolicyConversionException.class) - .isThrownBy(() -> translator.convertRequest(null)) - .withMessageContaining("this convertRequest shouldn't be used"); + .isThrownBy(() -> translator.convertRequest(null)) + .withMessageContaining("this convertRequest shouldn't be used"); assertThat(translator.convertResponse(null)).isNull(); } @Test - public void testLoadingDirectives() { + void testLoadingDirectives() { assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile(null)).isNull(); assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile("nonexistent.yaml")).isNull(); CoordinationDirective directive = CoordinationGuardTranslator - .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml"); + .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml"); assertThat(directive).isNotNull(); assertThat(directive.getCoordinationFunction()).isEqualTo("whatisthisvaluesupposedtobe"); assertThat(directive.getControlLoop()).hasSize(2); @@ -56,14 +57,14 @@ public class CoordinationGuardTranslatorTest { } @Test - public void testGeneratingXacml() { + void testGeneratingXacml() { CoordinationDirective directive = CoordinationGuardTranslator - .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml"); + .loadCoordinationDirectiveFromFile("src/test/resources/test-directive.yaml"); assertThatExceptionOfType(ToscaPolicyConversionException.class) - .isThrownBy(() -> CoordinationGuardTranslator - .generateXacmlFromCoordinationDirective(directive, "idontexist.yaml")) - .withMessageContaining("Unable to find prototype "); + .isThrownBy(() -> CoordinationGuardTranslator + .generateXacmlFromCoordinationDirective(directive, "idontexist.yaml")) + .withMessageContaining("Unable to find prototype "); } } diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java index 31e576ff..a11f19d8 100644 --- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021,2023 Nordix Foundation. + * Modifications Copyright (C) 2021, 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,28 +28,26 @@ import static org.assertj.core.api.Assertions.assertThatCode; import com.att.research.xacml.api.Response; import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; +import java.nio.file.Path; import java.sql.Date; import java.time.Instant; import java.time.OffsetDateTime; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.ServiceLoader; import java.util.UUID; import org.apache.commons.lang3.tuple.Pair; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.io.TempDir; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.TextFileUtils; @@ -66,47 +64,46 @@ import org.onap.policy.pdp.xacml.xacmltest.TestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class GuardPdpApplicationTest { +@TestMethodOrder(MethodOrderer.MethodName.class) +class GuardPdpApplicationTest { private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplicationTest.class); - private static Properties properties = new Properties(); + private static final Properties properties = new Properties(); private static File propertiesFile; private static XacmlApplicationServiceProvider service; private static DecisionRequest requestVfCount; - private static StandardCoder gson = new StandardCoder(); + private static final StandardCoder gson = new StandardCoder(); private static EntityManager em; + private static EntityManagerFactory emf; private static final String DENY = "Deny"; private static final String PERMIT = "Permit"; - @ClassRule - public static final TemporaryFolder policyFolder = new TemporaryFolder(); + @TempDir + static Path policyFolder; /** * Copies the xacml.properties and policies files into temporary folder and loads the service provider saving * instance of provider off for other tests to use. */ - @BeforeClass - public static void setup() throws Exception { + @BeforeAll + static void setup() throws Exception { LOGGER.info("Setting up class"); // - // Setup our temporary folder + // Set up our temporary folder // - XacmlPolicyUtils.FileCreator myCreator = (String filename) -> policyFolder.newFile(filename); + XacmlPolicyUtils.FileCreator myCreator = (String filename) -> policyFolder.resolve(filename).toFile(); propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents("src/test/resources/xacml.properties", properties, - myCreator); + myCreator); // // Load service // ServiceLoader<XacmlApplicationServiceProvider> applicationLoader = - ServiceLoader.load(XacmlApplicationServiceProvider.class); + ServiceLoader.load(XacmlApplicationServiceProvider.class); // // Find the guard service application and save for use in all the tests // StringBuilder strDump = new StringBuilder("Loaded applications:" + XacmlPolicyUtils.LINE_SEPARATOR); - Iterator<XacmlApplicationServiceProvider> iterator = applicationLoader.iterator(); - while (iterator.hasNext()) { - XacmlApplicationServiceProvider application = iterator.next(); + for (XacmlApplicationServiceProvider application : applicationLoader) { // // Is it our service? // @@ -132,33 +129,35 @@ public class GuardPdpApplicationTest { // Load Decision Requests // requestVfCount = - gson.decode(TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.vfCount.json"), - DecisionRequest.class); + gson.decode(TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.vfCount.json"), + DecisionRequest.class); // // Create EntityManager for manipulating DB // String persistenceUnit = CountRecentOperationsPip.ISSUER_NAME + ".persistenceunit"; - em = Persistence - .createEntityManagerFactory(GuardPdpApplicationTest.properties.getProperty(persistenceUnit), properties) - .createEntityManager(); + emf = Persistence.createEntityManagerFactory( + GuardPdpApplicationTest.properties.getProperty(persistenceUnit), properties); + em = emf.createEntityManager(); } /** * Close the entity manager. */ - @AfterClass - public static void cleanup() throws Exception { + @AfterAll + static void cleanup() { if (em != null) { em.close(); } + if (emf != null) { + emf.close(); + } } /** * Clears the database before each test so there are no operations in it. - * */ - @Before - public void startClean() throws Exception { + @BeforeEach + void startClean() { em.getTransaction().begin(); em.createQuery("DELETE FROM OperationsHistory").executeUpdate(); em.getTransaction().commit(); @@ -169,9 +168,8 @@ public class GuardPdpApplicationTest { * * @param expected from the response * @param response received - * **/ - public void checkDecision(String expected, DecisionResponse response) throws CoderException { + void checkDecision(String expected, DecisionResponse response) throws CoderException { LOGGER.info("Looking for {} Decision", expected); assertThat(response).isNotNull(); assertThat(response.getStatus()).isNotNull(); @@ -191,11 +189,10 @@ public class GuardPdpApplicationTest { /** * Request a decision and check that it matches expectation. * - * @param request to send to Xacml PDP + * @param request to send to Xacml PDP * @param expected from the response - * **/ - public void requestAndCheckDecision(DecisionRequest request, String expected) throws CoderException { + void requestAndCheckDecision(DecisionRequest request, String expected) throws CoderException { // // Ask for a decision // @@ -207,7 +204,7 @@ public class GuardPdpApplicationTest { } @Test - public void test1Basics() throws CoderException, IOException { + void test1Basics() { LOGGER.info("**************** Running test1Basics ****************"); // // Make sure there's an application name @@ -225,37 +222,36 @@ public class GuardPdpApplicationTest { assertThat(service.supportedPolicyTypes()).isNotEmpty(); assertThat(service.supportedPolicyTypes()).hasSize(5); assertThat(service.canSupportPolicyType( - new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.FrequencyLimiter", "1.0.0"))) - .isTrue(); + new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.FrequencyLimiter", "1.0.0"))) + .isTrue(); assertThat(service.canSupportPolicyType( - new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.FrequencyLimiter", "1.0.1"))) - .isFalse(); + new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.FrequencyLimiter", "1.0.1"))) + .isFalse(); assertThat(service.canSupportPolicyType( - new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.MinMax", "1.0.0"))).isTrue(); + new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.MinMax", "1.0.0"))).isTrue(); assertThat(service.canSupportPolicyType( - new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.MinMax", "1.0.1"))).isFalse(); + new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.MinMax", "1.0.1"))).isFalse(); assertThat(service.canSupportPolicyType( - new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.Blacklist", "1.0.0"))).isTrue(); + new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.Blacklist", "1.0.0"))).isTrue(); assertThat(service.canSupportPolicyType( - new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.Blacklist", "1.0.1"))).isFalse(); + new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.Blacklist", "1.0.1"))).isFalse(); assertThat(service.canSupportPolicyType(new ToscaConceptIdentifier( - "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", "1.0.0"))).isTrue(); + "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", "1.0.0"))).isTrue(); assertThat(service.canSupportPolicyType(new ToscaConceptIdentifier( - "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", "1.0.1"))).isFalse(); + "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", "1.0.1"))).isFalse(); assertThat(service.canSupportPolicyType(new ToscaConceptIdentifier("onap.foo", "1.0.1"))).isFalse(); assertThat(service.canSupportPolicyType( - new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.Filter", "1.0.0"))).isTrue(); + new ToscaConceptIdentifier("onap.policies.controlloop.guard.common.Filter", "1.0.0"))).isTrue(); } @Test - public void test2NoPolicies() throws CoderException { + void test2NoPolicies() { LOGGER.info("**************** Running test2NoPolicies ****************"); assertThatCode(() -> requestAndCheckDecision(requestVfCount, PERMIT)).doesNotThrowAnyException(); } @Test - public void test3FrequencyLimiter() - throws CoderException, FileNotFoundException, IOException, XacmlApplicationException { + void test3FrequencyLimiter() throws CoderException, XacmlApplicationException { LOGGER.info("**************** Running test3FrequencyLimiter ****************"); // // Now load the vDNS frequency limiter Policy - make sure @@ -263,7 +259,7 @@ public class GuardPdpApplicationTest { // into the PDP. // List<ToscaPolicy> loadedPolicies = - TestUtils.loadPolicies("policies/vDNS.policy.guard.frequencylimiter.input.tosca.yaml", service); + TestUtils.loadPolicies("policies/vDNS.policy.guard.frequencylimiter.input.tosca.yaml", service); assertThat(loadedPolicies).hasSize(1); assertThat(loadedPolicies.get(0).getName()).isEqualTo("guard.frequency.scaleout"); // @@ -282,7 +278,7 @@ public class GuardPdpApplicationTest { @SuppressWarnings("unchecked") @Test - public void test4MinMax() throws CoderException, FileNotFoundException, IOException, XacmlApplicationException { + void test4MinMax() throws CoderException, XacmlApplicationException { LOGGER.info("**************** Running test4MinMax ****************"); // // Now load the vDNS min max Policy - make sure @@ -290,7 +286,7 @@ public class GuardPdpApplicationTest { // into the PDP. // List<ToscaPolicy> loadedPolicies = - TestUtils.loadPolicies("policies/vDNS.policy.guard.minmaxvnfs.input.tosca.yaml", service); + TestUtils.loadPolicies("policies/vDNS.policy.guard.minmaxvnfs.input.tosca.yaml", service); assertThat(loadedPolicies).hasSize(1); assertThat(loadedPolicies.get(0).getName()).isEqualTo("guard.minmax.scaleout"); // @@ -327,13 +323,13 @@ public class GuardPdpApplicationTest { @SuppressWarnings("unchecked") @Test - public void test5Blacklist() throws CoderException, XacmlApplicationException { + void test5Blacklist() throws CoderException, XacmlApplicationException { LOGGER.info("**************** Running test5Blacklist ****************"); // // Load the blacklist policy in with the others. // List<ToscaPolicy> loadedPolicies = - TestUtils.loadPolicies("policies/vDNS.policy.guard.blacklist.input.tosca.yaml", service); + TestUtils.loadPolicies("policies/vDNS.policy.guard.blacklist.input.tosca.yaml", service); assertThat(loadedPolicies).hasSize(1); assertThat(loadedPolicies.get(0).getName()).isEqualTo("guard.blacklist.scaleout"); // @@ -344,7 +340,7 @@ public class GuardPdpApplicationTest { // vfcount=1 between min of 1 and max of 2: change the // ((Map<String, Object>) requestVfCount.getResource().get("guard")).put("target", - "the-vfmodule-where-root-is-true"); + "the-vfmodule-where-root-is-true"); // // vfcount=0 below min of 1: should get a Deny because target IS blacklisted // @@ -353,7 +349,7 @@ public class GuardPdpApplicationTest { // vfcount=1 between min of 1 and max of 2: change the // ((Map<String, Object>) requestVfCount.getResource().get("guard")).put("target", - "another-vfmodule-where-root-is-true"); + "another-vfmodule-where-root-is-true"); // // vfcount=0 below min of 1: should get a Deny because target IS blacklisted // @@ -362,14 +358,14 @@ public class GuardPdpApplicationTest { @SuppressWarnings("unchecked") @Test - public void test6Filters() throws Exception { + void test6Filters() throws Exception { LOGGER.info("**************** Running test6Filters ****************"); // // Re-Load Decision Request - so we can start from scratch // requestVfCount = - gson.decode(TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.vfCount.json"), - DecisionRequest.class); + gson.decode(TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.vfCount.json"), + DecisionRequest.class); // // Ensure we are a permit to start // @@ -378,7 +374,7 @@ public class GuardPdpApplicationTest { // Load the filter policy in with the others. // List<ToscaPolicy> loadedPolicies = - TestUtils.loadPolicies("src/test/resources/test.policy.guard.filters.yaml", service); + TestUtils.loadPolicies("src/test/resources/test.policy.guard.filters.yaml", service); assertThat(loadedPolicies).hasSize(2); // // Although the region is blacklisted, the id is not @@ -388,7 +384,7 @@ public class GuardPdpApplicationTest { // Put in a different vnf id // ((Map<String, Object>) requestVfCount.getResource().get("guard")).put("generic-vnf.vnf-id", - "different-vnf-id-should-be-denied"); + "different-vnf-id-should-be-denied"); // // The region is blacklisted, and the id is not allowed // @@ -397,7 +393,7 @@ public class GuardPdpApplicationTest { // Let's switch to a different region // ((Map<String, Object>) requestVfCount.getResource().get("guard")).put("cloud-region.cloud-region-id", - "RegionTwo"); + "RegionTwo"); // // The region is whitelisted, and the id is also allowed // @@ -406,7 +402,7 @@ public class GuardPdpApplicationTest { // Put in a blacklisted vnf id // ((Map<String, Object>) requestVfCount.getResource().get("guard")).put("generic-vnf.vnf-id", - "f17face5-69cb-4c88-9e0b-7426db7edddd"); + "f17face5-69cb-4c88-9e0b-7426db7edddd"); // // Although region is whitelisted, the id is blacklisted // @@ -415,7 +411,7 @@ public class GuardPdpApplicationTest { // Let's switch to a different region // ((Map<String, Object>) requestVfCount.getResource().get("guard")).put("cloud-region.cloud-region-id", - "RegionThree"); + "RegionThree"); // // There is no filter for this region, but the id is still blacklisted // @@ -424,7 +420,7 @@ public class GuardPdpApplicationTest { // Put in a different vnf id // ((Map<String, Object>) requestVfCount.getResource().get("guard")).put("generic-vnf.vnf-id", - "different-vnf-id-should-be-permitted"); + "different-vnf-id-should-be-permitted"); // // There is no filter for this region, and the id is not blacklisted // @@ -432,19 +428,19 @@ public class GuardPdpApplicationTest { } @Test - public void test7TimeInRange() throws Exception { + void test7TimeInRange() throws Exception { LOGGER.info("**************** Running test7TimeInRange ****************"); // // Re-Load Decision Request - so we can start from scratch // DecisionRequest requestInRange = - gson.decode(TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.timeinrange.json"), - DecisionRequest.class); + gson.decode(TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.timeinrange.json"), + DecisionRequest.class); // // Load the test policy in with the others. // List<ToscaPolicy> loadedPolicies = - TestUtils.loadPolicies("src/test/resources/test-time-in-range.yaml", service); + TestUtils.loadPolicies("src/test/resources/test-time-in-range.yaml", service); assertThat(loadedPolicies).hasSize(1); // // Mock what the current date and time is. Set to 12 Noon @@ -497,20 +493,20 @@ public class GuardPdpApplicationTest { // // Get the properties // - Map<String, Object> properties = (Map<String, Object>) request.getResource().get("guard"); - assertThat(properties).isNotNull(); + Map<String, Object> localProps = (Map<String, Object>) request.getResource().get("guard"); + assertThat(localProps).isNotNull(); // // Add an entry // OperationsHistory newEntry = new OperationsHistory(); - newEntry.setActor(properties.get("actor").toString()); - newEntry.setOperation(properties.get("operation").toString()); - newEntry.setClosedLoopName(properties.get("clname").toString()); + newEntry.setActor(localProps.get("actor").toString()); + newEntry.setOperation(localProps.get("operation").toString()); + newEntry.setClosedLoopName(localProps.get("clname").toString()); newEntry.setOutcome("SUCCESS"); newEntry.setStarttime(Date.from(Instant.now().minusMillis(20000))); newEntry.setEndtime(Date.from(Instant.now())); newEntry.setRequestId(UUID.randomUUID().toString()); - newEntry.setTarget(properties.get("target").toString()); + newEntry.setTarget(localProps.get("target").toString()); LOGGER.info("Inserting {}", newEntry); em.getTransaction().begin(); em.persist(newEntry); diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java index 1c925ce2..4b21bf38 100644 --- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,16 +28,16 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.TextFileUtils; import org.onap.policy.models.decisions.concepts.DecisionRequest; import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException; -public class GuardPolicyRequestTest { +class GuardPolicyRequestTest { @Test - public void testAnomalies() throws ToscaPolicyConversionException { + void testAnomalies() throws ToscaPolicyConversionException { DecisionRequest decisionRequest = new DecisionRequest(); assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull(); @@ -95,12 +96,12 @@ public class GuardPolicyRequestTest { } @Test - public void testFilterResources() throws Exception { + void testFilterResources() throws Exception { StandardCoder gson = new StandardCoder(); DecisionRequest request = gson.decode( - TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.filter.json"), - DecisionRequest.class); + TextFileUtils.getTextFileAsString("src/test/resources/requests/guard.filter.json"), + DecisionRequest.class); GuardPolicyRequest guardRequest = GuardPolicyRequest.createInstance(request); diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java index ac36ec72..d80d85b1 100644 --- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -58,26 +58,26 @@ import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionExcepti import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class GuardTranslatorTest { +class GuardTranslatorTest { private static final Logger LOGGER = LoggerFactory.getLogger(GuardTranslatorTest.class); private static final StandardYamlCoder yamlCoder = new StandardYamlCoder(); - private static StandardCoder gson = new StandardCoder(); + private static final StandardCoder gson = new StandardCoder(); - private GuardTranslator translator = new GuardTranslator(); + private final GuardTranslator translator = new GuardTranslator(); @Test - public void testRequest() throws Exception { + void testRequest() throws Exception { DecisionRequest decisionRequest = gson.decode( - TextFileUtils.getTextFileAsString( - "src/test/resources/requests/guard.vfCount.json"), - DecisionRequest.class); + TextFileUtils.getTextFileAsString( + "src/test/resources/requests/guard.vfCount.json"), + DecisionRequest.class); Request xacmlRequest = translator.convertRequest(decisionRequest); assertThat(xacmlRequest).isNotNull(); } @Test - public void testResponse() { + void testResponse() { StdStatus status = new StdStatus(StdStatusCode.STATUS_CODE_OK); StdMutableResult result = new StdMutableResult(Decision.PERMIT, status); StdMutableResponse response = new StdMutableResponse(result); @@ -101,7 +101,7 @@ public class GuardTranslatorTest { @Test - public void testBadPolicies() throws Exception { + void testBadPolicies() throws Exception { String policyYaml = ResourceUtils.getResourceAsString("src/test/resources/test-bad-policies.yaml"); // // Serialize it into a class @@ -127,7 +127,7 @@ public class GuardTranslatorTest { name2message.put("blacklist-noblacklist", "item \"blacklist\""); name2message.put("filter-noalgorithm", "item \"algorithm\""); name2message.put("filter-badalgorithm", - "Unexpected value for algorithm, should be whitelist-overrides or blacklist-overrides"); + "Unexpected value for algorithm, should be whitelist-overrides or blacklist-overrides"); name2message.put("filter-nofilter", "item \"filters\""); name2message.put("filter-nocollection", "Cannot decode FilterDefinition"); name2message.put("filter-noarray", "Cannot decode FilterDefinition"); @@ -142,7 +142,7 @@ public class GuardTranslatorTest { // for (Map<String, ToscaPolicy> policies : completedJtst.getToscaTopologyTemplate().getPolicies()) { for (ToscaPolicy policy : policies.values()) { - LOGGER.info("Testing policy " + policy.getName()); + LOGGER.info("Testing policy {}", policy.getName()); String expectedMsg = name2message.get(policy.getName()); assertThat(expectedMsg).as(policy.getName()).isNotNull(); @@ -154,7 +154,7 @@ public class GuardTranslatorTest { } @Test - public void testPolicyConversion() throws Exception { + void testPolicyConversion() throws Exception { String policyYaml = ResourceUtils.getResourceAsString("src/test/resources/test-policies.yaml"); // // Serialize it into a class @@ -198,13 +198,13 @@ public class GuardTranslatorTest { // Validate each policy type // if (GuardTranslator.POLICYTYPE_FREQUENCY.equals(policy.getType())) { - validateFrequency(policy, xacmlPolicy); + validateFrequency(xacmlPolicy); } else if (GuardTranslator.POLICYTYPE_MINMAX.equals(policy.getType())) { validateMinMax(policy, xacmlPolicy); } else if (GuardTranslator.POLICYTYPE_BLACKLIST.equals(policy.getType())) { validateBlacklist(policy, xacmlPolicy); } else if (GuardTranslator.POLICYTYPE_FILTER.equals(policy.getType())) { - validateFilter(policy, xacmlPolicy); + validateFilter(xacmlPolicy); } } } @@ -213,11 +213,11 @@ public class GuardTranslatorTest { testPol.setProperties(new LinkedHashMap<>()); assertThatExceptionOfType(ToscaPolicyConversionException.class) - .isThrownBy(() -> translator.convertPolicy(testPol)); + .isThrownBy(() -> translator.convertPolicy(testPol)); testPol.setProperties(null); assertThatExceptionOfType(ToscaPolicyConversionException.class) - .isThrownBy(() -> translator.convertPolicy(testPol)); + .isThrownBy(() -> translator.convertPolicy(testPol)); } private void validateCommon(ToscaPolicy policy, PolicyType xacmlPolicy) { @@ -225,7 +225,6 @@ public class GuardTranslatorTest { boolean foundOperation = false; boolean foundTarget = false; boolean foundControlLoop = false; - //boolean foundTimeRange = false; assertThat(xacmlPolicy.getTarget()).isNotNull(); assertThat(xacmlPolicy.getTarget().getAnyOf()).isNotEmpty(); @@ -238,11 +237,11 @@ public class GuardTranslatorTest { // These fields are required // if (ToscaDictionary.ID_RESOURCE_GUARD_ACTOR.toString().equals( - match.getAttributeDesignator().getAttributeId())) { + match.getAttributeDesignator().getAttributeId())) { assertThat(match.getAttributeValue().getContent()).isNotNull(); foundActor = true; } else if (ToscaDictionary.ID_RESOURCE_GUARD_RECIPE.toString().equals( - match.getAttributeDesignator().getAttributeId())) { + match.getAttributeDesignator().getAttributeId())) { assertThat(match.getAttributeValue().getContent()).isNotNull(); foundOperation = true; } else { @@ -250,22 +249,16 @@ public class GuardTranslatorTest { // These fields are optional // if (ToscaDictionary.ID_RESOURCE_GUARD_TARGETID.toString().equals( - match.getAttributeDesignator().getAttributeId())) { + match.getAttributeDesignator().getAttributeId())) { assertThat(policy.getProperties()).containsKey("target"); foundTarget = true; } if (ToscaDictionary.ID_RESOURCE_GUARD_CLNAME.toString().equals( - match.getAttributeDesignator().getAttributeId())) { + match.getAttributeDesignator().getAttributeId())) { assertThat(policy.getProperties()).containsKey(GuardTranslator.FIELD_CONTROLLOOP); foundControlLoop = true; } - /* - if (XACML3.ID_ENVIRONMENT_CURRENT_TIME.toString().equals( - match.getAttributeDesignator().getAttributeId())) { - assertThat(policy.getProperties()).containsKey(GuardTranslator.FIELD_TIMERANGE); - foundTimeRange = true; - } - */ + } } } @@ -283,9 +276,9 @@ public class GuardTranslatorTest { } } - private void validateFrequency(ToscaPolicy policy, PolicyType xacmlPolicy) { + private void validateFrequency(PolicyType xacmlPolicy) { for (Object rule : xacmlPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { - if (! (rule instanceof RuleType)) { + if (!(rule instanceof RuleType)) { continue; } assertThat(((RuleType) rule).getCondition()).isNotNull(); @@ -297,7 +290,7 @@ public class GuardTranslatorTest { boolean foundTarget = false; boolean foundMinOrMax = false; for (Object rule : xacmlPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { - if (! (rule instanceof RuleType)) { + if (!(rule instanceof RuleType)) { continue; } for (AnyOfType anyOf : ((RuleType) rule).getTarget().getAnyOf()) { @@ -306,13 +299,13 @@ public class GuardTranslatorTest { assertThat(allOf.getMatch()).isNotEmpty(); for (MatchType match : allOf.getMatch()) { if (ToscaDictionary.ID_RESOURCE_GUARD_TARGETID.toString().equals( - match.getAttributeDesignator().getAttributeId())) { + match.getAttributeDesignator().getAttributeId())) { assertThat(policy.getProperties()).containsKey(GuardTranslator.FIELD_TARGET); foundTarget = true; } else if (ToscaDictionary.ID_RESOURCE_GUARD_VFCOUNT.toString().equals( - match.getAttributeDesignator().getAttributeId())) { + match.getAttributeDesignator().getAttributeId())) { assertThat(policy.getProperties().keySet()).containsAnyOf(GuardTranslator.FIELD_MIN, - GuardTranslator.FIELD_MAX); + GuardTranslator.FIELD_MAX); foundMinOrMax = true; } } @@ -325,7 +318,7 @@ public class GuardTranslatorTest { private void validateBlacklist(ToscaPolicy policy, PolicyType xacmlPolicy) { boolean foundBlacklist = false; for (Object rule : xacmlPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { - if (! (rule instanceof RuleType)) { + if (!(rule instanceof RuleType)) { continue; } assertThat(((RuleType) rule).getTarget()).isNotNull(); @@ -337,7 +330,7 @@ public class GuardTranslatorTest { assertThat(allOf.getMatch()).hasSize(1); for (MatchType match : allOf.getMatch()) { assertThat(match.getAttributeDesignator().getAttributeId()) - .isEqualTo(ToscaDictionary.ID_RESOURCE_GUARD_TARGETID.toString()); + .isEqualTo(ToscaDictionary.ID_RESOURCE_GUARD_TARGETID.toString()); assertThat(match.getAttributeValue().getContent()).containsAnyOf("vnf1", "vnf2"); // // This just checks that policy did have a blacklist in it. @@ -351,10 +344,10 @@ public class GuardTranslatorTest { assertThat(foundBlacklist).isTrue(); } - private void validateFilter(ToscaPolicy policy, PolicyType xacmlPolicy) { + private void validateFilter(PolicyType xacmlPolicy) { assertThat(xacmlPolicy.getRuleCombiningAlgId()).endsWith("-overrides"); for (Object rule : xacmlPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) { - if (! (rule instanceof RuleType)) { + if (!(rule instanceof RuleType)) { continue; } assertThat(((RuleType) rule).getTarget()).isNotNull(); diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/SonCoordinationTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/SonCoordinationTest.java index 4e7bb12f..5d19a905 100644 --- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/SonCoordinationTest.java +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/SonCoordinationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,25 +27,24 @@ import static org.assertj.core.api.Assertions.assertThat; import com.att.research.xacml.api.Response; import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import java.io.File; -import java.io.IOException; +import java.nio.file.Path; import java.time.Instant; import java.util.Date; -import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.ServiceLoader; import java.util.UUID; import org.apache.commons.lang3.tuple.Pair; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.io.TempDir; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.TextFileUtils; @@ -60,36 +59,37 @@ import org.onap.policy.pdp.xacml.xacmltest.TestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class SonCoordinationTest { +@TestMethodOrder(MethodOrderer.MethodName.class) +class SonCoordinationTest { private static final Logger LOGGER = LoggerFactory.getLogger(SonCoordinationTest.class); - private static Properties properties = new Properties(); + private static final Properties properties = new Properties(); private static File propertiesFile; private static XacmlApplicationServiceProvider service; private static DecisionRequest requestVpciNode1; private static DecisionRequest requestVsonhNode1; - private static StandardCoder gson = new StandardCoder(); + private static final StandardCoder gson = new StandardCoder(); private static EntityManager em; + private static EntityManagerFactory emf; private static final String DENY = "Deny"; private static final String PERMIT = "Permit"; - @ClassRule - public static final TemporaryFolder policyFolder = new TemporaryFolder(); + @TempDir + static Path policyFolder; /** * Copies the xacml.properties and policies files into * temporary folder and loads the service provider saving * instance of provider off for other tests to use. */ - @BeforeClass - public static void setup() throws Exception { + @BeforeAll + static void setup() throws Exception { LOGGER.info("Setting up class"); // - // Setup our temporary folder + // Set up our temporary folder // XacmlPolicyUtils.FileCreator myCreator = - (String filename) -> policyFolder.newFile(filename); + (String filename) -> policyFolder.resolve(filename).toFile(); propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents( "src/test/resources/xacml.properties", properties, myCreator); // @@ -102,9 +102,7 @@ public class SonCoordinationTest { // StringBuilder strDump = new StringBuilder("Loaded applications:" + XacmlPolicyUtils.LINE_SEPARATOR); - Iterator<XacmlApplicationServiceProvider> iterator = applicationLoader.iterator(); - while (iterator.hasNext()) { - XacmlApplicationServiceProvider application = iterator.next(); + for (XacmlApplicationServiceProvider application : applicationLoader) { // // Is it our service? // @@ -138,18 +136,16 @@ public class SonCoordinationTest { "src/test/resources/requests/coordination.cl.vSonh.node.1.json"), DecisionRequest.class); String persistenceUnit = CountRecentOperationsPip.ISSUER_NAME + ".persistenceunit"; - em = Persistence - .createEntityManagerFactory(SonCoordinationTest.properties.getProperty(persistenceUnit), - properties) - .createEntityManager(); + emf = Persistence.createEntityManagerFactory( + SonCoordinationTest.properties.getProperty(persistenceUnit), properties); + em = emf.createEntityManager(); } /** * Clears the database before each test. - * */ - @Before - public void startClean() throws Exception { + @BeforeEach + void startClean() { em.getTransaction().begin(); em.createQuery("DELETE FROM OperationsHistory").executeUpdate(); em.getTransaction().commit(); @@ -158,11 +154,14 @@ public class SonCoordinationTest { /** * Close the entity manager. */ - @AfterClass - public static void cleanup() throws Exception { + @AfterAll + static void cleanup() { if (em != null) { em.close(); } + if (emf != null) { + emf.close(); + } } /** @@ -170,9 +169,8 @@ public class SonCoordinationTest { * * @param expected from the response * @param response received - * **/ - public void checkDecision(String expected, DecisionResponse response) throws CoderException { + void checkDecision(String expected, DecisionResponse response) throws CoderException { LOGGER.info("Looking for {} Decision", expected); assertThat(response).isNotNull(); assertThat(response.getStatus()).isNotNull(); @@ -186,11 +184,10 @@ public class SonCoordinationTest { /** * Request a decision and check that it matches expectation. * - * @param request to send to Xacml PDP + * @param request to send to Xacml PDP * @param expected from the response - * **/ - public void requestAndCheckDecision(DecisionRequest request, String expected) + void requestAndCheckDecision(DecisionRequest request, String expected) throws CoderException { // @@ -204,7 +201,7 @@ public class SonCoordinationTest { } @Test - public void test1() throws CoderException, IOException, XacmlApplicationException { + void test1() throws CoderException, XacmlApplicationException { LOGGER.info("**************** Running vPci and vSonh Control Loops ****************"); // // Now load the test coordination policy - make sure @@ -228,7 +225,7 @@ public class SonCoordinationTest { // // Open vSonh on node1 // - long vsonhId = insertOperationEvent(requestVsonhNode1, "Started"); + long vsonhId = insertOperationEvent(requestVsonhNode1); // // Under current coordination policy vPci should get a deny // @@ -244,7 +241,7 @@ public class SonCoordinationTest { // // Open vPci on node1 // - long vpciId = insertOperationEvent(requestVpciNode1, "Started"); + long vpciId = insertOperationEvent(requestVpciNode1); // // Under current coordination policy vSonh should get a deny // @@ -260,23 +257,23 @@ public class SonCoordinationTest { } @SuppressWarnings("unchecked") - private long insertOperationEvent(DecisionRequest request, String outcome) { + private long insertOperationEvent(DecisionRequest request) { // // Get the properties // - Map<String, Object> properties = (Map<String, Object>) request.getResource().get("guard"); + Map<String, Object> localProps = (Map<String, Object>) request.getResource().get("guard"); // // Add an entry // OperationsHistory newEntry = new OperationsHistory(); - newEntry.setActor(properties.get("actor").toString()); - newEntry.setOperation(properties.get("operation").toString()); - newEntry.setClosedLoopName(properties.get("clname").toString()); - newEntry.setOutcome(outcome); + newEntry.setActor(localProps.get("actor").toString()); + newEntry.setOperation(localProps.get("operation").toString()); + newEntry.setClosedLoopName(localProps.get("clname").toString()); + newEntry.setOutcome("Started"); newEntry.setStarttime(Date.from(Instant.now().minusMillis(20000))); newEntry.setEndtime(Date.from(Instant.now())); newEntry.setRequestId(UUID.randomUUID().toString()); - newEntry.setTarget(properties.get("target").toString()); + newEntry.setTarget(localProps.get("target").toString()); em.getTransaction().begin(); em.persist(newEntry); em.getTransaction().commit(); @@ -284,7 +281,6 @@ public class SonCoordinationTest { } private void updateOperationEvent(long id, String outcome) { - OperationsHistory updateEntry = em.find(OperationsHistory.class, id); updateEntry.setOutcome(outcome); updateEntry.setEndtime(Date.from(Instant.now())); |