2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package jtest.org.onap.ccsdk.sli.adaptors.ra;
24 import java.util.Date;
25 import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestDb;
26 import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable;
28 public class DataSetup {
30 private TestDb testDb;
32 private TestTable resource = null;
33 private TestTable allocationItem = null;
35 private static final String[] RESOURCE_COLUMNS =
36 {"asset_id", "resource_name", "resource_type", "lt_used", "rr_used"};
38 private static final String[] ALLOCATION_ITEM_COLUMNS = {"resource_id", "application_id", "resource_set_id",
39 "resource_union_id", "resource_share_group_list", "lt_used", "rr_used", "allocation_time"};
41 private void initTables() {
42 if (resource == null) {
43 resource = testDb.table("RESOURCE", "resource_id", RESOURCE_COLUMNS);
45 if (allocationItem == null) {
46 allocationItem = testDb.table("ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS);
50 public void cleanup() {
52 allocationItem.delete("true");
53 resource.delete("true");
56 public void setupLimitItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId,
60 Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'");
62 resource.add(assetId, resourceName, "Limit", used, null);
63 rid = resource.getLastId();
65 allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, used, null, new Date());
68 public void setupRangeItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId,
72 Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'");
74 resource.add(assetId, resourceName, "Range", null, used);
75 rid = resource.getLastId();
77 allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, null, used, new Date());
80 public boolean checkRangeItem(String resourceName, String assetId, String resourceSetId, String used) {
81 String where = "resource_id = (SELECT resource_id FROM RESOURCE WHERE resource_name = '" + resourceName
82 + "' AND asset_id = '" + assetId + "') AND resource_set_id = '" + resourceSetId + "'";
83 Object usedInDb = allocationItem.getColumn("rr_used", where);
84 return used.equals(usedInDb);
87 public void setTestDb(TestDb testDb) {