473a99f4c011d4103f5176a991db3e2e98e4a110
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / test / java / jtest / org / onap / ccsdk / sli / adaptors / rm / DataSetup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                         reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package jtest.org.onap.ccsdk.sli.adaptors.rm;
23
24 import java.util.Date;
25
26 import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestDb;
27 import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable;
28
29 public class DataSetup {
30
31     private TestDb testDb;
32
33     private TestTable resource = null;
34     private TestTable allocationItem = null;
35
36     private static final String[] RESOURCE_COLUMNS =
37             { "asset_id", "resource_name", "resource_type", "lt_used", "ll_label", "ll_reference_count", "rr_used" };
38
39     private static final String[] ALLOCATION_ITEM_COLUMNS = {
40             "resource_id", "application_id", "resource_set_id", "resource_union_id", "resource_share_group_list",
41             "lt_used", "ll_label", "rr_used", "allocation_time" };
42
43     private void initTables() {
44         if (resource == null)
45             resource = testDb.table("RESOURCE", "resource_id", RESOURCE_COLUMNS);
46         if (allocationItem == null)
47             allocationItem = testDb.table("ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS);
48     }
49
50     public void cleanup() {
51         allocationItem.delete("true");
52         resource.delete("true");
53     }
54
55     public void setupLimitItem(
56             String resourceName,
57             String assetId,
58             String resourceSetId,
59             String resourceUnionId,
60             long used) {
61         initTables();
62
63         Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'");
64         if (rid == null) {
65             resource.add(assetId, resourceName, "Limit", 1, null, null, null);
66             rid = resource.getLastId();
67         }
68         allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, used, null, null, new Date());
69     }
70
71     public void setupRangeItem(
72             String resourceName,
73             String assetId,
74             String resourceSetId,
75             String resourceUnionId,
76             String used) {
77         initTables();
78
79         Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'");
80         if (rid == null) {
81             resource.add(assetId, resourceName, "Range", null, null, null, used);
82             rid = resource.getLastId();
83         }
84         allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, null, null, used, new Date());
85     }
86
87     public void setupLabelItem(
88             String resourceName,
89             String assetId,
90             String resourceSetId,
91             String resourceUnionId,
92             String label) {
93         initTables();
94
95         Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'");
96         if (rid == null) {
97             resource.add(assetId, resourceName, "Label", null, label, 1, null);
98             rid = resource.getLastId();
99         }
100         allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, null, label, null, new Date());
101     }
102
103     public void setTestDb(TestDb testDb) {
104         this.testDb = testDb;
105     }
106 }