Skip to content

Commit

Permalink
Get WebACRecipesIT into initial shape
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj authored and Andrew Woods committed Sep 4, 2015
1 parent ac1bc9c commit 47528ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 51 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -111,6 +111,13 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-http-api</artifactId>
<version>4.3.1-SNAPSHOT</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
Expand Down
84 changes: 33 additions & 51 deletions src/test/java/org/fcrepo/integration/auth/webac/WebACRecipesIT.java
Expand Up @@ -15,81 +15,63 @@
*/
package org.fcrepo.integration.auth.webac;

import static javax.ws.rs.core.Response.Status.CREATED;
import static org.junit.Assert.assertEquals;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
import java.util.UUID;
import org.fcrepo.integration.http.api.AbstractResourceIT;

import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.FileEntity;
import org.apache.http.message.AbstractHttpMessage;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
* @author Peter Eichman
* @author whikloj
* @since September 4, 2015
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring-test/test-container.xml")
public class WebACRecipesIT {
public class WebACRecipesIT extends AbstractResourceIT {

private static Logger logger = getLogger(WebACRecipesIT.class);

protected static final int SERVER_PORT = Integer.parseInt(System.getProperty("fcrepo.dynamic.test.port", "8080"));
private final ClassLoader classLoader = getClass().getClassLoader();

protected static final String HOSTNAME = "localhost";

protected static final String serverAddress = "http://" + HOSTNAME + ":" + SERVER_PORT + "/rest/";

protected final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();

protected static CloseableHttpClient client;

public WebACRecipesIT() {
connectionManager.setMaxTotal(Integer.MAX_VALUE);
connectionManager.setDefaultMaxPerRoute(20);
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
client = HttpClientBuilder.create().setConnectionManager(connectionManager).build();
@Before
public void setUp() throws IOException {
logger.debug("setup complete");
}

@Before
public void setUp() throws ClientProtocolException, IOException {
// TODO: this should be factored out into a repeatable method to set up each scenario
final HttpPost postRequest = new HttpPost(serverAddress);
@Test
public void scenario1() throws Exception {
logger.info("Running scenario1");
final String objA = getRandomPid();
final HttpPut method = super.putObjMethod("rest/" + objA);
final FileEntity acl = new FileEntity(new File(classLoader.getResource("acls/01/acl.ttl").getFile()));
setAuth(method, "fedoraAdmin");
method.setHeader("Content-type", "text/turtle");
method.setEntity(acl);
try (final CloseableHttpResponse response = super.execute(method)) {
assertEquals(CREATED.getStatusCode(), super.getStatus(response));
}
}

final String creds = "username:password";
protected static void setAuth(final AbstractHttpMessage method, final String username) {
final String creds = username + ":password";
// in test configuration we don't need real passwords
final String encCreds = new String(Base64.encodeBase64(creds.getBytes()));
final String basic = "Basic " + encCreds;
postRequest.setHeader("Authorization", basic);

final InputStream acl = this.getClass().getResourceAsStream("/acls/01/acl.ttl");
final InputStreamEntity acl_entity = new InputStreamEntity(acl);
postRequest.setEntity(acl_entity);
postRequest.setHeader("Content-Type", "text/turtle;charset=UTF-8");

// XXX: this is currently failing in the test repository with a
// "java.lang.VerifyError: Bad type on operand stack"
// see https://gist.github.com/peichman-umd/7f2eb8833ef8cd0cdfc1#gistcomment-1566271
final HttpResponse res = client.execute(postRequest);
System.err.println(res.getStatusLine());

logger.debug("setup complete");
method.setHeader("Authorization", basic);
}

@Test
public void test() {
protected static String getRandomPid() {
return UUID.randomUUID().toString();
}

}

0 comments on commit 47528ac

Please sign in to comment.