Cucumber - DocStringType - Jackson Data Bind UnrecognizedPropertyException - Even If Property Existed - cucumber

Below is my Feature File
Scenario Outline: CucumberTest
Given Generate Data Set
"""json
{
"tcIdentifier":"TC1"
}
"""
Examples:
|TESTCASEIDENTIFIER|
|TC1 |
Step Defintion Would Look Like Below
#Given("Generate Data Set")
public void generateDataSet(DataSetMetaData dataSetMetaData) {
System.out.println(dataSetMetaData);
}
#DocStringType
public DataSetMetaData createTestDataForSorting(String details) throws JsonProcessingException {
return new ObjectMapper().readValue(details, DataSetMetaData.class);
}
Details of the DataSetMetaData
#Getter
#Setter
#ToString
#AllArgsConstructor
#Builder
#NoArgsConstructor
public class DataSetMetaData {
private String tcIdentifier;
}
Expected : Data Binding from the Docstring to be Transformed to DataSetMetaData POJO
ACtual : We Are Encountered with the Exception
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "tcIdentifier" not marked as ignorable (0 known properties: ])
From Some of the Previous Responses on similar - Exception - community has suggested to Annotate the Field as #JsonProperty - What I am Failing to Understand - if the variable Names matches the JSON Data Key - Ideally Binding Should work - For some Strange Reason - even if the attribute Exist - UnrecognizedPropertyException: Unrecognized field "tcIdentifier"
Following are the maven Co-ordinates related to the Cucumber and Jackson Dependencies
implementation group: 'io.cucumber', name: 'cucumber-java', version: '7.3.4
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '7.2'
Do let me know if any Further Information is required

#M.P. Korstanje and #GaƫlJ - Thank you very much for insights and giving directions towards analysis in the right Direction
Adding the Lombok Dependencies with the scope of annotationProcessor did the magic - Hope it Helps

Related

Groovy YamlBuilder field case

I'm trying to generate a cloudformation template with groovy YamlBuilder, that's why case matters here. The issue is that by default YamlBuilder converts pascal-case fields to camel-case.
Please see the example (runnable via groovyConsole):
import groovy.yaml.YamlBuilder
class Person {
String Name = 'Mickey Mouse'
}
YamlBuilder builder = new YamlBuilder()
builder {
Node new Person()
}
builder.toString()
The code above returns "Name" field in lower case:
---
Node:
name: "Mickey Mouse"
I need:
---
Node:
Name: "Mickey Mouse"
I've tried plenty of options but haven't found how can I tell YamlBuilder to keep "Name" field case. Or maybe I can use some annotations over the field?

GORM setup using Gradle and Groovy

Can anyone please share the steps to setup GORM using gradle and use the same in groovy ?
GORM for Hibernate has excellent documentation
Particularly the section of Using GORM For Hibernate Outside Grails
At minimum you need:
compile "org.grails:grails-datastore-gorm-hibernate5:6.1.10.RELEASE"
runtime "com.h2database:h2:1.4.192"
runtime "org.apache.tomcat:tomcat-jdbc:8.5.0"
runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.5.0"
runtime "org.slf4j:slf4j-api:1.7.10"
Entities should go under src/main/groovy
#Entity
class Person implements GormEntity<Person> {
String firstName
String lastName
static constraints = {
firstName blank:false
lastName blank:false
}
}
and then finally bootstrap the data store somewhere:
import org.grails.orm.hibernate.HibernateDatastore
Map configuration = [
'hibernate.hbm2ddl.auto':'create-drop',
'dataSource.url':'jdbc:h2:mem:myDB'
]
HibernateDatastore datastore = new HibernateDatastore( configuration, Person)

My first basic Cucumber program (Scenario) fails - Java

I wrote my first Cucumber program today, and it fails. I wrote a very basic one, a simple scenario and it's step definition. Below is the feature file code and the step definition code.
Step Definiton code:
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
public class Testing_Example1 {
#When("^I am on x page$")
public void i_am_on_x_page() throws Throwable {
System.out.println("I am on xPage");
}
#Then("^I see that element$")
public void i_see_that_element() throws Throwable {
System.out.println("I can see that page");
}
}
Feature File Code:
Feature: Testing
Scenario: s1
When I am on x page
Then I see that element
I have added the system variables as well - The JAVA_HOME and the maven variables as well and linked it to the PATH variable I system variables.
I have added dependencies in the POM file, such as the Cucumber-Java, Cucumber-Junit and for selenium as well and yet my program fails and says the steps are undefined.
Output:
1 Scenarios (1 undefined)
2 Steps (2 undefined)0m0.000s
You can implement missing steps with the snippets below:
#When("^I am on x page$")
public void i_am_on_x_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#Then("^I see that element$")
public void i_see_that_element() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Undefined step: When I am on x page
Undefined step: Then I see that element
Process finished with exit code 0
I guess it's because my feature file is not getting linked with the step definition file, but I don't understand what is missing that the feature file does not execute properly and scenarios fail. Someone who has knowledge about this, do help.
Thank You!
I found the solution to this. I just edited the configuration of the feature file - > edit configurations -> Paste the path of the package in which your step definition file is present -> apply.
I just has to link the feature file to the step definition using Glue.
Specify the stepdefintion & feature file details in your cucumber runner class.
#CucumberOptions(
plugin={"pretty", "html:target/cucumber-html-report","json:target/cucumber-report.json"},
features = "src/test/resources",
glue ="com.vg.pw.ui.stepdefinitions",
)
public class CucumberRunner {
...
}

