@Test public void shouldCreateLog1411() throws Exception { String rawXML = TestUtilities.getResourceAsString("log1411.xml"); com.hashmapinc.tempus.WitsmlObjects.v1411.ObjLogs logs = WitsmlMarshal.deserialize( rawXML, com.hashmapinc.tempus.WitsmlObjects.v1411.ObjLogs.class); com.hashmapinc.tempus.WitsmlObjects.v1411.ObjLog log = logs.getLog().get(0); ChannelSet channelSet = ChannelSet.from1411(log); String csPayload = channelSet.toJson(); String endpointCS = this.url + this.logChannelsetPath; HttpRequestWithBody requestCS = Unirest.post(endpointCS); requestCS.queryString("uid", log.getUid()); requestCS.queryString("uidWellbore", log.getUidWellbore()); requestCS.queryString("uidWell", log.getUidWell()); requestCS.header("Content-Type", "application/json"); requestCS.body(csPayload); HttpResponse<String> respCS = mock(HttpResponse.class); when(respCS.getBody()).thenReturn( "{\"uid\": \"" + log.getUid() + "\"," + "\"uuid\": \"testUUID\"}" ); when(respCS.getStatus()).thenReturn(201); String channelsPayload = Channel.channelListToJson(Channel.from1411(log)); String endpointCH = this.url + this.logChannelsPath; HttpRequestWithBody requestCHs = Unirest.post(endpointCH); requestCHs.queryString("channelSetUuid", "testUUID"); requestCHs.header("Content-Type", "application/json"); requestCHs.body(channelsPayload); HttpResponse<String> respCHs = mock(HttpResponse.class); when(respCHs.getStatus()).thenReturn(200); String dataPayload = DotLogDataHelper.convertDataToDotFrom1411(log); String endpointData = this.url + this.logDataPath; HttpRequestWithBody requestData = Unirest.post(endpointData); requestData.queryString("channelSetUuid", "testUUID"); requestData.header("Content-Type", "application/json"); requestData.body(dataPayload); HttpResponse<String> respData = mock(HttpResponse.class); when(respData.getBody()).thenReturn( "{\"uid\": \"" + log.getUid() + "\"," + "\"uuid\": \"testUUID\"}" ); when(respData.getStatus()).thenReturn(200); when(this.mockClient.makeRequest(any(HttpRequest.class), anyString(), anyString(), anyString())) .thenAnswer( invocation -> { HttpRequest req = invocation.getArgument(0); String userName = invocation.getArgument(1); String pass = invocation.getArgument(2); if (req.getHttpMethod().name().equals(requestCS.getHttpMethod().name()) && req.getUrl().equals(requestCS.getUrl()) && req.getHeaders().containsKey("Content-Type") && userName.equals("goodUsername") && pass.equals("goodPassword")) { return respCS; } else if (req.getHttpMethod().name().equals(requestCHs.getHttpMethod().name()) && req.getUrl().equals(requestCHs.getUrl()) && req.getHeaders().containsKey("Content-Type") && userName.equals("goodUsername") && pass.equals("goodPassword")) { return respCHs; } else if (req.getHttpMethod().name().equals(requestData.getHttpMethod().name()) && req.getUrl().equals(requestData.getUrl()) && req.getHeaders().containsKey("Content-Type") && userName.equals("goodUsername") && pass.equals("goodPassword")) { return respData; } else { throw new InvalidUseOfMatchersException( String.format("Argument %s does not match", req.getUrl())); } }); String actualUid = this.delegator.createObject( log, "goodUsername", "goodPassword", "exchangeID", this.mockClient ); String expectedUid = log.getUid(); assertEquals(expectedUid, actualUid); }
public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } } }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { throw new ValveException(response.getBody()); } } DotDelegator(Map<String, String> config); }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { 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); }
DotDelegator { public String createObject(AbstractWitsmlObject witsmlObj, String username, String password, String exchangeID, DotClient client) throws ValveException, ValveAuthException, UnirestException, JsonProcessingException { String objectType = witsmlObj.getObjectType(); if ("log".equals(objectType)) { String response = createLogObject(witsmlObj, username, password, exchangeID, client); return response; } if ("fluidsReport".equalsIgnoreCase(objectType)) { String response = createFluidsReportObject(witsmlObj, username, password, exchangeID, client); return response; } String uid = witsmlObj.getUid(); String endpoint = this.getEndpoint(objectType); String payload = witsmlObj.getJSONString("1.4.1.1"); HttpRequestWithBody request; if (null == uid || uid.isEmpty()) { request = Unirest.post(endpoint); } else { request = Unirest.put(endpoint + uid); } if ("wellbore".equals(objectType)) { request.queryString("uidWell", witsmlObj.getParentUid()); } else if ("trajectory".equals(objectType)) { request.queryString("uidWellbore", witsmlObj.getParentUid()); request.queryString("uidWell", witsmlObj.getGrandParentUid()); } request.header("Content-Type", "application/json"); request.body(payload); HttpResponse<String> response = client.makeRequest(request, username, password, exchangeID); int status = response.getStatus(); if (201 == status || 200 == status) { return (null == uid || uid.isEmpty()) ? new JsonNode(response.getBody()).getObject().getString("uid") : uid; } else { 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);  }