XQuery assertion failure for SOAP UI - soap

I have been following this example:
https://bharathsharesinfo.wordpress.com/2013/03/16/assertions-xquery-match/
I have imported the wsdl file as per:
http://www.restfulwebservices.net/wcf/StockQuoteService.svc?wsdl
I have generated a MockService for the response and added a test case for the operation GetStockQuote. I have then added the XQuery Match assertion as follows (the declarations were added automatically):
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://www.restfulwebservices.net/DataContracts/2008/01';
declare namespace ns='http://www.restfulwebservices.net/ServiceContracts/2008/01';
<Result>
{
for $x in //ns1:GetStockQuoteResult[1]
return <Symbol>{data($x/a:Symbol/text())}</Symbol>
}
</Result>
I am returned with the following error:
XQuery Match Assertion failed for path [declare namespace ns1='http://www.restfulwebservices.net/DataContracts/2008/01'; declare namespace ns='http://www.restfulwebservices.net/ServiceContracts/2008/01'; { for $x in //ns1:GetStockQuoteResult[1] return {data($x/a:Symbol/text())} } ] : RuntimeException:java.lang.reflect.InvocationTargetException
Can you help?

As #wst correctly answer the a namespace prefix is missing; if you see the SOAPUI error log you will see:
XPST0081: XQuery static error in #...<Symbol>{data($x/a:Symbol/text#:
Prefix a has not been declared
Of course a solution is to simple declare the namespace a in your XQuery but
there is another option; in SOAPUI you can use * wildcard to reference any namespace, so your XQuery Assertion could be simplified to:
<Result>
{
for $x in //*:GetStockQuoteResult[1]
return <Symbol>{data($x/*:Symbol/text())}</Symbol>
}
</Result>

In your XPath, you reference a:Symbol, but the namespace prefix a is not declared and assigned to a namespace.

Related

Is it possible to modify an object namespace in a Mutating Webhook?

I have created a Mutating Webhook for a Namespaced CRD. In this Webhook, I would like to dynamically change the namespace of the resource, no matter what the user specified.
When I try to create a resource, I get the following error:
Error from server (BadRequest): error when creating "crd.yaml": the namespace of the provided object does not match the namespace sent on the request
Is it possible to perform this change and, if so, am I missing any configuration?
Sadly, it might not be possible: looking at the code here, you can see that if the resource you're attempting to create already has a namespace (the request), and your webhook attempts to mutate the object to replace the namespace (the object), then there will be a mismatch.
if err := EnsureObjectNamespaceMatchesRequestNamespace(ExpectedNamespaceForScope(requestNamespace, strategy.NamespaceScoped()), objectMeta); err != nil {
return err
}
You can see that the function EnsureObjectNamespaceMatchesRequestNamespace takes in two things: the expected namespace from the request and the object's metadata. If the request coming in is namespaced, then the request's namespace will be returned.
If you look at the function, you can see that your case falls through to the default case:
switch {
case objNamespace == requestNamespace:
// already matches, no-op
return nil
case objNamespace == metav1.NamespaceNone:
// unset, default to request namespace
obj.SetNamespace(requestNamespace)
return nil
case requestNamespace == metav1.NamespaceNone:
// cluster-scoped, clear namespace
obj.SetNamespace(metav1.NamespaceNone)
return nil
default:
// mismatch, error
return errors.NewBadRequest("the namespace of the provided object does not match the namespace sent on the request")
}
Did you end up figuring out a workaround for yourself?

using java annotations in rythm template engine

In the quest of getting JUnit tests to be part of how we use Ryhtm we came up with the code snippet below. All went well until we added
#Test
which obviously is a java annotation and uses the # marker as a syntax element that is also being used by Rythm. How can the desired effect be achieved to get the #annotation? To simply escape the ## does not work it gives a
Syntax error on token "#", delete this token
error. So How can a Java # annotation be used ?
I have also filed this as a bug report at https://github.com/greenlaw110/Rythm/issues/285
#// This is a rythm template
#import static org.junit.Assert.*
#import org.junit.Test.*
#def static {
class TestMe {
String name;
#Test
public void testMe() {
name="test";
assertEquals("test",name);
}
}
}
#{
TestMe testme=new TestMe();
testme.name="testme";
}
The TestMe has the name #(testme.name)
If you use a fully qualifying annotation it should work:
#org.junit.Test
#import org.junit.Test.* in your template code should be #import org.junit.Test, note that .* needs to be take off

Create an expression to get a sub element from entity, using a Xtext DSL

I'd like to know, how can I create a DSL, using Xtext.
This is my code, that I created:
Model:
(entities += Entity)*
(access += Acessing)*
;
Entity:
'entity' name = ID '{'
( variables += Variable )*
'}'
;
Variable:
'var' name=ID
;
Acessing:
'use' (entity = [Entity])'.'(variable = [Variable])
;
The code is a little bit incomplete, but in this way I'd like perform this operation as follows:
entity user {
var name
var phone
var address
}
use user.phone
I understand that I can use this tag [Entity] as a identifier from a specific element, but I don't know how can I get those sub elements from it.
How can I procede?
You are using the nameattribute for Entity and Variable. This is a special attribute which Xtext automatically uses to create namespaces and delivers a working scope provider for free. Elements are identified by their qualified name. You need only a single reference to access them.
To solve your problem, you only have to modify your Use grammar rule and introduce a rule which describes a qualified name. Your grammar then could look like this:
Model:
(entities+=Entity)*
(access+=Acessing)*;
Entity:
'entity' name=ID '{'
(variables+=Variable)*
'}';
Variable:
'var' name=ID;
Acessing:
'use' var=[Variable|QualifiedName];
QualifiedName:
ID ('.' ID)*;
As you can see, it now uses the QualifiedName name to identify a variable. I have just tried it and it works out of the box.

I can add to ::oo::define to add global tclOO class definition extensions, how can I do this non-globally?

I have found some TclOO resources that mention you can create subclasses of ::oo::class. You can also create bare objects using ::oo::object create, but you cannot migrate from a bare class to a real class (ie parent oo::object to parent oo::class)
I'm looking to create a DSL for defining modules, that just creates class definitions.
module create mysql 5.5 {
executable mysqld
method post_install { ... }
}
module create redis 2.6 {
executable redis-server
...
}
These could then be used as
set mod [mysql new]
$mod install
$mod post_install
While you can't make class-specific extension commands directly in the oo::define system, you can do the next-best-thing very easily. The trick is to use namespace path to profile-in the additional commands to the namespace just for the duration of the definition processing. Which is somewhat over-fancy way of saying that it's pretty easy in metaclass constructors to do this sort of stuff:
# First, build the definition of the extensions
namespace eval ::ModuleDefineExtensions {
proc executable {program} {
# I'm not quite sure how you want to handle this, but [uplevel] and
# [info level] will reveal what you need.
puts "define executable as $program here"
}
}
# Now, the [module] metaclass
oo::class create module {
superclass oo::class
constructor {definitionScript} {
# Save the old path
set oldpath [namespace eval ::oo::define {namespace path}]
# Set the new one
namespace eval ::oo::define {namespace path ::ModuleDefineExtensions}
# Now let the superclass constructor handle this, trapping errors
catch {next $definitionScript} msg opt
# Restore the old path
namespace eval ::oo::define [list namespace path $oldpath]
# Rethrow any errors
return -options $opt $msg
}
}
You probably need some more bits and pieces (e.g., a suitable default superclass of module classes that defines common methods) but those are conventional.
If you're using 8.6, the module definition can be simpler (this time without comments):
oo::class create module {
superclass oo::class
constructor {definitionScript} {
set oldpath [namespace eval ::oo::define {namespace path}]
namespace eval ::oo::define {namespace path ::ModuleDefineExtensions}
try {
next $definitionScript
} finally {
namespace eval ::oo::define [list namespace path $oldpath]
}
}
}
It's the same in principle, but uses the try/finally command of 8.6.

Why isn't my static member function recognised across assemblies?

I have a helper assembly which includes a function to identify object types:
namespace Util
{
using namespace System;
public ref class CastingHelpers
{
public:
template < class T, class U >
static System::Boolean isinst(U u);
static bool Test() {return true;}
};
}
...but for some reason, when I try and use it in a gui application which references the assembly:
Util::CastingHelpers::Test();
Util::CastingHelpers::isinst<SomeClass^>(someInstance);
..gives me an error:
2>.\DataProcessor.cpp(161) : error C2039: 'isinst' : is not a member of 'Util::CastingHelpers'
Note that test works fine. Is this something to do with the fact that isinst uses generics?
You are not creating a generic function, you are creating a C++ template function which is not exported from the assembly.
Use the keyword generic instead of template to create .NET generic types and methods.
The template method is only visible by code that #includes its declaration.