aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/pom.xml55
-rw-r--r--main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java7
-rw-r--r--main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java8
-rw-r--r--main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java13
-rw-r--r--main/src/main/java/org/onap/policy/api/main/config/WebConfig.java6
-rw-r--r--main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java8
-rw-r--r--main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java10
-rw-r--r--main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java5
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java144
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java11
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java12
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java2
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java5
-rw-r--r--main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java4
-rw-r--r--main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java5
-rw-r--r--main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java25
-rw-r--r--main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java4
-rw-r--r--main/src/main/resources/META-INF/persistence.xml5
-rw-r--r--main/src/main/resources/application.yaml4
-rw-r--r--main/src/main/resources/openapi/openapi.yaml2
-rw-r--r--main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java32
-rw-r--r--main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java12
-rw-r--r--main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java12
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java83
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java20
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java31
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java14
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java39
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java44
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java51
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java29
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java30
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java27
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java60
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java99
-rw-r--r--main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java77
-rw-r--r--main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java10
-rw-r--r--main/src/test/resources/META-INF/persistence.xml4
-rw-r--r--packages/policy-api-docker/pom.xml2
-rw-r--r--packages/policy-api-docker/src/main/docker/Dockerfile2
-rw-r--r--packages/policy-api-tarball/pom.xml4
-rw-r--r--packages/pom.xml7
-rw-r--r--pom.xml35
-rw-r--r--testsuites/performance/pom.xml5
-rw-r--r--testsuites/pom.xml7
-rw-r--r--testsuites/stability/pom.xml5
-rw-r--r--version.properties2
47 files changed, 528 insertions, 550 deletions
diff --git a/main/pom.xml b/main/pom.xml
index 893cec03..5f88ee54 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -30,11 +30,12 @@
<parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>policy-api</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>api-main</artifactId>
<name>${project.artifactId}</name>
<description>The main module of Policy Api that handles startup, lifecycle management, and parameters.</description>
+
<dependencies>
<dependency>
<groupId>org.onap.policy.models</groupId>
@@ -47,44 +48,24 @@
<version>${policy.common.version}</version>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.onap.policy.common</groupId>
<artifactId>utils-test</artifactId>
<version>${policy.common.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
+
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <!-- Exclude the default Jackson dependency -->
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-json</artifactId>
- </exclusion>
- </exclusions>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -100,14 +81,30 @@
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
- <artifactId>springdoc-openapi-ui</artifactId>
+ <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
- <version>${version.io.micrometer}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ </dependency>
</dependencies>
<build>
<resources>
@@ -153,9 +150,10 @@
</importMappings>
<configOptions>
<sourceFolder>src/gen/java</sourceFolder>
- <dateLibrary>java11</dateLibrary>
+ <dateLibrary>java17</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<useTags>true</useTags>
+ <jakarta>true</jakarta>
</configOptions>
</configuration>
</execution>
@@ -164,6 +162,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${version.springboot}</version>
<executions>
<execution>
<goals>
diff --git a/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java b/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java
index bd55344a..2d0a2285 100644
--- a/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java
+++ b/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +21,7 @@
package org.onap.policy.api.main.config;
-import javax.servlet.Filter;
+import jakarta.servlet.Filter;
import org.onap.policy.api.main.rest.aaf.AafApiFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
@@ -34,4 +35,4 @@ public class PolicyApiAafConfig {
public Filter aafFilter() {
return new AafApiFilter();
}
-} \ No newline at end of file
+}
diff --git a/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java b/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java
index c2c40ff2..802d37c8 100644
--- a/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java
+++ b/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,15 +27,14 @@ import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
+@Getter
@Component
@ConfigurationProperties("policy-preload")
public class PolicyPreloadConfig {
- @Getter
@Setter
List<String> policyTypes;
- @Getter
@Setter
List<String> policies;
-} \ No newline at end of file
+}
diff --git a/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java b/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java
index 231456d3..074675b6 100644
--- a/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java
+++ b/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java
@@ -23,7 +23,9 @@ package org.onap.policy.api.main.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
/**
@@ -31,6 +33,7 @@ import org.springframework.security.web.SecurityFilterChain;
*/
@Configuration
public class SecurityConfig {
+
/**
* Return the configuration of how access to this module's REST end points is secured.
*
@@ -40,11 +43,9 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
- .httpBasic()
- .and()
- .authorizeHttpRequests().anyRequest().authenticated()
- .and()
- .csrf().disable();
+ .httpBasic(Customizer.withDefaults())
+ .authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated())
+ .csrf(AbstractHttpConfigurer::disable);
return http.build();
}
-} \ No newline at end of file
+}
diff --git a/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java b/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java
index ffc0edfd..42e07d64 100644
--- a/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java
+++ b/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +21,6 @@
package org.onap.policy.api.main.config;
-import java.util.Arrays;
import java.util.List;
import org.onap.policy.api.main.config.converter.StringToEnumConverter;
import org.onap.policy.common.spring.utils.YamlHttpMessageConverter;
@@ -43,7 +43,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
var yamlConverter = new YamlHttpMessageConverter();
- yamlConverter.setSupportedMediaTypes(Arrays.asList(MediaType.parseMediaType("application/yaml")));
+ yamlConverter.setSupportedMediaTypes(List.of(MediaType.parseMediaType("application/yaml")));
converters.add(yamlConverter);
}
}
diff --git a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java
index 580ba33d..b5364395 100644
--- a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java
+++ b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +21,13 @@
package org.onap.policy.api.main.exception;
+import java.io.Serial;
+
/**
* This exception will be called if an error occurs in policy api external service.
*/
public class PolicyApiException extends Exception {
+ @Serial
private static final long serialVersionUID = -8507246953751956974L;
/**
@@ -48,7 +52,7 @@ public class PolicyApiException extends Exception {
* Instantiates a new policy api exception with a message and a caused by exception.
*
* @param message the message
- * @param exp the exception that caused this exception to be thrown
+ * @param exp the exception that caused this exception to be thrown
*/
public PolicyApiException(final String message, final Exception exp) {
super(message, exp);
diff --git a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java
index 19bf5e12..d4140d47 100644
--- a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java
+++ b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java
@@ -1,7 +1,8 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
package org.onap.policy.api.main.exception;
+import java.io.Serial;
import java.util.UUID;
import lombok.Getter;
import org.onap.policy.models.errors.concepts.ErrorResponse;
@@ -28,13 +30,13 @@ import org.onap.policy.models.errors.concepts.ErrorResponse;
/**
* This runtime exception will be called if a runtime error occurs when using policy api.
*/
+@Getter
public class PolicyApiRuntimeException extends RuntimeException {
+ @Serial
private static final long serialVersionUID = -8507246953751956974L;
- @Getter
private final UUID requestId;
- @Getter
private final ErrorResponse errorResponse;
/**
diff --git a/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java b/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java
index 93240df9..4b601439 100644
--- a/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java
+++ b/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Bell Canada. All rights reserved.
+ * Copyright (C) 2022-2023 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +21,7 @@
package org.onap.policy.api.main.exception;
-import javax.ws.rs.core.Response;
+import jakarta.ws.rs.core.Response;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
index a1e6db25..b44e60fa 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
@@ -4,7 +4,7 @@
* ================================================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020-2022 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2023 Nordix Foundation.
* Modifications Copyright (C) 2020-2023 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,9 +25,9 @@
package org.onap.policy.api.main.rest;
+import jakarta.ws.rs.core.Response.Status;
import java.util.List;
import java.util.UUID;
-import javax.ws.rs.core.Response.Status;
import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.exception.PolicyApiRuntimeException;
import org.onap.policy.api.main.rest.genapi.PolicyDesignApi;
@@ -41,8 +41,6 @@ import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.context.annotation.Profile;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
@@ -56,12 +54,6 @@ import org.springframework.web.bind.annotation.RestController;
@Profile("default")
public class ApiRestController extends CommonRestController implements PolicyDesignApi {
- private enum Target {
- POLICY,
- POLICY_TYPE,
- OTHER
- }
-
private final ToscaServiceTemplateService toscaServiceTemplateService;
private final HealthCheckProvider healthCheckProvider;
@@ -96,13 +88,12 @@ public class ApiRestController extends CommonRestController implements PolicyDes
* Retrieves all versions of a particular policy type.
*
* @param policyTypeId the ID of specified policy type
- *
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicyType(
- String policyTypeId,
- UUID requestId) {
+ String policyTypeId,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null);
return makeOkResponse(requestId, serviceTemplate);
@@ -116,15 +107,14 @@ public class ApiRestController extends CommonRestController implements PolicyDes
* Retrieves specified version of a particular policy type.
*
* @param policyTypeId the ID of specified policy type
- * @param versionId the version of specified policy type
- *
+ * @param versionId the version of specified policy type
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicyType(
- String policyTypeId,
- String versionId,
- UUID requestId) {
+ String policyTypeId,
+ String versionId,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId);
@@ -139,13 +129,12 @@ public class ApiRestController extends CommonRestController implements PolicyDes
* Retrieves latest version of a particular policy type.
*
* @param policyTypeId the ID of specified policy type
- *
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicyType(
- String policyTypeId,
- UUID requestId) {
+ String policyTypeId,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId);
return makeOkResponse(requestId, serviceTemplate);
@@ -159,13 +148,12 @@ public class ApiRestController extends CommonRestController implements PolicyDes
* Creates a new policy type.
*
* @param body the body of policy type following TOSCA definition
- *
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> createPolicyType(
- ToscaServiceTemplate body,
- UUID requestId) {
+ ToscaServiceTemplate body,
+ UUID requestId) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
}
@@ -182,15 +170,14 @@ public class ApiRestController extends CommonRestController implements PolicyDes
* Deletes specified version of a particular policy type.
*
* @param policyTypeId the ID of specified policy type
- * @param versionId the version of specified policy type
- *
+ * @param versionId the version of specified policy type
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicyType(
- String policyTypeId,
- String versionId,
- UUID requestId) {
+ String policyTypeId,
+ String versionId,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);
@@ -204,17 +191,16 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Retrieves all versions of a particular policy.
*
- * @param policyTypeId the ID of specified policy type
+ * @param policyTypeId the ID of specified policy type
* @param policyTypeVersion the version of specified policy type
- *
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getAllPolicies(
- String policyTypeId,
- String policyTypeVersion,
- PolicyFetchMode mode,
- UUID requestId) {
+ String policyTypeId,
+ String policyTypeVersion,
+ PolicyFetchMode mode,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
@@ -228,19 +214,18 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Retrieves all versions of a particular policy.
*
- * @param policyTypeId the ID of specified policy type
+ * @param policyTypeId the ID of specified policy type
* @param policyTypeVersion the version of specified policy type
- * @param policyId the ID of specified policy
- *
+ * @param policyId the ID of specified policy
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicy(
- String policyId,
- String policyTypeId,
- String policyTypeVersion,
- PolicyFetchMode mode,
- UUID requestId) {
+ String policyId,
+ String policyTypeId,
+ String policyTypeVersion,
+ PolicyFetchMode mode,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
@@ -255,21 +240,20 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Retrieves the specified version of a particular policy.
*
- * @param policyTypeId the ID of specified policy type
+ * @param policyTypeId the ID of specified policy type
* @param policyTypeVersion the version of specified policy type
- * @param policyId the ID of specified policy
- * @param policyVersion the version of specified policy
- *
+ * @param policyId the ID of specified policy
+ * @param policyVersion the version of specified policy
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicy(
- String policyId,
- String policyTypeId,
- String policyTypeVersion,
- String policyVersion,
- PolicyFetchMode mode,
- UUID requestId) {
+ String policyId,
+ String policyTypeId,
+ String policyTypeVersion,
+ String policyVersion,
+ PolicyFetchMode mode,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService
.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
@@ -284,19 +268,18 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Retrieves the latest version of a particular policy.
*
- * @param policyTypeId the ID of specified policy type
+ * @param policyTypeId the ID of specified policy type
* @param policyTypeVersion the version of specified policy type
- * @param policyId the ID of specified policy
- *
+ * @param policyId the ID of specified policy
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicy(
- String policyId,
- String policyTypeId,
- String policyTypeVersion,
- PolicyFetchMode mode,
- UUID requestId) {
+ String policyId,
+ String policyTypeId,
+ String policyTypeVersion,
+ PolicyFetchMode mode,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
@@ -311,18 +294,17 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Creates a new policy for a particular policy type and version.
*
- * @param policyTypeId the ID of specified policy type
+ * @param policyTypeId the ID of specified policy type
* @param policyTypeVersion the version of specified policy type
- * @param body the body of policy following TOSCA definition
- *
+ * @param body the body of policy following TOSCA definition
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> createPolicy(
- String policyTypeId,
- String policyTypeVersion,
- ToscaServiceTemplate body,
- UUID requestId) {
+ String policyTypeId,
+ String policyTypeVersion,
+ ToscaServiceTemplate body,
+ UUID requestId) {
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,
"/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
@@ -340,11 +322,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Deletes the specified version of a particular policy.
*
- * @param policyTypeId the ID of specified policy type
+ * @param policyTypeId the ID of specified policy type
* @param policyTypeVersion the version of specified policy type
- * @param policyId the ID of specified policy
- * @param policyVersion the version of specified policy
- *
+ * @param policyId the ID of specified policy
+ * @param policyVersion the version of specified policy
* @return the Response object containing the results of the API operation
*/
@Override
@@ -372,8 +353,8 @@ public class ApiRestController extends CommonRestController implements PolicyDes
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getPolicies(
- PolicyFetchMode mode,
- UUID requestId) {
+ PolicyFetchMode mode,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode);
@@ -391,17 +372,16 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Retrieves the specified version of a particular policy.
*
- * @param policyId the Name of specified policy
+ * @param policyId the Name of specified policy
* @param policyVersion the version of specified policy
- *
* @return the Response object containing the results of the API operation
*/
@Override
public ResponseEntity<ToscaServiceTemplate> getSpecificPolicy(
- String policyId,
- String policyVersion,
- PolicyFetchMode mode,
- UUID requestId) {
+ String policyId,
+ String policyVersion,
+ PolicyFetchMode mode,
+ UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode);
@@ -416,7 +396,6 @@ public class ApiRestController extends CommonRestController implements PolicyDes
* Creates one or more new policies in one call.
*
* @param body the body of policy following TOSCA definition
- *
* @return the Response object containing the results of the API operation
*/
@Override
@@ -438,9 +417,8 @@ public class ApiRestController extends CommonRestController implements PolicyDes
/**
* Deletes the specified version of a particular policy.
*
- * @param policyId the ID of specified policy
+ * @param policyId the ID of specified policy
* @param policyVersion the version of specified policy
- *
* @return the Response object containing the results of the API operation
*/
@Override
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java
index ef288e47..eadd8d34 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java
@@ -4,7 +4,7 @@
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
package org.onap.policy.api.main.rest;
+import java.util.Objects;
import java.util.UUID;
import org.onap.policy.api.main.exception.PolicyApiRuntimeException;
import org.onap.policy.common.utils.coder.Coder;
@@ -107,12 +108,10 @@ public class CommonRestController {
* @return the response builder, with version logging
*/
public static ResponseEntity.BodyBuilder addLoggingHeaders(ResponseEntity.BodyBuilder respBuilder, UUID requestId) {
- if (requestId == null) {
- // Generate a random uuid if client does not embed requestId in rest request
- return respBuilder.header(REQUEST_ID_NAME, UUID.randomUUID().toString());
- }
+ // Generate a random uuid if client does not embed requestId in rest request
+ return respBuilder.header(REQUEST_ID_NAME,
+ Objects.requireNonNullElseGet(requestId, UUID::randomUUID).toString());
- return respBuilder.header(REQUEST_ID_NAME, requestId.toString());
}
/**
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java b/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java
index 38fe0032..49c9bf45 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java
@@ -21,8 +21,8 @@
package org.onap.policy.api.main.rest.stub;
+import jakarta.validation.Valid;
import java.util.UUID;
-import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.rest.CommonRestController;
import org.onap.policy.api.main.rest.PolicyFetchMode;
@@ -42,7 +42,7 @@ public class ApiRestControllerStub extends CommonRestController implements Polic
@Override
public ResponseEntity<ToscaServiceTemplate> createPolicies(
- @Valid ToscaServiceTemplate body, UUID requestID) {
+ @Valid ToscaServiceTemplate body, UUID requestID) {
return stubUtils.getStubbedResponse(ToscaServiceTemplate.class);
}
@@ -57,15 +57,15 @@ public class ApiRestControllerStub extends CommonRestController implements Polic
@Override
public ResponseEntity<ToscaServiceTemplate> createPolicyType(
- @Valid ToscaServiceTemplate body, UUID requestID) {
+ @Valid ToscaServiceTemplate body, UUID requestID) {
return stubUtils.getStubbedResponse(ToscaServiceTemplate.class);
}
@Override
public ResponseEntity<ToscaServiceTemplate> deleteSpecificPolicy(
- String policyId,
- String policyVersion,
- UUID requestID) {
+ String policyId,
+ String policyVersion,
+ UUID requestID) {
return stubUtils.getStubbedResponse(ToscaServiceTemplate.class);
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java b/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java
index 2e9f4a21..5045eb69 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java
@@ -20,9 +20,9 @@
package org.onap.policy.api.main.rest.stub;
+import jakarta.validation.Valid;
import java.util.List;
import java.util.UUID;
-import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.rest.CommonRestController;
import org.onap.policy.api.main.rest.genapi.ToscaNodeTemplateDesignApi;
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java b/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java
index 562ce565..62f091cb 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java
@@ -21,11 +21,10 @@
package org.onap.policy.api.main.rest.stub;
import com.google.gson.Gson;
+import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,7 +67,7 @@ class StubUtils {
final var resource = new ClassPathResource(TOSCA_NODE_TEMPLATE_RESOURCE);
try (var inputStream = resource.getInputStream()) {
final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
- var targetObject = Arrays.asList(JSON_TRANSLATOR.fromJson(string, clazz));
+ var targetObject = List.of(JSON_TRANSLATOR.fromJson(string, clazz));
return new ResponseEntity<>(targetObject, HttpStatus.OK);
} catch (IOException e) {
log.error("Couldn't serialize response for content type application/json", e);
diff --git a/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java b/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java
index b4eec379..620248d4 100644
--- a/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java
+++ b/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2022-2023 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,8 @@
package org.onap.policy.api.main.service;
+import jakarta.ws.rs.core.Response;
import java.util.Optional;
-import javax.ws.rs.core.Response;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.repository.NodeTemplateRepository;
diff --git a/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java b/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java
index 0bac8722..e9d84be5 100644
--- a/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java
+++ b/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,9 +21,9 @@
package org.onap.policy.api.main.service;
+import jakarta.ws.rs.core.Response;
import java.util.List;
import java.util.stream.Collectors;
-import javax.ws.rs.core.Response;
import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.repository.PdpGroupRepository;
import org.onap.policy.models.base.PfModelRuntimeException;
diff --git a/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java b/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java
index 2e8fc9eb..9ec28d1b 100644
--- a/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java
+++ b/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,11 +21,10 @@
package org.onap.policy.api.main.service;
+import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-import javax.annotation.Nonnull;
-import javax.ws.rs.core.Response;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
@@ -119,12 +118,9 @@ public class ToscaServiceTemplateService {
// append the incoming fragment to the DB TOSCA service template
var dbServiceTemplateOpt = getDefaultJpaToscaServiceTemplateOpt();
JpaToscaServiceTemplate serviceTemplateToWrite;
- if (dbServiceTemplateOpt.isEmpty()) {
- serviceTemplateToWrite = incomingServiceTemplate;
- } else {
- serviceTemplateToWrite =
- ToscaServiceTemplateUtils.addFragment(dbServiceTemplateOpt.get(), incomingServiceTemplate);
- }
+ serviceTemplateToWrite = dbServiceTemplateOpt.map(
+ jpaToscaServiceTemplate -> ToscaServiceTemplateUtils.addFragment(jpaToscaServiceTemplate,
+ incomingServiceTemplate)).orElse(incomingServiceTemplate);
final var result = serviceTemplateToWrite.validate("service template");
if (!result.isValid()) {
@@ -265,12 +261,9 @@ public class ToscaServiceTemplateService {
// append the incoming fragment to the DB TOSCA service template
var dbServiceTemplateOpt = getDefaultJpaToscaServiceTemplateOpt();
JpaToscaServiceTemplate serviceTemplateToWrite;
- if (dbServiceTemplateOpt.isEmpty()) {
- serviceTemplateToWrite = incomingServiceTemplate;
- } else {
- serviceTemplateToWrite =
- ToscaServiceTemplateUtils.addFragment(dbServiceTemplateOpt.get(), incomingServiceTemplate);
- }
+ serviceTemplateToWrite = dbServiceTemplateOpt.map(
+ jpaToscaServiceTemplate -> ToscaServiceTemplateUtils.addFragment(jpaToscaServiceTemplate,
+ incomingServiceTemplate)).orElse(incomingServiceTemplate);
final var result = serviceTemplateToWrite.validate("Policies CRUD service template.");
if (!result.isValid()) {
@@ -501,7 +494,7 @@ public class ToscaServiceTemplateService {
* @return the TOSCA service template containing the node template that were deleted
* @throws PfModelException on errors deleting node templates
*/
- public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @Nonnull final String version)
+ public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version)
throws PfModelException {
LOGGER.debug("->deleteToscaNodeTemplate: name={}, version={}", name, version);
diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
index 55f49b18..edff3004 100644
--- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
+++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
@@ -3,7 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,13 +25,13 @@
package org.onap.policy.api.main.startstop;
import com.google.common.collect.Sets;
+import jakarta.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import javax.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.config.PolicyPreloadConfig;
import org.onap.policy.api.main.exception.PolicyApiException;
diff --git a/main/src/main/resources/META-INF/persistence.xml b/main/src/main/resources/META-INF/persistence.xml
index 43024eea..8adb850c 100644
--- a/main/src/main/resources/META-INF/persistence.xml
+++ b/main/src/main/resources/META-INF/persistence.xml
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START=======================================================
- Copyright (C) 2019-2020 Nordix Foundation.
+ Copyright (C) 2019-2020, 2022-2023 Nordix Foundation.
Modifications Copyright (C) 2021 AT&T Intellectual Property.
- Modification Copyright 2022 Nordix Foundation.
Modifications Copyright (C) 2023 Bell Canada. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
@@ -62,7 +61,7 @@
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class>
<properties>
- <property name="javax.persistence.schema-generation.database.action" value="none" />
+ <property name="jakarta.persistence.schema-generation.database.action" value="none" />
<property name="eclipselink.ddl-generation" value="none" />
<property name="eclipselink.logging.level" value="WARNING" />
</properties>
diff --git a/main/src/main/resources/application.yaml b/main/src/main/resources/application.yaml
index 305af94b..42e0025b 100644
--- a/main/src/main/resources/application.yaml
+++ b/main/src/main/resources/application.yaml
@@ -72,4 +72,6 @@ management:
base-path: /
exposure:
include: health,metrics,prometheus
- path-mapping.prometheus: metrics
+ path-mapping:
+ -metrics: plain-metrics
+ -prometheus: metrics
diff --git a/main/src/main/resources/openapi/openapi.yaml b/main/src/main/resources/openapi/openapi.yaml
index c8f44e5e..6303b431 100644
--- a/main/src/main/resources/openapi/openapi.yaml
+++ b/main/src/main/resources/openapi/openapi.yaml
@@ -1,7 +1,7 @@
openapi: 3.0.1
info:
title: Policy Framework Lifecycle API
- description: The Policy Fraemwork API allows the lifecycle of policy types and policyes to be managed
+ description: The Policy Framework API allows the lifecycle of policy types and policies to be managed
contact:
name: ONAP Support
url: https://lists.onap.org/g/onap-discuss
diff --git a/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java b/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java
index 3b90a106..08cb7f18 100644
--- a/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java
+++ b/main/src/test/java/org/onap/policy/api/contract/ApiContractTest.java
@@ -23,11 +23,10 @@ package org.onap.policy.api.contract;
import static org.junit.Assert.assertEquals;
+import jakarta.ws.rs.core.Response;
import java.io.IOException;
-import javax.ws.rs.core.Response;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.api.main.PolicyApiApplication;
import org.onap.policy.api.main.rest.utils.CommonTestRestController;
import org.onap.policy.common.utils.security.SelfSignedKeyStore;
@@ -38,25 +37,22 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
-@RunWith(SpringRunner.class)
@SpringBootTest(classes = PolicyApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-@ActiveProfiles({ "test", "stub" })
+@ActiveProfiles({"test", "stub"})
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
-public class ApiContractTest extends CommonTestRestController {
+class ApiContractTest extends CommonTestRestController {
protected static final String APP_JSON = "application/json";
protected static final String APP_YAML = "application/yaml";
private static final String TOSCA_NODE_TEMPLATE_RESOURCE =
- "nodetemplates/nodetemplates.metadatasets.input.tosca.json";
+ "nodetemplates/nodetemplates.metadatasets.input.tosca.json";
@LocalServerPort
private int apiPort;
private static SelfSignedKeyStore keystore;
-
- @BeforeClass
+ @BeforeAll
public static void setupParameters() throws IOException, InterruptedException {
keystore = new SelfSignedKeyStore();
}
@@ -72,20 +68,20 @@ public class ApiContractTest extends CommonTestRestController {
}
@Test
- public void testStubPolicyDesign() throws Exception {
+ void testStubPolicyDesign() throws Exception {
checkStubJsonGet("policies");
checkStubJsonGet("policies/policyname/versions/1.0.2");
checkStubJsonGet("policytypes");
checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16");
checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/latest");
- checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/");
+ checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0");
checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies");
checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/"
+ "9c65fa1f-2833-4076-a64d-5b62e35cd09b");
checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/"
- + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/latest");
+ + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/latest");
checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/"
- + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3");
+ + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3");
checkStubJsonGet("healthcheck");
checkStubJsonPost("policies");
@@ -95,11 +91,11 @@ public class ApiContractTest extends CommonTestRestController {
checkStubJsonDelete("policies/policyname/versions/1.0.2");
checkStubJsonDelete("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0");
checkStubJsonDelete("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/"
- + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3");
+ + "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3");
}
@Test
- public void testStubNodeTemplateDesign() throws Exception {
+ void testStubNodeTemplateDesign() throws Exception {
checkStubJsonGet("nodetemplates");
checkStubJsonGet("nodetemplates/k8stemplate/versions/1.0.0");
@@ -111,7 +107,7 @@ public class ApiContractTest extends CommonTestRestController {
}
@Test
- public void testErrors() throws Exception {
+ void testErrors() throws Exception {
var responseYaml = super.readResource("policies", APP_YAML, apiPort);
assertEquals(Response.Status.NOT_IMPLEMENTED.getStatusCode(), responseYaml.getStatus());
diff --git a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java
index 1212517c..47ca230d 100644
--- a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java
+++ b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiException.java
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,15 +23,14 @@
package org.onap.policy.api.main.exception;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class TestPolicyApiException {
+class TestPolicyApiException {
@Test
- public void test() {
- assertEquals(3, new ExceptionsTester().test(PolicyApiException.class));
+ void test() {
+ Assertions.assertEquals(3, new ExceptionsTester().test(PolicyApiException.class));
}
}
diff --git a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java
index 3e78ab2b..9fa735bc 100644
--- a/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java
+++ b/main/src/test/java/org/onap/policy/api/main/exception/TestPolicyApiRuntimeException.java
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,15 +23,14 @@
package org.onap.policy.api.main.exception;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class TestPolicyApiRuntimeException {
+class TestPolicyApiRuntimeException {
@Test
- public void test() {
- assertEquals(2, new ExceptionsTester().test(PolicyApiRuntimeException.class));
+ void test() {
+ Assertions.assertEquals(2, new ExceptionsTester().test(PolicyApiRuntimeException.class));
}
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
index 7442a8cc..4bcd86ca 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022-2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2022-2023 Nordix Foundation.
* Modifications Copyright (C) 2020-2023 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,21 +24,20 @@
package org.onap.policy.api.main.rest;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.core.Response.Status;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.api.main.PolicyApiApplication;
import org.onap.policy.api.main.rest.utils.CommonTestRestController;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
@@ -56,18 +55,16 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* Class to perform unit test of {@link ApiRestController}.
*
* @author Chenfei Gao (cgao@research.att.com)
*/
-@RunWith(SpringRunner.class)
@SpringBootTest(classes = PolicyApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({ "test", "default" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
-public class TestApiRestServer extends CommonTestRestController {
+class TestApiRestServer extends CommonTestRestController {
private static final String ALIVE = "alive";
private static final String SELF = NetworkUtil.getHostname();
@@ -161,8 +158,8 @@ public class TestApiRestServer extends CommonTestRestController {
* @throws IOException on I/O exceptions
* @throws InterruptedException if interrupted
*/
- @BeforeClass
- public static void setupParameters() throws IOException, InterruptedException {
+ @BeforeAll
+ static void setupParameters() throws IOException, InterruptedException {
keystore = new SelfSignedKeyStore();
}
@@ -177,12 +174,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testSwagger() throws Exception {
+ void testSwagger() throws Exception {
super.testSwagger(apiPort);
}
@Test
- public void testCreatePolicyTypes() throws Exception {
+ void testCreatePolicyTypes() throws Exception {
for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICYTYPES, resrcName, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -204,7 +201,7 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testCreatePolicies() throws Exception {
+ void testCreatePolicies() throws Exception {
for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -229,7 +226,7 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testSimpleCreatePolicies() throws Exception {
+ void testSimpleCreatePolicies() throws Exception {
for (String resrcName : TOSCA_POLICIES_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICIES, resrcName, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -255,7 +252,7 @@ public class TestApiRestServer extends CommonTestRestController {
@SuppressWarnings("unchecked")
@Test
- public void testToscaCompliantOpDroolsPolicies() throws Exception {
+ void testToscaCompliantOpDroolsPolicies() throws Exception {
Response rawResponse = createResource(POLICYTYPES, TOSCA_POLICYTYPE_OP_RESOURCE, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -306,29 +303,29 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testHealthCheckSuccessJson() throws Exception {
+ void testHealthCheckSuccessJson() throws Exception {
testHealthCheckSuccess(APP_JSON);
}
@Test
- public void testHealthCheckSuccessYaml() throws Exception {
+ void testHealthCheckSuccessYaml() throws Exception {
testHealthCheckSuccess(APP_YAML);
}
private void testHealthCheckSuccess(String mediaType) throws Exception {
final Invocation.Builder invocationBuilder = sendHttpsRequest(
- CONTEXT_PATH, HEALTHCHECK_ENDPOINT, mediaType, apiPort);
+ HEALTHCHECK_ENDPOINT, mediaType, apiPort);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
}
@Test
- public void testReadPolicyTypesJson() throws Exception {
+ void testReadPolicyTypesJson() throws Exception {
testReadPolicyTypes(APP_JSON);
}
@Test
- public void testReadPolicyTypesYaml() throws Exception {
+ void testReadPolicyTypesYaml() throws Exception {
testReadPolicyTypes(APP_YAML);
}
@@ -379,12 +376,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testDeletePolicyTypeJson() throws Exception {
+ void testDeletePolicyTypeJson() throws Exception {
testDeletePolicyType(APP_JSON);
}
@Test
- public void testDeletePolicyTypeYaml() throws Exception {
+ void testDeletePolicyTypeYaml() throws Exception {
testDeletePolicyType(APP_YAML);
}
@@ -410,12 +407,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testReadPoliciesJson() throws Exception {
+ void testReadPoliciesJson() throws Exception {
testReadPolicies(APP_JSON);
}
@Test
- public void testReadPoliciesYaml() throws Exception {
+ void testReadPoliciesYaml() throws Exception {
testReadPolicies(APP_YAML);
}
@@ -443,7 +440,7 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testNamingPolicyGet() throws Exception {
+ void testNamingPolicyGet() throws Exception {
Response rawResponse = readResource("policytypes/onap.policies.Naming/versions/1.0.0/"
+ "policies/SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP/versions/1.0.0", APP_JSON, apiPort);
@@ -507,12 +504,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testDeletePoliciesJson() throws Exception {
+ void testDeletePoliciesJson() throws Exception {
testDeletePolicies(APP_JSON);
}
@Test
- public void testDeletePoliciesYaml() throws Exception {
+ void testDeletePoliciesYaml() throws Exception {
testDeletePolicies(APP_YAML);
}
@@ -524,12 +521,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testDeletePolicyVersionJson() throws Exception {
+ void testDeletePolicyVersionJson() throws Exception {
testDeletePolicyVersion(APP_JSON);
}
@Test
- public void testDeletePolicyVersionYaml() throws Exception {
+ void testDeletePolicyVersionYaml() throws Exception {
testDeletePolicyVersion(APP_YAML);
}
@@ -565,12 +562,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testGetAllVersionOfPolicyJson() throws Exception {
+ void testGetAllVersionOfPolicyJson() throws Exception {
testGetAllVersionOfPolicy(APP_JSON);
}
@Test
- public void testGetAllVersionOfPolicyYaml() throws Exception {
+ void testGetAllVersionOfPolicyYaml() throws Exception {
testGetAllVersionOfPolicy(APP_YAML);
}
@@ -591,12 +588,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testGetPoliciesJson() throws Exception {
+ void testGetPoliciesJson() throws Exception {
getPolicies(APP_JSON);
}
@Test
- public void testGetPoliciesYaml() throws Exception {
+ void testGetPoliciesYaml() throws Exception {
getPolicies(APP_YAML);
}
@@ -619,12 +616,12 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testGetSpecificPolicyJson() throws Exception {
+ void testGetSpecificPolicyJson() throws Exception {
getSpecificPolicy(APP_JSON);
}
@Test
- public void testGetSpecificPolicyYaml() throws Exception {
+ void testGetSpecificPolicyYaml() throws Exception {
getSpecificPolicy(APP_YAML);
}
@@ -647,7 +644,7 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
- public void testDeleteSpecificPolicy() throws Exception {
+ void testDeleteSpecificPolicy() throws Exception {
Response rawResponse;
for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) {
rawResponse = createResource(POLICYTYPES, resrcName, apiPort);
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
index 2213bbf9..bf1d49be 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
@@ -3,7 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2023 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,31 +24,29 @@
package org.onap.policy.api.main.rest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
import java.util.UUID;
-import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
/**
* Class to perform unit testing of CommonRestController.
*/
-public class TestCommonRestController {
- private CommonRestController crc = new CommonRestController();
+class TestCommonRestController {
+ private final CommonRestController crc = new CommonRestController();
@Test
- public void testAddLoggingHeaders() {
+ void testAddLoggingHeaders() {
UUID requestId = UUID.randomUUID();
ResponseEntity<Void> rb = crc.makeOkResponse(requestId, null);
- assertEquals(requestId.toString(), rb.getHeaders().getFirst("X-ONAP-RequestID"));
+ Assertions.assertEquals(requestId.toString(), rb.getHeaders().getFirst("X-ONAP-RequestID"));
}
/*
* Tests null response for null object
*/
@Test
- public void testToJsonNull() {
- assertNull(crc.toJson(null));
+ void testToJsonNull() {
+ Assertions.assertNull(crc.toJson(null));
}
} \ No newline at end of file
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java
index c36fea17..8dd0d731 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java
@@ -23,18 +23,17 @@
package org.onap.policy.api.main.rest;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import jakarta.ws.rs.core.GenericType;
+import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.util.List;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.Response;
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.api.main.PolicyApiApplication;
import org.onap.policy.api.main.rest.utils.CommonTestRestController;
import org.onap.policy.api.main.service.ToscaServiceTemplateService;
@@ -49,13 +48,11 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* Class to perform unit test of {@link NodeTemplateController}.
*
*/
-@RunWith(SpringRunner.class)
@SpringBootTest(classes = PolicyApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({ "test", "default" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@@ -92,7 +89,7 @@ public class TestNodeTemplateController extends CommonTestRestController {
* @throws IOException on I/O exceptions
* @throws InterruptedException if interrupted
*/
- @BeforeClass
+ @BeforeAll
public static void setupParameters() throws IOException, InterruptedException {
keystore = new SelfSignedKeyStore();
}
@@ -101,7 +98,7 @@ public class TestNodeTemplateController extends CommonTestRestController {
* Clean up the database.
*
*/
- @After
+ @AfterEach
public void clearDb() {
for (String name : nodeTemplateKeys) {
try {
@@ -124,7 +121,7 @@ public class TestNodeTemplateController extends CommonTestRestController {
@Test
- public void testCreateToscaNodeTemplates() throws Exception {
+ void testCreateToscaNodeTemplates() throws Exception {
Response rawResponse = createResource(NODE_TEMPLATES, TOSCA_NODE_TEMPLATE_RESOURCE, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
@@ -147,7 +144,7 @@ public class TestNodeTemplateController extends CommonTestRestController {
@Test
- public void testReadNodeTemplates() throws Exception {
+ void testReadNodeTemplates() throws Exception {
Response rawResponse = readResource(NODE_TEMPLATES, APP_JSON, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
List<?> nodeTemplates = rawResponse.readEntity(List.class);
@@ -172,7 +169,7 @@ public class TestNodeTemplateController extends CommonTestRestController {
}
@Test
- public void testUpdateNodeTemplates() throws Exception {
+ void testUpdateNodeTemplates() throws Exception {
createResource(NODE_TEMPLATES, TOSCA_NODE_TEMPLATE_RESOURCE, apiPort);
Response rawResponse = updateResource(NODE_TEMPLATES, TOSCA_UPDATE_NODE_TEMPLATES, APP_JSON, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -197,7 +194,7 @@ public class TestNodeTemplateController extends CommonTestRestController {
}
@Test
- public void testDeleteNodeTemplates() throws Exception {
+ void testDeleteNodeTemplates() throws Exception {
createResource(NODE_TEMPLATES, TOSCA_NODE_TEMPLATE_RESOURCE, apiPort);
Response rawResponse = deleteResource(SPECIFIC_NODE_TEMPLATE, APP_JSON, apiPort);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java b/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java
index 18526971..7246cddd 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/aaf/TestAafApiFilter.java
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,15 +23,14 @@
package org.onap.policy.api.main.rest.aaf;
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
-
-public class TestAafApiFilter {
- private AafApiFilter aafApiFilter = new AafApiFilter();
+class TestAafApiFilter {
+ private final AafApiFilter aafApiFilter = new AafApiFilter();
@Test
- public void testGetPermissionTypeRoot() {
- assertEquals("org.onap.policy.policy-api", aafApiFilter.getPermissionTypeRoot());
+ void testGetPermissionTypeRoot() {
+ Assertions.assertEquals("org.onap.policy.policy-api", aafApiFilter.getPermissionTypeRoot());
}
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java
index 947ed6a5..8e9bf70d 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy API
* ================================================================================
- * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2022-2023 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,19 +22,18 @@
package org.onap.policy.api.main.rest.utils;
-import static org.junit.Assert.assertTrue;
-
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.client.WebTarget;
+import jakarta.ws.rs.core.Response;
import java.security.SecureRandom;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.jupiter.api.Assertions;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.coder.CoderException;
@@ -46,7 +45,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
* Util class to perform REST unit tests.
- *
*/
public class CommonTestRestController {
@@ -60,9 +58,10 @@ public class CommonTestRestController {
protected static final String CONTEXT_PATH = "/policy/api/v1/";
protected void testSwagger(final int apiPort) throws Exception {
- final Invocation.Builder invocationBuilder = sendHttpsRequest(CONTEXT_PATH, "v3/api-docs", APP_JSON, apiPort);
+ final Invocation.Builder invocationBuilder = sendHttpsRequest("v3/api-docs", APP_JSON, apiPort);
final String resp = invocationBuilder.get(String.class);
- assertTrue((resp).contains("{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"Policy Framework Lifecycle API\""));
+ Assertions.assertTrue(
+ (resp).contains("{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"Policy Framework Lifecycle API\""));
}
protected Response createResource(String endpoint, String resourceName, int apiPort)
@@ -70,10 +69,10 @@ public class CommonTestRestController {
ToscaServiceTemplate rawServiceTemplate = getRawServiceTemplate(resourceName);
String mediaType = getMediaType(resourceName);
- mediaType = mediaType == null ? APP_JSON : mediaType;
+ mediaType = mediaType == null ? APP_JSON : mediaType;
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
return invocationBuilder.post(entity);
}
@@ -81,14 +80,14 @@ public class CommonTestRestController {
protected Response readResource(String endpoint, String mediaType, int apiPort) throws Exception {
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
return invocationBuilder.get();
}
protected Response deleteResource(String endpoint, String mediaType, int apiPort) throws Exception {
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
return invocationBuilder.delete();
}
@@ -98,7 +97,7 @@ public class CommonTestRestController {
ToscaServiceTemplate rawServiceTemplate = getRawServiceTemplate(resourceName);
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
return invocationBuilder.put(entity);
}
@@ -112,7 +111,7 @@ public class CommonTestRestController {
}
protected Invocation.Builder sendHttpsRequest(
- final String context, final String endpoint, String mediaType, int apiPort) throws Exception {
+ final String endpoint, String mediaType, int apiPort) throws Exception {
final TrustManager[] noopTrustManager = NetworkUtil.getAlwaysTrustingManager();
@@ -131,7 +130,7 @@ public class CommonTestRestController {
client.register(YamlMessageBodyHandler.class);
}
- final WebTarget webTarget = client.target(HTTPS_PREFIX + apiPort + context + endpoint);
+ final WebTarget webTarget = client.target(HTTPS_PREFIX + apiPort + CONTEXT_PATH + endpoint);
final Invocation.Builder invocationBuilder = webTarget.request(mediaType);
@@ -148,7 +147,7 @@ public class CommonTestRestController {
} else if (APP_YAML.equals(getMediaType(resourceName))) {
rawServiceTemplate = decodeYaml(resourceName);
}
- return rawServiceTemplate;
+ return rawServiceTemplate;
}
private String getMediaType(String resourceName) {
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java b/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java
index 4af30937..5c92bad1 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +22,11 @@
package org.onap.policy.api.main.service;
import java.util.Optional;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.onap.policy.api.main.repository.ToscaServiceTemplateRepository;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -50,17 +53,20 @@ public class TestCommonToscaServiceTemplateService {
@Mock
protected NodeTemplateService nodeTemplateService;
+ AutoCloseable autoCloseable;
+
/**
- * Setup the DB TOSCA service template object post create, and delete request.
- * @param dbSvcTemplate ToscaServiceTemplate object to update
+ * Set up the DB TOSCA service template object post create, and delete request.
+ *
+ * @param dbSvcTemplate ToscaServiceTemplate object to update
* @param svcTemplateFragment the CRUD operation response ToscaServiceTemplate object
- * @param operation the CRUD operation performed
+ * @param operation the CRUD operation performed
*/
protected void mockDbServiceTemplate(ToscaServiceTemplate dbSvcTemplate, ToscaServiceTemplate svcTemplateFragment,
- TestToscaServiceTemplateServiceForPolicyCrud.Operation operation) {
+ TestToscaServiceTemplateServiceForPolicyCrud.Operation operation) {
if (operation != null) {
switch (operation) {
- case CREATE_POLICY_TYPE:
+ case CREATE_POLICY_TYPE -> {
dbSvcTemplate.getPolicyTypes().putAll(svcTemplateFragment.getPolicyTypes());
if (svcTemplateFragment.getDataTypes() != null) {
if (dbSvcTemplate.getDataTypes() == null) {
@@ -69,18 +75,14 @@ public class TestCommonToscaServiceTemplateService {
dbSvcTemplate.getDataTypes().putAll(svcTemplateFragment.getDataTypes());
}
}
- break;
- case DELETE_POLICY_TYPE:
+ }
+ case DELETE_POLICY_TYPE ->
dbSvcTemplate.getPolicyTypes().keySet().removeAll(svcTemplateFragment.getPolicyTypes().keySet());
- break;
- case CREATE_POLICY:
+ case CREATE_POLICY ->
dbSvcTemplate.setToscaTopologyTemplate(svcTemplateFragment.getToscaTopologyTemplate());
- break;
- case DELETE_POLICY:
- dbSvcTemplate.getToscaTopologyTemplate().setPolicies(null);
- break;
- default:
- break;
+ case DELETE_POLICY -> dbSvcTemplate.getToscaTopologyTemplate().setPolicies(null);
+ default -> {
+ }
}
}
Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME,
@@ -91,9 +93,15 @@ public class TestCommonToscaServiceTemplateService {
/**
* Setup to return empty DB service template.
*/
- @Before
+ @BeforeEach
public void setUp() {
+ autoCloseable = MockitoAnnotations.openMocks(this);
Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME,
JpaToscaServiceTemplate.DEFAULT_VERSION))).thenReturn(Optional.of(new JpaToscaServiceTemplate()));
}
+
+ @AfterEach
+ public void tearDown() throws Exception {
+ autoCloseable.close();
+ }
} \ No newline at end of file
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java b/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java
index 7d85eef2..265f5271 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy API
* ================================================================================
- * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2022-2023 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,13 +27,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import java.util.Optional;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.MockitoAnnotations;
import org.onap.policy.api.main.repository.NodeTemplateRepository;
import org.onap.policy.api.main.repository.NodeTypeRepository;
import org.onap.policy.common.utils.coder.CoderException;
@@ -41,14 +41,12 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeType;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class TestNodeTemplateService {
+class TestNodeTemplateService {
@Mock
private NodeTemplateRepository nodeTemplateRepository;
@@ -63,17 +61,20 @@ public class TestNodeTemplateService {
private static final String UPDATED_NODE_TEMPLATE_JSON = "nodetemplates/nodetemplates.metadatasets.update.json";
private static ToscaServiceTemplate updatedToscaServiceTemplate;
- private StandardCoder standardCoder;
- private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator();
+ private final YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator();
ToscaServiceTemplate policyServiceTemplate;
+ AutoCloseable closeable;
+
/**
* Set up for tests.
+ *
* @throws CoderException if error in json parsing
*/
- @Before
+ @BeforeEach
public void setUp() throws CoderException {
- standardCoder = new StandardCoder();
+ closeable = MockitoAnnotations.openMocks(this);
+ StandardCoder standardCoder = new StandardCoder();
policyServiceTemplate =
yamlJsonTranslator.fromYaml(ResourceUtils.getResourceAsString(POLICY_WITH_METADATA_SET_REF),
ToscaServiceTemplate.class);
@@ -82,11 +83,15 @@ public class TestNodeTemplateService {
ToscaServiceTemplate.class);
}
+ @AfterEach
+ void tearDown() throws Exception {
+ closeable.close();
+ }
+
@Test
- public void testVerifyNodeType() {
- assertThatThrownBy(() -> {
- nodeTemplateService.verifyNodeTypeInDbTemplate(new JpaToscaNodeTemplate());
- }).hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$");
+ void testVerifyNodeType() {
+ assertThatThrownBy(() -> nodeTemplateService.verifyNodeTypeInDbTemplate(new JpaToscaNodeTemplate()))
+ .hasMessageMatching("^NODE_TYPE .* for toscaNodeTemplate .* does not exist$");
JpaToscaNodeTemplate jpaToscaNodeTemplate = new JpaToscaNodeTemplate();
PfConceptKey nodeType = new PfConceptKey("dummyType", "1.0.0");
@@ -97,19 +102,19 @@ public class TestNodeTemplateService {
}
@Test
- public void testNodeTemplateUsedInPolicy() {
+ void testNodeTemplateUsedInPolicy() {
assertDoesNotThrow(() -> nodeTemplateService.assertNodeTemplateNotUsedInPolicy("dummyName", "1.0.0",
new JpaToscaServiceTemplate(policyServiceTemplate)));
- assertThatThrownBy(() -> {
- nodeTemplateService.assertNodeTemplateNotUsedInPolicy("apexMetadata_decisionMaker", "1.0.0",
- new JpaToscaServiceTemplate(policyServiceTemplate));
- }).hasMessage("Node template is in use, it is referenced in Tosca Policy operational.apex.decisionMaker "
- + "version 1.0.0");
+ assertThatThrownBy(() -> nodeTemplateService
+ .assertNodeTemplateNotUsedInPolicy("apexMetadata_decisionMaker", "1.0.0",
+ new JpaToscaServiceTemplate(policyServiceTemplate)))
+ .hasMessage("Node template is in use, it is referenced in Tosca Policy operational.apex.decisionMaker "
+ + "version 1.0.0");
}
@Test
- public void testNodeTemplateUpdate() throws PfModelException {
+ void testNodeTemplateUpdate() {
Mockito.when(nodeTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(new JpaToscaNodeType()));
Mockito.when(nodeTemplateRepository.findById(Mockito.any())).thenReturn(Optional.of(
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java
index 4c04a08e..d46592fc 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,12 +27,12 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.MockitoAnnotations;
import org.onap.policy.api.main.repository.PdpGroupRepository;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -39,8 +40,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
-@RunWith(MockitoJUnitRunner.class)
-public class TestPdpGroupService {
+class TestPdpGroupService {
@Mock
private PdpGroupRepository pdpGroupRepository;
@@ -48,12 +48,16 @@ public class TestPdpGroupService {
@InjectMocks
private PdpGroupService pdpGroupService;
+ AutoCloseable closeable;
+
/**
* Test setup.
+ *
* @throws CoderException decode errors
*/
- @Before
+ @BeforeEach
public void setUp() throws CoderException {
+ closeable = MockitoAnnotations.openMocks(this);
var pdpGroups = new StandardCoder().decode(ResourceUtils.getResourceAsString("pdpgroups/PdpGroups.json"),
PdpGroups.class).getGroups();
List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>();
@@ -62,8 +66,13 @@ public class TestPdpGroupService {
when(pdpGroupRepository.findAll()).thenReturn(jpaPdpGroupList);
}
+ @AfterEach
+ void tearDown() throws Exception {
+ closeable.close();
+ }
+
@Test
- public void testAssertPolicyTypeNotSupportedInPdpGroup() {
+ void testAssertPolicyTypeNotSupportedInPdpGroup() {
assertThatCode(() -> pdpGroupService.assertPolicyTypeNotSupportedInPdpGroup("policy_type_not_supported",
"1.0.0")).doesNotThrowAnyException();
@@ -73,7 +82,7 @@ public class TestPdpGroupService {
}
@Test
- public void testAssertPolicyNotDeployedInPdpGroup() {
+ void testAssertPolicyNotDeployedInPdpGroup() {
assertThatCode(() -> pdpGroupService.assertPolicyNotDeployedInPdpGroup("policy_not_deployed", "1.0.0"))
.doesNotThrowAnyException();
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java
index f9baf76a..6820ad3f 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyService.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,26 +23,37 @@ package org.onap.policy.api.main.service;
import static org.assertj.core.api.Assertions.assertThatCode;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.MockitoAnnotations;
import org.onap.policy.api.main.repository.PolicyRepository;
import org.onap.policy.models.base.PfConceptKey;
-@RunWith(MockitoJUnitRunner.class)
-public class TestPolicyService {
+class TestPolicyService {
@Mock
private PolicyRepository policyRepository;
- @InjectMocks
+ @Mock
private PolicyService policyService;
+ AutoCloseable autoCloseable;
+
+ @BeforeEach
+ void before() {
+ autoCloseable = MockitoAnnotations.openMocks(this);
+ }
+
+ @AfterEach
+ void after() throws Exception {
+ autoCloseable.close();
+ }
+
@Test
- public void testDeletePolicy() {
+ void testDeletePolicy() {
PfConceptKey id = new PfConceptKey("dummy", "1.0.0");
Mockito.doNothing().when(policyRepository).deleteById(id);
assertThatCode(() -> policyService.deletePolicy(id)).doesNotThrowAnyException();
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java
index 21f1ba4d..278d5971 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,17 +23,17 @@ package org.onap.policy.api.main.service;
import static org.assertj.core.api.Assertions.assertThatCode;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.MockitoAnnotations;
import org.onap.policy.api.main.repository.PolicyTypeRepository;
import org.onap.policy.models.base.PfConceptKey;
-@RunWith(MockitoJUnitRunner.class)
-public class TestPolicyTypeService {
+class TestPolicyTypeService {
@Mock
private PolicyTypeRepository policyTypeRepository;
@@ -40,8 +41,20 @@ public class TestPolicyTypeService {
@InjectMocks
private PolicyTypeService policyTypeService;
+ AutoCloseable closeable;
+
+ @BeforeEach
+ public void setUp() {
+ closeable = MockitoAnnotations.openMocks(this);
+ }
+
+ @AfterEach
+ void tearDown() throws Exception {
+ closeable.close();
+ }
+
@Test
- public void testDeletePolicy() {
+ void testDeletePolicy() {
PfConceptKey id = new PfConceptKey("dummy", "1.0.0");
Mockito.doNothing().when(policyTypeRepository).deleteById(id);
assertThatCode(() -> policyTypeService.deletePolicyType(id)).doesNotThrowAnyException();
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java
index 8f8fc464..fee7f403 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateForNodeTemplate.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy API
* ================================================================================
- * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2022-2023 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,16 +24,14 @@ package org.onap.policy.api.main.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
@@ -42,20 +40,17 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServiceTemplateService {
+class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServiceTemplateService {
private static final String NODE_TEMPLATES_JSON = "nodetemplates/nodetemplates.metadatasets.input.tosca.json";
private static final String UPDATED_NODE_TEMPLATE_JSON = "nodetemplates/nodetemplates.metadatasets.update.json";
private static ToscaServiceTemplate toscaServiceTemplate;
private static ToscaServiceTemplate updatedToscaServiceTemplate;
- private StandardCoder standardCoder;
@InjectMocks
private ToscaServiceTemplateService toscaServiceTemplateService;
-
- @Before
+ @BeforeEach
public void setUp() {
super.setUp();
}
@@ -65,9 +60,9 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ
*
* @throws CoderException when error parsing the json
*/
- @Before
- public void fetchToscaNodeTemplateJson() throws CoderException {
- standardCoder = new StandardCoder();
+ @BeforeEach
+ void fetchToscaNodeTemplateJson() throws CoderException {
+ StandardCoder standardCoder = new StandardCoder();
toscaServiceTemplate =
standardCoder.decode(ResourceUtils.getResourceAsString(NODE_TEMPLATES_JSON), ToscaServiceTemplate.class);
updatedToscaServiceTemplate =
@@ -76,7 +71,7 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ
}
@Test
- public void testToscaNodeTemplatesGet() throws Exception {
+ void testToscaNodeTemplatesGet() throws Exception {
assertNotNull(toscaServiceTemplate);
var createdTemplate = toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate);
@@ -99,11 +94,10 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ
}
@Test
- public void testToscaNodeTemplatesCreate() throws Exception {
+ void testToscaNodeTemplatesCreate() throws Exception {
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.createToscaNodeTemplates(null);
- }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> toscaServiceTemplateService.createToscaNodeTemplates(null))
+ .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
ToscaServiceTemplate createdNodeTemplates =
toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate);
@@ -113,11 +107,10 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ
}
@Test
- public void testToscaNodeTemplateUpdate() throws Exception {
+ void testToscaNodeTemplateUpdate() throws Exception {
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.updateToscaNodeTemplates(null);
- }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> toscaServiceTemplateService.updateToscaNodeTemplates(null))
+ .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
JpaToscaNodeTemplate jpaNodeTemplate = new JpaToscaNodeTemplate();
PfConceptKey key = new PfConceptKey("apexMetadata_grpc", "1.0.0");
@@ -131,21 +124,18 @@ public class TestToscaServiceTemplateForNodeTemplate extends TestCommonToscaServ
}
@Test
- public void testToscaNodeTemplateDelete() throws Exception {
+ void testToscaNodeTemplateDelete() throws Exception {
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deleteToscaNodeTemplate(null, null);
- }).hasMessageMatching("^name is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> toscaServiceTemplateService.deleteToscaNodeTemplate(null, null))
+ .hasMessageMatching("^name is marked .*on.*ull but is null$");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deleteToscaNodeTemplate("name", null);
- }).hasMessageMatching("^version is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> toscaServiceTemplateService.deleteToscaNodeTemplate("name", null))
+ .hasMessageMatching("^version is marked .*on.*ull but is null$");
var createdTemplate = toscaServiceTemplateService.createToscaNodeTemplates(toscaServiceTemplate);
mockDbServiceTemplate(createdTemplate, null, null);
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deleteToscaNodeTemplate("dummyname", "1.0.1");
- }).hasMessage("node template dummyname:1.0.1 not found");
+ assertThatThrownBy(() -> toscaServiceTemplateService.deleteToscaNodeTemplate("dummyname", "1.0.1"))
+ .hasMessage("node template dummyname:1.0.1 not found");
ToscaServiceTemplate responseTemplate =
toscaServiceTemplateService.deleteToscaNodeTemplate("apexMetadata_decisionMaker", "1.0.0");
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java
index 69864282..14d9056e 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyCrud.java
@@ -3,8 +3,8 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
- * Modifications Copyright (C) 2020,2022 Bell Canada.
+ * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2022 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,24 +27,21 @@ package org.onap.policy.api.main.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import jakarta.ws.rs.core.Response;
import java.util.Optional;
-import javax.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -54,11 +51,10 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
*
* @author Chenfei Gao (cgao@research.att.com)
*/
-@RunWith(MockitoJUnitRunner.class)
-public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonToscaServiceTemplateService {
+class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonToscaServiceTemplateService {
- private static StandardCoder standardCoder = new StandardCoder();
- private static StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
+ private static final StandardCoder standardCoder = new StandardCoder();
+ private static final StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
private static final String POLICY_RESOURCE = "policies/vCPE.policy.monitoring.input.tosca.json";
private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.monitoring.tcagen2.yaml";
@@ -83,48 +79,43 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
@InjectMocks
private ToscaServiceTemplateService toscaServiceTemplateService;
- @Before
+ @BeforeEach
public void setUp() {
super.setUp();
}
@Test
- public void testFetchPolicies() {
+ void testFetchPolicies() {
Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME,
JpaToscaServiceTemplate.DEFAULT_VERSION))).thenReturn(Optional.empty());
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", null, null, null);
- }).hasMessage("service template not found in database");
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", null, null, null))
+ .hasMessage("service template not found in database");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", null, null);
- }).hasMessage("service template not found in database");
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", null, null))
+ .hasMessage("service template not found in database");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0", null);
- }).hasMessage("service template not found in database");
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0", null))
+ .hasMessage("service template not found in database");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchPolicies(null, null, "dummy", "1.0.0", null);
- }).hasMessage("service template not found in database");
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicies(null, null, "dummy", "1.0.0", null))
+ .hasMessage("service template not found in database");
}
@Test
- public void testFetchLatestPolicies() {
+ void testFetchLatestPolicies() {
Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME,
JpaToscaServiceTemplate.DEFAULT_VERSION))).thenReturn(Optional.empty());
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchLatestPolicies("dummy", "dummy", "dummy", null);
- }).hasMessage("service template not found in database");
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchLatestPolicies("dummy", "dummy", "dummy", null))
+ .hasMessage("service template not found in database");
}
@Test
- public void testCreatePolicy() throws Exception {
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.createPolicy("dummy", "1.0.0", new ToscaServiceTemplate());
- }).hasMessage("topology template not specified on service template");
+ void testCreatePolicy() throws Exception {
+ assertThatThrownBy(() -> toscaServiceTemplateService
+ .createPolicy("dummy", "1.0.0", new ToscaServiceTemplate()))
+ .hasMessage("topology template not specified on service template");
var policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
@@ -179,7 +170,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
}
@Test
- public void testCreateOperationalDroolsPolicy() throws CoderException {
+ void testCreateOperationalDroolsPolicy() throws CoderException {
var policyTypeServiceTemplate = standardYamlCoder.decode(
ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class);
@@ -199,7 +190,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
}
@Test
- public void testSimpleCreatePolicy() throws Exception {
+ void testSimpleCreatePolicy() throws Exception {
assertThatThrownBy(() -> {
String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE);
@@ -291,11 +282,10 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
}
@Test
- public void testDeletePolicy() throws CoderException, PfModelException {
+ void testDeletePolicy() throws CoderException {
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deletePolicy("dummy", "1.0.0", "dummy", "1.0.0");
- }).hasMessage("no policies found");
+ assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicy("dummy", "1.0.0", "dummy", "1.0.0"))
+ .hasMessage("no policies found");
var policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
@@ -312,10 +302,10 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
var exceptionMessage = "policy is in use, it is deployed in PDP group dummy subgroup dummy";
Mockito.doThrow(new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, exceptionMessage))
.when(pdpGroupService).assertPolicyNotDeployedInPdpGroup("onap.restart.tca", "1.0.0");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- "onap.restart.tca", "1.0.0");
- }).hasMessage(exceptionMessage);
+ assertThatThrownBy(() -> toscaServiceTemplateService
+ .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0"))
+ .hasMessage(exceptionMessage);
+
Mockito.doNothing().when(pdpGroupService).assertPolicyNotDeployedInPdpGroup("onap.restart.tca", "1.0.0");
var deletePolicyResponseFragment = toscaServiceTemplateService
@@ -323,14 +313,13 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
assertFalse(deletePolicyResponseFragment.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
mockDbServiceTemplate(serviceTemplate, deletePolicyResponseFragment, Operation.DELETE_POLICY);
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- "onap.restart.tca", "1.0.0");
- }).hasMessageContaining("no policies found");
+ assertThatThrownBy(() -> toscaServiceTemplateService
+ .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0"))
+ .hasMessageContaining("no policies found");
}
@Test
- public void testFetchAllPolicies() throws Exception {
+ void testFetchAllPolicies() throws Exception {
// Create Policy Type
var policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
@@ -353,7 +342,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
}
@Test
- public void testFetchSpecificPolicy_availablePolicy() throws Exception {
+ void testFetchSpecificPolicy_availablePolicy() throws Exception {
// Create Policy Type
var policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
@@ -375,7 +364,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
}
@Test
- public void testFetchSpecificPolicy_unavailablePolicy() throws Exception {
+ void testFetchSpecificPolicy_unavailablePolicy() throws Exception {
// Create Policy Type
var policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
@@ -397,7 +386,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
}
@Test
- public void testDeleteSpecificPolicy_availablePolicy() throws Exception {
+ void testDeleteSpecificPolicy_availablePolicy() throws Exception {
var policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate);
@@ -415,7 +404,7 @@ public class TestToscaServiceTemplateServiceForPolicyCrud extends TestCommonTosc
}
@Test
- public void testDeleteSpecificPolicy_unavailablePolicy() throws Exception {
+ void testDeleteSpecificPolicy_unavailablePolicy() throws Exception {
var policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate);
diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java
index cea2bcf0..9dcb4333 100644
--- a/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java
+++ b/main/src/test/java/org/onap/policy/api/main/service/TestToscaServiceTemplateServiceForPolicyTypeCrud.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,22 +22,19 @@
package org.onap.policy.api.main.service;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
-import javax.ws.rs.core.Response;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import jakarta.ws.rs.core.Response;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -45,10 +43,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
*
* @author Chenfei Gao (cgao@research.att.com)
*/
-@RunWith(MockitoJUnitRunner.class)
-public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommonToscaServiceTemplateService {
+class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommonToscaServiceTemplateService {
- private static StandardYamlCoder coder = new StandardYamlCoder();
+ private static final StandardYamlCoder coder = new StandardYamlCoder();
private static final String POLICY_TYPE_VERSION = "1.0.0";
private static final String POLICY_RESOURCE_MONITORING = "policies/vCPE.policy.monitoring.input.tosca.yaml";
@@ -76,20 +73,18 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
/**
* Test setup.
*/
- @Before
+ @BeforeEach
public void setUp() {
super.setUp();
}
@Test
- public void testFetchPolicyTypes() throws PfModelException {
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchPolicyTypes("dummy", null);
- }).hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=null) do not exist");
+ void testFetchPolicyTypes() {
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicyTypes("dummy", null))
+ .hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=null) do not exist");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchPolicyTypes("dummy", "dummy");
- }).hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=dummy) do not exist");
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchPolicyTypes("dummy", "dummy"))
+ .hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=dummy) do not exist");
// FIXME
// ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null);
@@ -97,15 +92,13 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
}
@Test
- public void testFetchLatestPolicyTypes() {
-
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.fetchLatestPolicyTypes("dummy");
- }).hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=LATEST) do not exist");
+ void testFetchLatestPolicyTypes() {
+ assertThatThrownBy(() -> toscaServiceTemplateService.fetchLatestPolicyTypes("dummy"))
+ .hasMessage("policy types for filter ToscaEntityFilter(name=dummy, version=LATEST) do not exist");
}
@Test
- public void testCreatePolicyType() throws CoderException {
+ void testCreatePolicyType() throws CoderException {
var policyTypeServiceTemplate = coder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class);
var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate);
@@ -116,10 +109,9 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
policyTypeServiceTemplate.getPolicyTypes().get("onap.policies.monitoring.tcagen2")
.setDescription("Some other description");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate);
- }).hasMessageContaining("item \"entity\" value \"onap.policies.monitoring.tcagen2:1.0.0\" INVALID, "
- + "does not equal existing entity");
+ assertThatThrownBy(() -> toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate))
+ .hasMessageContaining("item \"entity\" value \"onap.policies.monitoring.tcagen2:1.0.0\" INVALID, "
+ + "does not equal existing entity");
assertThatThrownBy(() -> {
ToscaServiceTemplate badPolicyType =
@@ -132,7 +124,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
}
@Test
- public void testCreateOperationalPolicyTypes() throws CoderException {
+ void testCreateOperationalPolicyTypes() throws CoderException {
ToscaServiceTemplate policyTypeServiceTemplate = coder.decode(
ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate);
@@ -152,7 +144,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
}
@Test
- public void testCreateApexOperationalPolicyTypes() throws CoderException {
+ void testCreateApexOperationalPolicyTypes() throws CoderException {
var policyTypeServiceTemplate = coder.decode(
ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_COMMON), ToscaServiceTemplate.class);
var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate);
@@ -168,7 +160,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
}
@Test
- public void testDeletePolicyType() throws CoderException {
+ void testDeletePolicyType() throws CoderException {
var policyTypeServiceTemplate = coder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class);
var serviceTemplate = toscaServiceTemplateService.createPolicyType(policyTypeServiceTemplate);
@@ -183,9 +175,8 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
mockDbServiceTemplate(serviceTemplate, createPolicyResponseFragment, Operation.CREATE_POLICY);
var exceptionMessage = "policy type onap.policies.monitoring.tcagen2:1.0.0 is in use, "
+ "it is referenced in policy onap.restart.tca:1.0.0";
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", "1.0.0");
- }).hasMessage(exceptionMessage);
+ assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2",
+ "1.0.0")).hasMessage(exceptionMessage);
var deletePolicyResponseFragment = toscaServiceTemplateService
.deletePolicy("onap.policies.monitoring.tcagen2", "1.0.0", "onap.restart.tca", "1.0.0");
@@ -195,9 +186,8 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
exceptionMessage = "policy type is in use, it is referenced in PDP group dummy subgroup dummy";
Mockito.doThrow(new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, exceptionMessage))
.when(pdpGroupService).assertPolicyTypeNotSupportedInPdpGroup("onap.policies.monitoring.tcagen2", "1.0.0");
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", "1.0.0");
- }).hasMessage(exceptionMessage);
+ assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2",
+ "1.0.0")).hasMessage(exceptionMessage);
Mockito.doNothing().when(pdpGroupService)
.assertPolicyTypeNotSupportedInPdpGroup("onap.policies.monitoring.tcagen2", "1.0.0");
@@ -206,8 +196,7 @@ public class TestToscaServiceTemplateServiceForPolicyTypeCrud extends TestCommon
assertFalse(deletePolicyTypeResponseFragment.getPolicyTypes().isEmpty());
mockDbServiceTemplate(serviceTemplate, deletePolicyTypeResponseFragment, Operation.DELETE_POLICY_TYPE);
- assertThatThrownBy(() -> {
- toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2", "1.0.0");
- }).hasMessage("policy type onap.policies.monitoring.tcagen2:1.0.0 not found");
+ assertThatThrownBy(() -> toscaServiceTemplateService.deletePolicyType("onap.policies.monitoring.tcagen2",
+ "1.0.0")).hasMessage("policy type onap.policies.monitoring.tcagen2:1.0.0 not found");
}
} \ No newline at end of file
diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java b/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java
index aa86d739..d7df3d81 100644
--- a/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java
+++ b/main/src/test/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializerTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,21 +24,18 @@ package org.onap.policy.api.main.startstop;
import static org.assertj.core.api.Assertions.assertThatCode;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
import org.onap.policy.api.main.PolicyApiApplication;
import org.onap.policy.api.main.config.PolicyPreloadConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
-@RunWith(SpringRunner.class)
@SpringBootTest(classes = PolicyApiApplication.class)
@ActiveProfiles("test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
-public class ApiDatabaseInitializerTest {
+class ApiDatabaseInitializerTest {
@Autowired
private PolicyPreloadConfig params;
@@ -46,7 +44,7 @@ public class ApiDatabaseInitializerTest {
private ApiDatabaseInitializer adi;
@Test
- public void testInitializeApiDatabase() {
+ void testInitializeApiDatabase() {
assertThatCode(() -> adi.initializeApiDatabase(params.getPolicyTypes(),
params.getPolicies())).doesNotThrowAnyException();
diff --git a/main/src/test/resources/META-INF/persistence.xml b/main/src/test/resources/META-INF/persistence.xml
index 68f49dae..f73f7d05 100644
--- a/main/src/test/resources/META-INF/persistence.xml
+++ b/main/src/test/resources/META-INF/persistence.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START=======================================================
- Copyright (C) 2019-2020 Nordix Foundation.
+ Copyright (C) 2019-2020, 2023 Nordix Foundation.
Modifications Copyright (C) 2021 AT&T Intellectual Property.
Modifications Copyright (C) 2023 Bell Canada. All rights reserved.
================================================================================
@@ -56,7 +56,7 @@
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger</class>
<properties>
- <property name="javax.persistence.schema-generation.database.action" value="create" />
+ <property name="jakarta.persistence.schema-generation.database.action" value="create" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="INFO" />
diff --git a/packages/policy-api-docker/pom.xml b/packages/policy-api-docker/pom.xml
index c1d3b8c1..f9d2b97d 100644
--- a/packages/policy-api-docker/pom.xml
+++ b/packages/policy-api-docker/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>api-packages</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>
diff --git a/packages/policy-api-docker/src/main/docker/Dockerfile b/packages/policy-api-docker/src/main/docker/Dockerfile
index 7f41c757..91ede32d 100644
--- a/packages/policy-api-docker/src/main/docker/Dockerfile
+++ b/packages/policy-api-docker/src/main/docker/Dockerfile
@@ -26,7 +26,7 @@ RUN mkdir /packages /extracted
COPY /maven/lib/policy-api.tar.gz /packages/
RUN tar xvzf /packages/policy-api.tar.gz --directory /extracted/
-FROM onap/policy-jre-alpine:3.0.0-SNAPSHOT
+FROM onap/policy-jre-alpine:3.0.1-SNAPSHOT
LABEL maintainer="Policy Team"
LABEL org.opencontainers.image.title="Policy API"
diff --git a/packages/policy-api-tarball/pom.xml b/packages/policy-api-tarball/pom.xml
index a666ec5f..ecab83f0 100644
--- a/packages/policy-api-tarball/pom.xml
+++ b/packages/policy-api-tarball/pom.xml
@@ -20,12 +20,12 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>api-packages</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>policy-api-tarball</artifactId>
diff --git a/packages/pom.xml b/packages/pom.xml
index a1aabfac..520be642 100644
--- a/packages/pom.xml
+++ b/packages/pom.xml
@@ -20,12 +20,13 @@
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>policy-api</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>api-packages</artifactId>
@@ -33,7 +34,7 @@
<name>${project.artifactId}</name>
<properties>
- <!-- There is no code in this sub-module, only holds interfaces. So skip sonar. -->
+ <!-- There is no code in this submodule, only holds interfaces. So skip sonar. -->
<sonar.skip>true</sonar.skip>
</properties>
diff --git a/pom.xml b/pom.xml
index deb8fa33..fe58f2bc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
================================================================================
Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation.
Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,19 +22,19 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.parent</groupId>
<artifactId>integration</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- <relativePath />
+ <version>4.0.1-SNAPSHOT</version>
+ <relativePath/>
</parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>policy-api</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
@@ -42,8 +42,8 @@
<description>Code that define our external API.</description>
<properties>
- <policy.common.version>2.0.0-SNAPSHOT</policy.common.version>
- <policy.models.version>3.0.0-SNAPSHOT</policy.models.version>
+ <policy.common.version>2.0.1-SNAPSHOT</policy.common.version>
+ <policy.models.version>3.0.1-SNAPSHOT</policy.models.version>
</properties>
<modules>
@@ -58,35 +58,30 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.onap.policy.common</groupId>
<artifactId>policy-endpoints</artifactId>
<version>${policy.common.version}</version>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-server</artifactId>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-security</artifactId>
+ <artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</dependency>
<dependency>
- <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-servlet</artifactId>
- <version>${version.jersey}</version>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
</dependency>
</dependencies>
diff --git a/testsuites/performance/pom.xml b/testsuites/performance/pom.xml
index 9dafc8bd..9ee4c164 100644
--- a/testsuites/performance/pom.xml
+++ b/testsuites/performance/pom.xml
@@ -18,12 +18,13 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>api-testsuites</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>api-performance</artifactId>
<build>
diff --git a/testsuites/pom.xml b/testsuites/pom.xml
index c49276c3..dad3137f 100644
--- a/testsuites/pom.xml
+++ b/testsuites/pom.xml
@@ -18,19 +18,20 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>policy-api</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>api-testsuites</artifactId>
<packaging>pom</packaging>
<properties>
- <!-- There is no code in this sub-module, only holds interfaces. So skip sonar. -->
+ <!-- There is no code in this submodule, only holds interfaces. So skip sonar. -->
<sonar.skip>true</sonar.skip>
</properties>
diff --git a/testsuites/stability/pom.xml b/testsuites/stability/pom.xml
index fcd0bd40..57d7491d 100644
--- a/testsuites/stability/pom.xml
+++ b/testsuites/stability/pom.xml
@@ -18,12 +18,13 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.policy.api</groupId>
<artifactId>api-testsuites</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.0.1-SNAPSHOT</version>
</parent>
<artifactId>api-stability</artifactId>
<build>
diff --git a/version.properties b/version.properties
index 4ba0a9a8..3288dcdc 100644
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
minor=3
minor=0
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}