diff --git a/src/main/Main.java b/src/main/Main.java index 04f4f6c..46054ed 100644 --- a/src/main/Main.java +++ b/src/main/Main.java @@ -20,8 +20,8 @@ public static void main(String[] args) { // post.start(); init(); - //api.jsonAcquisition("src/main/you.json"); - api.doRestTest(); + api.jsonAcquisition("src/main/you.json"); + //api.doRestTest(); System.out.println(api.getResults()); } diff --git a/src/restfulchecker/RestChecker.java b/src/restfulchecker/RestChecker.java index 4b39cf0..60f76c6 100644 --- a/src/restfulchecker/RestChecker.java +++ b/src/restfulchecker/RestChecker.java @@ -1,15 +1,13 @@ package restfulchecker; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; -import java.io.PrintStream; import java.util.ArrayList; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; public class RestChecker { private ArrayList accounts = new ArrayList<>(); @@ -27,6 +25,8 @@ private ArrayList keys = new ArrayList<>(); private ArrayList values = new ArrayList<>(); private NecessaryParam getnesParam = new NecessaryParam(); + private ArrayList removeParam = new ArrayList<>(); + private JsonNode readJson; public static final int ACCOUNT_NUM = 5; @@ -40,6 +40,10 @@ accounts.add(new RestAccount(url)); } + public void setRemoveParam(String removeParam) { + this.removeParam.add(removeParam); + } + public ArrayList getAccounts() { return accounts; } @@ -56,6 +60,10 @@ return judgeResult; } + public NecessaryParam getGetnesParam() { + return getnesParam; + } + public void setupRestTest(Method method, ArrayList queryParam, ArrayList formParam, ArrayList pathParam) { this.type = method; @@ -162,15 +170,12 @@ } public void jsonAcquisition(String path) { - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper json = new ObjectMapper(); try { - BufferedReader reader = new BufferedReader(new FileReader(new File(path))); - String line = null; - StringBuilder builder = new StringBuilder(); - while ((line = reader.readLine()) != null) { - builder.append(line); - } - jstr = builder.toString(); + readJson = json.readTree(new File(path)); + JsonNode gg = readJson.get("snippet"); + jsonRemove(gg, "title"); + System.out.println(readJson); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -180,8 +185,24 @@ } } - public NecessaryParam getGetnesParam() { - return getnesParam; + public String jsonRemove(String JsonString, String fieldName) { + ObjectMapper jsonstr = new ObjectMapper(); + try { + JsonNode json = jsonstr.readTree(JsonString); + ObjectNode obj = (ObjectNode) json; + obj.remove(fieldName); + return obj.toString(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + } + + public String jsonRemove(JsonNode Json, String fieldName) { + ObjectNode obj = (ObjectNode) Json; + obj.remove(fieldName); + return obj.toString(); } public enum Method {