I'm trying to pass a value from a key which is in e.g . "29.00". The request I'm passing this value to doesn't accept double quotations around the value. It's accepting 2 decimal points only and a number. e.g 29.00
The issue is when I use parseInt(amount) or parseFloat(amount) its drops the last zero. So the value becomes 29.0 which the api is not accepting.
I just need the value to be in 2 decimal points so the trailing 0 is not dropped.
I have used JS functions like function(test) { return parseInt(amount).toFixed(2)} but it is not working.
A sample of code I have used:
def reqJson = read ('Json/PaynowPayload.json')
def amount = SearchResults.ratePlans[0].rooms[0].totalCost.amount
def Newamount = parseInt(amount).toFixed(2)
set reqJson.payment.amount.minorUnits = Newamount
Any help would be appreciated
First, let me say that in my opinion, if the server does not accept 29.0 and only 29.00 it is a bug on the server-side and Karate has done the right thing to surface this for you.
Anyway, you can always "force" a string as the payload like this, and also look at the text keyword:
* url 'https://httpbin.org/anything'
* header Content-Type = 'application/json'
* request '{ "foo": 29.00 }'
* method post
Even though the request log may show 29.0 you can verify that the above request does what you expect because the response will echo the request sent:
1 > POST https://httpbin.org/anything
1 > Content-Type: application/json; charset=UTF-8
1 > Content-Length: 16
1 > Host: httpbin.org
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/11.0.11)
1 > Accept-Encoding: gzip,deflate
{"foo":29.0}
16:34:12.445 [main] DEBUG com.intuit.karate - response time in milliseconds: 1293
1 < 200
1 < Date: Fri, 02 Jul 2021 11:04:12 GMT
1 < Content-Type: application/json
1 < Content-Length: 510
1 < Connection: keep-alive
1 < Server: gunicorn/19.9.0
1 < Access-Control-Allow-Origin: *
1 < Access-Control-Allow-Credentials: true
{"args":{},"data":"{ \"foo\": 29.00 }","more": "..."}
So now it is up to you to create the JSON string required. Here's just one way, there are other possibilities (Karate 1.X):
* def temp = java.lang.String.format("%.2f", new java.lang.Double(29))
* def body = `{ "foo": ${temp} }`
* url 'https://httpbin.org/anything'
* header Content-Type = 'application/json'
* request body
* method post
Hello I have a question concerning data processing in groovy.
I have a groovy step in which I call a method that gives me a list of json in return, then I parse it to test a value
here is the code :
props = get_device_properties(device_id)
log.info "props = $props"
log.info "size " + props.size()
log.info "class " + props.class
//props = jsonSlurper.parseText(props)
log.info "***************************** t1"
props.find(){
log.info it.name
// check the field songTitle
if (it.name == "songTitle")
{
// first check media
if(init_correct == false)
{
log.info "init = " + it.value
if (it.value == "UNKNOWN")
found == true
log.info "***************************** t2"
here is a log of the process :
Tue Jan 28 11:34:56 CET 2020: INFO: props = [[satisfied:true, href:...
Tue Jan 28 11:35:03 CET 2020: INFO: size 31
Tue Jan 28 11:35:03 CET 2020: INFO: class class java.util.ArrayList
Tue Jan 28 11:35:03 CET 2020: INFO: ***************************** t1
Tue Jan 28 11:35:03 CET 2020: INFO: songTitle
Tue Jan 28 11:35:03 CET 2020: INFO: init = Sad But True
Tue Jan 28 11:35:03 CET 2020: INFO: ***************************** t2
If I parse the map directly there is a gap of time between method return and start of the next processing :
t2 - t1 is around 7s
If 'get_device_properties' returns a String instead of the arrayList and I do a parseText (uncomment the 5th line) on this string, I don't have the extra processing time before I can parse the map
Tue Jan 28 11:35:39 CET 2020: INFO: props = [{"satisfied":true,"href":...
Tue Jan 28 11:35:39 CET 2020: INFO: size 25138
Tue Jan 28 11:35:39 CET 2020: INFO: class class java.lang.String
Tue Jan 28 11:35:39 CET 2020: INFO: ***************************** t1
Tue Jan 28 11:35:39 CET 2020: INFO: songTitle
Tue Jan 28 11:35:39 CET 2020: INFO: init = Sad But True
Tue Jan 28 11:35:39 CET 2020: INFO: ***************************** t2
t2 - t1 = 0
can anyone help me to understand why this happens ?
indeed, I usually tend to use the most straightforward way to implement my script ...
I am following one of dojo/store/JsonRest tutorial (https://dojotoolkit.org/reference-guide/1.10/dojo/store/JsonRest.html#dojo-store-jsonrest). As mentioned in the tutorial I am returning "Content-Range: items 0-24/66" in the header from server side (java).
I have tested in SOAP UI as well and the header is there in the server response:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Range: items 0-3/6
Content-Type: application/json
Content-Length: 402
Date: Thu, 16 Mar 2017 01:14:23 GMT
When I access the total as in following
var results = store.query({
start: 0,
count: 3
}).then(function (deals){
//do something
});
results.total.then(function(total){
//do something
});
Here I am getting results.total is undefined error. Any idea?
Please see screen shot is the content of results.
Content of Results
The returned total is available as a further promise on the returned promise of data which returns the total number of available rows indicated in the Content-Range: header as a number, so you can retrieve it like this:
var results = store.query({
start: 0,
count: 3
}).then(function(deals) {
// move this promise inside outer promise
results.total.then(function(total) {
//do something
});
});
Did a few more research and found out that following code can be used to get both response data and total. Not really sure why it wasn't working on above code blocks though.
var results = store.query({
start: 0,
count: 3
});
results.then(function (data) {
// You can access the response data here
results.total.then(function (total) {
// You can access total here
});
});
That is what i tried to do
session.get(Company.class, 1);
Hibernate:
select
company0_.Company_ID as Company1_31_4_,
company0_.version as version2_31_4_,
company0_.Address_ID as Address5_31_4_,
company0_.Company_Code as Company3_31_4_,
company0_.Company_Name as Company4_31_4_,
company0_.Phone_ID as Phone6_31_4_,
address1_.Address_ID as Address1_0_0_,
address1_.version as version2_0_0_,
address1_.Comapny_ID as Comapny4_0_0_,
address1_.Address as Address3_0_0_,
company2_.Company_ID as Company1_31_1_,
company2_.version as version2_31_1_,
company2_.Address_ID as Address5_31_1_,
company2_.Company_Code as Company3_31_1_,
company2_.Company_Name as Company4_31_1_,
company2_.Phone_ID as Phone6_31_1_,
phone3_.Phone_ID as Phone1_77_2_,
phone3_.version as version2_77_2_,
phone3_.Comapny_ID as Comapny5_77_2_,
phone3_.Fax_Number as Fax3_77_2_,
phone3_.Phone_Number as Phone4_77_2_,
company4_.Company_ID as Company1_31_3_,
company4_.version as version2_31_3_,
company4_.Address_ID as Address5_31_3_,
company4_.Company_Code as Company3_31_3_,
company4_.Company_Name as Company4_31_3_,
company4_.Phone_ID as Phone6_31_3_
from
greentk_final.Company company0_
left outer join
greentk_final.Address address1_
on company0_.Address_ID=address1_.Address_ID
left outer join
greentk_final.Company company2_
on address1_.Comapny_ID=company2_.Company_ID
left outer join
greentk_final.Phones phone3_
on company0_.Phone_ID=phone3_.Phone_ID
left outer join
greentk_final.Company company4_
on phone3_.Comapny_ID=company4_.Company_ID
where
company0_.Company_ID=?
Feb 04, 2014 1:58:11 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1054, SQLState: 42S22
Feb 04, 2014 1:58:11 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Unknown column 'address1_.Comapny_ID' in 'field list'
Feb 04, 2014 1:58:11 AM org.hibernate.event.internal.DefaultLoadEventListener onLoad
INFO: HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2036)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1836)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1815)
at org.hibernate.loader.Loader.doQuery(Loader.java:899)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:311)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2117)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3927)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:460)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:429)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:206)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:145)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1092)
at org.hibernate.internal.SessionImpl.immediateLoad(SessionImpl.java:1007)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:173)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:285)
at org.hibernate.engine.internal.StatefulPersistenceContext.unproxyAndReassociate(StatefulPersistenceContext.java:677)
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:90)
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:957)
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:936)
at main.Main.main(Main.java:53)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'address1_.Comapny_ID' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)
... 24 more
package model;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import model.calibration.AbstractModel;
/**
*
* #author Islam Morad
*/
#Entity
#Table(name = "Address")
public class Address extends AbstractModel implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7162754693551897604L;
private long addressID;
private String street;
private Company company;
/**
* #return the addressID
*/
#Id
#GeneratedValue
#Column(name = "Address_ID", nullable = false)
public long getAddressID() {
return addressID;
}
/**
* #param addressID
* the addressID to set
*/
public void setAddressID(long addressID) {
this.addressID = addressID;
}
/**
* #return the street
*/
#Column(name = "Address", nullable = false)
public String getStreet() {
return street;
}
/**
* #param street
* the street to set
*/
public void setStreet(String street) {
this.street = street;
}
/**
* #return the company
*/
#OneToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "Comapny_ID")
public Company getCompany() {
return company;
}
/**
* #param company
* the company to set
*/
public void setCompany(Company company) {
this.company = company;
}
}
Here is the full stack-trace again
Feb 06, 2014 9:20:26 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Feb 06, 2014 9:20:27 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.2.Final}
Feb 06, 2014 9:20:27 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Feb 06, 2014 9:20:27 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Feb 06, 2014 9:20:27 AM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /main/hibernate.cfg.xml
Feb 06, 2014 9:20:27 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /main/hibernate.cfg.xml
Feb 06, 2014 9:20:28 AM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: GreenTK
Feb 06, 2014 9:20:29 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Feb 06, 2014 9:20:29 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Feb 06, 2014 9:20:29 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Feb 06, 2014 9:20:29 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/testing]
Feb 06, 2014 9:20:29 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****}
Feb 06, 2014 9:20:32 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Feb 06, 2014 9:20:34 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Feb 06, 2014 9:20:34 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Feb 06, 2014 9:20:34 AM org.hibernate.search.Version <clinit>
INFO: HSEARCH000034: Hibernate Search 4.3.0.Final
Feb 06, 2014 9:20:34 AM org.hibernate.search.impl.ConfigContext getLuceneMatchVersion
WARN: HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
Feb 06, 2014 9:20:38 AM org.hibernate.internal.SessionFactoryRegistry addSessionFactory
WARN: HHH000277: Could not bind factory to JNDI
org.hibernate.service.jndi.JndiException: Error parsing JNDI name [GreenTK]
at o rg.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)
org.hibernate.service.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:108)
at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java: 89)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:480)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1769)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
at main.HibernateUtil.<clinit>(HibernateUtil.java:28)
at main.Main.main(Main.java:48)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.getNameParser(InitialContext.java:499)
at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86)
... 7 more
Hibernate:
select
company0_.Company_ID as Company1_31_4_,
company0_.version as version2_31_4_,
company0_.Address_ID as Address5_31_4_,
company0_.Company_Code as Company3_31_4_,
company0_.Company_Name as Company4_31_4_,
company0_.Phone_ID as Phone6_31_4_,
address1_.Address_ID as Address1_0_0_,
address1_.version as version2_0_0_,
address1_.Company_ID as Company4_0_0_,
address1_.Address as Address3_0_0_,
company2_.Company_ID as Company1_31_1_,
company2_.version as version2_31_1_,
company2_.Address_ID as Address5_31_1_,
company2_.Company_Code as Company3_31_1_,
company2_.Company_Name as Company4_31_1_,
company2_.Phone_ID as Phone6_31_1_,
phone3_.Phone_ID as Phone1_77_2_,
phone3_.version as version2_77_2_,
phone3_.Company_ID as Company5_77_2_,
phone3_.Fax_Number as Fax3_77_2_,
phone3_.Phone_Number as Phone4_77_2_,
company4_.Company_ID as Company1_31_3_,
company4_.version as version2_31_3_,
company4_.Address_ID as Address5_31_3_,
company4_.Company_Code as Company3_31_3_,
company4_.Company_Name as Company4_31_3_,
company4_.Phone_ID as Phone6_31_3_
from
testing.Company company0_
left outer join
testing.Address address1_
on company0_.Address_ID=address1_.Address_ID
left outer join
testing.Company company2_
on address1_.Company_ID=company2_.Company_ID
left outer join
testing.Phone phone3_
on company0_.Phone_ID=phone3_.Phone_ID
left outer join
testing.Company company4_
on phone3_.Company_ID=company4_.Company_ID
where
company0_.Company_ID=?
Your problem is a typo in address entity:
#JoinColumn(name = "Comapny_ID")
should be
#JoinColumn(name = "Company_ID")
I faced to following problem with sending invitation in .net using exchange API
Send invitation in Israel timezone with start time =09/09/2013 4.30 Israel.
But it is displayed in outlook 09/09/2013 6.30 Israel.
It works properly for other time zones for example for EST.
Does anybody has any idea how to fix this?
Sample:
service.AutodiscoverUrl(loginForm.tbEmailAddress.Text, f);
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Israel Standard Time");
Appointment appointment = new Appointment(service);
appointment.Subject = "subj";
appointment.Body = new MessageBody(BodyType.Text, "body");
appointment.StartTimeZone = timeZoneInfo;
appointment.Start = GetDateTime(new DateTime(2013, 09, 09, 04, 0, 0));
appointment.EndTimeZone = timeZoneInfo;
appointment.End = GetDateTime(new DateTime(2013, 09, 09, 04, 30, 0));
appointment.IsAllDayEvent = false;
appointment.Importance = Importance.Normal;
appointment.RequiredAttendees.Add("Lena", "email...");
appointment.Save(SendInvitationsMode.SendOnlyToAll);
...
private static DateTime GetDateTime(DateTime dateTime)
{
return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute,
dateTime.Second, dateTime.Millisecond, DateTimeKind.Unspecified
);
}
I use Microsoft.Exchange.WebServices.dll 15.0.516.14
it's actually a known issue with Exchange EWS itself. Developer can only trust the date time returned without the timezone information, and the correct timezone for that time should be UTC always.