Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start parsing web.xml for the test web app config
- Loading branch information
Showing
16 changed files
with
510 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/org/fcrepo/auth/oauth/integration/api/TestBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.fcrepo.auth.oauth.integration.api; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.JAXBException; | ||
import javax.xml.bind.Unmarshaller; | ||
|
||
import org.fcrepo.auth.oauth.integration.api.bind.ContextParam; | ||
import org.fcrepo.auth.oauth.integration.api.bind.FilterMapping; | ||
import org.fcrepo.auth.oauth.integration.api.bind.Listener; | ||
import org.fcrepo.auth.oauth.integration.api.bind.ServletMapping; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TestBinding { | ||
|
||
private final Logger LOGGER = LoggerFactory.getLogger(TestBinding.class); | ||
|
||
@Test | ||
public void testBinding() throws JAXBException { | ||
JAXBContext context = JAXBContext.newInstance(WebAppConfig.class); | ||
Unmarshaller u = context.createUnmarshaller(); | ||
WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResourceAsStream("/web.xml")); | ||
assertEquals("Fedora-on-ModeShape", o.displayName()); | ||
assertTrue(o.contextParams.contains( | ||
new ContextParam( | ||
"contextConfigLocation", | ||
"classpath:spring-test/rest.xml; " + | ||
"classpath:spring-test/repo.xml; " + | ||
"classpath:spring-test/security.xml"))); | ||
assertTrue(o.contextParams.contains( | ||
new ContextParam( | ||
"org.modeshape.jcr.RepositoryName", | ||
"repo"))); | ||
assertTrue(o.contextParams.contains( | ||
new ContextParam( | ||
"org.modeshape.jcr.URL", | ||
"/test_repository.json"))); | ||
assertTrue(o.listeners.contains( | ||
new Listener(null, "org.springframework.web.context.ContextLoaderListener"))); | ||
assertTrue(o.listeners.contains( | ||
new Listener(null, "org.modeshape.web.jcr.ModeShapeJcrDeployer"))); | ||
ServletMapping sm = o.servletMappings("jersey-servlet").iterator().next(); | ||
assertNotNull(sm); | ||
assertEquals("/*", sm.urlPattern()); | ||
|
||
FilterMapping fm = o.filterMappings("TokenFilter").iterator().next(); | ||
assertNotNull(fm); | ||
assertEquals("/token", fm.urlPattern()); | ||
|
||
fm = o.filterMappings("OpFilter").iterator().next(); | ||
assertNotNull(fm); | ||
assertEquals("/rest/objects/authenticated/*", fm.urlPattern()); | ||
|
||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/test/java/org/fcrepo/auth/oauth/integration/api/WebAppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.fcrepo.auth.oauth.integration.api; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlElements; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
import org.fcrepo.auth.oauth.integration.api.bind.ContextParam; | ||
import org.fcrepo.auth.oauth.integration.api.bind.Displayable; | ||
import org.fcrepo.auth.oauth.integration.api.bind.Filter; | ||
import org.fcrepo.auth.oauth.integration.api.bind.FilterMapping; | ||
import org.fcrepo.auth.oauth.integration.api.bind.Listener; | ||
import org.fcrepo.auth.oauth.integration.api.bind.Servlet; | ||
import org.fcrepo.auth.oauth.integration.api.bind.ServletMapping; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.Collections2; | ||
|
||
@XmlRootElement(namespace="http://java.sun.com/xml/ns/javaee", name="web-app") | ||
public class WebAppConfig extends Displayable { | ||
|
||
@XmlElements(value = {@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="context-param")}) | ||
List<ContextParam> contextParams; | ||
|
||
@XmlElements(value = {@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="listener")}) | ||
List<Listener> listeners; | ||
|
||
@XmlElements(value = {@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="servlet")}) | ||
List<Servlet> servlets; | ||
|
||
@XmlElements(value = {@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="filter")}) | ||
List<Filter> filters; | ||
|
||
@XmlElements(value = {@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="servlet-mapping")}) | ||
List<ServletMapping> servletMappings; | ||
|
||
@XmlElements(value = {@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="filter-mapping")}) | ||
List<FilterMapping> filterMappings; | ||
|
||
public Collection<ServletMapping> servletMappings(String servletName) { | ||
return Collections2.filter(servletMappings, new SMapFilter(servletName)); | ||
} | ||
|
||
public Collection<FilterMapping> filterMappings(String filterName) { | ||
return Collections2.filter(filterMappings, new FMapFilter(filterName)); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public Collection<ContextParam> contextParams() { | ||
return (contextParams != null) ? contextParams : Collections.EMPTY_LIST; | ||
} | ||
|
||
private static class SMapFilter implements Predicate<ServletMapping> { | ||
String servletName; | ||
|
||
SMapFilter(String sName) { | ||
servletName = sName; | ||
} | ||
|
||
@Override | ||
public boolean apply(ServletMapping input) { | ||
return (servletName == null) ? input.servletName() == null : | ||
servletName.equals(input.servletName()); | ||
} | ||
|
||
|
||
} | ||
private static class FMapFilter implements Predicate<FilterMapping> { | ||
String filterName; | ||
|
||
FMapFilter(String sName) { | ||
filterName = sName; | ||
} | ||
|
||
@Override | ||
public boolean apply(FilterMapping input) { | ||
return (filterName == null) ? input.filterName() == null : | ||
filterName.equals(input.filterName()); | ||
} | ||
|
||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/test/java/org/fcrepo/auth/oauth/integration/api/bind/ContextParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.fcrepo.auth.oauth.integration.api.bind; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
|
||
@XmlRootElement(namespace="http://java.sun.com/xml/ns/javaee", name="context-param") | ||
public class ContextParam extends Param { | ||
|
||
public ContextParam() { | ||
super(); | ||
} | ||
|
||
public ContextParam(String name, String value) { | ||
super(name, value); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/org/fcrepo/auth/oauth/integration/api/bind/Describable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.fcrepo.auth.oauth.integration.api.bind; | ||
|
||
import javax.xml.bind.annotation.XmlElement; | ||
|
||
|
||
public abstract class Describable { | ||
|
||
@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="description") | ||
String description; | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/test/java/org/fcrepo/auth/oauth/integration/api/bind/Displayable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.fcrepo.auth.oauth.integration.api.bind; | ||
|
||
import javax.xml.bind.annotation.XmlElement; | ||
|
||
|
||
public abstract class Displayable extends Describable { | ||
|
||
@XmlElement(namespace="http://java.sun.com/xml/ns/javaee", name="display-name") | ||
String displayName; | ||
|
||
public String displayName() { | ||
return this.displayName; | ||
} | ||
} |
Oops, something went wrong.