@Test(expected = BlkchnException.class) public void testExecuteCreateAssetWithoutFieldsStorageCSV() throws Exception { AbstractAssetManager Am = new AbstractAssetManager() { @Override public Properties getDBProperties() { return null; } }; String sqlCreate = "CREATE ASSET user_asset1" + " WITH STORAGE TYPE CSV " + "FIELDS DELIMITED BY ',' " + "RECORDS DELIMITED BY \"\\n\""; LogicalPlan plan = getLogicalPlan(sqlCreate); Am.logicalPlan = plan; String privateSaveDBMethod = "saveSchemaInDB"; AbstractAssetManager spyObject = PowerMockito.spy(Am); PowerMockito.doNothing().when(spyObject,privateSaveDBMethod,anyString(), any()); spyObject.executeCreateAsset(); }
@SuppressWarnings("unchecked") public void executeCreateAsset() { if (!logicalPlan.getType().equals(SQLType.CREATE_ASSET)) { throw new BlkchnException("Statement executed is not of type 'CREATE ASSET'"); } JSONObject json = new JSONObject(); TreeNode createAsset = logicalPlan.getCreateAsset(); String asset = createAsset.getChildType(Asset.class, 0).getChildType(IdentifierNode.class, 0).getValue(); json.put("storageType", createAsset.getChildType(StorageType.class, 0).getChildType(IdentifierNode.class, 0) .getValue().trim()); if (createAsset.hasChildType(ColumnTypeList.class)) { List<ColumnType> colTypes = createAsset.getChildType(ColumnTypeList.class, 0) .getChildType(ColumnType.class); JSONArray colTypeArr = new JSONArray(); for(ColumnType colType : colTypes) { JSONObject colTypeJSON = new JSONObject(); colTypeJSON.put("colName", colType.getChildType(IdentifierNode.class, 0).getValue().trim()); colTypeJSON.put("colType", colType.getChildType(IdentifierNode.class, 1).getValue().trim()); colTypeArr.add(colTypeJSON); } json.put("columnDetails", colTypeArr); } else if("CSV".equals(json.get("storageType").toString().trim())) { throw new BlkchnException("Column Details should be mentioned while creating asset of storage type CSV"); } if(createAsset.hasChildType(FieldDelimiter.class)) { json.put("fieldDelimiter", createAsset.getChildType(FieldDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } if(createAsset.hasChildType(RecordDelimiter.class)) { json.put("recordDelimiter", createAsset.getChildType(RecordDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } saveSchemaInDB(asset, json); }
AbstractAssetManager { @SuppressWarnings("unchecked") public void executeCreateAsset() { if (!logicalPlan.getType().equals(SQLType.CREATE_ASSET)) { throw new BlkchnException("Statement executed is not of type 'CREATE ASSET'"); } JSONObject json = new JSONObject(); TreeNode createAsset = logicalPlan.getCreateAsset(); String asset = createAsset.getChildType(Asset.class, 0).getChildType(IdentifierNode.class, 0).getValue(); json.put("storageType", createAsset.getChildType(StorageType.class, 0).getChildType(IdentifierNode.class, 0) .getValue().trim()); if (createAsset.hasChildType(ColumnTypeList.class)) { List<ColumnType> colTypes = createAsset.getChildType(ColumnTypeList.class, 0) .getChildType(ColumnType.class); JSONArray colTypeArr = new JSONArray(); for(ColumnType colType : colTypes) { JSONObject colTypeJSON = new JSONObject(); colTypeJSON.put("colName", colType.getChildType(IdentifierNode.class, 0).getValue().trim()); colTypeJSON.put("colType", colType.getChildType(IdentifierNode.class, 1).getValue().trim()); colTypeArr.add(colTypeJSON); } json.put("columnDetails", colTypeArr); } else if("CSV".equals(json.get("storageType").toString().trim())) { throw new BlkchnException("Column Details should be mentioned while creating asset of storage type CSV"); } if(createAsset.hasChildType(FieldDelimiter.class)) { json.put("fieldDelimiter", createAsset.getChildType(FieldDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } if(createAsset.hasChildType(RecordDelimiter.class)) { json.put("recordDelimiter", createAsset.getChildType(RecordDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } saveSchemaInDB(asset, json); } }
AbstractAssetManager { @SuppressWarnings("unchecked") public void executeCreateAsset() { if (!logicalPlan.getType().equals(SQLType.CREATE_ASSET)) { throw new BlkchnException("Statement executed is not of type 'CREATE ASSET'"); } JSONObject json = new JSONObject(); TreeNode createAsset = logicalPlan.getCreateAsset(); String asset = createAsset.getChildType(Asset.class, 0).getChildType(IdentifierNode.class, 0).getValue(); json.put("storageType", createAsset.getChildType(StorageType.class, 0).getChildType(IdentifierNode.class, 0) .getValue().trim()); if (createAsset.hasChildType(ColumnTypeList.class)) { List<ColumnType> colTypes = createAsset.getChildType(ColumnTypeList.class, 0) .getChildType(ColumnType.class); JSONArray colTypeArr = new JSONArray(); for(ColumnType colType : colTypes) { JSONObject colTypeJSON = new JSONObject(); colTypeJSON.put("colName", colType.getChildType(IdentifierNode.class, 0).getValue().trim()); colTypeJSON.put("colType", colType.getChildType(IdentifierNode.class, 1).getValue().trim()); colTypeArr.add(colTypeJSON); } json.put("columnDetails", colTypeArr); } else if("CSV".equals(json.get("storageType").toString().trim())) { throw new BlkchnException("Column Details should be mentioned while creating asset of storage type CSV"); } if(createAsset.hasChildType(FieldDelimiter.class)) { json.put("fieldDelimiter", createAsset.getChildType(FieldDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } if(createAsset.hasChildType(RecordDelimiter.class)) { json.put("recordDelimiter", createAsset.getChildType(RecordDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } saveSchemaInDB(asset, json); }  }
AbstractAssetManager { @SuppressWarnings("unchecked") public void executeCreateAsset() { if (!logicalPlan.getType().equals(SQLType.CREATE_ASSET)) { throw new BlkchnException("Statement executed is not of type 'CREATE ASSET'"); } JSONObject json = new JSONObject(); TreeNode createAsset = logicalPlan.getCreateAsset(); String asset = createAsset.getChildType(Asset.class, 0).getChildType(IdentifierNode.class, 0).getValue(); json.put("storageType", createAsset.getChildType(StorageType.class, 0).getChildType(IdentifierNode.class, 0) .getValue().trim()); if (createAsset.hasChildType(ColumnTypeList.class)) { List<ColumnType> colTypes = createAsset.getChildType(ColumnTypeList.class, 0) .getChildType(ColumnType.class); JSONArray colTypeArr = new JSONArray(); for(ColumnType colType : colTypes) { JSONObject colTypeJSON = new JSONObject(); colTypeJSON.put("colName", colType.getChildType(IdentifierNode.class, 0).getValue().trim()); colTypeJSON.put("colType", colType.getChildType(IdentifierNode.class, 1).getValue().trim()); colTypeArr.add(colTypeJSON); } json.put("columnDetails", colTypeArr); } else if("CSV".equals(json.get("storageType").toString().trim())) { throw new BlkchnException("Column Details should be mentioned while creating asset of storage type CSV"); } if(createAsset.hasChildType(FieldDelimiter.class)) { json.put("fieldDelimiter", createAsset.getChildType(FieldDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } if(createAsset.hasChildType(RecordDelimiter.class)) { json.put("recordDelimiter", createAsset.getChildType(RecordDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } saveSchemaInDB(asset, json); }  @SuppressWarnings("unchecked") void executeCreateAsset(); void executeDropAsset(); String getSchemaJSON(String asset); abstract Properties getDBProperties(); }
AbstractAssetManager { @SuppressWarnings("unchecked") public void executeCreateAsset() { if (!logicalPlan.getType().equals(SQLType.CREATE_ASSET)) { throw new BlkchnException("Statement executed is not of type 'CREATE ASSET'"); } JSONObject json = new JSONObject(); TreeNode createAsset = logicalPlan.getCreateAsset(); String asset = createAsset.getChildType(Asset.class, 0).getChildType(IdentifierNode.class, 0).getValue(); json.put("storageType", createAsset.getChildType(StorageType.class, 0).getChildType(IdentifierNode.class, 0) .getValue().trim()); if (createAsset.hasChildType(ColumnTypeList.class)) { List<ColumnType> colTypes = createAsset.getChildType(ColumnTypeList.class, 0) .getChildType(ColumnType.class); JSONArray colTypeArr = new JSONArray(); for(ColumnType colType : colTypes) { JSONObject colTypeJSON = new JSONObject(); colTypeJSON.put("colName", colType.getChildType(IdentifierNode.class, 0).getValue().trim()); colTypeJSON.put("colType", colType.getChildType(IdentifierNode.class, 1).getValue().trim()); colTypeArr.add(colTypeJSON); } json.put("columnDetails", colTypeArr); } else if("CSV".equals(json.get("storageType").toString().trim())) { throw new BlkchnException("Column Details should be mentioned while creating asset of storage type CSV"); } if(createAsset.hasChildType(FieldDelimiter.class)) { json.put("fieldDelimiter", createAsset.getChildType(FieldDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } if(createAsset.hasChildType(RecordDelimiter.class)) { json.put("recordDelimiter", createAsset.getChildType(RecordDelimiter.class, 0).getChildType(IdentifierNode.class, 0).getValue().trim()); } saveSchemaInDB(asset, json); }  @SuppressWarnings("unchecked") void executeCreateAsset(); void executeDropAsset(); String getSchemaJSON(String asset); abstract Properties getDBProperties();  }