Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r6350 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/messaging src/main/java/net/geant/perfsonar/templates src/test/groovy/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/messaging src/test/java/net/geant/perfsonar/messaging/xpath src/test/java/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar/templates

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r6350 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/messaging src/main/java/net/geant/perfsonar/templates src/test/groovy/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/messaging src/test/java/net/geant/perfsonar/messaging/xpath src/test/java/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar/templates


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r6350 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/messaging src/main/java/net/geant/perfsonar/templates src/test/groovy/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/messaging src/test/java/net/geant/perfsonar/messaging/xpath src/test/java/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar/templates
  • Date: Mon, 6 May 2013 14:01:14 +0100 (BST)
  • Authentication-results: sfpop-ironport04.merit.edu; dkim=neutral (message not signed) header.i=none

Author: psnc.pietrzak
Date: 2013-05-06 14:01:14 +0100 (Mon, 06 May 2013)
New Revision: 6350

Added:

trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java

trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java

trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java

trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/SelfTestResult.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/StaticMethodTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XMLDogTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
Removed:

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/InvalidDeserializerConfigurationTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
Modified:
trunk/perfsonar-base/messaging/pom.xml

trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java

trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java

trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java

trunk/perfsonar-base/messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java

trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java
Log:
Improved debug information for developers.

Modified: trunk/perfsonar-base/messaging/pom.xml
===================================================================
--- trunk/perfsonar-base/messaging/pom.xml 2013-05-06 12:58:23 UTC (rev
6349)
+++ trunk/perfsonar-base/messaging/pom.xml 2013-05-06 13:01:14 UTC (rev
6350)
@@ -16,11 +16,26 @@
<description>Library for serialization and deserialization of perfSONAR
messages.</description>
<packaging>bundle</packaging>

- <scm>
+ <scm>

<connection>scm:svn:http://svn.geant.net/GEANT/SA2/ps-java-services/trunk/perfsonar-base/messaging/</connection>

<developerConnection>scm:svn:svn+ssh:///GEANT/SA2/ps-java-services/trunk/perfsonar-base/messaging/</developerConnection>

<url>https://svn.geant.net/fisheye/browse/SA2T3-ps-java-services/trunk/perfsonar-base/messaging/</url>
</scm>
+
+ <developers>
+ <developer>
+ <id>blazej.pietrzak</id>
+ <name>Blazej Pietrzak</name>
+
<email></email>
+ <organization>PSNC</organization>
+
<organizationUrl>http://www.man.poznan.pl/</organizationUrl>
+ <roles>
+ <role>architect</role>
+ <role>developer</role>
+ </roles>
+ <timezone>+1</timezone>
+ </developer>
+ </developers>

<dependencies>
<dependency>
@@ -107,22 +122,13 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+
<version>2.3.2</version><!--$NO-MVN-MAN-VER$--> <!-- Groovy Eclipse Compiler
does not work with 3.0 -->
<!-- This also means that one has to install
the Groovy-Eclipse configurator for m2Eclipse -->
<!-- See
http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven#Groovy-EclipsecompilerpluginforMaven-Groovy-Eclipseconfiguratorform2Eclipse
-->
<configuration>

<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>false</verbose>
- <!-- This includes/testIncludes
section if currently needed for the groovy-eclipse-compiler to work -->
- <!-- See
http://markmail.org/message/ti6svvi4apwecvjq -->
- <includes>
- <include>**/*.groovy</include>
- <include>**/*.java</include>
- </includes>
- <testIncludes>
- <testInclude>**/*.groovy</testInclude>
- <testInclude>**/*.java</testInclude>
- </testIncludes>
- </configuration>
+ </configuration>
<dependencies>
<dependency>

<groupId>org.codehaus.groovy</groupId>
@@ -144,5 +150,41 @@
</executions>
</plugin>
</plugins>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to
store Eclipse m2e settings only. It has no influence on the Maven build
itself.-->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+
<artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+
<pluginExecution>
+
<pluginExecutionFilter>
+
<groupId>
+
org.apache.maven.plugins
+
</groupId>
+
<artifactId>
+
maven-compiler-plugin
+
</artifactId>
+
<versionRange>
+
[2.3.2,)
+
</versionRange>
+
<goals>
+
<goal>testCompile</goal>
+
<goal>compile</goal>
+
</goals>
+
</pluginExecutionFilter>
+
<action>
+
<ignore></ignore>
+
</action>
+
</pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
</build>
</project>

Added:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/DeserializationException.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,53 @@
+package net.geant.perfsonar.messaging;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class DeserializationException extends Exception implements
Iterable<Throwable> {
+ private static final long serialVersionUID = 2627705969628394226L;
+ private List<Throwable> exceptions = new ArrayList<Throwable>();
+
+ public DeserializationException(List<Throwable> exceptions) {
+ super(toString(exceptions));
+ this.exceptions.addAll(exceptions);
+ }
+
+ public DeserializationException(Throwable... ex) {
+ super(toString(ex));
+ for (Throwable t : ex) {
+ exceptions.add(t);
+ }
+ }
+
+ private static String toString(Throwable[] ex) {
+ final StringBuffer text = new StringBuffer();
+ boolean firstTime = true;
+ for (Throwable t : ex) {
+ if (firstTime)
+ firstTime = false;
+ else
+ text.append("\n");
+ text.append(t.getMessage());
+ }
+ return text.toString();
+ }
+
+ private static String toString(List<Throwable> exceptions) {
+ final StringBuffer text = new StringBuffer();
+ boolean firstTime = true;
+ for (Throwable ex : exceptions) {
+ if (firstTime)
+ firstTime = false;
+ else
+ text.append("\n");
+ text.append(ex.getMessage());
+ }
+ return text.toString();
+ }
+
+ @Override
+ public Iterator<Throwable> iterator() {
+ return exceptions.iterator();
+ }
+}

Added:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/InMemoryInstancesListener.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,62 @@
+package net.geant.perfsonar.messaging;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.xpath.XPathException;
+
+import jlibs.xml.sax.dog.NodeItem;
+import jlibs.xml.sax.dog.expr.Expression;
+import jlibs.xml.sax.dog.expr.InstantEvaluationListener;
+
+/**
+ * Creates objects from XPath events and stores them in memory.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ */
+public class InMemoryInstancesListener extends InstantEvaluationListener {
+ final Map<Class<?>, List<Object>> instances = new Hashtable<Class<?>,
List<Object>>();
+ final List<Throwable> exceptions = new ArrayList<Throwable>();
+
+ @Override
+ public void onNodeHit(Expression expression, NodeItem nodeItem) {
+ final Method method =
XPathDeserializer.getXPathMethod(expression.getXPath());
+ executeMethod(method, nodeItem.value, instances, expression);
+ }
+
+ @Override
+ public void finishedNodeSet(Expression expression) {
+ //Empty implementation
+ }
+
+ @Override
+ public void onResult(Expression expression, Object result) {
+ final Method method =
XPathDeserializer.getXPathMethod(expression.getXPath());
+ executeMethod(method, (String) result.toString(), instances,
expression);
+ }
+
+ public List<?> getObjects() {
+ final List<Object> result = new ArrayList<Object>();
+ for (List<Object> temp : instances.values())
+ result.addAll(temp);
+ return result;
+ }
+
+ private void executeMethod(final Method method, String value, final
Map<Class<?>,
+ List<Object>> instances, Expression expr) {
+ if (value == null)
+ exceptions.add(new XPathException("XPath(" +
expr.getXPath() + ") returned null."));
+ try {
+ method.execute(value, instances);
+ } catch (Throwable ex) {
+ exceptions.add(ex);
+ }
+ }
+
+ public List<Throwable> getExceptions() {
+ return Collections.unmodifiableList(exceptions);
+ }
+}

