Problems casting a null object with Spock - exception

I have a Spock test that fails over two Mac OS X Lion machines, but works over other Linux machines and the Spock Web Console.
I found another related question: Why I get a cannot cast object 'null' error, when testing my controller?
I'm using Grails 2.0.0 and Spock 0.6. Any suggestions? Seems to be a bug
def "casting null object"() {
expect:
null as BigDecimal == null
}
| Failure: casting null object(com.arturoherrero.MySpec)
| org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'null' with class 'org.codehaus.groovy.runtime.NullObject' to class 'java.math.BigDecimal'

Looks like you've hit this bug with Grails 2.0.0
That says it was fixed for Grails 2.0.2, so maybe an upgrade on one of your machines to check is in order?
Fingers crossed!

Related

Mockito Core Matcher-GreaterThan

I am trying to upgrade the mockito version in my project.
Current version: mockito-all [1.9.5]
Upgrade to : mockito-core [2.8.8]
Some of my old tests are failing with this issue
Test:
.andExpect(jsonPath("$.paymentTransaction.totalAmount").value(new GreaterThan<Double>(0.0D)))
Failure Message:
java.lang.AssertionError: For JSON path $.paymentTransaction.totalAmount type of value
Expected :class org.mockito.internal.matchers.GreaterThan
Actual :class java.lang.Double
Any clue, if this is to be handled in a different way with the mockito version upgrade ?
You ended up using the wrong overload:
public ResultMatcher value(Object expectedValue)
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/result/JsonPathResultMatchers.html#value-java.lang.Object-
Instead of
public <T> ResultMatcher value(Matcher<T> matcher)
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/result/JsonPathResultMatchers.html#value-org.hamcrest.Matcher-
The reason is you used matcher from Mockito, not from Hamcrest. You need to use:
org.hamcrest.Matchers.greaterThan(T value)
Also, note that there is an overload of jsonPath taking a Hamcrest matcher as a second argument (no need to call value)

java.lang.NoSuchMethodError while switching from owl-api 3.5 to 4.x

I've used the owl-api version 3.5 and now I would like to switch to Version 4, but I get a runtime exception. Like in the following example code (which works fine with version 3.5) a java.lang.NoSuchMethodError it thrown every time invoking the function "manager.addAxiom(...)".
WLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://example.com/owlapi/families");
OWLOntology ont = manager.createOntology(ontologyIRI);
OWLDataFactory factory = manager.getOWLDataFactory();
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLIndividual mary = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#Mary"));
OWLObjectProperty hasWife = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasWife"));
OWLObjectPropertyAssertionAxiom axiom1 = factory.getOWLObjectPropertyAssertionAxiom(hasWife, john, mary);
manager.addAxiom(ont, axiom1);
...
The whole exeption which is thrown says:
Exception in thread "main" java.lang.NoSuchMethodError: org.semanticweb.owlapi.model.OWLOntologyManager.addAxiom(Lorg/semanticweb/owlapi/model/OWLOntology;Lorg/semanticweb/owlapi/model/OWLAxiom;)Lorg/semanticweb/owlapi/model/parameters/ChangeApplied;
at de.ifak.Writer.OWL.Example.OWLMinimalTest.main(OWLMinimalTest.java:26)
I've tested the code in a clean Java project and added the owl-api dependencies manual and later with maven. I've testet it with version 4.0.2 and 4.1.0-RC2. Both have shown the same behavior.
I couldn't find any solution for that. So I hope someone can help me.
Thanks,
Chris
Ok, I found a solution by myself.
If I change the code
manager.addAxiom(ont, axiom1);
to
Set<OWLAxiom> axiomsToAdd = new HashSet<OWLAxiom>();
axiomsToAdd.add(axiom1);
manager.addAxioms(ont, axiomsToAdd);
all works fine, even with version 4.1 of the owl-api.
Edit:
Ok I made a mistake. It works fine with version 4.0.2 but with version 4.1 I get the same exception when I call:
manager.addAxioms(ont, axiomsToAdd);
like when I call:
manager.addAxiom(ont, axiom1);
The addAxiom method is still there but its return type has changed. Are you assigning the value returned to a variable?

Jasper string functions method undefined error

Using Jasper Reports 5.6.1. Added some text functions to a previously working text field jrxml (just want to truncate if longer than 75 chars). Works in iReport Studio, but not in Java.
<textFieldExpression><![CDATA[IF(LEN($F{AccountName})<75,$F{AccountName},LEFT($F{AccountName},75)+"...")]]></textFieldExpression>
Error message:
Error occured while trying to fetch the HTML Output from the Jasper Service (Errors were encountered when compiling report expressions class file:
1. The method LEN(String) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<->
2. The method LEFT(String, int) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<-->
3. The method LEN(String) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getOldValue()))<75,((java.lang.String)field_AccountName.getOldValue()),LEFT(((java.lang.String)field_AccountName.getOldValue()),75)+"..."); //$JR_EXPR_ID=9$
<->
4. The method LEFT(String, int) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getOldValue()))<75,((java.lang.String)field_AccountName.getOldValue()),LEFT(((java.lang.String)field_AccountName.getOldValue()),75)+"..."); //$JR_EXPR_ID=9$
<-->
5. The method LEN(String) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<->
6. The method LEFT(String, int) is undefined for the type ICC_1422636250096_198427
value = IF(LEN(((java.lang.String)field_AccountName.getValue()))<75,((java.lang.String)field_AccountName.getValue()),LEFT(((java.lang.String)field_AccountName.getValue()),75)+"..."); //$JR_EXPR_ID=9$
<-->
6 errors
)
I checked packages in jasperreports-5.6.1.jar file, includes functions package. Exhaustive web search turned up nothing. What could it be?
I have a similar error message. Where you able to resolve this? Works fine in Jaspersoft Studio 6.0.1, but throws this when compiling w/ Java:
The method IF(boolean, BigDecimal, BigDecimal) is undefined for the type Blank_A4_1_1423164610392_674232
Update: I was able to solve this by including the functions jar on my classpath. See that if that works for you. See jasperreports-functions-5.6.1.jar at http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%205.6.1/
When using GlassFish, verify that you have all jasper libraries on your production server. They should be under glassfish/domains/domain1/lib/ext. If the jars are not there (or some of them, such as the fonts or some other not non-requisite lib) you might experience the behavior you are describing.

