Java Code Examples for io.restassured.RestAssured#enableLoggingOfRequestAndResponseIfValidationFails()

The following examples show how to use io.restassured.RestAssured#enableLoggingOfRequestAndResponseIfValidationFails() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HerdRestUtil.java    From herd-mdl with Apache License 2.0 7 votes vote down vote up
private static RequestSpecification getBaseRequestSpecification(User user) {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RequestSpecBuilder requestSpecBuilder = new RequestSpecBuilder()
        .log(LogDetail.ALL)
        .setRelaxedHTTPSValidation()
        .setContentType("application/xml");

    //Only set authentication when auth is enabled
    if (BooleanUtils.toBoolean(TestProperties.get(StackInputParameterKeyEnum.ENABLE_SSL_AUTH))) {
        LOGGER.info("Setting Basic Auth for user: " + user.getUsername());
        PreemptiveBasicAuthScheme authenticationScheme = new PreemptiveBasicAuthScheme();
        authenticationScheme.setUserName(user.getUsername());
        authenticationScheme.setPassword(user.getPassword());
        requestSpecBuilder.setAuth(authenticationScheme)
            .setAuth(authenticationScheme);
    }
    return requestSpecBuilder.build().redirects().follow(true);
}
 
Example 2
Source File: GetMailboxesMethodTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Throwable {
    jmapServer = createJmapServer();
    jmapServer.start();
    mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
    aclProbe = jmapServer.getProbe(ACLProbeImpl.class);
    quotaProbe = jmapServer.getProbe(QuotaProbesImpl.class);

    RestAssured.requestSpecification = jmapRequestSpecBuilder
            .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort().getValue())
            .build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

    DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);
    dataProbe.addDomain(DOMAIN);
    dataProbe.addUser(ALICE.asString(), ALICE_PASSWORD);
    dataProbe.addUser(BOB.asString(), BOB_PASSWORD);
    accessToken = authenticateJamesUser(baseUri(jmapServer), ALICE, ALICE_PASSWORD);

    message = Message.Builder.of()
        .setSubject("test")
        .setBody("testmail", StandardCharsets.UTF_8)
        .build();
}
 
Example 3
Source File: SetMailboxesMethodTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Throwable {
    jmapServer = createJmapServer();
    jmapServer.start();
    mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
    DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);
    
    RestAssured.requestSpecification = jmapRequestSpecBuilder
            .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort().getValue())
            .build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

    username = Username.of("username@" + DOMAIN);
    String password = "password";
    dataProbe.addDomain(DOMAIN);
    dataProbe.addUser(username.asString(), password);
    inboxId = mailboxProbe.createMailbox("#private", username.asString(), DefaultMailboxes.INBOX);
    accessToken = authenticateJamesUser(baseUri(jmapServer), username, password);
}
 
Example 4
Source File: DemoRamlRestTest.java    From raml-module-builder with Apache License 2.0 6 votes vote down vote up
/**
 * @param context  the test context.
 */
@BeforeClass
public static void setUp(TestContext context) throws IOException {
  // some tests (withoutParameter, withoutYearParameter) fail under other locales like Locale.GERMANY
  Locale.setDefault(Locale.US);

  vertx = VertxUtils.getVertxWithExceptionHandler();
  port = NetworkUtils.nextFreePort();
  RestAssured.port = port;
  RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
  tenant = new RequestSpecBuilder().addHeader("x-okapi-tenant", TENANT).build();

  try {
    deployRestVerticle(context);
  } catch (Exception e) {
    context.fail(e);
  }
}
 
