@Test public void test_data_can_be_extracted() throws AdapterException { String data = "[{\r\n" + " \"id\": 1234,\r\n" + " \"teamId\": \"xxxx-aax7-45asdf-b194-c736b605700d\",\r\n" + " \"name\": \"TheName\",\r\n" + " \"isPublic\": true,\r\n" + " \"customFields\": [],\r\n" + " \"links\": [\r\n" + " {\r\n" + " \"rel\": \"self\",\r\n" + " \"uri\": \"/projects/113\"\r\n" + " },\r\n" + " {\r\n" + " \"rel\": \"teams\",\r\n" + " \"uri\": \"/auth/teams/\"\r\n" + " },\r\n" + " {\r\n" + " \"rel\": \"latestscan\",\r\n" + " \"uri\": \"/sast/scans?projectId=12213&last=1\"\r\n" + " },\r\n" + " {\r\n" + " \"rel\": \"allscans\",\r\n" + " \"uri\": \"/sast/scans?projectId=12213\"\r\n" + " },\r\n" + " {\r\n" + " \"rel\": \"scansettings\",\r\n" + " \"uri\": \"/sast/scanSettings/1234\"\r\n" + " },\r\n" + " {\r\n" + " \"type\": \"local\",\r\n" + " \"rel\": \"source\",\r\n" + " \"uri\": null\r\n" + " }\r\n" + " ]\r\n" + " }\r\n" + "]{Cache-Control=[no-cache], Pragma=[no-cache], Content-Type=[application/json; charset=utf-8], Expires=[-1], Server=[Microsoft-IIS/8.5], api-version=[2.0], X-AspNet-Version=[4.0.30319], X-Powered-By=[ASP.NET], Date=[Tue, 25 Sep 2018 14:06:42 GMT], Content-Length=[725]}"; CheckmarxSessionData result = supportToTest.extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport.FOR_UNKNOWN_ADAPTER,data); assertNotNull(result); assertEquals(1234L,result.getProjectId()); assertEquals("TheName",result.getProjectName()); }
CheckmarxSessionData extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport support, String json) throws AdapterException { CheckmarxSessionData data = new CheckmarxSessionData(); Access rootNode = support.fetchRootNode(json); Access first = support.fetchArray(0, rootNode.asArray()); data.setProjectId(first.fetch("id").asLong()); data.setProjectName(first.fetch("name").asText()); return data; }
CheckmarxProjectSupport { CheckmarxSessionData extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport support, String json) throws AdapterException { CheckmarxSessionData data = new CheckmarxSessionData(); Access rootNode = support.fetchRootNode(json); Access first = support.fetchArray(0, rootNode.asArray()); data.setProjectId(first.fetch("id").asLong()); data.setProjectName(first.fetch("name").asText()); return data; } }
CheckmarxProjectSupport { CheckmarxSessionData extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport support, String json) throws AdapterException { CheckmarxSessionData data = new CheckmarxSessionData(); Access rootNode = support.fetchRootNode(json); Access first = support.fetchArray(0, rootNode.asArray()); data.setProjectId(first.fetch("id").asLong()); data.setProjectName(first.fetch("name").asText()); return data; }  }
CheckmarxProjectSupport { CheckmarxSessionData extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport support, String json) throws AdapterException { CheckmarxSessionData data = new CheckmarxSessionData(); Access rootNode = support.fetchRootNode(json); Access first = support.fetchArray(0, rootNode.asArray()); data.setProjectId(first.fetch("id").asLong()); data.setProjectName(first.fetch("name").asText()); return data; }  void ensureProjectExists(CheckmarxContext context); }
CheckmarxProjectSupport { CheckmarxSessionData extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport support, String json) throws AdapterException { CheckmarxSessionData data = new CheckmarxSessionData(); Access rootNode = support.fetchRootNode(json); Access first = support.fetchArray(0, rootNode.asArray()); data.setProjectId(first.fetch("id").asLong()); data.setProjectName(first.fetch("name").asText()); return data; }  void ensureProjectExists(CheckmarxContext context);  }