The type System.DateTime is not a supported type. Change to use System.DateTimeOffset

We are creating a WebApi 2.2 service and are using the technologies listed above. Our backend datastore is MySql 5.6. We are using dotConnect for MySql to work with the data store. In the database, there is a RowVersion column with a type of Timestamp. In EF, I successfully generated the model, but I noticed that RowVersion is set to DateTime. When I run the WebApi, I get the following runtime exception, so I need to change the type to DateTimeOffset because Timestamp is not available.
In our application, we will use the RowVersion with ETags for concurrency handling. So, we will only read the RowVersion in our application; The database will automatically update the RowVersion whenever an insert or update happens.
I do not know how to correct this issue... Perhaps, there is some way to add an automatic type conversion so the RowVersion in the model is an Int64 and we automatically convert between the Int64 and Timestamp by sending the Timestamp.value to our application. We are only reading it, so this seems reasonable.
When I change the RowVersion to Int64 in the EF model and build the application, I receive the following error:
Error 1 Error 2019: Member Mapping specified is not valid. The type
'Edm.Int64[Nullable=True,DefaultValue=]' of member 'Version' in type
'Model.customer' is not compatible with
'Devart.Data.MySql.timestamp[Nullable=True,DefaultValue=,Precision=0]'
of member 'Version' in type
'Model.Store.customers'. C:\PROJECTS\ServiceMySql\ServiceMySql\Models\Model.edmx 898 17 ServiceMySql
I'd really appreciate your help to figure out how to resolve this issue.
Thank you for your time and suggestions,
Mike
Exception mentioned at the beginning of this posting:
System.ArgumentException was unhandled by user code
HResult=-2147024809 Message=The type
'System.Nullable1[[System.DateTime, mscorlib, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089]]' of property
'Version' in the 'XXXXServiceMySql.Models.customer' type is not a
supported type. Change to use 'System.DateTimeOffset' or ignore this
type by calling Ignore<XXXXServiceMySql.Models.customer>() on
'System.Web.OData.Builder.ODataModelBuilder'. Parameter name:
navigationProperty Source=System.Web.OData
ParamName=navigationProperty StackTrace:
at System.Web.OData.Builder.EntityTypeConfiguration.AddNavigationProperty(PropertyInfo
navigationProperty, EdmMultiplicity multiplicity, Boolean
containsTarget)
at System.Web.OData.Builder.EntityTypeConfiguration.AddNavigationProperty(PropertyInfo
navigationProperty, EdmMultiplicity multiplicity)
at System.Web.OData.Builder.ODataConventionModelBuilder.MapEntityType(EntityTypeConfiguration
entity)
at System.Web.OData.Builder.ODataConventionModelBuilder.MapType(StructuralTypeConfiguration
edmType)
at System.Web.OData.Builder.ODataConventionModelBuilder.MapTypes()
at System.Web.OData.Builder.ODataConventionModelBuilder.GetEdmModel()
at XXXXServiceMySql.WebApiConfig.GenerateEdmModel() in c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\App_Start\WebApiConfig.cs:line
89
at XXXXServiceMySql.WebApiConfig.Register(HttpConfiguration config) in
c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\App_Start\WebApiConfig.cs:line
55
at System.Web.Http.GlobalConfiguration.Configure(Action1 configurationCallback)
at XXXXServiceMySql.WebApiApplication.Application_Start() in c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\Global.asax.cs:line 17
InnerException:
I believe that, as of the latest version WebApi OData v4 (5.4.0), DateTime is supported to a degree. It still is defined as DateTimeOffset in the metadata, but at least your model can deal with DateTime. See http://odata.github.io/WebApi/datetime-support/ for more details.

Why are the date fields in my rails object / model evaluating to nil when I can clearly see that they are not?

I'm using ruby 1.8.6 and rails 1.2.3 (ancient but I'm debugging an old app)
A model called Payperiod has attributes begindate and enddate and after importing the db, the dates are all there (apparently)
But in the console and in the app, the date attributes eval to nil. Why?
Below is some code pasted from the console:
pp = Payperiod.find 95
=> #<Payperiod:0xb6d60f90 #attributes={"enddate"=>"2010-10-25", "title"=>"", "begindate"=>"2010-10-12", "id"=>"95", "region_id"=>"1", "active"=>"1"}>
pp.enddate
=> nil
Is this a mysql issue?
It's worth checking whether there are methods defined with the same names as the attributes which would override the default active record behaviour.
This isn't really an "answer" because I don't have specific info, but when I installed ruby 1.8.7 instead of 1.8.6, the problem vanished.
Phil