Skip to content

Commit

Permalink
Some more test-related work. This still doesn't work as a self-contai…
Browse files Browse the repository at this point in the history
…ned integration-test,

but it passes against an already running instance of kitchen-sink at localhost:8080
  • Loading branch information
Edwin Shin committed Feb 28, 2013
1 parent 9c3e1dd commit 62d8d43
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 26 deletions.
13 changes: 13 additions & 0 deletions pom.xml
Expand Up @@ -83,6 +83,19 @@
</exclusion>
</exclusions>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
71 changes: 45 additions & 26 deletions src/test/java/org/fcrepo/example/cmis/CmisIT.java
@@ -1,74 +1,88 @@

package org.fcrepo.example.cmis;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.bindings.spi.StandardAuthenticationProvider;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Element;



//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration({"/spring/repo.xml", "/spring/eventing.xml",
// "/spring/jms.xml", "/spring/generator.xml", "/spring-test/rest.xml"})
public class CmisIT {

private Session session;

private static final String BASE_URL = "http://localhost:8080";

protected static HttpClient client;

protected static final PoolingClientConnectionManager connectionManager =
new PoolingClientConnectionManager();

static {
connectionManager.setMaxTotal(Integer.MAX_VALUE);
connectionManager.setDefaultMaxPerRoute(5);
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
client = new DefaultHttpClient(connectionManager);
}

@Before
public void setUp() throws Exception {
assertEquals(201,
getStatus(new HttpPost(BASE_URL + "/rest/objects/new")));

// default factory implementation
SessionFactoryImpl factory = SessionFactoryImpl.newInstance();
Map<String, String> parameter = new HashMap<String, String>();

// user credentials
//parameter.put(SessionParameter.USER, user);
//parameter.put(SessionParameter.PASSWORD, passw);
//parameter.put(SessionParameter.USER, null);
//parameter.put(SessionParameter.PASSWORD, null);

// connection settings
parameter.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES
.value());
parameter
.put(SessionParameter.WEBSERVICES_ACL_SERVICE,
BASE_URL +
parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, BASE_URL +
"/services/ACLService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE,
BASE_URL +
parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, BASE_URL +
"/services/DiscoveryService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE,
BASE_URL + "/services/MultiFilingService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE,
BASE_URL + "/services/NavigationService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE,
BASE_URL +
parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, BASE_URL +
"/services/ObjectService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_POLICY_SERVICE,
BASE_URL +
parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, BASE_URL +
"/services/PolicyService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE,
BASE_URL + "/services/RelationshipService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE,
BASE_URL + "/services/RepositoryService?wsdl");
parameter
.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE,
BASE_URL + "/services/VersioningService?wsdl");

parameter.put(SessionParameter.REPOSITORY_ID, "cmis_repo:default");
parameter.put(SessionParameter.REPOSITORY_ID, "repo");

// create session
session =
Expand All @@ -95,4 +109,9 @@ public void test() {
System.out.println("Root: " + root);
}

protected int getStatus(HttpUriRequest method)
throws ClientProtocolException, IOException {
return client.execute(method).getStatusLine().getStatusCode();
}

}
111 changes: 111 additions & 0 deletions src/test/resources/spring-test/rest.xml
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml"/>

<!-- Context that houses JAX-RS Resources that compose the API
as well as som utility gear. -->

<context:annotation-config/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>

<jaxrs:server address="http://localhost:8080/v3">
<jaxrs:serviceBeans>
<bean class="org.fcrepo.api.legacy.FedoraRepository"/>
<bean class="org.fcrepo.api.legacy.FedoraDatastreams"/>
<bean class="org.fcrepo.api.legacy.FedoraIdentifiers"/>
<bean class="org.fcrepo.api.legacy.FedoraNamespaces"/>
<bean class="org.fcrepo.api.legacy.FedoraObjects"/>
<bean class="org.fcrepo.generator.DublinCore"/>
</jaxrs:serviceBeans>
<jaxrs:extensionMappings>
<entry key="json" value="application/json"/>
<entry key="xml" value="application/xml"/>
</jaxrs:extensionMappings>
<jaxrs:providers>
<ref bean="pathNotFoundExceptionMapper"/>
<ref bean="accessControlExceptionMapper"/>
<ref bean="wildcardExceptionMapper"/>
<ref bean="jaxbElementProvider"/>
<ref bean="jsonProvider"/>
</jaxrs:providers>
</jaxrs:server>

<jaxrs:server address="http://localhost:8080/rest">
<jaxrs:serviceBeans>
<bean class="org.fcrepo.api.FedoraRepository"/>
<bean class="org.fcrepo.api.FedoraDatastreams"/>
<bean class="org.fcrepo.api.FedoraIdentifiers"/>
<bean class="org.fcrepo.api.FedoraNamespaces"/>
<bean class="org.fcrepo.api.FedoraObjects"/>
<bean class="org.fcrepo.generator.DublinCore"/>
<bean class="org.fcrepo.syndication.RSSPublisher"/>
</jaxrs:serviceBeans>
<jaxrs:extensionMappings>
<entry key="json" value="application/json"/>
<entry key="xml" value="application/xml"/>
</jaxrs:extensionMappings>
<jaxrs:providers>
<ref bean="pathNotFoundExceptionMapper"/>
<ref bean="accessControlExceptionMapper"/>
<ref bean="wildcardExceptionMapper"/>
<ref bean="jaxbElementProvider"/>
<ref bean="jsonProvider"/>
<bean class="org.apache.cxf.jaxrs.provider.XSLTJaxbProvider">
<property name="outMediaTemplates">
<map>
<entry key="text/html" value="classpath:/views/object.xslt"/>
</map>
</property>
<!--
<property name="resolver">
<bean class="org.apache.xml.resolver.helpers.BootstrapResolver"/>
</property>
-->
</bean>
</jaxrs:providers>
</jaxrs:server>

<jaxrs:server address="http://localhost:8080/rest/modeshape">
<jaxrs:serviceBeans>
<bean class="org.modeshape.web.jcr.rest.ModeShapeRestService"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.modeshape.web.jcr.rest.output.HtmlBodyWriter"/>
<bean class="org.modeshape.web.jcr.rest.output.JSONBodyWriter"/>
<bean class="org.modeshape.web.jcr.rest.output.TextBodyWriter"/>
</jaxrs:providers>
</jaxrs:server>

<bean name="pathNotFoundExceptionMapper"
class="org.fcrepo.exceptionhandlers.PathNotFoundExceptionMapper"/>
<bean name="accessControlExceptionMapper"
class="org.fcrepo.exceptionhandlers.AccessControlExceptionMapper"/>
<bean name="wildcardExceptionMapper"
class="org.fcrepo.exceptionhandlers.WildcardExceptionMapper">
<property name="showStackTrace" value="true"/>
</bean>
<bean name="jaxbElementProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="marshallerProperties">
<util:map>
<entry key="jaxb.formatted.output">
<value type="java.lang.Boolean">true</value>
</entry>
</util:map>
</property>
</bean>
<bean name="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="ignoreNamespaces" value="true"/>
</bean>
</beans>

0 comments on commit 62d8d43

Please sign in to comment.