Added:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/Method.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,107 @@
+package net.geant.perfsonar.messaging;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class Method {
+
+ private final java.lang.reflect.Method method;
+ private int count = 0;
+
+ private final java.lang.reflect.Method identifierMethod;
+ private final Object object;
+
+ public Method(java.lang.reflect.Method method) {
+ this(method, null, null);
+ }
+
+ public Method(java.lang.reflect.Method method,
java.lang.reflect.Method identifierMethod) {
+ this(method, identifierMethod, null);
+ }
+
+ public Method(java.lang.reflect.Method method,
java.lang.reflect.Method identifierMethod, Object object) {
+ this.method = method;
+ this.identifierMethod = identifierMethod;
+ this.object = object;
+ }
+
+ public void execute(String arg, Map<Class<?>, List<Object>>
instances) throws Throwable {
+ try {
+ if (getParameterType().equals(String.class)) {
+ method.invoke(getInstance(instances), arg);
+ } else {
+ final Object reference =
getReference(instances, arg);
+ if (reference == null)
+ return;
+ method.invoke(getInstance(instances),
reference);
+ }
+ } catch (InvocationTargetException ex) {
+ throw new RuntimeException("Method: " + toString(),
ex.getTargetException());
+ //throw ex.getTargetException();
+ }
+
+ count++;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ protected Object getInstance(Map<Class<?>, List<Object>> instances)
throws InstantiationException, IllegalAccessException {
+ if (Modifier.isStatic(method.getModifiers()))
+ throw new IllegalStateException("Static methods are
forbidden for xpath configuration: " + method);
+ if (object != null)
+ return object;
+ if (instances.get(method.getDeclaringClass()) == null) {
+ instances.put(method.getDeclaringClass(), new
ArrayList<Object>());
+ }
+ if (instances.get(method.getDeclaringClass()).size() < count
+ 1)
+
instances.get(method.getDeclaringClass()).add(method.getDeclaringClass().newInstance());
+
+ try {
+ return instances.get(method.getDeclaringClass()).get(count);
+ } catch (IndexOutOfBoundsException ex) {
+ ex.printStackTrace();
+ throw ex;
+ }
+ }
+
+ protected Object getReference(Map<Class<?>, List<Object>> instances,
String value) throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
+ if (identifierMethod == null)
+ return null;
+
+ if (instances.get(identifierMethod.getDeclaringClass()) ==
null)
+ return null;
+
+ for (Object instance :
instances.get(identifierMethod.getDeclaringClass())) {
+ try {
+ if
(identifierMethod.invoke(instance).equals(value))
+ return instance;
+ } catch (NullPointerException ex) {
+ throw new NullPointerException("Identifier
value is not set for " + instance
+ + ". Check xpath for setting
identifier or verify whether xpath for reference is correct.");
+ }
+ }
+
+ return null;
+ }
+
+ public boolean isParameterType(Class<?> type) {
+ return getParameterType().equals(type);
+ }
+
+ private Class<?> getParameterType() {
+ return method.getParameterTypes()[0];
+ }
+
+ public void resetCount() {
+ count = 0;
+ }
+
+ public String toString() {
+ return this.method.toString() + " [" + count + "]";
+ }
+}

Copied:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/SelfTestResult.java
(from rev 6224,
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java)
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/SelfTestResult.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/SelfTestResult.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,162 @@
+package net.geant.perfsonar.messaging;
+
+import static net.geant.perfsonar.messaging.XPathDeserializer.any;
+import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
+import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
+
+/**
+ * This class is used in unit tests to check the behavior of a service wrt
self
+ * tests
+ *
+ * @author Blazej Pietrzak -

+ * @author Antoine Delvaux -

+ *
+ */
+public class SelfTestResult implements Comparable<SelfTestResult> {
+ static {
+ declarePrefix("nmwg", "http://ggf.org/ns/nmwg/base/2.0/";);
+ try {
+
whenXPath("nmwg:message/nmwg:data/nmwg:metadata/@id").then(
+
SelfTestResult.class).setName(any(String.class));
+
+
whenXPath("nmwg:message/nmwg:data/nmwg:data/nmwg:datum/text()")
+
.then(SelfTestResult.class).setMessage(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data/nmwg:metadata/nmwg:eventType/text()")
+
.then(SelfTestResult.class).setEventType(any(String.class));
+ } catch (Exception ex) {
+ }
+ }
+
+ protected String name;
+ protected String message;
+ protected String status;
+ protected String serviceName;
+ protected String serviceType;
+
+ public SelfTestResult(String name, String message, String status,
+ String serviceName, String serviceType) {
+ this.name = name;
+ this.message = message;
+ this.status = status;
+ this.serviceName = serviceName;
+ this.serviceType = serviceType;
+ }
+
+ public SelfTestResult() {
+ }
+
+ public static SelfTestResult failure(String name, String message,
+ String serviceName, String serviceType) {
+ return new SelfTestResult(name, message, "failure",
serviceName,
+ serviceType);
+ }
+
+ public static SelfTestResult success(String name, String message,
+ String serviceName, String serviceType) {
+ return new SelfTestResult(name, message, "success",
serviceName,
+ serviceType);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ @Override
+ public int compareTo(SelfTestResult arg) {
+ return getName().compareTo(arg.getName());
+ }
+
+ public void setEventType(String eventType) {
+ if (eventType.contains("success"))
+ status = "success";
+ else
+ status = "failure";
+
+ String[] elems = eventType.substring(
+
"http://schemas.perfsonar.net/tools/admin/selftest/".length())
+ .split("/");
+
+ serviceType = elems[0];
+ serviceName = elems[1];
+ }
+
+ @Override
+ public String toString() {
+ return status + " (name=" + name + ", message=" + message
+ + ", service-name=" + serviceName + ",
service-type="
+ + serviceType + ")";
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((message == null) ? 0 :
message.hashCode());
+ result = prime * result + ((name == null) ? 0 :
name.hashCode());
+ result = prime * result
+ + ((serviceName == null) ? 0 :
serviceName.hashCode());
+ result = prime * result
+ + ((serviceType == null) ? 0 :
serviceType.hashCode());
+ result = prime * result + ((status == null) ? 0 :
status.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SelfTestResult other = (SelfTestResult) obj;
+ if (message == null) {
+ if (other.message != null)
+ return false;
+ } else if (!message.equals(other.message))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (serviceName == null) {
+ if (other.serviceName != null)
+ return false;
+ } else if (!serviceName.equals(other.serviceName))
+ return false;
+ if (serviceType == null) {
+ if (other.serviceType != null)
+ return false;
+ } else if (!serviceType.equals(other.serviceType))
+ return false;
+ if (status == null) {
+ if (other.status != null)
+ return false;
+ } else if (!status.equals(other.status))
+ return false;
+ return true;
+ }
+}

Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathConfiguration.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -42,8 +42,11 @@
return proxy.invokeSuper(obj, args);
}

+ if
(!obj.getClass().getSuperclass().equals(method.getDeclaringClass()))
+ return null;
+
if (args.length != 1)
- throw new IllegalArgumentException("Setter method
must have exactly one argument of type String.");
+ return null;

if (this.object != null)
XPathDeserializer.putXPath(xpath, object, method);

Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/messaging/XPathDeserializer.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -1,12 +1,7 @@
package net.geant.perfsonar.messaging;

-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -14,14 +9,13 @@
import javax.xml.xpath.XPathException;

import jlibs.xml.DefaultNamespaceContext;
-import jlibs.xml.sax.dog.NodeItem;
import jlibs.xml.sax.dog.XMLDog;
-import jlibs.xml.sax.dog.XPathResults;
-import jlibs.xml.sax.dog.expr.Expression;
-
+import jlibs.xml.sax.dog.sniff.DOMBuilder;
+import jlibs.xml.sax.dog.sniff.Event;
import net.sf.cglib.proxy.Enhancer;

import org.jaxen.saxpath.SAXPathException;
+import org.jaxen.saxpath.XPathSyntaxException;
import org.xml.sax.InputSource;

/**
@@ -64,14 +58,10 @@
*
*/
public class XPathDeserializer {
-
private final static DefaultNamespaceContext context = new
DefaultNamespaceContext();
- private Map<Class<?>, List<Object>> instances = new
Hashtable<Class<?>, List<Object>>();
+ private final static Map<String, Method> xpaths = new
Hashtable<String, Method>();
+ private final static Map<Class<?>, java.lang.reflect.Method>
identifiers = new Hashtable<Class<?>, java.lang.reflect.Method>();

- private static Map<Method, Object> objects = new Hashtable<Method,
Object>();
- private static Map<String, Method> xpaths = new Hashtable<String,
Method>();
- private static Map<Class<?>, Method> identifiers = new
Hashtable<Class<?>, Method>();
-
public static void declarePrefix(String prefix, String uri) {
context.declarePrefix(prefix, uri);
}
@@ -89,88 +79,100 @@
return (T) Enhancer.create(type, new ReferenceInterceptor());
}

+ public static java.lang.reflect.Method findIdentifier(Class<?> type) {
+ return identifiers.get(type);
+ }
+
public static <T> T any(Class<T> type) {
return null;
}

- public static void putXPath(String xpath, Object object, Method
method) {
- objects.put(method, object);
- xpaths.put(xpath, method);
+ public static void putXPath(String xpath, Object object,
java.lang.reflect.Method method) {
+ xpaths.put(xpath, new Method(method,
identifiers.get(method.getParameterTypes()[0]), object));
}

- public static void putXPath(String xpath, Method method) {
- xpaths.put(xpath, method);
+ public static synchronized void putXPath(String xpath,
java.lang.reflect.Method method) {
+ xpaths.put(xpath, new Method(method,
identifiers.get(method.getParameterTypes()[0])));
}

+ protected static void putIdentifier(Class<?> declaringClass,
java.lang.reflect.Method method) {
+ XPathDeserializer.identifiers.put(declaringClass, method);
+ }
+
public static void clearConfiguration() {
xpaths.clear();
}

- private static Set<String> getXPaths() {
+ private static synchronized Set<String> getXPaths() {
return xpaths.keySet();
}

- private static Method getXPathMethod(String xpath) {
+ protected static Method getXPathMethod(String xpath) {
return xpaths.get(xpath);
}
+
+ public static Map<String, Method> temp() {
+ return xpaths;
+ }

public XPathDeserializer() {
}
+
+ public static String validate(String xpath) {
+ final XMLDog dog = new XMLDog(context);
+ try {
+ dog.addXPath(xpath);
+ } catch (XPathSyntaxException ex) {
+ return "Invalid XPath: " + ex.getMultilineMessage();
+ } catch (SAXPathException ex) {
+ return "Invalid XPath: " + ex.getMessage();
+ }
+
+ return null;
+ }

/**
* Deserializes objects from xml stream using streaming XPath
expressions.
+ * @throws Throwable
*/
- @SuppressWarnings("unchecked")
- public List<?> deserialize(InputSource reader) throws
SAXPathException, XPathException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException, InstantiationException {

+ public List<?> deserialize(InputSource reader) throws
DeserializationException {
final XMLDog dog = new XMLDog(context);
- final List<Expression> expressions = new
ArrayList<Expression>();
+ final List<Throwable> exceptions = new ArrayList<Throwable>();
for (String xpath : XPathDeserializer.getXPaths()) {
- expressions.add(dog.addXPath(xpath));
+ try {
+ dog.addXPath(xpath);
+ } catch (XPathSyntaxException ex) {
+ exceptions.add(new XPathException("Invalid
XPath: " + ex.getMultilineMessage()));
+ } catch (SAXPathException ex) {
+ exceptions.add(new XPathException("Invalid
XPath: " + ex.getMessage()));
+ }
}

- final XPathResults results = dog.sniff(reader);
+ if (exceptions.size() > 0)
+ throw new DeserializationException(exceptions);

- for (Expression expr : sort(expressions)) {
- final Method method =
XPathDeserializer.getXPathMethod(expr.getXPath());
-
- if (results.getResult(expr) instanceof String)
- process(method, (String)
results.getResult(expr));
- else {
- processNodeItem(expr, (Collection<NodeItem>)
results.getResult(expr), method);
- }
- }
+ final Event event = dog.createEvent(); // must be after all
expressions are added.
+ event.setXMLBuilder(new DOMBuilder());

- final List<Object> result = new ArrayList<Object>();
- for (List<Object> temp : instances.values())
- result.addAll(temp);
- return result;
+ final InMemoryInstancesListener listener = new
InMemoryInstancesListener();

- }
-
- private void processNodeItem(Expression expr, final
Collection<NodeItem> temp, Method method) throws IllegalAccessException,
- InvocationTargetException, InstantiationException {
- if (temp.size() <= 0)
- return;
+ event.setListener(listener);

- for (NodeItem item : temp) {
- process(method, item.value);
+ try {
+ dog.sniff(event, reader, false/*useSTAX*/);
+ } catch (XPathException ex) {
+ throw new DeserializationException(ex);
+ } finally {
+ for (Method method : xpaths.values()) {
+ method.resetCount();
+ }
}
+
+ if (listener.getExceptions().size() > 0)
+ throw new
DeserializationException(listener.getExceptions());
+
+ return listener.getObjects();
}
-
- private void process(final Method method, String value)
- throws IllegalAccessException,
InvocationTargetException,
- InstantiationException {
- if (method.getParameterTypes()[0].equals(String.class)) {
- method.invoke(getInstance(method), value);
- } else {
- final Object reference = getReference(value,
identifiers.get(method.getParameterTypes()[0]));
- if (reference == null)
- return;
- method.invoke(getInstance(method), reference);
- }
-
- increment(method);
- }

@SuppressWarnings("unchecked")
public <T> List<T> getObjects(Class<T> type, List<Object> objects) {
@@ -182,71 +184,4 @@
}
return result;
}
-
- private List<Expression> sort(List<Expression> expressions) {
- final List<Expression> result = new ArrayList<Expression>();
- final Iterator<Expression> iter = expressions.iterator();
-
- if (expressions.size() <= 0)
- return result;
-
- for (Expression expr = iter.next(); iter.hasNext(); expr =
iter.next()) {
- Method method =
XPathDeserializer.getXPathMethod(expr.getXPath());
- if (method == null)
- throw new RuntimeException("Cannot find
method for xpath " + expr.getXPath());
- if
(method.getParameterTypes()[0].equals(String.class)) {
- result.add(expr);
- iter.remove();
- }
- }
-
- result.addAll(expressions);
-
- return result;
- }
-
- private Object getReference(String value, Method identifierMethod)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
- if (instances.get(identifierMethod.getDeclaringClass()) ==
null)
- return null;
-
- for (Object instance :
instances.get(identifierMethod.getDeclaringClass())) {
- if (identifierMethod.invoke(instance).equals(value))
- return instance;
- }
- return null;
- }
-
- private void increment(Method method) {
- if (counts.get(method) == null)
- counts.put(method, 0);
-
- counts.put(method, counts.get(method) + 1);
- }
-
- private Map<Method, Integer> counts = new Hashtable<Method,
Integer>();
-
- private int getCount(Method method) {
- if (counts.get(method) == null)
- counts.put(method, 0);
-
- return counts.get(method);
- }
-
- private Object getInstance(Method method) throws
InstantiationException, IllegalAccessException {
- if (Modifier.isStatic(method.getModifiers()))
- return null;
- if (objects.get(method) != null)
- return objects.get(method);
- if (instances.get(method.getDeclaringClass()) == null) {
- instances.put(method.getDeclaringClass(), new
ArrayList<Object>());
- }
- if (instances.get(method.getDeclaringClass()).size() <
getCount(method) + 1)
-
instances.get(method.getDeclaringClass()).add(method.getDeclaringClass().newInstance());
-
- return
instances.get(method.getDeclaringClass()).get(getCount(method));
- }
-
- protected static void putIdentifier(Class<?> declaringClass, Method
method) {
- XPathDeserializer.identifiers.put(declaringClass, method);
- }
}

Modified:
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
===================================================================
---
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/main/java/net/geant/perfsonar/templates/TemplateEngine.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.InputStream;
+import java.io.StringWriter;
import java.io.Writer;

import org.apache.velocity.VelocityContext;
@@ -47,6 +48,11 @@
getTemplate(homeDir, name));
}

+ public static String evaluate(String template) {
+ final StringWriter out = new StringWriter();
+ templateEngine.evaluate(context, out, "successMessage", template);
+ return out.toString();
+ }

/**
* Put data to the context. Data can be used in templates with a
macro ${identifier}

Modified:
trunk/perfsonar-base/messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy
===================================================================
---
trunk/perfsonar-base/messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/test/groovy/net/geant/perfsonar/templates/NMWG.groovy
2013-05-06 13:01:14 UTC (rev 6350)
@@ -1,5 +1,6 @@
package net.geant.perfsonar.templates

+import net.geant.perfsonar.messaging.SelfTestResult;
import net.geant.perfsonar.mp.sshtelnet.Command;
import net.geant.perfsonar.mp.sshtelnet.Router;

@@ -38,6 +39,10 @@

static Reader toSelfTestRequest(String id) {
createRequest(id, "selftest", "1.0")
+ }
+
+ static Reader toSelfTestRequest(String id, String testName) {
+ createRequest(id, "selftest", "1.0/${testName}")
}

static Reader toMetadataKeyRequest(String id) {
@@ -136,11 +141,6 @@
'nmwg:parameter'(name:"url",
value:router.address.hostAddress)
}
}
- idx++
- }
-
- idx = 0
- routers.each { router ->
'nmwg:metadata'(id:"resultCodeMeta_${idx}") {

'nmwg:subject'(id:"resultCodeSubj_${idx}", metadataIdRef:"metadata${idx}")

'nmwg:eventType'("success.mp.sshtelnet")
@@ -159,10 +159,7 @@

'nmwg:parameters'(id:"params${idx}") {


'nmwg:parameter'(name:"command", value:command.name)

'nmwg:parameter'(name:"description", value:command.description)
- if
(command.syntax == null)
-
'nmwg:parameter'(name:"syntax")
- else
-
'nmwg:parameter'(name:"syntax", value:command.syntax)
+
'nmwg:parameter'(name:"syntax", value:command.syntax)
}

'nmwg:eventType'(command.eventType)
}
@@ -186,8 +183,8 @@
'nmwg:subject'(id:"subject${idx}") {

'nmwgtopo:endPoint'('xmlns:nmwgtopo':"http://ggf.org/ns/nmwg/topology/2.0/";,
type:"hostname", command.routerName)
}
- 'nmwg:parameters'(id:"params${idx}")
- 'nmwg:eventType'(command.eventType)
+ 'nmwg:parameters'(id:"params${idx}")
+ 'nmwg:eventType'(command.eventType)
}

'nmwg:data'(id:"data${idx}",
metadataIdRef:"meta${idx}") {

Added:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/InvalidXPathsTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,92 @@
+package net.geant.perfsonar.messaging;
+
+import static net.geant.perfsonar.messaging.XPathDeserializer.any;
+import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
+import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.io.Reader;
+import java.net.InetAddress;
+import java.util.Iterator;
+
+import javax.xml.xpath.XPathException;
+
+import net.geant.perfsonar.mp.sshtelnet.Command;
+import net.geant.perfsonar.mp.sshtelnet.Router;
+import net.geant.perfsonar.templates.NMWG;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+public class InvalidXPathsTest {
+ private static final String REQUEST_ID = "1";
+
+ private Reader reader;
+ private XPathDeserializer deserializer;
+
+ @Before
+ public void givenMessageAndDeserializationConfigured() throws
Exception {
+ reader = NMWG.toMetadataKeyResponse(REQUEST_ID, new
Router("metadata0",
+ "test1",
InetAddress.getAllByName("192.168.1.1")[0],
+ Command.PING_IPV6));
+
+ declarePrefix("nmwg", "http://ggf.org/ns/nmwg/base/2.0/";);
+ deserializer = new XPathDeserializer();
+ }
+
+ @After
+ public void clearConfiguration() {
+ XPathDeserializer.clearConfiguration();
+ }
+
+ @Test
+ public void shouldThrowExceptionWhenInvalidXPathSyntax() throws
Exception {
+ whenXPath("invalid
xpath1").then(Router.class).setId(any(String.class));
+ whenXPath("invalid xpath2").then(Router.class).setAddress(
+ any(String.class));
+
+ try {
+ deserializer.deserialize(new InputSource(reader));
+ fail("DeserializationException was not thrown");
+ } catch (DeserializationException ex) {
+ final Iterator<Throwable> iter = ex.iterator();
+ assertEquals(XPathException.class,
iter.next().getClass());
+ assertEquals(XPathException.class,
iter.next().getClass());
+ assertFalse(iter.hasNext());
+ }
+ }
+
+ @Test
+ public void shouldThrowExceptionWhenXPathReturnsNull() throws
Exception {
+
whenXPath("nmwg:message/nmwg:metadata[nmwg:parameters]/nmwg:subject")
+
.then(Router.class).setName(any(String.class));
+
+ try {
+ deserializer.deserialize(new InputSource(reader));
+ fail("DeserializationException was not thrown");
+ } catch (DeserializationException ex) {
+ final Iterator<Throwable> iter = ex.iterator();
+ assertEquals(XPathException.class,
iter.next().getClass());
+ assertFalse(iter.hasNext());
+ }
+ }
+
+ @Test
+ public void shouldThrowExceptionWhenUndeclaredPrefix() throws
Exception {
+
whenXPath("nmwg:message/nmwg:data/nmwgr:datum/nmwg:eventType/text()")
+
.then(Command.class).setEventType(any(String.class));
+
+ try {
+ deserializer.deserialize(new InputSource(reader));
+ fail("DeserializationException was not thrown");
+ } catch (DeserializationException ex) {
+ final Iterator<Throwable> iter = ex.iterator();
+ assertEquals(XPathException.class,
iter.next().getClass());
+ assertFalse(iter.hasNext());
+ }
+ }
+}

Added:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodOnObjectTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,40 @@
+package net.geant.perfsonar.messaging;
+
+import static org.junit.Assert.*;
+
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import net.geant.perfsonar.mp.sshtelnet.Command;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MethodOnObjectTest {
+ final Map<Class<?>, List<Object>> instances = new Hashtable<Class<?>,
List<Object>>();
+ final Command expected = new Command();
+ private Method method;
+
+ @Before
+ public void givenMethodWithObject() throws Exception {
+ expected.setName("object");
+ method = new Method(Command.class.getMethod("setName",
String.class), null, expected);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ method = null;
+ }
+
+ @Test
+ public void shouldReturnObject() throws Exception {
+ assertTrue(expected == method.getInstance(instances));
+ }
+
+ @Test
+ public void shouldBeEmpty() {
+ assertTrue(instances.isEmpty());
+ }
+}

Added:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/MethodTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,99 @@
+package net.geant.perfsonar.messaging;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import net.geant.perfsonar.mp.sshtelnet.Command;
+import net.geant.perfsonar.mp.sshtelnet.Router;
+import net.geant.perfsonar.mp.sshtelnet.RouterReference;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MethodTest {
+ private Method eventTypeMethod;
+ private Method commandNameMethod;
+ private Method currentRouterMethod;
+ private Method routerIdMethod;
+ private Method routerNameMethod;
+
+ private final Map<Class<?>, List<Object>> instances = new
Hashtable<Class<?>, List<Object>>();
+ private final Map<Class<?>, List<Object>> expected = new
Hashtable<Class<?>, List<Object>>();
+
+ @Before
+ public void setUp() throws Throwable {
+ new Command();
+ eventTypeMethod = createCommandMethod("setEventType",
String.class);
+ commandNameMethod = createCommandMethod("setName",
String.class);
+ currentRouterMethod = new
Method(RouterReference.class.getMethod("setCurrentRouter", Router.class),
Router.class.getMethod("getId"));
+ routerIdMethod = new Method(Router.class.getMethod("setId",
String.class), Router.class.getMethod("getId"));
+ routerNameMethod = new
Method(Router.class.getMethod("setName", String.class),
Router.class.getMethod("getId"));
+ //instances.put((Class)Router.class,
(List)Arrays.asList(router));
+ whenExecutingMethods(instances);
+ }
+
+ private Method createCommandMethod(String methodName, Class<?>...
params) throws NoSuchMethodException {
+ return new Method(Command.class.getMethod(methodName,
params), Command.class.getMethod("getId"));
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ instances.clear();
+ expected.clear();
+ new RouterReference().setCurrentRouter(null);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void shouldReturnTwoCommandsAndRouter() throws Throwable {
+ final Router router = createRouter();
+ expected.put((Class<?>) Router.class, (List)
Arrays.asList(createRouter()));
+ expected.put((Class<?>) Command.class, (List)
router.getCommands());
+ expected.put((Class<?>) RouterReference.class,
instances.get(RouterReference.class));
+
+ assertEquals(expected, instances);
+ }
+
+ @Test
+ public void shouldSetCurrentRouter() {
+ assertEquals(createRouter(),
+
+ RouterReference.getCurrentRouter());
+ }
+
+ private Router createRouter() {
+ return new Router("router2", "router", null,
+ new Command("test1", null, null, "testing1"),
+ new Command("test2", null, null, "testing2"));
+ }
+
+ private void whenExecutingMethods(
+ final Map<Class<?>, List<Object>> instances) throws
Throwable {
+
+ //router.setId("router2");
+ routerIdMethod.execute("router2", instances);
+
+ //router.setName("router");
+ routerNameMethod.execute("router", instances);
+
+ //RouterReference.setCurrentRouter(getReference("router2"));
+ currentRouterMethod.execute("router2", instances);
+
+ //command1.setEventType("testing1");
+ eventTypeMethod.execute("testing1", instances);
+
+ //command1.setName("test1");
+ commandNameMethod.execute("test1", instances);
+
+ //command2.setName("test2");
+ commandNameMethod.execute("test2", instances);
+
+ //command2.setEventType("testing2");
+ eventTypeMethod.execute("testing2", instances);
+ }
+}

Added:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/StaticMethodTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/StaticMethodTest.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/StaticMethodTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,41 @@
+package net.geant.perfsonar.messaging;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class StaticMethodTest {
+
+ final Map<Class<?>, List<Object>> instances = new Hashtable<Class<?>,
List<Object>>();
+ private Method method;
+
+ public static void staticMethod() { }
+
+ @Before
+ public void givenStaticMethod() throws Exception {
+ method = new
Method(StaticMethodTest.class.getMethod("staticMethod"));
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ method = null;
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void shouldThrowException() throws Exception {
+ assertNull(method.getInstance(instances));
+ }
+
+ @Test
+ public void shouldBeEmpty() {
+ assertTrue(instances.isEmpty());
+ }
+
+}

Copied:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XMLDogTest.java
(from rev 6224,
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java)
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XMLDogTest.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XMLDogTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,85 @@
+package net.geant.perfsonar.messaging;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import jlibs.xml.DefaultNamespaceContext;
+import jlibs.xml.sax.dog.NodeItem;
+import jlibs.xml.sax.dog.XMLDog;
+import jlibs.xml.sax.dog.expr.Expression;
+import jlibs.xml.sax.dog.expr.InstantEvaluationListener;
+import jlibs.xml.sax.dog.sniff.DOMBuilder;
+import jlibs.xml.sax.dog.sniff.Event;
+import net.geant.perfsonar.templates.NMWG;
+
+import org.jaxen.saxpath.SAXPathException;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+public class XMLDogTest {
+ private static final String REQUEST_ID = "request1";
+ private DefaultNamespaceContext nsContext;
+ private XMLDog dog;
+ private String xpathResult;
+
+ @Before
+ public void givenXMLDog() {
+ nsContext = new DefaultNamespaceContext();
+ nsContext.declarePrefix("nmwg",
"http://ggf.org/ns/nmwg/base/2.0/";);
+ dog = new XMLDog(nsContext);
+ }
+
+ @Test
+ public void shouldEvaluatePrimitiveTypesFromStream() throws Exception
{
+ final Event event = createEvent("string(nmwg:message/@id)",
new InstantEvaluationListener() {
+ @Override
+ public void onNodeHit(Expression expression, NodeItem
nodeItem) { fail(); }
+
+ @Override
+ public void finishedNodeSet(Expression expression) {
fail(); }
+
+ @Override
+ public void onResult(Expression expression, Object
result) {
+ xpathResult = result.toString();
+ }
+ });
+
+ dog.sniff(event, new
InputSource(NMWG.toEchoRequest(REQUEST_ID)), false/*useSTAX*/);
+ Thread.sleep(1000);
+ assertEquals(REQUEST_ID, xpathResult);
+ }
+
+ @Test
+ public void shouldEvaluateNodesFromStream() throws Exception {
+ final Event event = createEvent("nmwg:message/@id", new
InstantEvaluationListener() {
+ private String tempResult;
+ @Override
+ public void onNodeHit(Expression expression, NodeItem
nodeItem) {
+ tempResult = nodeItem.value;
+ }
+
+ @Override
+ public void finishedNodeSet(Expression expression) {
+ xpathResult = tempResult;
+ }
+
+ @Override
+ public void onResult(Expression expression, Object
result) {
+ fail();
+ }
+ });
+
+ dog.sniff(event, new
InputSource(NMWG.toEchoRequest(REQUEST_ID)), false/*useSTAX*/);
+ Thread.sleep(1000);
+ assertEquals(REQUEST_ID, xpathResult);
+ }
+
+ private Event createEvent(String xpath, InstantEvaluationListener
listener) throws SAXPathException {
+ dog.addXPath(xpath);
+ final Event event = dog.createEvent(); // must be after all
expressions are added.
+ event.setXMLBuilder(new DOMBuilder());
+ event.setListener(listener);
+ return event;
+ }
+
+}

Copied:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java
(from rev 6224,
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java)
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/XPathDeserializerTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,97 @@
+package net.geant.perfsonar.messaging;
+
+import static net.geant.perfsonar.messaging.XPathDeserializer.any;
+import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
+import static net.geant.perfsonar.messaging.XPathDeserializer.getReference;
+import static net.geant.perfsonar.messaging.XPathDeserializer.identifier;
+import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
+import static org.junit.Assert.assertEquals;
+
+import java.io.Reader;
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.List;
+
+import net.geant.perfsonar.mp.sshtelnet.Command;
+import net.geant.perfsonar.mp.sshtelnet.Router;
+import net.geant.perfsonar.mp.sshtelnet.RouterReference;
+import net.geant.perfsonar.templates.NMWG;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+public class XPathDeserializerTest {
+ private static final String REQUEST_ID = "1";
+
+ private Router[] routers;
+ private Reader reader;
+ private XPathDeserializer deserializer;
+
+ @Before
+ public void givenMessageAndDeserializationConfigured() throws
Exception {
+
+ routers = new Router[] {
+ new Router("metadata0", "test1",
+
InetAddress.getAllByName("192.168.1.1")[0],
+ Command.PING_IPV6),
+ new Router("metadata1", "test2",
+
InetAddress.getAllByName("192.168.1.2")[0],
+ Command.SHOW_ENVIRONMENT) };
+
+ reader = NMWG.toMetadataKeyResponse(REQUEST_ID, routers);
+
+ declarePrefix("nmwg", "http://ggf.org/ns/nmwg/base/2.0/";);
+ declarePrefix("nmwgr", "http://ggf.org/ns/nmwg/result/2.0/";);
+
+ whenXPath("nmwg:message/nmwg:metadata[nmwg:parameters]/@id")
+ .then(Router.class).setId(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:metadata/nmwg:parameters/nmwg:parameter[@name='url']/@value")
+
.then(Router.class).setAddress(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:metadata[nmwg:parameters]/nmwg:subject/text()")
+
.then(Router.class).setName(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/@metadataIdRef")
+ .then(RouterReference.class).setCurrentRouter(
+ getReference(Router.class,
identifier(Router.class).getId()));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='command']/@value")
+
.then(Command.class).setName(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='description']/@value")
+
.then(Command.class).setDescription(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='syntax']/@value")
+
.then(Command.class).setSyntax(any(String.class));
+
+ whenXPath(
+
"nmwg:message/nmwg:data/nmwgr:datum/nmwg:eventType/text()")
+
.then(Command.class).setEventType(any(String.class));
+
+ deserializer = new XPathDeserializer();
+ }
+
+ @After
+ public void clearConfiguration() {
+ XPathDeserializer.clearConfiguration();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void shouldReturnRouters() throws Throwable {
+ final List<Object> actual = (List<Object>)
deserializer.deserialize(new InputSource(reader));
+
+ assertEquals(Arrays.asList(Command.PING_IPV6,
Command.SHOW_ENVIRONMENT), deserializer.getObjects(Command.class, actual));
+ assertEquals(Arrays.asList(new Router("metadata0", "test1",
InetAddress.getAllByName("192.168.1.1")[0], Command.PING_IPV6),
+ new Router("metadata1", "test2",
InetAddress.getAllByName("192.168.1.2")[0], Command.SHOW_ENVIRONMENT)),
deserializer.getObjects(Router.class, actual));
+ }
+}

Deleted:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/InvalidDeserializerConfigurationTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/InvalidDeserializerConfigurationTest.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/InvalidDeserializerConfigurationTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -1,42 +0,0 @@
-package net.geant.perfsonar.messaging.xpath;
-
-import static net.geant.perfsonar.messaging.XPathDeserializer.any;
-import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
-import net.geant.perfsonar.messaging.XPathDeserializer;
-import net.geant.perfsonar.mp.sshtelnet.Command;
-import net.geant.perfsonar.templates.NMWG;
-
-import org.jaxen.saxpath.SAXPathException;
-import org.jaxen.saxpath.XPathSyntaxException;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.InputSource;
-
-public class InvalidDeserializerConfigurationTest {
-
- private static final String REQUEST_ID = "request1";
- private XPathDeserializer deserializer;
-
- @Before
- public void givenDeserializer() {
- XPathDeserializer.clearConfiguration();
- deserializer = new XPathDeserializer();
- }
-
- @Test(expected = XPathSyntaxException.class)
- public void shouldThrowWhenInvalidXPath() throws Exception {
- whenXPath("invalid xpath").then(Command.class).setSyntax(
- any(String.class));
-
- deserializer.deserialize(new
InputSource(NMWG.toEchoRequest(REQUEST_ID)));
- }
-
- @Test(expected=SAXPathException.class)
- public void shouldThrowWhenNamespaceIsNotDefined() throws Exception {
- whenXPath(
-
"nmwg:message/nmwg:metadata/select:parameters/nmwg:parameter[name=startTime]/text()")
-
.then(Command.class).setSyntax(any(String.class));
-
- deserializer.deserialize(new
InputSource(NMWG.toEchoRequest(REQUEST_ID)));
- }
-}

Deleted:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XMLDogTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -1,85 +0,0 @@
-package net.geant.perfsonar.messaging.xpath;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import jlibs.xml.DefaultNamespaceContext;
-import jlibs.xml.sax.dog.NodeItem;
-import jlibs.xml.sax.dog.XMLDog;
-import jlibs.xml.sax.dog.expr.Expression;
-import jlibs.xml.sax.dog.expr.InstantEvaluationListener;
-import jlibs.xml.sax.dog.sniff.DOMBuilder;
-import jlibs.xml.sax.dog.sniff.Event;
-import net.geant.perfsonar.templates.NMWG;
-
-import org.jaxen.saxpath.SAXPathException;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.InputSource;
-
-public class XMLDogTest {
- private static final String REQUEST_ID = "request1";
- private DefaultNamespaceContext nsContext;
- private XMLDog dog;
- private String xpathResult;
-
- @Before
- public void givenXMLDog() {
- nsContext = new DefaultNamespaceContext();
- nsContext.declarePrefix("nmwg",
"http://ggf.org/ns/nmwg/base/2.0/";);
- dog = new XMLDog(nsContext);
- }
-
- @Test
- public void shouldEvaluatePrimitiveTypesFromStream() throws Exception
{
- final Event event = createEvent("string(nmwg:message/@id)",
new InstantEvaluationListener() {
- @Override
- public void onNodeHit(Expression expression, NodeItem
nodeItem) { fail(); }
-
- @Override
- public void finishedNodeSet(Expression expression) {
fail(); }
-
- @Override
- public void onResult(Expression expression, Object
result) {
- xpathResult = result.toString();
- }
- });
-
- dog.sniff(event, new
InputSource(NMWG.toEchoRequest(REQUEST_ID)), false/*useSTAX*/);
- Thread.sleep(1000);
- assertEquals(REQUEST_ID, xpathResult);
- }
-
- @Test
- public void shouldEvaluateNodesFromStream() throws Exception {
- final Event event = createEvent("nmwg:message/@id", new
InstantEvaluationListener() {
- private String tempResult;
- @Override
- public void onNodeHit(Expression expression, NodeItem
nodeItem) {
- tempResult = nodeItem.value;
- }
-
- @Override
- public void finishedNodeSet(Expression expression) {
- xpathResult = tempResult;
- }
-
- @Override
- public void onResult(Expression expression, Object
result) {
- fail();
- }
- });
-
- dog.sniff(event, new
InputSource(NMWG.toEchoRequest(REQUEST_ID)), false/*useSTAX*/);
- Thread.sleep(1000);
- assertEquals(REQUEST_ID, xpathResult);
- }
-
- private Event createEvent(String xpath, InstantEvaluationListener
listener) throws SAXPathException {
- dog.addXPath(xpath);
- final Event event = dog.createEvent(); // must be after all
expressions are added.
- event.setXMLBuilder(new DOMBuilder());
- event.setListener(listener);
- return event;
- }
-
-}

Deleted:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/messaging/xpath/XPathDeserializerTest.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -1,93 +0,0 @@
-package net.geant.perfsonar.messaging.xpath;
-
-import static net.geant.perfsonar.messaging.XPathDeserializer.any;
-import static net.geant.perfsonar.messaging.XPathDeserializer.declarePrefix;
-import static net.geant.perfsonar.messaging.XPathDeserializer.getReference;
-import static net.geant.perfsonar.messaging.XPathDeserializer.identifier;
-import static net.geant.perfsonar.messaging.XPathDeserializer.whenXPath;
-import static org.junit.Assert.assertEquals;
-
-import java.io.Reader;
-import java.net.InetAddress;
-import java.util.Arrays;
-import java.util.List;
-
-import net.geant.perfsonar.messaging.XPathDeserializer;
-import net.geant.perfsonar.mp.sshtelnet.Command;
-import net.geant.perfsonar.mp.sshtelnet.Router;
-import net.geant.perfsonar.templates.NMWG;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.InputSource;
-
-public class XPathDeserializerTest {
- private static final String REQUEST_ID = "1";
-
- private Router[] routers;
- private Reader reader;
- private XPathDeserializer deserializer;
-
- @Before
- public void givenMessageAndDeserializationConfigured() throws
Exception {
-
- routers = new Router[] {
- new Router("metadata0", "test1",
-
InetAddress.getAllByName("192.168.1.1")[0],
- Command.PING_IPV6),
- new Router("metadata1", "test2",
-
InetAddress.getAllByName("192.168.1.2")[0],
- Command.SHOW_ENVIRONMENT) };
-
- reader = NMWG.toMetadataKeyResponse(REQUEST_ID, routers);
-
- declarePrefix("nmwg", "http://ggf.org/ns/nmwg/base/2.0/";);
- declarePrefix("nmwgr", "http://ggf.org/ns/nmwg/result/2.0/";);
-
-
whenXPath("nmwg:message/nmwg:metadata[starts-with(@id,'metadata')]/@id")
- .then(Router.class).setId(any(String.class));
-
- whenXPath(
-
"nmwg:message/nmwg:metadata/nmwg:subject[starts-with(@id, 'subject')]/text()")
-
.then(Router.class).setName(any(String.class));
-
- whenXPath(
-
"nmwg:message/nmwg:metadata[starts-with(nmwg:subject/@id,
'subject')]/nmwg:parameters/nmwg:parameter[@name='url']/@value")
-
.then(Router.class).setAddress(any(String.class));
-
- whenXPath(
-
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/@metadataIdRef")
- .then(Command.class).setCurrentRouter(
- getReference(Router.class,
identifier(Router.class).getId()));
-
- whenXPath(
-
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='command']/@value")
-
.then(Command.class).setName(any(String.class));
-
- whenXPath(
-
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='description']/@value")
-
.then(Command.class).setDescription(any(String.class));
-
- whenXPath(
-
"nmwg:message/nmwg:data[starts-with(@metadataIdRef,
'metadata')]/nmwgr:datum/nmwg:parameters/nmwg:parameter[@name='syntax']/@value")
-
.then(Command.class).setSyntax(any(String.class));
-
- deserializer = new XPathDeserializer();
- }
-
- @After
- public void clearConfiguration() {
- XPathDeserializer.clearConfiguration();
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void shouldReturnRouters() throws Exception {
- final List<Object> actual = (List<Object>)
deserializer.deserialize(new InputSource(reader));
-
- assertEquals(Arrays.asList(Command.PING_IPV6,
Command.SHOW_ENVIRONMENT), deserializer.getObjects(Command.class, actual));
- assertEquals(Arrays.asList(new Router("metadata0", "test1",
InetAddress.getAllByName("192.168.1.1")[0]),
- new Router("metadata1", "test2",
InetAddress.getAllByName("192.168.1.2")[0])),
deserializer.getObjects(Router.class, actual));
- }
-}

Modified:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Command.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -21,33 +21,39 @@
public static final Command PING_IPV6 = new Command("ping inet6",
"ping an [IPv6 address]", "[IPv6 address]",
"http://schemas.perfsonar.net/tools/sshtelnet/IPv6_PING/1.0";);

public static final Command TRACEROUTER_IPV6 = new
Command("traceroute inet6", "trace the ipv6 path to [ipv6 address]", "[IPv6
address]",
"http://schemas.perfsonar.net/tools/sshtelnet/IPv6_TRACEROUTE/1.0";);
-
- private static Router currentRouter;

- private String routerName;
-
+ private String routerName;
private String name;
private String description;
private String syntax;
-
+ private String eventType;
+ private String id;
+ private String result;
+
private Router router;
-
- private String eventType;
+
+ Command(Command cmd, String routerName) {
+ setDescription(cmd.description);
+ setEventType(cmd.eventType);
+ setName(cmd.name);
+ setSyntax(cmd.syntax);
+ setRouterName(routerName);
+ }

- private Command(String name, String description, String syntax,
String eventType) {
- this(currentRouter, name, description, syntax, eventType);
+ public Command(String name, String description, String syntax, String
eventType) {
+ this(RouterReference.getCurrentRouter(), name, description,
syntax, eventType);
}

private Command(Router router, String name, String description,
String syntax, String eventType) {
- this.router = router;
this.name = name;
this.description = description;
this.syntax = syntax;
this.eventType = eventType;
+ setRouter(router);
}

public Command() {
- this(currentRouter, null, null, null, null);
+ this(RouterReference.getCurrentRouter(), null, null, null,
null);
}

public String getEventType() {
@@ -72,6 +78,7 @@

public void execute() throws IOException {
//router.execute(this);
+ result = "For address family: IPv4 Unicast@@@@@@For address
family: IPv6 Unicast@@@@@@For address family: VPNv4 Unicast@@@@@@For address
family: IPv4 Multicast@@@@@@For address family: IPv6 Multicast@@@@@@For
address family: NSAP Unicast@@@---END---";
}

@Override
@@ -80,7 +87,15 @@
int result = 1;
result = prime * result
+ ((description == null) ? 0 :
description.hashCode());
+ result = prime * result
+ + ((eventType == null) ? 0 :
eventType.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 :
name.hashCode());
+ result = prime * result
+ + ((this.result == null) ? 0 :
this.result.hashCode());
+ result = prime * result + ((router == null) ? 0 :
router.hashCode());
+ result = prime * result
+ + ((routerName == null) ? 0 :
routerName.hashCode());
result = prime * result + ((syntax == null) ? 0 :
syntax.hashCode());
return result;
}
@@ -94,16 +109,37 @@
if (getClass() != obj.getClass())
return false;
Command other = (Command) obj;
+
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
+ if (eventType == null) {
+ if (other.eventType != null)
+ return false;
+ } else if (!eventType.equals(other.eventType))
+ return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
+ if (result == null) {
+ if (other.result != null)
+ return false;
+ } else if (!result.equals(other.result))
+ return false;
+ if (router == null) {
+ if (other.router != null)
+ return false;
+ } else if (!router.getName().equals(other.router.getName()))
+ return false;
+ if (routerName == null) {
+ if (other.routerName != null)
+ return false;
+ } else if (!routerName.equals(other.routerName))
+ return false;
if (syntax == null) {
if (other.syntax != null)
return false;
@@ -111,14 +147,11 @@
return false;
return true;
}
-
- public void setCurrentRouter(Router router) {
- Command.currentRouter = router;
- this.router = router;
- }

public void setRouter(Router router) {
this.router = router;
+ if (router != null)
+ router.addCommand(this);
}

public void setName(String name) {
@@ -135,12 +168,12 @@

@Override
public String toString() {
- return "Command [name=" + name + ", description=" +
description
+ return "Command [id=" + id + ", name=" + name + ",
eventType=" + eventType + ", description=" + description
+ ", syntax=" + syntax + ", router=" +
(router != null ? router.getName() : routerName) + "]";
}

public String getResult() {
- return "For address family: IPv4 Unicast@@@@@@For address
family: IPv6 Unicast@@@@@@For address family: VPNv4 Unicast@@@@@@For address
family: IPv4 Multicast@@@@@@For address family: IPv6 Multicast@@@@@@For
address family: NSAP Unicast@@@---END---";
+ return result;
}

public String getRouterName() {
@@ -150,14 +183,16 @@
public void setRouterName(String routerName) {
this.routerName = routerName;
}
-
- public Command newInstance() {
- final Command result = new Command();
- result.setDescription(this.description);
- result.setEventType(this.eventType);
- result.setName(this.name);
- result.setRouterName(this.routerName);
- result.setSyntax(this.syntax);
- return result;
+
+ public void setId(String id) {
+ this.id = id;
}
+
+ public String getId() {
+ return id;
+ }
+
+ public void setResult(String result) {
+ this.result = result;
+ }
}

Modified:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/Router.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -1,5 +1,6 @@
package net.geant.perfsonar.mp.sshtelnet;

+import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
@@ -10,18 +11,17 @@

private static final int PORT_UNDEFINED = -1;

- public String name;
+ private String name;

- public InetAddress address;
+ private InetAddress address;

- public int port;
+ private int port;

private String id;

private List<Command> commands = new ArrayList<Command>();

public Router() {
-
}

public Router(String id, String name, InetAddress address, Command...
commands) {
@@ -35,7 +35,6 @@
this.port = port;
for (Command c : commands) {
c.setRouter(this);
- addCommand(c);
}
}

@@ -52,7 +51,8 @@
}

public void addCommand(Command command) {
- commands.add(command);
+ if (!commands.contains(command))
+ commands.add(command);
}

public List<Command> getCommands() {
@@ -90,11 +90,6 @@
return false;
} else if (!commands.equals(other.commands))
return false;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
if (name == null) {
if (other.name != null)
return false;
@@ -103,10 +98,9 @@
return true;
}

-// public RouterConnection connect() throws IOException {
-// //return connectionManager.connect(url, port);
-// return null;
-// }
+ public void connect() throws IOException {
+ throw new IOException("Not implemented yet.");
+ }

@Override
public String toString() {

Added:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
(rev 0)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/mp/sshtelnet/RouterReference.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -0,0 +1,28 @@
+package net.geant.perfsonar.mp.sshtelnet;
+
+
+/**
+ * Used for injecting Router instances in Command objects.
+ *
+ * @author <a
href="mailto:">Blazej
Pietrzak</a>
+ *
+ */
+public class RouterReference {
+
+ private static Router currentRouter = null;
+
+ public void setCurrentRouter(Router router) {
+ RouterReference.currentRouter = router;
+ }
+
+ public static Router getCurrentRouter() {
+ return RouterReference.currentRouter;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == null)
+ return false;
+
+ return (obj instanceof RouterReference);
+ }
+}

Deleted:
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
===================================================================
---
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
2013-05-06 12:58:23 UTC (rev 6349)
+++
trunk/perfsonar-base/messaging/src/test/java/net/geant/perfsonar/templates/SelfTestResult.java
2013-05-06 13:01:14 UTC (rev 6350)
@@ -1,31 +0,0 @@
-package net.geant.perfsonar.templates;
-
-/**
- * This class is used in unit tests to check the behavior of a service wrt
self tests
- * @author Blazej Pietrzak -

- * @author Antoine Delvaux -

- *
- */
-public class SelfTestResult {
- protected String name;
- protected String message;
- protected String status;
- protected String serviceName;
- protected String serviceType;
-
- private SelfTestResult(String name, String message, String status,
String serviceName, String serviceType) {
- this.name = name;
- this.message = message;
- this.status = status;
- this.serviceName = serviceName;
- this.serviceType = serviceType;
- }
-
- public static SelfTestResult failure(String name, String message, String
serviceName, String serviceType) {
- return new SelfTestResult(name, message, "failure", serviceName,
serviceType);
- }
-
- public static SelfTestResult success(String name, String message, String
serviceName, String serviceType) {
- return new SelfTestResult(name, message, "success", serviceName,
serviceType);
- }
-}



  • [pS-dev] [GEANT/SA2/ps-java-services] r6350 - in trunk/perfsonar-base/messaging: . src/main/java/net/geant/perfsonar/messaging src/main/java/net/geant/perfsonar/templates src/test/groovy/net/geant/perfsonar/templates src/test/java/net/geant/perfsonar/messaging src/test/java/net/geant/perfsonar/messaging/xpath src/test/java/net/geant/perfsonar/mp/sshtelnet src/test/java/net/geant/perfsonar/templates, svn-noreply, 05/06/2013

Archive powered by MHonArc 2.6.16.

Top of Page