Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Hello, world\!

  • Loading branch information...
commit 8e6c39766f60a6e7d13cef73075181926beff9cd 1 parent 13f2df3
Josh authored
21 README
View
@@ -0,0 +1,21 @@
+
+Copyright (C) 2010 Shopzilla, Inc
+
+
+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.
+
+
+
+http://tech.shopzilla.com
+
+
232 pom.xml
View
@@ -0,0 +1,232 @@
+<!--
+ *
+ * Copyright (C) 2010 Shopzilla, Inc
+ *
+ *
+ * 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.
+ *
+ *
+ *
+ * http://tech.shopzilla.com
+ *
+ *
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.shopzilla.utilities</groupId>
+ <artifactId>spring</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>core</name>
+ <properties>
+ <spring.version>3.0.2.RELEASE</spring.version>
+ <junit.version>4.7</junit.version>
+ </properties>
+
+ <contributors>
+ <contributor>
+ <name>Tim Morrow</name>
+ <email>tmorrow@Shopzilla.com</email>
+ <url>http://timmorrow.org/</url>
+ </contributor>
+ <contributor>
+ <name>Rod Barlow</name>
+ <email>rbarlow@Shopzilla.com</email>
+ <url>http://rodneybarlow.org</url>
+ </contributor>
+ <contributor>
+ <name>Robert Roland</name>
+ <email>rroland@shopzilla.com</email>
+ <url>http://robertroland.org</url>
+ </contributor>
+ <contributor>
+ <name>Josh Long</name>
+ <email>jlong@shopzilla.com</email>
+ <url>http://joshlong.com</url>
+ </contributor>
+ <contributor>
+ <name>Mark Lui</name>
+ <email>mlui@Shopzilla.com</email>
+ </contributor>
+ </contributors>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock</artifactId>
+ <version>2.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-legacy</artifactId>
+ <version>2.5.1</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-help-plugin</artifactId>
+ <version>2.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ <configuration>
+ <formats>
+ <format>html</format>
+ <format>xml</format>
+ </formats>
+ <check>
+ <!-- 90% -->
+ <totalLineRate>90</totalLineRate>
+ <totalBranchRate>90</totalBranchRate>
+ </check>
+ <instrumentation>
+ <ignores>
+ <ignore>org.apache.commons.logging.*</ignore>
+ </ignores>
+ </instrumentation>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>clean</goal>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <inherited>true</inherited>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>index</report>
+ </reports>
+ </reportSet>
+ <reportSet>
+ <id>sunlink</id>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ <inherited>true</inherited>
+ <configuration>
+ <links>
+ <link>http://java.sun.com/javase/6/docs/api/</link>
+ </links>
+ </configuration>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-docck-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+
+ <links>
+ <link>http://java.sun.com/javase/6/docs/api/</link>
+ </links>
+ <linksource>true</linksource>
+ <quiet>true</quiet>
+ <show>private</show>
+ <sourcepath>${basedir}/src/main/java;${basedir}/src/test/java</sourcepath>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jxr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <configuration>
+ <threshold>Normal</threshold>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+
+</project>
117 src/main/java/com/shopzilla/spring/util/config/ShopzillaNamespaceUtils.java
View
@@ -0,0 +1,117 @@
+/*
+ *
+ * Copyright (C) 2010 Shopzilla, Inc
+ *
+ *
+ * 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.
+ *
+ *
+ *
+ * http://tech.shopzilla.com
+ *
+ *
+ */
+
+package com.shopzilla.spring.util.config;
+
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.core.Conventions;
+import org.springframework.util.StringUtils;
+import org.w3c.dom.Element;
+
+/**
+ * This class was stolen largely from {@link org.springframework.integration.config.xml.IntegrationNamespaceUtils} from the Spring Integration project: it's useful, but we can't risk having a forced dependency on it ATM.
+ */
+public class ShopzillaNamespaceUtils {
+
+ /**
+ * Populates the specified bean definition property with the value of the attribute whose name is provided if that attribute is defined in the given element.
+ *
+ * @param builder the bean definition to be configured
+ * @param element the XML element where the attribute should be defined
+ * @param attributeName the name of the attribute whose value will be used to populate the property
+ * @param propertyName the name of the property to be populated
+ */
+ public void setValueIfAttributeDefined(BeanDefinitionBuilder builder, Element element,
+ String attributeName, String propertyName) {
+ String attributeValue = element.getAttribute(attributeName);
+
+ if (StringUtils.hasText(attributeValue)) {
+ builder.addPropertyValue(propertyName, attributeValue);
+ }
+ }
+
+ /**
+ * Populates the bean definition property corresponding to the specified attributeName with the value of that attribute if it is defined in the given element. <p>The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the "foo-bar" attribute would
+ * match the "fooBar" property).
+ *
+ * @param beanDefinitionBuilder - the bean definition to be configured
+ * @param element - the XML element where the attribute should be defined
+ * @param attributeName - the name of the attribute whose value will be set on the property
+ *
+ * @see org.springframework.core.Conventions#attributeNameToPropertyName(String)
+ */
+ public void setValueIfAttributeDefined(BeanDefinitionBuilder beanDefinitionBuilder,
+ Element element, String attributeName) {
+ setValueIfAttributeDefined(beanDefinitionBuilder, element, attributeName,
+ Conventions.attributeNameToPropertyName(attributeName));
+ }
+
+ /**
+ * Populates the specified bean definition property with the reference to a bean. The bean reference is identified by the value from the attribute whose name is provided if that attribute is defined in the given element.
+ *
+ * @param builder the bean definition to be configured
+ * @param element the XML element where the attribute should be defined
+ * @param attributeName the name of the attribute whose value will be used as a bean reference to populate the property
+ * @param propertyName the name of the property to be populated
+ */
+ public void setReferenceIfAttributeDefined(BeanDefinitionBuilder builder, Element element,
+ String attributeName, String propertyName) {
+ String attributeValue = element.getAttribute(attributeName);
+
+ if (StringUtils.hasText(attributeValue)) {
+ builder.addPropertyReference(propertyName, attributeValue);
+ }
+ }
+
+ /**
+ * Populates the bean definition property corresponding to the specified attributeName with the reference to a bean identified by the value of that attribute if the attribute is defined in the given element. <p>The property name will be the camel-case equivalent of the lower case hyphen
+ * separated attribute (e.g. the "foo-bar" attribute would match the "fooBar" property).
+ *
+ * @param builder - the bean definition to be configured
+ * @param element - the XML element where the attribute should be defined
+ * @param attributeName - the name of the attribute whose value will be used as a bean reference to populate the property
+ *
+ * @see Conventions#attributeNameToPropertyName(String)
+ * @see Conventions#attributeNameToPropertyName(String)
+ */
+ public void setReferenceIfAttributeDefined(BeanDefinitionBuilder builder, Element element,
+ String attributeName) {
+ setReferenceIfAttributeDefined(builder, element, attributeName,
+ Conventions.attributeNameToPropertyName(attributeName));
+ }
+
+ /**
+ * Provides a user friendly description of an element based on its node name and, if available, its "id" attribute value. This is useful for creating error messages from within bean definition parsers.
+ */
+ public String createElementDescription(Element element) {
+ String elementId = "'" + element.getNodeName() + "'";
+ String id = element.getAttribute("id");
+
+ if (StringUtils.hasText(id)) {
+ elementId += (" with id='" + id + "'");
+ }
+
+ return elementId;
+ }
+}
181 src/test/java/com/shopzilla/spring/util/config/ShopzillaNamespaceUtilsTest.java
View
@@ -0,0 +1,181 @@
+/*
+ *
+ * Copyright (C) 2010 Shopzilla, Inc
+ *
+ *
+ * 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.
+ *
+ *
+ *
+ * http://tech.shopzilla.com
+ *
+ *
+ */
+
+package com.shopzilla.spring.util.config;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author <a href="mailto:josh@joshlong.com">Josh Long</a>
+ */
+public class ShopzillaNamespaceUtilsTest {
+ private Mockery context = new Mockery() {
+ {
+ setImposteriser(ClassImposteriser.INSTANCE);
+ }
+ };
+
+ private BeanDefinitionBuilder beanDefinitionBuilder;
+ private Element element;
+ private ShopzillaNamespaceUtils shopzillaNamespaceUtils;
+
+ @Before
+ public void before() throws Throwable {
+ this.shopzillaNamespaceUtils = new ShopzillaNamespaceUtils();
+ this.beanDefinitionBuilder = this.context.mock(BeanDefinitionBuilder.class);
+ this.element = this.context.mock(Element.class);
+ }
+
+ @After
+ public void after() throws Throwable {
+ this.context.assertIsSatisfied();
+ }
+
+ @Test
+ public void testSetValueIfAttributeDefined4ParamWithEmptyAttribute()
+ throws Throwable {
+ final String attr = "attr";
+ final String prop = "prop";
+ this.context.checking(new Expectations() {
+ {
+ one(element).getAttribute(attr);
+ will(returnValue(null));
+ }
+ });
+
+ this.shopzillaNamespaceUtils.setValueIfAttributeDefined(beanDefinitionBuilder, element, attr, prop);
+ }
+
+ @Test
+ public void testSetValueIfAttributeDefined4Param()
+ throws Throwable {
+ final String attr = "attr";
+ final String prop = "prop";
+ final String val = "value";
+ this.context.checking(new Expectations() {
+ {
+ one(element).getAttribute(attr);
+ will(returnValue(val));
+ one(beanDefinitionBuilder).addPropertyValue(prop, val);
+ }
+ });
+ this.shopzillaNamespaceUtils.setValueIfAttributeDefined(beanDefinitionBuilder, element, attr, prop);
+ }
+
+ @Test
+ public void testSetValueIfAttributeDefined3Param()
+ throws Throwable {
+ final String attr = "attr";
+ final String prop = "attr";
+ final String val = "value";
+ this.context.checking(new Expectations() {
+ {
+ one(element).getAttribute(attr);
+ will(returnValue(val));
+ one(beanDefinitionBuilder).addPropertyValue(prop, val);
+ }
+ });
+ this.shopzillaNamespaceUtils.setValueIfAttributeDefined(beanDefinitionBuilder, element, attr);
+ }
+
+ @Test
+ public void testSetReferenceIfAttributeDefinedWithNullAttribute()
+ throws Throwable {
+ final String attr = "attr";
+ final String prop = "attr";
+ this.context.checking(new Expectations() {
+ {
+ one(element).getAttribute(attr);
+ will(returnValue(null));
+ }
+ });
+ this.shopzillaNamespaceUtils.setReferenceIfAttributeDefined(beanDefinitionBuilder, element, attr, prop);
+ }
+
+ @Test
+ public void testSetReferenceIfAttributeDefined() throws Throwable {
+ final String attr = "attr";
+ final String prop = "attr";
+ final String val = "value";
+ this.context.checking(new Expectations() {
+ {
+ one(element).getAttribute(attr);
+ will(returnValue(val));
+ one(beanDefinitionBuilder).addPropertyReference(prop, val);
+ }
+ });
+ this.shopzillaNamespaceUtils.setReferenceIfAttributeDefined(beanDefinitionBuilder, element, attr, prop);
+ }
+
+ @Test
+ public void testSetReferenceIfAttributeDefined3Param()
+ throws Throwable {
+ final String attr = "attr";
+ final String prop = "attr";
+ final String val = "value";
+ this.context.checking(new Expectations() {
+ {
+ one(element).getAttribute(attr);
+ will(returnValue(val));
+ one(beanDefinitionBuilder).addPropertyReference(prop, val);
+ }
+ });
+ this.shopzillaNamespaceUtils.setReferenceIfAttributeDefined(beanDefinitionBuilder, element, attr);
+ }
+
+ @Test
+ public void testCreateElementDescriptionWithNullID()
+ throws Throwable {
+ this.context.checking(new Expectations() {
+ {
+ one(element).getNodeName();
+ will(returnValue("nodeName"));
+ one(element).getAttribute("id");
+ will(returnValue(null));
+ }
+ });
+ this.shopzillaNamespaceUtils.createElementDescription(element);
+ }
+
+ @Test
+ public void testCreateElementDescription() throws Throwable {
+ this.context.checking(new Expectations() {
+ {
+ one(element).getNodeName();
+ will(returnValue("nodeName"));
+ one(element).getAttribute("id");
+ will(returnValue("id"));
+ }
+ });
+ this.shopzillaNamespaceUtils.createElementDescription(element);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.