From 7148e8085cfa9d39a1773670e3116ccd42ce1d46 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 28 Mar 2014 20:39:35 +0100 Subject: [PATCH] added ScmModule to read module.xml which is produced by the scm-annotation-processor --- .../java/sonia/scm/plugin/ClassElement.java | 141 +++++++++++ .../scm/plugin/ExtensionPointElement.java | 165 +++++++++++++ .../main/java/sonia/scm/plugin/Plugin.java | 126 ++-------- .../main/java/sonia/scm/plugin/ScmModule.java | 230 ++++++++++++++++++ .../sonia/scm/plugin/SubscriberElement.java | 165 +++++++++++++ .../java/sonia/scm/plugin/ScmModuleTest.java | 115 +++++++++ .../resources/sonia/scm/plugin/module.xml | 71 ++++++ 7 files changed, 913 insertions(+), 100 deletions(-) create mode 100644 scm-core/src/main/java/sonia/scm/plugin/ClassElement.java create mode 100644 scm-core/src/main/java/sonia/scm/plugin/ExtensionPointElement.java create mode 100644 scm-core/src/main/java/sonia/scm/plugin/ScmModule.java create mode 100644 scm-core/src/main/java/sonia/scm/plugin/SubscriberElement.java create mode 100644 scm-core/src/test/java/sonia/scm/plugin/ScmModuleTest.java create mode 100644 scm-core/src/test/resources/sonia/scm/plugin/module.xml diff --git a/scm-core/src/main/java/sonia/scm/plugin/ClassElement.java b/scm-core/src/main/java/sonia/scm/plugin/ClassElement.java new file mode 100644 index 0000000000..070c69ec17 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/plugin/ClassElement.java @@ -0,0 +1,141 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.plugin; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.base.Objects; + +//~--- JDK imports ------------------------------------------------------------ + +import javax.xml.bind.annotation.XmlElement; + +/** + * + * @author Sebastian Sdorra + * @since 2.0.0 + */ +public final class ClassElement +{ + + /** + * Constructs ... + * + */ + ClassElement() {} + + /** + * Constructs ... + * + * + * @param clazz + */ + public ClassElement(Class clazz) + { + this.clazz = clazz; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param obj + * + * @return + */ + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + + if (getClass() != obj.getClass()) + { + return false; + } + + final ClassElement other = (ClassElement) obj; + + return Objects.equal(clazz, other.clazz); + } + + /** + * Method description + * + * + * @return + */ + @Override + public int hashCode() + { + return Objects.hashCode(clazz); + } + + /** + * Method description + * + * + * @return + */ + @Override + public String toString() + { + //J- + return Objects.toStringHelper(this) + .add("clazz", clazz) + .toString(); + //J+ + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public Class getClazz() + { + return clazz; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + @XmlElement(name = "class") + private Class clazz; +} diff --git a/scm-core/src/main/java/sonia/scm/plugin/ExtensionPointElement.java b/scm-core/src/main/java/sonia/scm/plugin/ExtensionPointElement.java new file mode 100644 index 0000000000..e64e704c3f --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/plugin/ExtensionPointElement.java @@ -0,0 +1,165 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.plugin; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.base.Objects; + +//~--- JDK imports ------------------------------------------------------------ + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Sebastian Sdorra + * @since 2.0.0 + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "extension-point") +public final class ExtensionPointElement +{ + + /** + * Constructs ... + * + */ + ExtensionPointElement() {} + + /** + * Constructs ... + * + * + * @param clazz + * @param multiple + */ + public ExtensionPointElement(Class clazz, boolean multiple) + { + this.clazz = clazz; + this.multiple = multiple; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param obj + * + * @return + */ + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + + if (getClass() != obj.getClass()) + { + return false; + } + + final ExtensionPointElement other = (ExtensionPointElement) obj; + + return Objects.equal(clazz, other.clazz) + && Objects.equal(multiple, other.multiple); + } + + /** + * Method description + * + * + * @return + */ + @Override + public int hashCode() + { + return Objects.hashCode(clazz, multiple); + } + + /** + * Method description + * + * + * @return + */ + @Override + public String toString() + { + //J- + return Objects.toStringHelper(this) + .add("class", clazz) + .add("multiple", multiple) + .toString(); + //J+ + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public Class getClazz() + { + return clazz; + } + + /** + * Method description + * + * + * @return + */ + public boolean isMultiple() + { + return multiple; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + @XmlElement(name = "class") + private Class clazz; + + /** Field description */ + @XmlElement(name = "multi") + private boolean multiple = true; +} diff --git a/scm-core/src/main/java/sonia/scm/plugin/Plugin.java b/scm-core/src/main/java/sonia/scm/plugin/Plugin.java index 8c1a45298c..4038553f80 100644 --- a/scm-core/src/main/java/sonia/scm/plugin/Plugin.java +++ b/scm-core/src/main/java/sonia/scm/plugin/Plugin.java @@ -39,14 +39,10 @@ import com.google.common.base.Objects; //~--- JDK imports ------------------------------------------------------------ -import java.util.Set; - import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; /** * @@ -54,9 +50,33 @@ import javax.xml.bind.annotation.XmlTransient; */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) -public class Plugin +public final class Plugin extends ScmModule { + /** + * Constructs ... + * + */ + Plugin() {} + + /** + * Constructs ... + * + * + * @param information + * @param resources + * @param condition + */ + public Plugin(PluginInformation information, PluginResources resources, + PluginCondition condition) + { + this.information = information; + this.resources = resources; + this.condition = condition; + } + + //~--- methods -------------------------------------------------------------- + /** * Method description * @@ -82,8 +102,6 @@ public class Plugin return Objects.equal(condition, other.condition) && Objects.equal(information, other.information) - && Objects.equal(packageSet, other.packageSet) - && Objects.equal(path, other.path) && Objects.equal(resources, other.resources); } @@ -96,8 +114,7 @@ public class Plugin @Override public int hashCode() { - return Objects.hashCode(condition, information, packageSet, packageSet, - resources); + return Objects.hashCode(condition, information, resources); } /** @@ -113,8 +130,6 @@ public class Plugin return Objects.toStringHelper(this) .add("condition", condition) .add("information", information) - .add("packageSet", packageSet) - .add("path", path) .add("resources", resources) .toString(); //J+ @@ -144,28 +159,6 @@ public class Plugin return information; } - /** - * Method description - * - * - * @return - */ - public Set getPackageSet() - { - return packageSet; - } - - /** - * Method description - * - * - * @return - */ - public String getPath() - { - return path; - } - /** * Method description * @@ -177,64 +170,6 @@ public class Plugin return resources; } - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * - * @param condition - */ - public void setCondition(PluginCondition condition) - { - this.condition = condition; - } - - /** - * Method description - * - * - * @param information - */ - public void setInformation(PluginInformation information) - { - this.information = information; - } - - /** - * Method description - * - * - * @param packageSet - */ - public void setPackageSet(Set packageSet) - { - this.packageSet = packageSet; - } - - /** - * Method description - * - * - * @param path - */ - public void setPath(String path) - { - this.path = path; - } - - /** - * Method description - * - * - * @param resources - */ - public void setResources(PluginResources resources) - { - this.resources = resources; - } - //~--- fields --------------------------------------------------------------- /** Field description */ @@ -244,15 +179,6 @@ public class Plugin /** Field description */ private PluginInformation information; - /** Field description */ - @XmlElement(name = "package") - @XmlElementWrapper(name = "packages") - private Set packageSet; - - /** Field description */ - @XmlTransient - private String path; - /** Field description */ private PluginResources resources; } diff --git a/scm-core/src/main/java/sonia/scm/plugin/ScmModule.java b/scm-core/src/main/java/sonia/scm/plugin/ScmModule.java new file mode 100644 index 0000000000..2e4472c50d --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/plugin/ScmModule.java @@ -0,0 +1,230 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.plugin; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; + +//~--- JDK imports ------------------------------------------------------------ + +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Sebastian Sdorra + * @since 2.0.0 + */ +@XmlRootElement(name = "module") +@XmlAccessorType(XmlAccessType.FIELD) +public class ScmModule +{ + + /** Field description */ + private static final Unwrapper unwrapper = new Unwrapper(); + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public Iterable> getEvents() + { + return unwrap(events); + } + + /** + * Method description + * + * + * @return + */ + public Iterable getExtensionPoints() + { + return nonNull(extensionPoints); + } + + /** + * Method description + * + * + * @return + */ + public Iterable> getExtensions() + { + return unwrap(extensions); + } + + /** + * Method description + * + * + * @return + */ + public Iterable> getJaxrsProviders() + { + return unwrap(jaxrsProviders); + } + + /** + * Method description + * + * + * @return + */ + public Iterable> getJaxrsResources() + { + return unwrap(jaxrsResources); + } + + /** + * Method description + * + * + * @return + */ + public Iterable getSubscribers() + { + return nonNull(subscribers); + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param iterable + * @param + * + * @return + */ + private Iterable nonNull(Iterable iterable) + { + if (iterable == null) + { + iterable = ImmutableSet.of(); + } + + return iterable; + } + + /** + * Method description + * + * + * @param iterable + * + * @return + */ + private Iterable> unwrap(Iterable iterable) + { + Iterable> unwrapped; + + if (iterable != null) + { + unwrapped = Iterables.transform(iterable, unwrapper); + } + else + { + unwrapped = ImmutableSet.of(); + } + + return unwrapped; + } + + //~--- inner classes -------------------------------------------------------- + + /** + * Class description + * + * + * @version Enter version here..., 14/03/28 + * @author Enter your name here... + */ + private static class Unwrapper implements Function> + { + + /** + * Method description + * + * + * @param classElement + * + * @return + */ + @Override + public Class apply(ClassElement classElement) + { + return classElement.getClazz(); + } + } + + + ; + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + @XmlElement(name = "event") + private Set events; + + /** Field description */ + @XmlElement(name = "extension-point") + private Set extensionPoints; + + /** Field description */ + @XmlElement(name = "extension") + private Set extensions; + + /** Field description */ + @XmlElement(name = "jaxrs-provider") + private Set jaxrsProviders; + + /** Field description */ + @XmlElement(name = "jaxrs-resource") + private Set jaxrsResources; + + /** Field description */ + @XmlElement(name = "subscriber") + private Set subscribers; +} diff --git a/scm-core/src/main/java/sonia/scm/plugin/SubscriberElement.java b/scm-core/src/main/java/sonia/scm/plugin/SubscriberElement.java new file mode 100644 index 0000000000..d3ea576088 --- /dev/null +++ b/scm-core/src/main/java/sonia/scm/plugin/SubscriberElement.java @@ -0,0 +1,165 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.plugin; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.base.Objects; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +//~--- JDK imports ------------------------------------------------------------ + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Sebastian Sdorra + * @since 2.0.0 + */ +@XmlRootElement(name = "subscriber") +@XmlAccessorType(XmlAccessType.FIELD) +public final class SubscriberElement +{ + + /** + * Constructs ... + * + */ + SubscriberElement() {} + + /** + * Constructs ... + * + * + * @param subscriberClass + * @param eventClass + */ + public SubscriberElement(Class subscriberClass, Class eventClass) + { + this.subscriberClass = subscriberClass; + this.eventClass = eventClass; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param obj + * + * @return + */ + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + + if (getClass() != obj.getClass()) + { + return false; + } + + final SubscriberElement other = (SubscriberElement) obj; + + return Objects.equal(eventClass, other.eventClass) + && Objects.equal(subscriberClass, other.subscriberClass); + } + + /** + * Method description + * + * + * @return + */ + @Override + public int hashCode() + { + return Objects.hashCode(eventClass, subscriberClass); + } + + /** + * Method description + * + * + * @return + */ + @Override + public String toString() + { + //J- + return Objects.toStringHelper(this) + .add("eventClass", eventClass) + .add("subscriberClass", subscriberClass) + .toString(); + //J+ + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @return + */ + public Class getEventClass() + { + return eventClass; + } + + /** + * Method description + * + * + * @return + */ + public Class getSubscriberClass() + { + return subscriberClass; + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + @XmlElement(name = "event") + private Class eventClass; + + /** Field description */ + @XmlElement(name = "class") + private Class subscriberClass; +} diff --git a/scm-core/src/test/java/sonia/scm/plugin/ScmModuleTest.java b/scm-core/src/test/java/sonia/scm/plugin/ScmModuleTest.java new file mode 100644 index 0000000000..fa9f6329fe --- /dev/null +++ b/scm-core/src/test/java/sonia/scm/plugin/ScmModuleTest.java @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Neither the name of SCM-Manager; + * nor the names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.plugin; + +//~--- non-JDK imports -------------------------------------------------------- + +import com.google.common.io.Resources; + +import org.junit.Test; + +import static org.hamcrest.Matchers.*; + +import static org.junit.Assert.*; + +//~--- JDK imports ------------------------------------------------------------ + +import java.net.URL; + +import javax.xml.bind.JAXB; + +/** + * + * @author Sebastian Sdorra + */ +public class ScmModuleTest +{ + + /** + * Method description + * + */ + @Test + public void testUnmarshall() + { + URL resource = Resources.getResource("sonia/scm/plugin/module.xml"); + ScmModule module = JAXB.unmarshal(resource, ScmModule.class); + + // stupid cast to Class to make hamecrest generics happy + + //J- + assertThat( + module.getExtensions(), + containsInAnyOrder( + (Class) String.class, + (Class) Integer.class + ) + ); + assertThat( + module.getExtensionPoints(), + containsInAnyOrder( + new ExtensionPointElement(String.class, true), + new ExtensionPointElement(Long.class, true), + new ExtensionPointElement(Integer.class, false) + ) + ); + assertThat( + module.getEvents(), + containsInAnyOrder( + (Class) String.class, + (Class) Boolean.class + ) + ); + assertThat( + module.getSubscribers(), + containsInAnyOrder( + new SubscriberElement(Long.class, Integer.class), + new SubscriberElement(Double.class, Float.class) + ) + ); + assertThat( + module.getJaxrsProviders(), + containsInAnyOrder( + (Class) Integer.class, + (Class) Long.class + ) + ); + assertThat( + module.getJaxrsResources(), + containsInAnyOrder( + (Class) Float.class, + (Class) Double.class + ) + ); + //J+ + } +} diff --git a/scm-core/src/test/resources/sonia/scm/plugin/module.xml b/scm-core/src/test/resources/sonia/scm/plugin/module.xml new file mode 100644 index 0000000000..48ba7124ae --- /dev/null +++ b/scm-core/src/test/resources/sonia/scm/plugin/module.xml @@ -0,0 +1,71 @@ + + + + + + java.lang.Long + java.lang.Integer + + + + java.lang.Double + java.lang.Float + + + + + + java.lang.String + + + + java.lang.Boolean + + + + + + java.lang.String + + + + java.lang.Integer + false + + + + java.lang.Long + true + + + + + + java.lang.String + + + + java.lang.Integer + + + + + + java.lang.Integer + + + + java.lang.Long + + + + + + java.lang.Float + + + + java.lang.Double + + +