diff options
author | 2019-04-11 18:47:26 -0400 | |
---|---|---|
committer | 2019-04-11 20:11:06 -0400 | |
commit | e696cd9f5bafd0830017ad38355c2e8fe64f980b (patch) | |
tree | 9dababf31b5c9972d807704d9ab8cb5811994b65 /main/src/main | |
parent | a229e2bccfdcf40c56c4d87d9e3cc5cd9dabb2a8 (diff) |
Add junit tests for endpoints
Add junit tests to improve code coverage to > 80%.
Modify db setting and remove db authorization from persistence.
Issue-ID: POLICY-1441
Change-Id: I6070ac9ba6adba836adeeb547610c27dccf577bd
Signed-off-by: Chenfei Gao <cgao@research.att.com>
Diffstat (limited to 'main/src/main')
-rw-r--r-- | main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java | 64 | ||||
-rw-r--r-- | main/src/main/resources/META-INF/persistence.xml | 6 |
2 files changed, 63 insertions, 7 deletions
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 0c46df4e..1863b23a 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 @@ -364,6 +364,66 @@ public class ApiRestController { }
/**
+ * 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
+ */
+ @GET
+ @Path("/policytypes/{policyTypeId}/versions/latest")
+ @ApiOperation(value = "Retrieve latest version of a policy type",
+ notes = "Returns latest version for the specified policy type",
+ response = ToscaServiceTemplate.class,
+ responseHeaders = {
+ @ResponseHeader(name = "X-MinorVersion",
+ description = "Used to request or communicate a MINOR version back from the client"
+ + " to the server, and from the server back to the client",
+ response = String.class),
+ @ResponseHeader(name = "X-PatchVersion",
+ description = "Used only to communicate a PATCH version in a response for"
+ + " troubleshooting purposes only, and will not be provided by"
+ + " the client on request",
+ response = String.class),
+ @ResponseHeader(name = "X-LatestVersion",
+ description = "Used only to communicate an API's latest version",
+ response = String.class),
+ @ResponseHeader(name = "X-ONAP-RequestID",
+ description = "Used to track REST transactions for logging purpose",
+ response = UUID.class)
+ },
+ authorizations = @Authorization(value = "basicAuth"),
+ tags = { "PolicyType", },
+ extensions = {
+ @Extension(name = "interface info", properties = {
+ @ExtensionProperty(name = "api-version", value = "1.0.0"),
+ @ExtensionProperty(name = "last-mod-release", value = "Dublin")
+ })
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = 401, message = "Authentication Error"),
+ @ApiResponse(code = 403, message = "Authorization Error"),
+ @ApiResponse(code = 404, message = "Resource Not Found"),
+ @ApiResponse(code = 500, message = "Internal Server Error")
+ })
+ public Response getLatestVersionOfPolicyType(
+ @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
+ @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+
+ try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
+ updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(serviceTemplate).build();
+ } catch (PfModelException | PfModelRuntimeException pfme) {
+ updateApiStatisticsCounter(Target.POLICY_TYPE, Result.FAILURE, HttpMethod.GET);
+ return addLoggingHeaders(addVersionControlHeaders(
+ Response.status(pfme.getErrorResponse().getResponseCode())), requestId)
+ .entity(pfme.getErrorResponse()).build();
+ }
+ }
+
+ /**
* Creates a new policy type.
*
* @param body the body of policy type following TOSCA definition
@@ -694,7 +754,7 @@ public class ApiRestController { * @return the Response object containing the results of the API operation
*/
@GET
- @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/latest")
+ @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/latest")
@ApiOperation(value = "Retrieve the latest version of a particular policy",
notes = "Returns the latest version of specified policy",
response = ToscaServiceTemplate.class,
@@ -760,7 +820,7 @@ public class ApiRestController { * @return the Response object containing the results of the API operation
*/
@GET
- @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/deployed")
+ @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/deployed")
@ApiOperation(value = "Retrieve deployed versions of a particular policy in pdp groups",
notes = "Returns deployed versions of specified policy in pdp groups",
response = ToscaPolicy.class, responseContainer = "List",
diff --git a/main/src/main/resources/META-INF/persistence.xml b/main/src/main/resources/META-INF/persistence.xml index 7bda7dab..1d4abd42 100644 --- a/main/src/main/resources/META-INF/persistence.xml +++ b/main/src/main/resources/META-INF/persistence.xml @@ -33,14 +33,10 @@ <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class> <properties> - <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" /> - <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://policydb:3306/policy" /> - <property name="javax.persistence.jdbc.user" value="policy_user" /> - <property name="javax.persistence.jdbc.password" value="policy_user" /> <property name="javax.persistence.schema-generation.database.action" value="create" /> <property name="eclipselink.ddl-generation" value="create-or-extend-tables" /> <property name="eclipselink.ddl-generation.output-mode" value="database" /> <property name="eclipselink.logging.level" value="INFO" /> </properties> </persistence-unit> -</persistence>
\ No newline at end of file +</persistence> |