Response response = given().body(requestBody).when().post("/admin"); Result result = response.as(Result.class);
@Nonnull public Iterable<RestMinimalApplicationLink> getAllApplinks() { return ImmutableList.copyOf(applinksTester.get(SimpleRestRequest.DEFAULT_INSTANCE) .as(RestMinimalApplicationLink[].class)); }
/** * @param credentials credentials to log in with * @return authentication cookie value to use for subsequent interactions with the product */ @Nonnull @SuppressWarnings("ConstantConditions") public String getAuthentication(@Nonnull TestAuthentication credentials) { Response response = authTester.get(AuthRequest.forCredentials(credentials)); String authCookie = response.as(BaseRestEntity.class).getString(SESSION_ID); checkState(authCookie != null, "Auth cookie was not set for base URL: " + baseUrl); return authCookie; }
@Nonnull public RestMinimalApplicationLink getApplink(String id) { return applinksTester.get(new CustomizableRestRequest.Builder().addPath(id).build()) .as(RestMinimalApplicationLink.class); }
@SuppressWarnings("unchecked") public List<ApplinkTypeMetadata> getApplicationTypeMetadata() { List<ApplinkTypeMetadata> applicationList = new ArrayList<ApplinkTypeMetadata>(); List<Map<String, String>> applicationTypes = tester.get(new CustomizableRestRequest.Builder() .addPath(APPLICATION_TYPE_RESOURCE_PATH) .build()).as(List.class); for (Map<String, String> application : applicationTypes) { applicationList.add(new ApplinkTypeMetadata(application)); } return applicationList; } }
@SuppressWarnings("unchecked") public List<ApplinkTypeMetadata> getEntityTypeMetadata() { List<ApplinkTypeMetadata> entityList = new ArrayList<ApplinkTypeMetadata>(); List<Map<String, String>> entityTypes = tester.get(new CustomizableRestRequest.Builder() .addPath(ENTITY_TYPE_RESOURCE_PATH) .build()).as(List.class); for (Map<String, String> entity : entityTypes) { entityList.add(new ApplinkTypeMetadata(entity)); } return entityList; }
@Nonnull public ApplinkOAuthStatus getOAuthStatus(@Nonnull TestedInstance instance, @Nonnull String applinkId) { checkNotNull(applinkId, "applinkId"); Response response = new ApplinkStatusRestTester(instance).getOAuth(new ApplinkOAuthStatusRequest.Builder(applinkId) .authentication(TestAuthentication.admin()) .expectStatus(OK) .build()); return response.as(RestApplinkOAuthStatus.class).asDomain(); }
@Nullable public String getProperty(@Nonnull String key) { Response response = systemPropertiesTester.get(new PropertyRequest.Builder(key) .expectStatus(okOrNotFound()) .build()); return response.getStatusCode() == Status.OK.getStatusCode() ? response.as(BaseRestEntity.class).getString(VALUE_PROPERTY) : null; }
@Nonnull public RestAccessToken addConsumerToken(@Nonnull TestApplink.Side side, @Nonnull String username, @Nonnull RestAccessToken token) { Response response = createConsumerTester(side.product()).put(new CustomizableRestRequest.Builder() .addPath(side.id()) .addPath(username) .body(token) .expectStatus(Status.CREATED) .build()); return response.as(RestAccessToken.class); }
@Nonnull public RestAccessToken getServiceProviderAccessToken(@Nonnull TestApplink.Side side, @Nonnull String username) { Response response = createServiceProviderTester(side.product()).get(new CustomizableRestRequest.Builder() .addPath(side.id()) .addPath(username) .expectStatus(Status.OK) .build()); return response.as(RestAccessToken.class); }
@Nonnull public RestAccessToken createServiceProviderToken(@Nonnull TestApplink.Side side, @Nonnull String username) { Response response = createServiceProviderTester(side.product()).put(new CustomizableRestRequest.Builder() .addPath(side.id()) .addPath(username) .expectStatus(Status.CREATED) .build()); return response.as(RestAccessToken.class); }
public RestAccessToken getConsumerToken(@Nonnull TestApplink.Side side, @Nonnull String username) { Response response = createConsumerTester(side.product()).get(new CustomizableRestRequest.Builder() .addPath(side.id()) .addPath(username) .expectStatus(Status.OK) .build()); return response.as(RestAccessToken.class); }
public static OAuth2AccessToken getClientCredentialsAccessToken(String clientId, String clientSecret) { return given() .parameters("grant_type", "client_credentials") .auth() .preemptive() .basic(clientId, clientSecret) .when() .post("/oauth/token") .as(OAuth2AccessToken.class); }
public Model getResourceAsModel(String uri, String mediaType) { return buildBaseRequestSpecification() .header(ACCEPT, mediaType) .expect() .statusCode(isSuccessful()) .when() .get(uri).as(Model.class, new RdfObjectMapper(uri)); }
@Test( groups = {SHOULD}, description = "LDP servers should respond with a text/turtle representation of the " + "requested LDP-RS whenever the Accept request header is absent [turtle].") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldprs-get-conneg", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testGetResourceAsTurtleNoAccept() { // No Accept header buildBaseRequestSpecification() .expect().statusCode(isSuccessful()).contentType(TEXT_TURTLE) .when().get(getResourceUri()).as(Model.class, new RdfObjectMapper(getResourceUri())); }
public static OAuth2AccessToken getPasswordGrantAccessToken(String username, String password) { return given() .when() .contentType(APPLICATION_FORM_URLENCODED_VALUE) .formParam("grant_type", "password") .formParam("username", username) .formParam("password", password) .formParam("client_id", CLIENT_ID_ADMIN) .formParam("client_secret", CLIENT_SECRET_ADMIN) .post("/oauth/token") .as(OAuth2AccessToken.class); }
@Test public void testValidatePropertiesJsonio() throws Exception { ObjectNode validationResult = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreSerProps()) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/validate").as(ObjectNode.class); assertNotNull(validationResult); assertEquals("OK", validationResult.get("status").textValue()); }
@Test public void testValidateProperties() throws Exception { ObjectNode validationResult = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/validate").as(ObjectNode.class); assertNotNull(validationResult); assertEquals("OK", validationResult.get("status").textValue()); }
@Test public void testGetSchema_wrongSql() throws java.io.IOException { // given UiSpecsPropertiesDto datasetConnectionInfo = new UiSpecsPropertiesDto(); datasetConnectionInfo.setProperties(mapper.readValue( getClass().getResourceAsStream("jdbc_data_set_properties_no_schema_wrong_table_name.json"), ObjectNode.class)); datasetConnectionInfo.setDependencies(singletonList(getJdbcDataStoreProperties())); String dataSetDefinitionName = "JDBCDataset"; // when ApiError response = given().content(datasetConnectionInfo).contentType(APPLICATION_JSON_UTF8_VALUE) // .accept(APPLICATION_JSON_UTF8_VALUE) // .expect().statusCode(400).log().ifValidationFails() // .post(getVersionPrefix() + "/runtimes/schema").as(ApiError.class); // then assertEquals("TCOMP_JDBC_SQL_SYNTAX_ERROR", response.getCode()); assertEquals("Table/View 'TOTO' does not exist.", response.getMessage()); }
@Test public void testTriggerOnProperty_nonExistentTrigger() throws Exception { String callback = "toto"; String propName = "tagId"; ApiError errorContainer = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(400).log().ifValidationFails() // .with() // .content(buildTestDataStoreFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/trigger/{callback}/{propName}", callback, propName).as(ApiError.class); assertEquals("Talend_ALL_UNEXPECTED_ARGUMENT", errorContainer.getCode()); assertNotNull(errorContainer.getMessageTitle()); assertNotNull(errorContainer.getMessage()); }