Liferay - Hook for GroupWrapper

I'm trying to override the getDescriptiveName() method in com.liferay.portal.model.Group
I found a wrapper (com.liferay.portal.model.GroupWrapper), so I tried to write a hook as written in the documentation :
liferay-hook.xml:
<service>
<service-type>com.liferay.portal.model.GroupWrapper</service-type>
<service-impl>fr.villedeniort.hook.expando.GroupWrapperImpl</service-impl>
</service>
fr.villedeniort.hook.expando.GroupWrapperImpl.java:
public class GroupWrapperImpl extends GroupWrapper {
public GroupWrapperImpl(Group group) {
super(group);
}
#Override
public java.lang.String getDescriptiveName()
throws com.liferay.portal.kernel.exception.PortalException,
com.liferay.portal.kernel.exception.SystemException {
return super.getDescriptiveName();
}
When the hook is deployed, it raises an exception :
java.lang.NoSuchMethodException: fr.villedeniort.hook.expando.GroupWrapperImpl.<init>(com.liferay.portal.model.GroupWrapper)
I browse the code I found out that it breaks at this part for a reason I ignore:
Constructor<?> serviceImplConstructor = serviceImplClass.getConstructor(new Class<?>[] {serviceTypeClass});
At this point, variables have theses values:
serviceType "com.liferay.portal.model.GroupWrapper" (id=14829)
serviceImpl "fr.villedeniort.hook.expando.GroupWrapperImpl" (id=14830)
serviceTypeClass Class<T> (com.liferay.portal.model.GroupWrapper) (id=14831)
serviceImplClass Class<T> (fr.villedeniort.hook.expando.GroupWrapperImpl) (id=14832)
Do you have any idea?
Thanks!
You should have also a constructor without any argument. Now you have one with constuctor arguments, but there is no pure class constructor that java searches when it makes class instance. After calling the pure constructor java then calls the argumented one.
I had similar case in some other context and this was the solution. <init> tag on the error message refers on this kind of issue.
Apparently, it's not possible to hook other classes than Services, so I had to find a different way. For my case, I hooked a JSP and wrote my own method to get the right descriptive name from the hook.

which spring ws jaxb annotation to change xml element name

I am using a sping ws endpoint with jaxb marshalling/unmarshalling to proudce a list of Organisation objects (our local type). The endpoint is SOAP 1.1, no parameters supplied on the request message.
I understand JAXB doesn't handle lists very well, so I use a wrapper class.
#XmlRootElement(name="orgResponse", namespace=....)
public class OrganisationListWrapper {
private ArrayList<Organisation> organisationList;
public getOrganisationList() {
return organisationList;
}
public setOrganisationList(ArrayList<Organisation> organisationList) {
this.organisationList = organisationList;
}
}
The endpoint....
#PayloadRoot(localPart=.... namespace=....)
#ResponsePayload
public OrganisationListWrapper getOrganisations() {
OrganisationListWrapper wrapper = new OrganisationListWrapper();
wrapper.setOrganisationList(.... call service layer get list ....);
return wrapper;
}
This works fine and I get a SOAP payload with
<orgResponse>
<organisationList>
... contents of organisation 1
</organisationList>
<organisationList>
... comtents of organisation 2
</organisationList>
.... etc ....
</orgResponse>
The Organisation class is not JAXB annotated. It is part of a large list of pre-existing classes that are being exposed through web services for the first time. Trying to get by without going in and annotating them all by hand.
I was able to override the name OrganisationWrapper with orgResponse in the XmlRootElement annotation. I would like to override the organisationList name in the child element with organisation but haven't been able to find an annotation that does this.
I can replace the array list name with organisation and it will work fine, but our coding standard here required us to put List on the end of our list names. I would like to try and stick to that. I have tried XmlElement, but that produced a jaxb exception.
Any suggestions would be appreciated.
Because JAXB default the access type to PUBLIC_MEMBER, make sure you annotate the property (getter) and not the field:
#XmlElement(name="organisation")
public getOrganisationList() {
return organisationList;
}
If you want to annotate the field then add the following annotation to your class:
#XmlAccessorType(XmlAccessType.FIELD)

Resources