org.jboss.pnc.causeway.test.PncImportResourceIT.java Source code

Java tutorial

Introduction

Here is the source code for org.jboss.pnc.causeway.test.PncImportResourceIT.java

Source

/**
 * Copyright (C) 2015 Red Hat, Inc. (jbrazdil@redhat.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.pnc.causeway.test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.jboss.pnc.causeway.test.util.HttpCommandResult;
import org.junit.Test;

import java.util.Date;

/**
 * Created by jdcasey on 2/11/16.
 */
public class PncImportResourceIT extends AbstractTest {
    @Test
    public void checkTestMethod() throws Exception {
        withNewHttpClient((driver, client) -> {
            String var = Long.toHexString(new Date().getTime());

            try {
                String url = formatUrl("/import/test", var);
                HttpGet request = new HttpGet(url);
                request.setHeader("Content-Type", "application/json");
                request.setHeader("Accept", "application/json");
                request.setHeader("RESTEASY_CHOSEN_ACCEPT", "*");

                HttpResponse response = client.execute(request);
                assertThat(response.getStatusLine().getStatusCode(), equalTo(200));

                String result = IOUtils.toString(response.getEntity().getContent()).trim();
                assertThat(result, equalTo(var));
            } catch (Exception e) {
                return new HttpCommandResult(e);
            }

            return new HttpCommandResult();
        });
    }
}