DotDelegator { public void updateObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); String version = witsmlObj.getVersion(); if ("fluidsReport".equalsIgnoreCase(objectType)) { updateFluidsReport(witsmlObj, username, password, exchangeID, client); } else { String payload; if ("1.4.1.1".equals(version)) { payload = witsmlObj.getJSONString("1.4.1.1"); } else { payload = witsmlObj.getJSONString("1.3.1.1"); } payload = JsonUtil.removeEmpties(new JSONObject(payload)); if (LOG_OBJECT.equals(objectType)) { updateLog(witsmlObj, username, password, exchangeID, client, payload); } else { String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType) + uid; HttpRequestWithBody request = Unirest.put(endpoint); HttpResponse<String> response; request.header("Content-Type", "application/json"); if (payload.length() > 0) { request.body(payload); addQueryStringParams(objectType, request, witsmlObj); response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { LOG.info(ValveLogging.getLogRespMsg(exchangeID, "Successfully updated object with UID: " + uid, response)); } else { LOG.warning(ValveLogging.getLogRespMsg(exchangeID, "Failed to update object with UID: " + uid, response)); throw new ValveException(response.getBody()); } } } } } DotDelegator(Map<String, String> config); void deleteObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); void performElementDelete(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); void updateObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); String updateFluidsReport(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); void updateLog(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client, String payload); String getUuid(AbstractWitsmlObject witsmlObj, String uid, DotClient client, String username,
			String password, String exchangeID); String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); String createFluidsReportObject(AbstractWitsmlObject witsmlObj, String username, String password,
			String exchangeID, DotClient client); String createLogObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID,
			DotClient client); static short mnemonicsChecks( String channelPayload,
										 String dataPayload,
										 String version ); HttpResponse<String> performPost(String payload, String endpoint, HashMap<String, String> requestParams,
			DotClient client, String username, String password, String exchangeID); String[] getMappedPayloads4Log(String version, String payload, AbstractWitsmlObject witsmlObj); AbstractWitsmlObject getObject(AbstractWitsmlObject witsmlObject, String username, String password,
			String exchangeID, DotClient client, Map<String, String> optionsIn); ArrayList<AbstractWitsmlObject> search(AbstractWitsmlObject witsmlObject, String username, String password,
			String exchangeID, DotClient client, Map<String, String> optionsIn);  }
@Test public void shouldUpdateTrajectory1311() throws Exception { ObjTrajectory traj1311 = new ObjTrajectory(); traj1311.setUid("traj1311"); traj1311.setName("traj1311"); traj1311.setUidWellbore("wellbore1311"); traj1311.setUidWell("well1311"); String endpoint = this.url + this.trajectoryPath + traj1311.getUid(); HttpRequest req1311 = Unirest.put(endpoint); req1311.header("Content-Type", "application/json"); req1311.queryString("uidWellbore", traj1311.getUidWellbore()); req1311.queryString("uidWell", traj1311.getUidWell()); HttpResponse<String> resp = mock(HttpResponse.class); when(resp.getStatus()).thenReturn(200); when(this.mockClient.makeRequest(argThat(someReq -> ( someReq.getHttpMethod().name().equals(req1311.getHttpMethod().name()) && someReq.getUrl().equals(req1311.getUrl()) && someReq.getHeaders().containsKey("Content-Type") )), eq("goodUsername"), eq("goodPassword"), anyString())).thenReturn(resp); this.delegator.updateObject(traj1311, "goodUsername", "goodPassword", "exchangeID", this.mockClient); verify(this.mockClient).makeRequest(argThat(someReq -> ( someReq.getHttpMethod().name().equals(req1311.getHttpMethod().name()) && someReq.getUrl().equals(req1311.getUrl()) && someReq.getHeaders().containsKey("Content-Type") )), eq("goodUsername"), eq("goodPassword"), anyString()); }
@Test public void shouldUpdateTrajectory1411() throws Exception { com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectory traj1411 = new com.hashmapinc.tempus.WitsmlObjects.v1411.ObjTrajectory(); traj1411.setUid("traj1411"); traj1411.setName("traj1411"); traj1411.setUidWellbore("wellbore1411"); traj1411.setUidWell("well1411"); String endpoint = this.url + this.trajectoryPath + traj1411.getUid(); HttpRequest req1411 = Unirest.put(endpoint); req1411.header("Content-Type", "application/json"); req1411.queryString("uidWellbore", traj1411.getUidWellbore()); req1411.queryString("uidWell", traj1411.getUidWell()); HttpResponse<String> resp = mock(HttpResponse.class); when(resp.getStatus()).thenReturn(200); when(this.mockClient.makeRequest(argThat(someReq -> ( someReq.getHttpMethod().name().equals(req1411.getHttpMethod().name()) && someReq.getUrl().equals(req1411.getUrl()) && someReq.getHeaders().containsKey("Content-Type") )), eq("goodUsername"), eq("goodPassword"), anyString())).thenReturn(resp); this.delegator.updateObject(traj1411, "goodUsername", "goodPassword", "exchangeID", this.mockClient); verify(this.mockClient).makeRequest(argThat(someReq -> ( someReq.getHttpMethod().name().equals(req1411.getHttpMethod().name()) && someReq.getUrl().equals(req1411.getUrl()) && someReq.getHeaders().containsKey("Content-Type") )), eq("goodUsername"), eq("goodPassword"), anyString()); }