DotValve implements IValve { @Override @Async("asyncCustomTaskExecutor") public CompletableFuture<String> getObject(QueryContext qc) throws ValveException { ArrayList<AbstractWitsmlObject> queryResponses; if (qc.WITSML_OBJECTS.size() == 1 && (qc.WITSML_OBJECTS.get(0).getUid() == null || "".equals(qc.WITSML_OBJECTS.get(0).getUid()))) { queryResponses = doSearch(qc); } else { if ( "trajectory".equals(qc.OBJECT_TYPE) && trajHasSearchQueryArgs(qc) ) { queryResponses = doSearch(qc); } else { queryResponses = getSingularObject(qc); } } String xmlResponse = DotTranslator.consolidateObjectsToXML(queryResponses, qc.CLIENT_VERSION, qc.OBJECT_TYPE); return CompletableFuture.completedFuture(xmlResponse); } DotValve(Map<String, String> config);  DotValve(DotClient client, DotDelegator delegator); @Override String getName(); @Override String getDescription(); @Override String getObjectSelectionCapability(String WMLtypeIn); @Override @Async("asyncCustomTaskExecutor") CompletableFuture<String> getObject(QueryContext qc); static boolean trajHasSearchQueryArgs( QueryContext qc ); @Override @Async("asyncCustomTaskExecutor") CompletableFuture<String> createObject(QueryContext qc); @Override @Async("asyncCustomTaskExecutor") CompletableFuture<Boolean> deleteObject(QueryContext qc); @Override @Async("asyncCustomTaskExecutor") CompletableFuture<Boolean> updateObject(QueryContext qc); @Override void authenticate(String username, String password); Map<String, AbstractWitsmlObject[]> getCap();  }
@Test public void shouldGetSingleObject() throws Exception { ArrayList<AbstractWitsmlObject> witsmlObjects; witsmlObjects = new ArrayList<>(); ObjWell well = new ObjWell(); well.setName("well-1"); well.setUid("well-1"); witsmlObjects.add(well); QueryContext qc = new QueryContext( "1.3.1.1", "well", new HashMap<>(), "", witsmlObjects, "goodUsername", "goodPassword", "shouldGetSingleObject" ); when( this.mockDelegator.getObject(well, qc.USERNAME, qc.PASSWORD,qc.EXCHANGE_ID, this.mockClient, qc.OPTIONS_IN) ).thenReturn(well); String expected = well.getXMLString("1.3.1.1"); String actual = this.valve.getObject(qc).get(); assertEquals(expected, actual); }
@Test public void shouldGetLogSingleObject() throws Exception { ArrayList<AbstractWitsmlObject> witsmlObjects; witsmlObjects = new ArrayList<>(); ObjLog log = new ObjLog(); log.setUid("HM_800007"); log.setUidWell("U2"); log.setUidWellbore("WBDD600"); witsmlObjects.add(log); QueryContext qc = new QueryContext( "1.4.1.1", "log", new HashMap<>(), "", witsmlObjects, "goodUsername", "goodPassword", "shouldGetSingleObject" ); when( this.mockDelegator.getObject(log, qc.USERNAME, qc.PASSWORD,qc.EXCHANGE_ID, this.mockClient, qc.OPTIONS_IN) ).thenReturn(log); String expected = log.getXMLString("1.4.1.1"); String actual = this.valve.getObject(qc).get(); assertEquals(expected, actual); }
@Test public void shouldGetEmptyObject() throws Exception { ArrayList<AbstractWitsmlObject> witsmlObjects; witsmlObjects = new ArrayList<>(); ObjWell well = new ObjWell(); well.setName("well-1"); well.setUid("well-1"); witsmlObjects.add(well); QueryContext qc = new QueryContext( "1.3.1.1", "well", null, "", witsmlObjects, "goodUsername", "goodPassword", "shouldGetEmptyObject" ); when( this.mockDelegator.getObject(well, qc.USERNAME, qc.PASSWORD,qc.EXCHANGE_ID, this.mockClient, qc.OPTIONS_IN) ).thenReturn(null); String expected = WitsmlMarshal.serialize(new ObjWells()); String actual = this.valve.getObject(qc).get(); assertEquals(expected, actual); }
@Test public void shouldGetPluralObject() throws Exception { ArrayList<AbstractWitsmlObject> witsmlObjects; witsmlObjects = new ArrayList<>(); com.hashmapinc.tempus.WitsmlObjects.v1311.ObjWellbore wellboreA = new com.hashmapinc.tempus.WitsmlObjects.v1311.ObjWellbore(); wellboreA.setName("wellbore-A"); wellboreA.setUid("wellbore-A"); witsmlObjects.add(wellboreA); com.hashmapinc.tempus.WitsmlObjects.v1311.ObjWellbore wellboreB = new com.hashmapinc.tempus.WitsmlObjects.v1311.ObjWellbore(); wellboreB.setName("wellbore-B"); wellboreB.setUid("wellbore-B"); witsmlObjects.add(wellboreB); QueryContext qc = new QueryContext( "1.3.1.1", "wellbore", new HashMap<>(), "", witsmlObjects, "goodUsername", "goodPassword", "shouldGetPluralObject" ); doReturn(wellboreA).when(this.mockDelegator).getObject(wellboreA, qc.USERNAME, qc.PASSWORD, qc.EXCHANGE_ID, this.mockClient, new HashMap<>()); doReturn(wellboreB).when(this.mockDelegator).getObject(wellboreB, qc.USERNAME, qc.PASSWORD, qc.EXCHANGE_ID, this.mockClient, new HashMap<>()); String expected = wellboreA.getXMLString("1.3.1.1").replace("</wellbores>", "") + wellboreB.getXMLString("1.3.1.1").replace( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<wellbores version=\"1.3.1.1\" xmlns=\"http: "" ); String actual = this.valve.getObject(qc).get(); assertEquals(expected, actual); }
@Test public void shouldSearchWellsWithEmptyUID() throws Exception { String query = TestUtilities.getResourceAsString("well1311FullEmptyQueryNoUid.xml"); String response = TestUtilities.getResourceAsString("well1311FullEmptyQueryNoUidResponse.xml"); String completeResponse = TestUtilities.getResourceAsString("well1311NoUidSearchFullValveResponse.xml"); ObjWells wellsResponse= WitsmlMarshal.deserialize(response, ObjWells.class); ObjWells wellsQuery = WitsmlMarshal.deserialize(query, ObjWells.class); ObjWell singularWellQuery = wellsQuery.getWell().get(0); ObjWell singularWellResponse = wellsResponse.getWell().get(0); List<AbstractWitsmlObject> wmlObjectsQuery = new ArrayList<>(); wmlObjectsQuery.add(singularWellQuery); List<AbstractWitsmlObject> wmlObjectsResp = new ArrayList<>(); wmlObjectsResp.add(singularWellResponse); QueryContext qc = new QueryContext( "1.3.1.1", "well", new HashMap<>(), query, wmlObjectsQuery, "goodUsername", "goodPassword", "shouldGetPluralObject" ); doReturn(wmlObjectsResp).when(this.mockDelegator).search(singularWellQuery, qc.USERNAME, qc.PASSWORD, qc.EXCHANGE_ID, this.mockClient, new HashMap<>()); String actual = this.valve.getObject(qc).get(); assertEquals(completeResponse, actual); }