GraphQLQueryConverter { public static String getQuery(AbstractWitsmlObject wmlObject) throws IOException { switch (wmlObject.getObjectType()){ case "well": return getWellQuery(wmlObject); case "wellbore": return createWellboreQuery(wmlObject.getJSONString("1.4.1.1")); default: return null; } }  static String getQuery(AbstractWitsmlObject wmlObject); static String getQuery(AbstractWitsmlObject wmlObject, String wellboreUuid); static String getWellboreAndWellUuidQuery(AbstractWitsmlObject wmlObject); static String getWellboreNameQuery(AbstractWitsmlObject wmlObject); static String getWellNameQuery(AbstractWitsmlObject wmlObject);  }
@Test public void generateProperGraphQLQueryForWellbore() throws Exception { final String variablesNodeName = "variables"; final String queryNodeName = "query"; final String wellboreArgNodeName = "wellboreArgument"; final String wellboreOpenQuery = "wellboreOpenQuery1411.xml"; JSONObject wellboreQueryFields = new JSONObject(); String queryString = TestUtilities.getResourceAsString(wellboreOpenQuery); ObjWellbores queryObject = WitsmlMarshal.deserialize(queryString, ObjWellbores.class); ObjWellbore singularObject = queryObject.getWellbore().get(0); JSONObject wellboreJson = new JSONObject(singularObject.getJSONString("1.4.1.1")); GraphQLQueryConverter converter = new GraphQLQueryConverter(); String graphQLQuery = converter.getQuery(singularObject); assertNotNull(graphQLQuery); checkNbuildQuery("uid", wellboreJson, graphQLQuery, wellboreQueryFields ); checkNbuildQuery("uidWell", wellboreJson, graphQLQuery, wellboreQueryFields ); checkNbuildQuery("name", wellboreJson, graphQLQuery, wellboreQueryFields ); checkNbuildQuery("nameWell", wellboreJson, graphQLQuery, wellboreQueryFields ); JSONObject comparable = new JSONObject(); comparable.put( queryNodeName, GraphQLQueryConstants.WELLBORE_QUERY ); JSONObject variables = new JSONObject(); variables.put( wellboreArgNodeName, wellboreQueryFields ); comparable.put( variablesNodeName, variables ); String comparableToString = comparable.toString(2); ObjectMapper om = new ObjectMapper(); Map<String, Object> producedMap = (Map<String, Object>) (om.readValue(graphQLQuery, Map.class)); Map<String, Object> expectedMap = (Map<String, Object>) (om.readValue(comparableToString, Map.class)); assertEquals( producedMap, expectedMap ); }
@Test public void generateProperGraphQLQueryForTrajectory() throws Exception { String queryXML = TestUtilities.getResourceAsString("trajectoryGraphql/trajectoryGraphqlQuery1411.xml"); ObjTrajectory obj = ((ObjTrajectorys) WitsmlMarshal.deserialize(queryXML, ObjTrajectorys.class)).getTrajectory().get(0); GraphQLQueryConverter converter = new GraphQLQueryConverter(); String graphQLQuery = converter.getQuery(obj, "test"); assertNotNull(graphQLQuery); assertTrue(graphQLQuery.contains("title")); }