Example 5
Source File: TestControllerEndpoints.java    From proteus with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp()
{
	RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

	try
	{
			byte[] bytes  = new byte[8388608];
		Random random = new Random(); 
		random.nextBytes(bytes);

		file = Files.createTempFile("test-asset", ".mp4").toFile();
		
		LongStream.range(1L,10L).forEach( l -> {
			
			idSet.add(l);
		});
		 

	} catch (Exception e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 6
Source File: AbstractApiTest.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Subclasses most call this method:
 *
 * <pre>
 * &#64;BeforeClass
 * public static void setUpBeforeClass() {
 *   AbstractApiTest.setUpBeforeClass();
 *   ...
 * }
 * </pre>
 */
protected static void setUpBeforeClass() {
  String restTestHost = System.getProperty("REST_TEST_HOST");
  if (restTestHost == null) {
    restTestHost = RestTestUtils.DEFAULT_HOST;
  }
  RestAssured.baseURI = restTestHost;
  RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

  String restTestAdminName = System.getProperty("REST_TEST_ADMIN_NAME");
  if (restTestAdminName == null) {
    restTestAdminName = RestTestUtils.DEFAULT_ADMIN_NAME;
  }
  String restTestAdminPw = System.getProperty("REST_TEST_ADMIN_PW");
  if (restTestAdminPw == null) {
    restTestAdminPw = RestTestUtils.DEFAULT_ADMIN_PW;
  }

  ADMIN_TOKEN = login(restTestAdminName, restTestAdminPw);
}
 
Example 7
Source File: FormAuthNoRedirectTestCase.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormAuthFailure() {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    CookieFilter cookies = new CookieFilter();
    RestAssured
            .given()
            .filter(cookies)
            .redirects().follow(false)
            .when()
            .formParam("j_username", "a d m i n")
            .formParam("j_password", "wrongpassword")
            .post("/j_security_check")
            .then()
            .assertThat()
            .statusCode(302)
            .header("location", containsString("/error"))
            .header("quarkus-credential", nullValue());
}
 
Example 8
Source File: FormAuthNoRedirectTestCase.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormBasedAuthSuccessLandingPage() {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    CookieFilter cookies = new CookieFilter();
    RestAssured
            .given()
            .filter(cookies)
            .redirects().follow(false)
            .when()
            .formParam("j_username", "a d m i n")
            .formParam("j_password", "a d m i n")
            .post("/j_security_check")
            .then()
            .assertThat()
            .statusCode(200)
            .cookie("quarkus-credential", notNullValue());
}
 
Example 9
Source File: AbstractApiTests.java    From molgenis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Subclasses most call this method:
 *
 * <pre>
 * &#64;BeforeClass
 * public static void setUpBeforeClass() {
 *   AbstractApiTest.setUpBeforeClass();
 *   ...
 * }
 * </pre>
 */
protected static void setUpBeforeClass() {
  String restTestHost = System.getProperty("REST_TEST_HOST");
  if (restTestHost == null) {
    restTestHost = RestTestUtils.DEFAULT_HOST;
  }
  RestAssured.baseURI = restTestHost;
  RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

  String restTestAdminName = System.getProperty("REST_TEST_ADMIN_NAME");
  if (restTestAdminName == null) {
    restTestAdminName = RestTestUtils.DEFAULT_ADMIN_NAME;
  }
  String restTestAdminPw = System.getProperty("REST_TEST_ADMIN_PW");
  if (restTestAdminPw == null) {
    restTestAdminPw = RestTestUtils.DEFAULT_ADMIN_PW;
  }

  String adminToken = login(restTestAdminName, restTestAdminPw);
  ADMIN_TOKENS.set(adminToken);
}
 
Example 10
Source File: FormAuthTestCase.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Test()
public void testSecureAccessSuccess() {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    given().auth()
            .form("stuart", "test",
                    new FormAuthConfig("j_security_check", "j_username", "j_password")
                            .withLoggingEnabled())
            .when().get("/secure-test").then().statusCode(200);

    given().auth()
            .form("jdoe", "p4ssw0rd",
                    new FormAuthConfig("j_security_check", "j_username", "j_password")
                            .withLoggingEnabled())
            .when().get("/secure-test").then().statusCode(403);

    given().auth()
            .form("scott", "jb0ss",
                    new FormAuthConfig("j_security_check", "j_username", "j_password")
                            .withLoggingEnabled())
            .when().get("/jaxrs-secured/rolesClass").then().statusCode(200);
}
 
Example 11
Source File: MessageRoutesTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void beforeEach() {
    taskManager = new MemoryTaskManager(new Hostname("foo"));
    mailboxManager = InMemoryIntegrationResources.defaultResources().getMailboxManager();
    searchIndex = mock(ListeningMessageSearchIndex.class);;
    Mockito.when(searchIndex.add(any(), any(), any())).thenReturn(Mono.empty());
    Mockito.when(searchIndex.deleteAll(any(), any())).thenReturn(Mono.empty());
    ReIndexerPerformer reIndexerPerformer = new ReIndexerPerformer(
        mailboxManager,
        searchIndex,
        mailboxManager.getMapperFactory());
    JsonTransformer jsonTransformer = new JsonTransformer();

    webAdminServer = WebAdminUtils.createWebAdminServer(
            new TasksRoutes(taskManager, jsonTransformer,
                DTOConverter.of(
                    MessageIdReindexingTaskAdditionalInformationDTO.module(mailboxManager.getMessageIdFactory()))),
            new MessagesRoutes(taskManager,
                new InMemoryMessageId.Factory(),
                new MessageIdReIndexerImpl(reIndexerPerformer),
                jsonTransformer,
                ImmutableSet.of()))
        .start();

    RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer).build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
 
Example 12
Source File: DomainQuotaRoutesTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp(WebAdminQuotaSearchTestSystem testSystem) throws Exception {
    testSystem.getQuotaSearchTestSystem().getDomainList()
        .addDomain(FOUND_LOCAL);

    maxQuotaManager = testSystem.getQuotaSearchTestSystem().getMaxQuotaManager();

    RestAssured.requestSpecification = testSystem.getRequestSpecification();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
 
Example 13
Source File: ConfigurationExtension.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void beforeAll( ExtensionContext context )
{
    RestAssured.baseURI = TestConfiguration.get().baseUrl();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RestAssured.defaultParser = Parser.JSON;
    RestAssured.requestSpecification = defaultRequestSpecification();
}
 
Example 14
Source File: MailRepositoriesRoutesTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    createMailRepositoryStore();

    MemoryTaskManager taskManager = new MemoryTaskManager(new Hostname("foo"));
    JsonTransformer jsonTransformer = new JsonTransformer();
    MailQueueFactory<? extends ManageableMailQueue> queueFactory = new MemoryMailQueueFactory(new RawMailQueueItemDecoratorFactory());
    spoolQueue = queueFactory.createQueue(MailQueueFactory.SPOOL);
    customQueue = queueFactory.createQueue(CUSTOM_QUEUE);

    MailRepositoryStoreService repositoryStoreService = new MailRepositoryStoreService(mailRepositoryStore);

    ReprocessingService reprocessingService = new ReprocessingService(queueFactory, repositoryStoreService);

    webAdminServer = WebAdminUtils.createWebAdminServer(
            new MailRepositoriesRoutes(repositoryStoreService,
                jsonTransformer, reprocessingService, taskManager),
        new TasksRoutes(taskManager, jsonTransformer,
            DTOConverter.of(ReprocessingOneMailTaskAdditionalInformationDTO.module(),
                ReprocessingAllMailsTaskAdditionalInformationDTO.module(),
                WebAdminClearMailRepositoryTaskAdditionalInformationDTO.module())))
        .start();

    RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer)
        .setBasePath(MailRepositoriesRoutes.MAIL_REPOSITORIES)
        .build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
 
Example 15
Source File: CorsHeaderAPITest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Throwable {
    jmapServer = createJmapServer();
    jmapServer.start();

    RestAssured.requestSpecification = jmapRequestSpecBuilder
            .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort().getValue())
            .build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

    DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);
    dataProbe.addDomain(DOMAIN);
    dataProbe.addUser(ALICE.asString(), ALICE_PASSWORD);
    accessToken = authenticateJamesUser(baseUri(jmapServer), ALICE, ALICE_PASSWORD);
}
 
