protected Invocation prepareResource(final String key, final List<String> text, final String sourceLanguage, final String destLanguage) { Invocation.Builder builder = client.target(URL).request(MediaType.APPLICATION_JSON); final MultivaluedHashMap entity = new MultivaluedHashMap(); entity.put("text", text); entity.add("key", key); if ((StringUtils.isBlank(sourceLanguage))) { entity.add("lang", destLanguage); } else { entity.add("lang", sourceLanguage + "-" + destLanguage); } return builder.buildPost(Entity.form(entity)); }
@Override Invocation makeInvocation(WebTarget target, String user, String item, String strength) { return target.path("/pref/" + user + "/" + item).request() .buildPost(Entity.text(strength)); } },
public RpcClientResult post(String path, String content) { if (null == serverUri) { throw new RuntimeException("service url is null"); } WebTarget target = client.target(serverUri).path(path); return target.request().buildPost(Entity.entity(content, MediaType.APPLICATION_JSON)).invoke(RpcClientResult.class); }
@Override Invocation buildRequest(WebTarget initial, ContextListener context) { WebTarget target = initial.path("_search/scroll"); context.addContext(target); return target.request().header(CONTENT_TYPE, APPLICATION_JSON).buildPost(Entity.json(this)); } }
@Test public void testFolderParentNotFound() throws Exception { expectSuccess(getBuilder(getAPIv2().path("space/s1")).buildPut(Entity.json(new Space(null, "s1", null, null, null, 0, null))), Space.class); expectSuccess(getBuilder(getAPIv2().path("space/s1/folder/")).buildPost(Entity.json("{\"name\": \"f1\"}")), Folder.class); expectStatus(Status.BAD_REQUEST, getBuilder(getAPIv2().path("space/s1/folder/wrongfolder/")).buildPost(Entity.json("{\"name\": \"f1\"}"))); }
private void helperTestReplaceValuesCard(DatasetUI datasetUI, String function, Selection sel) { doc(String.format("get %s card preview", function)); ReplaceCards cards = expectSuccess( getBuilder(getAPIv2().path(versionedResourcePath(datasetUI) + "/" + function)) .buildPost(entity(sel, JSON)), new GenericType<ReplaceCards>() { }); assertEquals(1, cards.getValues().getMatchedValues()); assertEquals(6, cards.getValues().getUnmatchedValues()); assertEquals(7, cards.getValues().getAvailableValuesCount()); }
@Test public void testReapplyAndSaveWrongFolder(){ expectSuccess(getBuilder(getAPIv2().path("space/reapplyAndSave")).buildPut(Entity.json(new Space(null, "reapplyAndSave", null, null, null, 0, null))), Space.class); DatasetPath d1Path = new DatasetPath("reapplyAndSave.ds1"); createDatasetFromSQLAndSave(d1Path, "select s_name, s_phone from cp.\"tpch/supplier.parquet\"", asList("cp")); final DatasetUI d2 = createDatasetFromParent("reapplyAndSave.ds1").getDataset(); DatasetVersionResourcePath newVersion = getDatasetVersionPath(d2); expectStatus(Status.BAD_REQUEST, getBuilder(getAPIv2().path(newVersion.toString() + "/reapplyAndSave").queryParam("as", "reapplyAndSaveNotFound.ds3")).buildPost(null)); }
@Test public void testBadTransform() throws Exception { DatasetUI dataset = createDatasetFromParentAndSave("bad", "cp.\"tpch/supplier.parquet\""); ValidationErrorMessage result = expectError( CLIENT_ERROR, getBuilder( getAPIv2().path(versionedResourcePath(dataset) + "/transformAndPreview") ).buildPost(entity(new TransformDrop(null), JSON)), ValidationErrorMessage.class); assertEquals(asList("may not be empty"), result.getValidationErrorMessages().getFieldErrorMessages().get("droppedColumnName")); }
public UserLoginSession login() { UserLogin userLogin = new UserLogin(DEFAULT_USERNAME, DEFAULT_PASSWORD); return expectSuccess(currentApiV2.path("/login").request(JSON).buildPost(Entity.json(userLogin)), UserLoginSession.class); } }
private Thread createVDSInSpace(String name, String spaceName, String sql) { return new Thread(() -> { Dataset newVDS = createVDS(Arrays.asList(spaceName, name), sql); expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newVDS))); }); }
public ValidationResponse testValidateSQL(String queryString, int cursorPos, List<String> context) throws Exception { final String endpoint = "/sql/analyze/validate"; return expectSuccess( getBuilder(getAPIv2().path(endpoint)).buildPost(Entity.entity(new AnalyzeRequest(queryString, context, cursorPos), MediaType.APPLICATION_JSON_TYPE)), ValidationResponse.class ); } }
@Test public void testResetPassword() throws Exception { getCurrentDremioDaemon().close(); SetPassword.resetPassword(getCurrentDremioDaemon().getDACConfig(), DEFAULT_USERNAME, "tshiran123456"); startDaemon(); UserLogin userLogin = new UserLogin(DEFAULT_USERNAME, DEFAULT_PASSWORD); expectStatus(Status.UNAUTHORIZED, getAPIv2().path("/login").request(JSON).buildPost(Entity.json(userLogin)), GenericErrorMessage.class); userLogin = new UserLogin(DEFAULT_USERNAME, "tshiran123456"); expectSuccess(getAPIv2().path("/login").request(JSON).buildPost(Entity.json(userLogin)), UserLoginSession.class); } }
@Test public void successSupport() throws Exception { InitialPreviewResponse preview = createDatasetFromParent("cp.\"tpch/supplier.parquet\""); String url = preview.getPaginationUrl().replace("/job/", "/support/").replace("/data", ""); SupportResponse response = expectSuccess(getBuilder(url).buildPost(null), SupportResponse.class); // We really don't want to actually upload the S3 in tests, so it fails after creating the bundle. // Keep calm, carry on. assertFalse(response.isSuccess()); assertTrue(response.getUrl().startsWith("Unable to upload diagnostics in debug, available locally at: ")); }
private final <TResult, TRequest> TResult buildPost(Class<TResult> outputType, String path, TRequest requestBody, boolean includeAuthToken) throws IOException { Invocation.Builder builder = target.path(path).request(MediaType.APPLICATION_JSON_TYPE); if (includeAuthToken) { builder = builder.header(HttpHeader.AUTHORIZATION.toString(), TokenUtils.AUTH_HEADER_PREFIX + userSession.getToken()); } return readEntity(outputType, builder.buildPost(Entity.json(requestBody))); }
protected DatasetUIWithHistory saveAs(DatasetUI datasetUI, DatasetPath newName) { final Invocation invocation = getBuilder( getAPIv2() .path(versionedResourcePath(datasetUI) + "/save") .queryParam("as", newName) ).buildPost(entity("", JSON)); return expectSuccess(invocation, DatasetUIWithHistory.class); }
protected DatasetUI rename(DatasetPath datasetPath, String newName) { final Invocation invocation = getBuilder( getAPIv2() .path("dataset/" + datasetPath.toString() + "/rename") .queryParam("renameTo", newName) ).buildPost(null); return expectSuccess(invocation, DatasetUI.class); }
@Override public EvaluationResponse perform(WebTarget target) throws Exception { EvaluationRequest request = new EvaluationRequest() .setArguments(getArguments()); Invocation invocation = target.request(MediaType.APPLICATION_JSON).buildPost(Entity.json(request)); Response response = invocation.invoke(); return response.readEntity(EvaluationResponse.class); } };
@Override @Test public void testCreateStream() { String streamResourceURI = getURI() + "v1/scopes/" + scope1 + "/streams"; Response response = addAuthHeaders(client.target(streamResourceURI).request()).buildPost(Entity.json(createStreamRequest)).invoke(); assertEquals("Create Stream Status", expectedResult, response.getStatus()); response.close(); }
private Source createSource() { NASConf nasConf = new NASConf(); nasConf.path = TestTools.getWorkingPath() + "/src/test/resources"; Source newSource = new Source(); newSource.setName("catalog-test"); newSource.setType("NAS"); newSource.setConfig(nasConf); // create the source return expectSuccess(getBuilder(getPublicAPI(3).path(CATALOG_PATH)).buildPost(Entity.json(newSource)), new GenericType<Source>() {}); }
protected InitialPendingTransformResponse transformPeek(DatasetUI datasetUI, TransformBase transform) { final Invocation invocation = getBuilder( getAPIv2() .path(versionedResourcePath(datasetUI) + "/transformPeek") .queryParam("newVersion", newVersion()) ).buildPost(entity(transform, JSON)); return expectSuccess(invocation, InitialPendingTransformResponse.class); }