You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2015/05/17 08:48:35 UTC
svn commit: r1679818 - in /webservices/axiom/trunk/testing: ./
axiom-testsuite/
axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/ axiom-truth/
axiom-truth/src/ axiom-truth/src/main/ axiom-truth/src/main/java/
axiom-truth/src/main/java/org/ ...
Author: veithen
Date: Sun May 17 06:48:34 2015
New Revision: 1679818
URL: http://svn.apache.org/r1679818
Log:
Create a Google Truth extension for Axiom.
Added:
webservices/axiom/trunk/testing/axiom-truth/ (with props)
webservices/axiom/trunk/testing/axiom-truth/pom.xml (with props)
webservices/axiom/trunk/testing/axiom-truth/src/
webservices/axiom/trunk/testing/axiom-truth/src/main/
webservices/axiom/trunk/testing/axiom-truth/src/main/java/
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AbstractOMContainerSubject.java (with props)
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomTestVerb.java (with props)
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMAttributeSubject.java (with props)
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMContainerSubject.java (with props)
webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMElementSubject.java (with props)
Modified:
webservices/axiom/trunk/testing/axiom-testsuite/pom.xml
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReplace.java
webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReuseExistingPrefix.java
webservices/axiom/trunk/testing/pom.xml
Modified: webservices/axiom/trunk/testing/axiom-testsuite/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/pom.xml?rev=1679818&r1=1679817&r2=1679818&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/pom.xml (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/pom.xml Sun May 17 06:48:34 2015
@@ -45,8 +45,9 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
- <groupId>com.google.truth</groupId>
- <artifactId>truth</artifactId>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axiom-truth</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReplace.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReplace.java?rev=1679818&r1=1679817&r2=1679818&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReplace.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReplace.java Sun May 17 06:48:34 2015
@@ -18,6 +18,8 @@
*/
package org.apache.axiom.ts.om.element;
+import static org.apache.axiom.truth.AxiomTestVerb.ASSERT;
+
import java.util.Iterator;
import javax.xml.namespace.QName;
@@ -52,12 +54,12 @@ public class TestAddAttributeReplace ext
OMAttribute att1 = strategy.addAttribute(element, "test", ns1, "value1");
OMAttribute att2 = strategy.addAttribute(element, "test", ns2, "value2");
Iterator it = element.getAllAttributes();
- assertTrue(it.hasNext());
- assertSame(att2, it.next());
- assertFalse(it.hasNext());
- assertNull(att1.getOwner());
- assertSame(element, att2.getOwner());
- assertEquals("value1", att1.getAttributeValue());
- assertEquals("value2", att2.getAttributeValue());
+ ASSERT.that(it.hasNext()).isTrue();
+ ASSERT.that(it.next()).isSameAs(att2);
+ ASSERT.that(it.hasNext()).isFalse();
+ ASSERT.that(att1.getOwner()).isNull();
+ ASSERT.that(att2.getOwner()).isSameAs(element);
+ ASSERT.that(att1).hasValue("value1");
+ ASSERT.that(att2).hasValue("value2");
}
}
Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReuseExistingPrefix.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReuseExistingPrefix.java?rev=1679818&r1=1679817&r2=1679818&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReuseExistingPrefix.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddAttributeReuseExistingPrefix.java Sun May 17 06:48:34 2015
@@ -18,6 +18,8 @@
*/
package org.apache.axiom.ts.om.element;
+import static org.apache.axiom.truth.AxiomTestVerb.ASSERT;
+
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
@@ -41,7 +43,7 @@ public class TestAddAttributeReuseExisti
OMElement element = factory.createOMElement("element", null, parent);
parent.declareNamespace("urn:test", "p");
OMAttribute attr = element.addAttribute("attr", "test", factory.createOMNamespace("urn:test", null));
- assertEquals("p", attr.getPrefix());
- assertFalse(element.getAllDeclaredNamespaces().hasNext());
+ ASSERT.that(attr).hasPrefix("p");
+ ASSERT.that(element).hasNoNamespaceDeclarations();
}
}
Propchange: webservices/axiom/trunk/testing/axiom-truth/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun May 17 06:48:34 2015
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target
Added: webservices/axiom/trunk/testing/axiom-truth/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-truth/pom.xml?rev=1679818&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-truth/pom.xml (added)
+++ webservices/axiom/trunk/testing/axiom-truth/pom.xml Sun May 17 06:48:34 2015
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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.
+ -->
+<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>
+
+ <parent>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>testing</artifactId>
+ <version>1.2.15-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>axiom-truth</artifactId>
+
+ <name>Google Truth extension for Axiom</name>
+ <description>
+ Extension for Google Truth to make assertions about Axiom trees.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axiom-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.truth</groupId>
+ <artifactId>truth</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Propchange: webservices/axiom/trunk/testing/axiom-truth/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AbstractOMContainerSubject.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AbstractOMContainerSubject.java?rev=1679818&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AbstractOMContainerSubject.java (added)
+++ webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AbstractOMContainerSubject.java Sun May 17 06:48:34 2015
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.axiom.truth;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMNode;
+
+import com.google.common.truth.FailureStrategy;
+import com.google.common.truth.Subject;
+
+public abstract class AbstractOMContainerSubject<S extends AbstractOMContainerSubject<S,T>,T extends OMContainer> extends Subject<S,T> {
+ public AbstractOMContainerSubject(FailureStrategy failureStrategy, T subject) {
+ super(failureStrategy, subject);
+ }
+
+ public final void hasNumberOfChildren(int expected) {
+ OMNode child = getSubject().getFirstOMChild();
+ int actual = 0;
+ while (child != null) {
+ actual++;
+ child = child.getNextOMSibling();
+ }
+ if (actual != expected) {
+ failWithRawMessage("number of children is %d instead of %d", actual, expected);
+ }
+ }
+}
Propchange: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AbstractOMContainerSubject.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomTestVerb.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomTestVerb.java?rev=1679818&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomTestVerb.java (added)
+++ webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomTestVerb.java Sun May 17 06:48:34 2015
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.axiom.truth;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+
+import com.google.common.truth.FailureStrategy;
+import com.google.common.truth.IterableSubject;
+import com.google.common.truth.TestVerb;
+import com.google.common.truth.Truth;
+
+public final class AxiomTestVerb extends TestVerb {
+ public static final AxiomTestVerb ASSERT = new AxiomTestVerb(Truth.THROW_ASSERTION_ERROR);
+
+ private AxiomTestVerb(FailureStrategy failureStrategy) {
+ super(failureStrategy);
+ }
+
+ public <T,C extends Iterable<T>> IterableSubject<? extends IterableSubject<?,T,C>,T,C> that(final Iterator<T> target) {
+ return that(new Iterable<T>() {
+ @Override
+ public Iterator<T> iterator() {
+ return target;
+ }
+ });
+ }
+
+ public OMContainerSubject that(OMContainer target) {
+ return new OMContainerSubject(getFailureStrategy(), target);
+ }
+
+ public OMElementSubject that(OMElement target) {
+ return new OMElementSubject(getFailureStrategy(), target);
+ }
+
+ public OMAttributeSubject that(OMAttribute target) {
+ return new OMAttributeSubject(getFailureStrategy(), target);
+ }
+}
Propchange: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/AxiomTestVerb.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMAttributeSubject.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMAttributeSubject.java?rev=1679818&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMAttributeSubject.java (added)
+++ webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMAttributeSubject.java Sun May 17 06:48:34 2015
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.axiom.truth;
+
+import org.apache.axiom.om.OMAttribute;
+
+import com.google.common.base.Objects;
+import com.google.common.truth.FailureStrategy;
+import com.google.common.truth.Subject;
+
+public final class OMAttributeSubject extends Subject<OMAttributeSubject,OMAttribute>{
+ OMAttributeSubject(FailureStrategy failureStrategy, OMAttribute subject) {
+ super(failureStrategy, subject);
+ }
+
+ public void hasValue(String expected) {
+ if (!Objects.equal(getSubject().getAttributeValue(), expected)) {
+ fail("has value", expected);
+ }
+ }
+
+ public void hasPrefix(String expected) {
+ if (!Objects.equal(getSubject().getPrefix(), expected)) {
+ fail("has prefix", expected);
+ }
+ }
+}
Propchange: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMAttributeSubject.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMContainerSubject.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMContainerSubject.java?rev=1679818&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMContainerSubject.java (added)
+++ webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMContainerSubject.java Sun May 17 06:48:34 2015
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.axiom.truth;
+
+import org.apache.axiom.om.OMContainer;
+
+import com.google.common.truth.FailureStrategy;
+
+public final class OMContainerSubject extends AbstractOMContainerSubject<OMContainerSubject,OMContainer> {
+ OMContainerSubject(FailureStrategy failureStrategy, OMContainer subject) {
+ super(failureStrategy, subject);
+ }
+}
Propchange: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMContainerSubject.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMElementSubject.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMElementSubject.java?rev=1679818&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMElementSubject.java (added)
+++ webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMElementSubject.java Sun May 17 06:48:34 2015
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.axiom.truth;
+
+import org.apache.axiom.om.OMElement;
+
+import com.google.common.truth.FailureStrategy;
+
+public final class OMElementSubject extends AbstractOMContainerSubject<OMElementSubject,OMElement> {
+ OMElementSubject(FailureStrategy failureStrategy, OMElement subject) {
+ super(failureStrategy, subject);
+ }
+
+ public void hasNoNamespaceDeclarations() {
+ if (getSubject().getAllDeclaredNamespaces().hasNext()) {
+ fail("has no namespace declarations");
+ }
+ }
+}
Propchange: webservices/axiom/trunk/testing/axiom-truth/src/main/java/org/apache/axiom/truth/OMElementSubject.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axiom/trunk/testing/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/pom.xml?rev=1679818&r1=1679817&r2=1679818&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/pom.xml (original)
+++ webservices/axiom/trunk/testing/pom.xml Sun May 17 06:48:34 2015
@@ -33,6 +33,7 @@
<modules>
<module>axiom-testsuite</module>
+ <module>axiom-truth</module>
<module>dom-testsuite</module>
<module>jaxen-testsuite</module>
<module>multiton</module>