Merge "Remove more duplicate code from models"
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Thu, 18 Feb 2021 16:34:29 +0000 (16:34 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 18 Feb 2021 16:34:29 +0000 (16:34 +0000)
models-decisions/src/main/java/org/onap/policy/models/decisions/concepts/DecisionRequest.java
models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
models-interactions/model-impl/aai/src/test/java/org/onap/policy/aai/AaiManagerTest.java
models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/MainTest.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringProperties.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithToscaProperties.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithToscaPropertiesTest.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithStringPropertiesTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithToscaPropertiesTest.java [new file with mode: 0644]

index ca1e9e2..163d2cf 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Decision Models
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.policy.models.decisions.concepts;
 
 import com.google.gson.annotations.SerializedName;
+import java.time.LocalDate;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.ZoneOffset;
 import java.util.HashMap;
 import java.util.Map;
 import lombok.Data;
@@ -53,6 +57,18 @@ public class DecisionRequest {
     @SerializedName("action")
     private String  action;
 
+    @SerializedName("currentDateTime")
+    private OffsetDateTime currentDateTime;
+
+    @SerializedName("currentDate")
+    private LocalDate currentDate;
+
+    @SerializedName("currentTime")
+    private OffsetTime currentTime;
+
+    @SerializedName("timeZone")
+    private ZoneOffset timeZone;
+
     @SerializedName("resource")
     private Map<String, Object> resource;
 
@@ -71,6 +87,10 @@ public class DecisionRequest {
             this.getContext().putAll(request.getContext());
         }
         this.setAction(request.getAction());
+        this.setCurrentDate(request.getCurrentDate());
+        this.setCurrentDateTime(request.getCurrentDateTime());
+        this.setCurrentTime(request.getCurrentTime());
+        this.setTimeZone(request.getTimeZone());
         if (request.getResource() != null) {
             this.setResource(new HashMap<>());
             this.getResource().putAll(request.getResource());
index 76817df..16ee887 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * aai
  * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. 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 Samsung Electronics Co., Ltd.
  * ================================================================================
@@ -59,10 +59,10 @@ public final class AaiManager {
     private final RestManager restManager;
 
     /** custom query and other AAI resource URLs. */
-    private static final String CQ_URL = "/aai/v16/query?format=resource";
-    private static final String TENANT_URL = "/aai/v16/search/nodes-query?"
+    private static final String CQ_URL = "/aai/v21/query?format=resource";
+    private static final String TENANT_URL = "/aai/v21/search/nodes-query?"
                     + "search-node-type=vserver&filter=vserver-name:EQUALS:";
-    private static final String PREFIX = "/aai/v16";
+    private static final String PREFIX = "/aai/v21";
     private static final String PNF_URL = PREFIX + "/network/pnfs/pnf/";
     private static final String AAI_DEPTH_SUFFIX = "?depth=0";
 
index 33934d9..9b20fe9 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * aai
  * ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -94,9 +94,6 @@ public class AaiManagerTest {
         when(restManagerMock.put(eq(""), eq("Foo"), eq("Bar"), anyMap(), anyString(), anyString()))
                 .thenReturn(httpResponseErr0);
 
-        when(restManagerMock.get(eq("/aai/v11/query?format=resource"), eq("Foo"), eq("Bar"), anyMap()))
-                .thenReturn(httpResponseErr0);
-
         AaiCqResponse aaiCqResponseNull =
                 aaiManager.getCustomQueryResponse("", "Foo", "Bar", vserverNameRequestId, "Foo");
         assertNull(aaiCqResponseNull);
@@ -105,9 +102,6 @@ public class AaiManagerTest {
         when(restManagerMock.put(eq("Error"), eq("Foo"), eq("Bar"), anyMap(), anyString(), anyString()))
                 .thenReturn(httpResponseErr1);
 
-        when(restManagerMock.get(eq("Error/aai/v11/query?format=resource"), eq("Foo"), eq("Bar"), anyMap()))
-                .thenReturn(httpResponseErr1);
-
         AaiCqResponse aaiCqResponseErr =
                 aaiManager.getCustomQueryResponse("Error", "Foo", "Bar", vserverNameRequestId, "Foo");
         assertNull(aaiCqResponseErr);
index 27afb7b..adfa6d4 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * simulators
  * ================================================================================
- * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018, 2020-2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@ package org.onap.policy.simulators;
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
-import java.util.UUID;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.PUT;
@@ -37,33 +36,15 @@ import org.apache.commons.io.IOUtils;
 @Path("/aai")
 public class AaiSimulatorJaxRs {
 
-    private static final String DISABLE_CLOSEDLOOP = "disableClosedLoop";
-    private static final String ERROR = "error";
     private static final String GETFAIL = "getFail";
 
     /**
      * A&AI get query.
      *
-     * @param vnfId the VNF Id
      * @return the result
      */
     @GET
-    @Path("/v8/network/generic-vnfs/generic-vnf/{vnfId}")
-    @Consumes(MediaType.APPLICATION_JSON)
-    @Produces("application/json")
-    public String aaiGetQuery(@PathParam("vnfId") final String vnfId) {
-        return "{\"relationship-list\": {\"relationship\":[{\"related-to-property\": [{\"property-key\": "
-            + "\"service-instance.service-instance-name\"}]},{\"related-to-property\": [ {\"property-key\": "
-            + "\"vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
-    }
-
-    /**
-     * A&AI get query.
-     *
-     * @return the result
-     */
-    @GET
-    @Path("/v16/search/nodes-query")
+    @Path("/{version:v16|v21}/search/nodes-query")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces("application/json")
     public String aaiGetVserverQuery(@QueryParam("filter") final String filter) {
@@ -88,7 +69,7 @@ public class AaiSimulatorJaxRs {
      * @throws IOException if a response file cannot be read
      */
     @PUT
-    @Path("/v16/query")
+    @Path("/{version:v16|v21}/query")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces("application/json")
     public String aaiPutQuery(final String req) throws IOException {
@@ -103,7 +84,7 @@ public class AaiSimulatorJaxRs {
      * @throws IOException if a response file cannot be read
      */
     @GET
-    @Path("/v16/network/pnfs/pnf/{pnfName}")
+    @Path("/{version:v16|v21}/network/pnfs/pnf/{pnfName}")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces("application/json")
     public String aaiGetPnfQuery(@PathParam("pnfName") final String pnfName) throws IOException {
@@ -114,163 +95,4 @@ public class AaiSimulatorJaxRs {
         return IOUtils.toString(getClass().getResource("aai/AaiGetPnfResponse.json"),
                         StandardCharsets.UTF_8);
     }
-
-    /**
-     * Get by VNF name.
-     *
-     * @param vnfName the VNF name
-     * @return the response
-     */
-    @GET
-    @Path("/v11/network/generic-vnfs/generic-vnf")
-    @Consumes(MediaType.APPLICATION_JSON)
-    @Produces("application/json")
-    public String getByVnfName(@QueryParam("vnf-name") final String vnfName) {
-        if (GETFAIL.equals(vnfName)) {
-            return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not"
-                + " found for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
-                + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs"
-                + "/generic-vnf\",\"ERR.5.4.6114\"]}}}";
-        }
-        final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfName);
-        if (ERROR.equals(vnfName)) {
-            return "{ \"vnf-id\": \"error\", \"vnf-name\": \"" + vnfName
-                + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \""
-                + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \""
-                + "ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \""
-                + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \""
-                + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", "
-                + "\"is-closed-loop-disabled\": " + isDisabled
-                + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \""
-                + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer/"
-                + "1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/"
-                + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \""
-                + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \""
-                + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type"
-                + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \""
-                + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01"
-                + "\"} ], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name"
-                + "\"}]},{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/"
-                + "cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/"
-                + "USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver/3b2558f4-39d8-40e7-bfc7-30660fb52c45"
-                + "\", \"relationship-data\":[{ \"relationship-key\": \"cloud-region.cloud-owner\", \""
-                + "relationship-value\": \"att-aic\"},{ \"relationship-key\": \"cloud-region.cloud-region-id"
-                + "\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \"tenant.tenant-id"
-                + "\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \"relationship-key\": \""
-                + "vserver.vserver-id\", \"relationship-value\": \"3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \""
-                + "related-to-property\": [ {\"property-key\": \"vserver.vserver-name\",\"property-value\": \""
-                + "USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
-
-        }
-        final String vnfId = getUuidValue(vnfName, "5e49ca06-2972-4532-9ed4-6d071588d792");
-        return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName
-            + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \""
-            + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"ATT"
-            + "\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \""
-            + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \""
-            + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", "
-            + "\"is-closed-loop-disabled\": " + isDisabled
-            + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \""
-            + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer"
-            + "/1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/"
-            + "service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \"relationship-data\":[{ \""
-            + "relationship-key\": \"customer.global-customer-id\", \"relationship-value\": \""
-            + "1610_Func_Global_20160817084727\"},{ \"relationship-key\": \"service-subscription.service-type"
-            + "\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key\": \""
-            + "service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} ], \""
-            + "related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},{ \""
-            + "related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/"
-            + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver"
-            + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \""
-            + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \""
-            + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \""
-            + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \""
-            + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \""
-            + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \""
-            + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
-    }
-
-    /**
-     * Get by VNF Id.
-     *
-     * @param vnfId the VNF Id
-     * @return the response
-     */
-    @GET
-    @Path("/v11/network/generic-vnfs/generic-vnf/{vnfId}")
-    @Consumes(MediaType.APPLICATION_JSON)
-    @Produces("application/json")
-    public String getByVnfId(@PathParam("vnfId") final String vnfId) {
-        if (GETFAIL.equals(vnfId)) {
-            return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
-                + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
-                + "generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/"
-                + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}";
-        }
-        final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfId);
-        final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01");
-        return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName
-            + "\", \"vnf-type\": \"RT\", \"service-id\": \""
-            + "d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"equipment-role\": \"UCPE\", \"orchestration-status"
-            + "\": \"created\", \"management-option\": \"ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \""
-            + "ipv4-loopback0-address\": \"32.40.64.57\", \"nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345"
-            + "\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, "
-            + "\"prov-status\":\"ACTIVE\", \"" + "" + "is-closed-loop-disabled\": " + isDisabled
-            + ", \"resource-version\": \"1493389458092\", \""
-            + "relationship-list\": {\"relationship\":[{ \"related-to\": \"service-instance\", \"related-link"
-            + "\": \"/aai/v11/business/customers/customer/1610_Func_Global_20160817084727/service-subscriptions"
-            + "/service-subscription/uCPE-VMS/service-instances/service-instance/USUCP0PCOIL0110UJZZ01\", \""
-            + "relationship-data\":[{ \"relationship-key\": \"customer.global-customer-id\", \""
-            + "relationship-value\": \"1610_Func_Global_20160817084727\"},{ \"relationship-key\": \""
-            + "service-subscription.service-type\", \"relationship-value\": \"uCPE-VMS\"},{ \"relationship-key"
-            + "\": \"service-instance.service-instance-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01\"} "
-            + "], \"related-to-property\": [{\"property-key\": \"service-instance.service-instance-name\"}]},"
-            + "{ \"related-to\": \"vserver\", \"related-link\": \"/aai/v11/cloud-infrastructure/cloud-regions/"
-            + "cloud-region/att-aic/AAIAIC25/tenants/tenant/USUCP0PCOIL0110UJZZ01%3A%3AuCPE-VMS/vservers/vserver"
-            + "/3b2558f4-39d8-40e7-bfc7-30660fb52c45\", \"relationship-data\":[{ \"relationship-key\": \""
-            + "cloud-region.cloud-owner\", \"relationship-value\": \"att-aic\"},{ \"relationship-key\": \""
-            + "cloud-region.cloud-region-id\", \"relationship-value\": \"AAIAIC25\"},{ \"relationship-key\": \""
-            + "tenant.tenant-id\", \"relationship-value\": \"USUCP0PCOIL0110UJZZ01::uCPE-VMS\"},{ \""
-            + "relationship-key\": \"vserver.vserver-id\", \"relationship-value\": \""
-            + "3b2558f4-39d8-40e7-bfc7-30660fb52c45\"} ], \"related-to-property\": [ {\"property-key\": \""
-            + "vserver.vserver-name\",\"property-value\": \"USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}";
-    }
-
-    /**
-     * Get by VServer name.
-     *
-     * @param vserverName the VServer name
-     * @return the response
-     */
-    @GET
-    @Path("/v11/nodes/vservers")
-    @Consumes(MediaType.APPLICATION_JSON)
-    @Produces("application/json")
-    public String getByVserverName(@QueryParam("vserver-name") final String vserverName) {
-        if (GETFAIL.equals(vserverName)) {
-            return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
-                + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not"
-                + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}";
-        }
-        final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vserverName);
-        final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8");
-        return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \""
-            + vserverName
-            + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"in-maint\": false, \"is-closed-loop-disabled\": "
-            + isDisabled + ", \"prov-status\":\"ACTIVE\", \"resource-version\": \"1494001931513\", "
-            + "\"relationship-list\": {\"relationship\":[{ \"related-to"
-            + "\": \"generic-vnf\", \"related-link\": \"/aai/v11/network/generic-vnfs/generic-vnf/"
-            + "e1a41e99-4ede-409a-8f9d-b5e12984203a\", \"relationship-data\": [ {\"relationship-key\": \""
-            + "generic-vnf.vnf-id\",\"relationship-value\": \"e1a41e99-4ede-409a-8f9d-b5e12984203a\" }], \""
-            + "related-to-property\": [ {\"property-key\": \"generic-vnf.vnf-name\",\"property-value\": \""
-            + "USMSO1SX7NJ0103UJSW01\" }]},{ \"related-to\": \"pserver\", \"related-link\": \"/aai/v11/"
-            + "cloud-infrastructure/pservers/pserver/USMSO1SX7NJ0103UJZZ01\", \"relationship-data\": [ {\""
-            + "relationship-key\": \"pserver.hostname\",\"relationship-value\": \"USMSO1SX7NJ0103UJZZ01\" }], \""
-            + "related-to-property\": [{\"property-key\": \"pserver.pserver-name2\"}]} ]}}]}";
-    }
-
-    private String getUuidValue(final String value, final String defaultValue) {
-        return value != null ? UUID.nameUUIDFromBytes(value.getBytes()).toString() : defaultValue;
-    }
-
 }
index 1f52ed1..bb4fa7c 100644 (file)
@@ -145,11 +145,11 @@ public class MainTest {
                         .allowSelfSignedCerts(true).basePath("aai").build();
         HttpClient client = HttpClientFactoryInstance.getClientFactory().build(params);
 
-        Response response = client.get("/v8/network/generic-vnfs/generic-vnf/my-vnf");
+        Response response = client.get("/v21/network/pnfs/pnf/demo-pnf");
         assertEquals(200, response.getStatus());
 
         String result = response.readEntity(String.class);
-        assertThat(result).contains("USUCP0PCOIL0110UJZZ01-vsrx");
+        assertThat(result).contains("model-123456");
     }
 
     /**
index 54bd540..afe4a84 100644 (file)
@@ -55,7 +55,7 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
      * The Default Constructor creates a {@link JpaToscaWithStringProperties} object with
      * a null key.
      */
-    public JpaToscaWithStringProperties() {
+    protected JpaToscaWithStringProperties() {
         this(new PfConceptKey());
     }
 
@@ -65,7 +65,7 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
      *
      * @param key the key
      */
-    public JpaToscaWithStringProperties(@NonNull final PfConceptKey key) {
+    protected JpaToscaWithStringProperties(@NonNull final PfConceptKey key) {
         super(key);
     }
 
@@ -74,7 +74,7 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
      *
      * @param copyConcept the concept to copy from
      */
-    public JpaToscaWithStringProperties(@NonNull final JpaToscaWithStringProperties<T> copyConcept) {
+    protected JpaToscaWithStringProperties(@NonNull final JpaToscaWithStringProperties<T> copyConcept) {
         super(copyConcept);
         this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
     }
@@ -84,7 +84,7 @@ public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProp
      *
      * @param authorativeConcept the authorative concept to copy from
      */
-    public JpaToscaWithStringProperties(final T authorativeConcept) {
+    protected JpaToscaWithStringProperties(final T authorativeConcept) {
         super(new PfConceptKey());
         this.fromAuthorative(authorativeConcept);
     }
index 873d900..33e4e86 100644 (file)
@@ -66,7 +66,7 @@ public abstract class JpaToscaWithToscaProperties<T extends ToscaWithToscaProper
      * The Default Constructor creates a {@link JpaToscaWithToscaProperties} object with a
      * null key.
      */
-    public JpaToscaWithToscaProperties() {
+    protected JpaToscaWithToscaProperties() {
         this(new PfConceptKey());
     }
 
@@ -76,7 +76,7 @@ public abstract class JpaToscaWithToscaProperties<T extends ToscaWithToscaProper
      *
      * @param key the key
      */
-    public JpaToscaWithToscaProperties(@NonNull final PfConceptKey key) {
+    protected JpaToscaWithToscaProperties(@NonNull final PfConceptKey key) {
         super(key);
     }
 
@@ -85,7 +85,7 @@ public abstract class JpaToscaWithToscaProperties<T extends ToscaWithToscaProper
      *
      * @param copyConcept the concept to copy from
      */
-    public JpaToscaWithToscaProperties(final JpaToscaWithToscaProperties<T> copyConcept) {
+    protected JpaToscaWithToscaProperties(final JpaToscaWithToscaProperties<T> copyConcept) {
         super(copyConcept);
         this.properties = copyConcept.properties == null ? null : new LinkedHashMap<>(copyConcept.properties);
     }
@@ -95,7 +95,7 @@ public abstract class JpaToscaWithToscaProperties<T extends ToscaWithToscaProper
      *
      * @param authorativeConcept the authorative concept to copy from
      */
-    public JpaToscaWithToscaProperties(final T authorativeConcept) {
+    protected JpaToscaWithToscaProperties(final T authorativeConcept) {
         this.fromAuthorative(authorativeConcept);
     }
 
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithToscaPropertiesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaWithToscaPropertiesTest.java
new file mode 100644 (file)
index 0000000..213f93c
--- /dev/null
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.authorative.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import java.util.Map;
+import org.junit.Test;
+
+public class ToscaWithToscaPropertiesTest {
+
+    @Test
+    public void test() {
+        ToscaProperty prop1 = new ToscaProperty();
+        prop1.setDescription("description A");
+
+        ToscaProperty prop2 = new ToscaProperty();
+        prop2.setDescription("description B");
+
+        ToscaWithToscaProperties tosca = new ToscaWithToscaProperties();
+        assertEquals(tosca, new ToscaWithToscaProperties(tosca));
+
+        tosca.setProperties(Map.of("abc", prop1, "def", prop2));
+        assertEquals(tosca, new ToscaWithToscaProperties(tosca));
+
+        assertNotEquals(tosca, new ToscaWithToscaProperties());
+
+        assertThatThrownBy(() -> new ToscaWithToscaProperties(null)).hasMessageContaining("copyObject")
+                        .hasMessageContaining("is null");
+    }
+}
index 23e0e6a..7cd6fac 100644 (file)
@@ -104,17 +104,15 @@ public class JpaToscaWithStringPropertiesTest {
         jpa.setDescription(SOME_DESCRIPTION);
         jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
 
-        assertThat(jpa.compareTo(null)).isNegative();
-        assertThat(jpa.compareTo(jpa)).isZero();
-        assertThat(jpa.compareTo(new PfConceptKey())).isNotZero();
+        assertThat(jpa).isNotEqualByComparingTo(null).isEqualByComparingTo(jpa).isNotEqualByComparingTo(new MyJpa2());
 
         MyJpa jpa2 = new MyJpa();
         jpa2.setDescription(SOME_DESCRIPTION);
         jpa2.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
-        assertThat(jpa.compareTo(jpa2)).isZero();
+        assertThat(jpa).isEqualByComparingTo(jpa2);
 
         jpa2.setProperties(Map.of(KEY1, STRING1));
-        assertThat(jpa.compareTo(jpa2)).isNotZero();
+        assertThat(jpa).isNotEqualByComparingTo(jpa2);
     }
 
     @Test
@@ -211,4 +209,8 @@ public class JpaToscaWithStringPropertiesTest {
             return propValue.toString();
         }
     }
+
+    private static class MyJpa2 extends MyJpa {
+        private static final long serialVersionUID = 1L;
+    }
 }
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithToscaPropertiesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaWithToscaPropertiesTest.java
new file mode 100644 (file)
index 0000000..e259edf
--- /dev/null
@@ -0,0 +1,281 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithToscaProperties;
+
+public class JpaToscaWithToscaPropertiesTest {
+    private static final String SOME_DESCRIPTION = "some description";
+    private static final String KEY1 = "abc";
+    private static final String KEY2 = "def";
+    private static final PfConceptKey CONCEPT_KEY1 = new PfConceptKey("hello", "1.2.3");
+    private static final PfConceptKey CONCEPT_KEY2 = new PfConceptKey("world", "3.2.1");
+    private static final PfReferenceKey REF_KEY1 = new PfReferenceKey(CONCEPT_KEY1);
+    private static final PfReferenceKey REF_KEY2 = new PfReferenceKey(CONCEPT_KEY2);
+    private static final JpaToscaProperty JPA_PROP1 = new JpaToscaProperty(REF_KEY1);
+    private static final JpaToscaProperty JPA_PROP2 = new JpaToscaProperty(REF_KEY2);
+    private static ToscaProperty PROP1;
+    private static ToscaProperty PROP2;
+    private static final String DESCRIPT1 = "description A";
+    private static final String DESCRIPT2 = "description B";
+
+    private MyJpa jpa;
+
+    /**
+     * Initializes the properties.
+     */
+    @BeforeClass
+    public static void setUpBeforeClass() {
+        JPA_PROP1.setDescription(DESCRIPT1);
+        JPA_PROP2.setDescription(DESCRIPT2);
+
+        PROP1 = JPA_PROP1.toAuthorative();
+        PROP2 = JPA_PROP2.toAuthorative();
+    }
+
+    @Before
+    public void setUp() {
+        jpa = new MyJpa();
+    }
+
+    @Test
+    public void testGetKeys() {
+        PfConceptKey key = new PfConceptKey("bye", "9.8.7");
+
+        jpa = new MyJpa(key);
+        jpa.setDescription(SOME_DESCRIPTION);
+        jpa.setProperties(Map.of(KEY1, JPA_PROP1, KEY2, JPA_PROP2));
+
+        // properties should be included
+
+        List<PfKey> keys = jpa.getKeys();
+        Collections.sort(keys);
+
+        assertThat(keys).isEqualTo(
+                        List.of(PfConceptKey.getNullKey(), PfConceptKey.getNullKey(), key, REF_KEY1, REF_KEY2));
+    }
+
+    @Test
+    public void testClean() {
+        jpa.clean();
+
+        jpa.setDescription("  some description  ");
+
+        JpaToscaProperty prop1 = new JpaToscaProperty(JPA_PROP1);
+        prop1.setDescription(DESCRIPT1 + " ");
+
+        JpaToscaProperty prop2 = new JpaToscaProperty(JPA_PROP2);
+        prop2.setDescription(" " + DESCRIPT2);
+
+        jpa.setProperties(Map.of(KEY1, prop1, KEY2, prop2));
+
+        jpa.clean();
+        assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+        assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, JPA_PROP1, KEY2, JPA_PROP2));
+    }
+
+    @Test
+    public void testToAuthorative() {
+        jpa.setDescription(SOME_DESCRIPTION);
+        jpa.setProperties(Map.of(KEY1, JPA_PROP1, KEY2, JPA_PROP2));
+
+        MyTosca tosca = jpa.toAuthorative();
+        assertEquals(SOME_DESCRIPTION, tosca.getDescription());
+        assertThat(tosca.getProperties()).isEqualTo(Map.of(KEY1, PROP1, KEY2, PROP2));
+    }
+
+    @Test
+    public void testFromAuthorative() {
+        MyTosca tosca = new MyTosca();
+        tosca.setDescription(SOME_DESCRIPTION);
+
+        jpa.fromAuthorative(tosca);
+        assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+        assertThat(jpa.getProperties()).isNull();
+
+        tosca.setProperties(Map.of(KEY1, PROP1, KEY2, PROP2));
+
+        JpaToscaProperty jpa1 = new JpaToscaProperty(PROP1);
+        jpa1.setKey(new PfReferenceKey(jpa.getKey(), KEY1));
+
+        JpaToscaProperty jpa2 = new JpaToscaProperty(PROP2);
+        jpa2.setKey(new PfReferenceKey(jpa.getKey(), KEY2));
+
+        jpa = new MyJpa();
+        jpa.fromAuthorative(tosca);
+        assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+        assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, jpa1, KEY2, jpa2));
+    }
+
+    @Test
+    public void testCompareTo() {
+        jpa.setDescription(SOME_DESCRIPTION);
+        jpa.setProperties(Map.of(KEY1, JPA_PROP1, KEY2, JPA_PROP2));
+
+        assertThat(jpa).isNotEqualByComparingTo(null).isEqualByComparingTo(jpa).isNotEqualByComparingTo(new MyJpa2());
+
+        MyJpa jpa2 = new MyJpa();
+        jpa2.setDescription(SOME_DESCRIPTION);
+        jpa2.setProperties(Map.of(KEY1, JPA_PROP1, KEY2, JPA_PROP2));
+        assertThat(jpa).isEqualByComparingTo(jpa2);
+
+        jpa2.setProperties(Map.of(KEY1, JPA_PROP1));
+        assertThat(jpa).isNotEqualByComparingTo(jpa2);
+    }
+
+    @Test
+    public void testJpaToscaWithToscaProperties() {
+        assertThat(jpa.getProperties()).isNull();
+        assertThat(jpa.getKey().isNullKey()).isTrue();
+    }
+
+    @Test
+    public void testJpaToscaWithToscaPropertiesPfConceptKey() {
+        jpa = new MyJpa(CONCEPT_KEY1);
+        assertEquals(CONCEPT_KEY1, jpa.getKey());
+    }
+
+    @Test
+    public void testJpaToscaWithToscaPropertiesJpaToscaWithToscaPropertiesOfT() {
+        jpa.setDescription(SOME_DESCRIPTION);
+        assertEquals(jpa, new MyJpa(jpa));
+
+        jpa.setProperties(Map.of(KEY1, JPA_PROP1, KEY2, JPA_PROP2));
+        assertEquals(jpa, new MyJpa(jpa));
+    }
+
+    @Test
+    public void testJpaToscaWithToscaPropertiesT() {
+        MyTosca tosca = new MyTosca();
+        tosca.setName("world");
+        tosca.setVersion("3.2.1");
+        tosca.setDescription(SOME_DESCRIPTION);
+        tosca.setProperties(Map.of(KEY1, PROP1, KEY2, PROP2));
+
+        jpa = new MyJpa(tosca);
+        assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+
+        JpaToscaProperty jpa1 = new JpaToscaProperty(PROP1);
+        jpa1.setKey(new PfReferenceKey(jpa.getKey(), KEY1));
+
+        JpaToscaProperty jpa2 = new JpaToscaProperty(PROP2);
+        jpa2.setKey(new PfReferenceKey(jpa.getKey(), KEY2));
+
+        assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, jpa1, KEY2, jpa2));
+
+        assertEquals(new PfConceptKey("world", "3.2.1"), jpa.getKey());
+    }
+
+    @Test
+    public void testValidateWithKey() {
+        // null key - should fail
+        jpa.setText("some text");
+        assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
+
+        // valid
+        jpa.setKey(new PfConceptKey("xyz", "2.3.4"));
+        assertThat(jpa.validateWithKey("fieldB").isValid()).isTrue();
+
+        // null text - bean validator should fail
+        jpa.setText(null);
+        assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
+    }
+
+    @Test
+    public void testGetReferencedDataTypes() {
+        assertThat(jpa.getReferencedDataTypes()).isEmpty();
+
+        // one with a schema
+        PfConceptKey schemaKey = new PfConceptKey("schemaZ", "9.8.7");
+        JpaToscaSchemaDefinition schema = new JpaToscaSchemaDefinition();
+        schema.setType(schemaKey);
+        JpaToscaProperty prop1 = new JpaToscaProperty(JPA_PROP1);
+        prop1.setType(CONCEPT_KEY1);
+        prop1.setEntrySchema(schema);
+
+        // one property without a schema
+        JpaToscaProperty prop2 = new JpaToscaProperty(JPA_PROP2);
+        prop2.setType(CONCEPT_KEY2);
+        prop2.setEntrySchema(null);
+
+        jpa.setProperties(Map.of(KEY1, prop1, KEY2, prop2));
+
+        List<PfConceptKey> keys = new ArrayList<>(jpa.getReferencedDataTypes());
+        Collections.sort(keys);
+
+        assertThat(keys).isEqualTo(List.of(CONCEPT_KEY1, schemaKey, CONCEPT_KEY2));
+    }
+
+
+    private static class MyTosca extends ToscaWithToscaProperties {
+
+    }
+
+    @NoArgsConstructor
+    protected static class MyJpa extends JpaToscaWithToscaProperties<MyTosca> {
+        private static final long serialVersionUID = 1L;
+
+        @NotNull
+        @Getter
+        @Setter
+        private String text;
+
+        public MyJpa(MyJpa jpa) {
+            super(jpa);
+        }
+
+        public MyJpa(PfConceptKey key) {
+            super(key);
+        }
+
+        public MyJpa(MyTosca tosca) {
+            super(tosca);
+        }
+
+        @Override
+        public MyTosca toAuthorative() {
+            this.setToscaEntity(new MyTosca());
+            return super.toAuthorative();
+        }
+    }
+
+    private static class MyJpa2 extends MyJpa {
+        private static final long serialVersionUID = 1L;
+    }
+}