Example 16
Source File: ErrorRoutesTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    webAdminServer = WebAdminUtils.createWebAdminServer(new ErrorRoutes())
        .start();

    RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer)
            .setBasePath(ErrorRoutes.BASE_URL)
            .build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
 
Example 17
Source File: CassandraBulkOperationTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    RestAssured.defaultParser = Parser.JSON;
}
 
Example 18
Source File: MailboxesRoutesTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@BeforeEach
void beforeEach() throws Exception {
    client = MailboxIndexCreationUtil.prepareDefaultClient(
        elasticSearch.getDockerElasticSearch().clientProvider().get(),
        elasticSearch.getDockerElasticSearch().configuration());

    InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
    MailboxIdRoutingKeyFactory routingKeyFactory = new MailboxIdRoutingKeyFactory();

    InMemoryIntegrationResources resources = InMemoryIntegrationResources.builder()
        .preProvisionnedFakeAuthenticator()
        .fakeAuthorizator()
        .inVmEventBus()
        .defaultAnnotationLimits()
        .defaultMessageParser()
        .listeningSearchIndex(preInstanciationStage -> new ElasticSearchListeningMessageSearchIndex(
            preInstanciationStage.getMapperFactory(),
            new ElasticSearchIndexer(client,
                MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS,
                BATCH_SIZE),
            new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE,
                new InMemoryId.Factory(), messageIdFactory,
                MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS, routingKeyFactory),
            new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES),
            preInstanciationStage.getSessionProvider(), routingKeyFactory))
        .noPreDeletionHooks()
        .storeQuotaManager()
        .build();

    mailboxManager = resources.getMailboxManager();
    messageIdManager = resources.getMessageIdManager();
    taskManager = new MemoryTaskManager(new Hostname("foo"));
    InMemoryId.Factory mailboxIdFactory = new InMemoryId.Factory();

    searchIndex = spy((ListeningMessageSearchIndex) resources.getSearchIndex());

    ReIndexerPerformer reIndexerPerformer = new ReIndexerPerformer(
        mailboxManager,
        searchIndex,
        mailboxManager.getMapperFactory());
    ReIndexer reIndexer = new ReIndexerImpl(
        reIndexerPerformer,
        mailboxManager,
        mailboxManager.getMapperFactory());
    JsonTransformer jsonTransformer = new JsonTransformer();

    webAdminServer = WebAdminUtils.createWebAdminServer(
            new TasksRoutes(taskManager, jsonTransformer,
                DTOConverter.of(
                    WebAdminErrorRecoveryIndexationDTO.serializationModule(mailboxIdFactory),
                    WebAdminFullIndexationDTO.serializationModule(mailboxIdFactory),
                    WebAdminSingleMailboxReindexingTaskAdditionalInformationDTO.serializationModule(mailboxIdFactory),
                    SingleMessageReindexingTaskAdditionalInformationDTO.module(mailboxIdFactory))),
            new MailboxesRoutes(taskManager,
                jsonTransformer,
                ImmutableSet.of(
                    new MailboxesRoutes.ReIndexAllMailboxesTaskRegistration(
                        reIndexer, new PreviousReIndexingService(taskManager), mailboxIdFactory)),
                ImmutableSet.of(
                    new MailboxesRoutes.ReIndexOneMailboxTaskRegistration(
                        reIndexer, mailboxIdFactory)),
                ImmutableSet.of(
                    new MailboxesRoutes.ReIndexOneMailTaskRegistration(
                        reIndexer, mailboxIdFactory))))
        .start();

    RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer).build();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}
 
Example 19
Source File: FormAuthJpaTestCase.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Test
public void testFormBasedAuthSuccess() {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
    CookieFilter cookies = new CookieFilter();
    RestAssured
            .given()
            .filter(cookies)
            .redirects().follow(false)
            .when()
            .get("/servlet-secured")
            .then()
            .assertThat()
            .statusCode(302)
            .header("location", containsString("/login"))
            .cookie("quarkus-redirect-location", containsString("/servlet-secured"));

    RestAssured
            .given()
            .filter(cookies)
            .redirects().follow(false)
            .when()
            .formParam("j_username", "user")
            .formParam("j_password", "user")
            .post("/j_security_check")
            .then()
            .assertThat()
            .statusCode(302)
            .header("location", containsString("/servlet-secured"))
            .cookie("laitnederc-sukrauq", notNullValue());

    RestAssured
            .given()
            .filter(cookies)
            .redirects().follow(false)
            .when()
            .get("/servlet-secured")
            .then()
            .assertThat()
            .statusCode(200)
            .body(equalTo("A secured message"));

}
 
Example 20
Source File: PassTicketTest.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
@BeforeEach
public void setUp() {
    RestAssured.port = PORT;
    RestAssured.useRelaxedHTTPSValidation();
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
}