Using data provider I am fetching data from excel into a class and the test class contain multiple #Test. So now I need to pass all the arguments in the data provider to all the tests instead of using required parameters in a Test. So is there any way to declare the arguments in common, to use on
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestSample extends Library {
#BeforeClass()
public void Setup() {
}
#Test(dataProvider = "dataSupplier", priority = 0)
public void Verify_Test1(String adminName, String adminPassword, String emailId, String emailId1, String emailId2, String emailId3, String deviceCountry, String firstName, String lastName, String phoneNo, String productName, String productName1, String productName2, String productName3) {
startAdminLogin(adminName, adminPassword);
try {
} finally {
adminHomePage.clickAdminLogout();
}
}
#Test(dataProvider = "dataSupplier",priority = 1)
public void Verify_Test2(String adminName, String adminPassword, String emailId, String emailId1, String emailId2, String emailId3, String deviceCountry, String firstName, String lastName, String phoneNo, String productName, String productName1, String productName2, String productName3) {
startAdminLogin(adminName, adminPassword);
try {
} finally {
adminHomePage.clickAdminLogout();
}
}
#Test(dataProvider = "dataSupplier",priority = 2)
public void Verify_Test3(String adminName, String adminPassword, String emailId, String emailId1, String emailId2, String emailId3, String deviceCountry, String firstName, String lastName, String phoneNo, String productName, String productName1, String productName2, String productName3) {
startAdminLogin(adminName, adminPassword);
try {
} finally {
adminHomePage.clickAdminLogout();
}
}
#DataProvider
public Object[][] dataSupplier() {
List<Object[]> list2 = ExcelHelper.getDataList("adminUsers");
List<Object[]> list3 = ExcelHelper.getDataList(“userDetails”);
return mergeListToArray(list2, list3);
}
}
Related
I created a field with the datime type, I write data to the database from it, but an empty field is written, how to write down the date that I fill in the form?
<lightning-input class="date-area" type="datetime" format="MM/dd/yyyy" name="date" label="Select date"
onchange={handleDateChange} required></lightning-input>
handleDateChange(event) {
this.date = event.target.value;
console.log("Date", this.date);
}
public with sharing class TestDriveController {
public TestDriveController() {
}
#AuraEnabled
public static Boolean createApplicationTestDrive(String firstname, String lastname, String phone, String email, String carCenter, String product, String text, Datetime data){
Test_Drive__c testDrive = TestDriveService.createApplicationTestDrive(firstname, lastname, phone, email, carCenter, product, text, data);
return true;
}
}
public with sharing class TestDriveService {
public TestDriveService() {
}
public static Datetime formDatetimeFromStringGTM2(String dateToForm) {
if (!String.isBlank(dateToForm)) {
String correctDate = dateToForm.replace('T', ' ');
return correctDate;
}
return null;
}
public static Test_Drive__c createApplicationTestDrive(String firstname, String lastname, String phone, String email, String carCenter, String product, String text, Datetime data){
Datetime correctDate = formDatetimeFromStringGTM2(data);
return TestDriveManager.createApplicationTestDrive(firstname, lastname, phone, email, carCenter, product, text, correctDate);
}
}
public with sharing class TestDriveManager {
public TestDriveManager() {
}
public static Test_Drive__c createApplicationTestDrive(String firstname, String lastname, String phone, String email, String carCenter, String product, String text, Datetime data){
Test_Drive__c testDrive = new Test_Drive__c(
First_Name__c = firstname,
Last_Name__c = lastname,
Phone__c = phone,
Email__c = email,
Car_Center__c = carCenter,
Product__c = product,
Text__c = text,
Date__c = data
);
insert testDrive;
return testDrive;
}
}
Im trying to save info to DynamoDB but im currently getting the error java.lang.NullPointerException: null when using "save" on the AccountHelper class.
I followed the starter guide found on Github; https://github.com/derjust/spring-data-dynamodb
Here is my Model Class;
#DynamoDBTable(tableName = "Users")
public class User {
// #Id
private String _id;
private String bloodGroup;
private String firstName; // DO NOT change this, needs to stay firstName
private String surname;
private String email;
private String password;
private String addressline;
private String postcode;
private String latitude;
private String longitude;
public User() {}
// More Constructors, Getters & Setters
DynamoDB Config Class;
#EnableDynamoDBRepositories(includeFilters = {#ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {DynamoDBRepo.class})})
#Configuration
public class DynamoDBConfig {
#Value("${amazon.aws.accesskey}")
private String amazonAWSAccessKey;
#Value("${amazon.aws.secretkey}")
private String amazonAWSSecretKey;
public AWSCredentialsProvider amazonAWSCredentialsProvider() {
return new AWSStaticCredentialsProvider(amazonAWSCredentials());
}
#Bean
public AWSCredentials amazonAWSCredentials() {
return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);
}
#Primary
#Bean
public DynamoDBMapperConfig dynamoDBMapperConfig() {
return DynamoDBMapperConfig.DEFAULT;
}
#Bean
public DynamoDBMapper dynamoDBMapper(AmazonDynamoDB amazonDynamoDB, DynamoDBMapperConfig config) {
return new DynamoDBMapper(amazonDynamoDB, config);
}
#Bean
public AmazonDynamoDB amazonDynamoDB() {
return AmazonDynamoDBClientBuilder.standard().withCredentials(amazonAWSCredentialsProvider())
.withRegion(Regions.US_EAST_1).build();
}
}
Here is the method/class where i am getting the error;
#Service
public class AccountHelper {
private DynamoDBRepo dynamoDBRepo;
#Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;
public User create(String bloodGroup, String firstname, String surname, String email, String password, String addressline, String postcode) {
// Getting the error here
return dynamoDBRepo.save(new User(bloodGroup, firstname, surname, email, bCryptPasswordEncoder.encode(password), addressline, postcode));
}
// More methods below that i am not adding to keep this question to a minimum.
Here is my controller;
#Controller
#Component
public class AccountController {
#Autowired
private AccountHelper Service_functions;
#ResponseBody // Works
#PostMapping(value = "/create/{bloodGroup}/{firstname}/{surname}/{email}/{password}/{addressline}/{postcode}")
public String create( #PathVariable String bloodGroup , #PathVariable String firstname, #PathVariable String surname, #PathVariable String email, #PathVariable String password, #PathVariable String addressline, #PathVariable String postcode){
User CreateUser = Service_functions.create(bloodGroup, firstname, surname, email, password, addressline, postcode);
System.out.println("this is working");
return CreateUser.toString();
}
account properties;
spring.application.name=account-service
server.port=8020
eureka.client.service-url.defaultZone=http://localhost:8001/eureka/
amazon.aws.accesskey="" // i removed the keys
amazon.aws.secretkey=""
Any Suggestions/Help would be greatly on where i am going wrong.
Two things you need to fix here based on your details provided.
Add #Autowired annotation on your dynamoDBRepo variable so that it can be recognised as spring managed bean.
Based on your comment
i.e. error saying that it cannot find
com.bdonor.accountservice.Repository.DynamoDBRepo
You need to include com.bdonor.accountservice.Repository package as JPA repository package and enable jpa repository scan in your configuration.
I have created a Google Endpoint in my App Engine Server as follows:
package com.xxxxx.gcmbackend;
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.response.CollectionResponse;
import java.util.List;
import java.util.logging.Logger;
import javax.inject.Named;
import static com.xxxxxx.gcmbackend.OfyService.ofy;
#Api(
name = "register",
version = "v1",
namespace = #ApiNamespace(
ownerDomain = "gcmbackend.xxxxx.com",
ownerName = "gcmbackend.xxxxx.com",
packagePath=""
)
)
public class UserRegistrationEndpoint {
private static final Logger log = Logger.getLogger(RegistrationEndpoint.class.getName());
#ApiMethod(name = "register")
public void registerDevice(#Named("regId") String regId, #Named("username") String username, #Named("phone") String phone) {
if(findRecord(regId) != null) {
log.info("Device " + regId + " already registered, skipping register");
return;
}
RegistrationRecord record = new RegistrationRecord();
record.setRegId(regId);
record.setUsername(username);
record.setPhone(phone);
ofy().save().entity(record).now();
}
private RegistrationRecord findRecord(String regId) {
return ofy().load().type(RegistrationRecord.class).filter("regId", regId).first().now();
}
}
This works perfectly in creating new User records. The API is of the following format:
http://example.appspot.com/_ah/api/register/v1/registerDevice/<regId>/<username>/<phone>
However, I want the url to look like this:
http://example.appspot.com/_ah/api/register/v1/registerDevice/
and then send POST data as follows:
{
regId: "some_value",
username: "some_value",
phone: "some_value"
}
What do I need to change in my Endpoint in order to achieve this format?
You need to create a java bean with regId, username and phone attributes e.g. RegistrationInput.
public class RegistrationInput {
private String regId;
private String username;
private String phone;
public String getRegId() {
return regId;
}
public void setRegId(String regId) {
this.regId = regId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
Then add the above java bean RegistrationInput, as a parameter to the ApiMethod
#ApiMethod(name = "register")
public void registerDevice(RegistrationInput input) {
.....
}
I want to create a js array of type
Name(
{title : "Mr.",firstname : "Bill",lastname : "Gates"},
{title : "Mr.",firstname : "Bill",lastname : "Gates"},
{title : "Mr.",firstname : "Bill",lastname : "Gates"}
)
So basically i want to create associated array.
All the examples are like converting javascript array to java but in my case i want the other way round. I will be filling this array from java.
JSArray and JsMixedArray seems to be doing this but i could figure out how to add to them.
One approach could be to use a JSNI method to create the items/entries of your Array/Map as follows:
JsArray arr = JavaScriptObject.createArray().cast();
arr.push(newEntry("Mr.", "Bill", "Gates"));
....
private final native JavaScriptObject newEntry(String title,
String firstname, String lastname)/*-{
return {title: title, firstname: firstname, lastname: lastname};
}-*/;
You could also try to create the data structure you have in mind using the JSON utility methods: Put JSONObjects inside a JSONArray.
Variable $wnd.v will contain an array of objects.
Note: you will need to find a way how to convert your Java objects to a JSON (i used restygwt).
class PersonList {
List<Person> list;
}
class Person {
String title;
String firstName;
String lastName;
public Person () {}
public Person(String title, String firstName, String lastName) {
this.title = title;
this.firstName = firstName;
this.lastName = lastName;
}
}
public class Main implements EntryPoint {
public interface PersonCodec extends JsonEncoderDecoder<PersonList> {
}
PersonCodec personCodec = GWT.create(PersonCodec.class);
public void onModuleLoad() {
List<Person> list = new ArrayList<Person>();
list.add(new Person("Mr.", "Bill", "Gates"));
list.add(new Person("Mr.", "Andrey", "Mormysh"));
PersonList personList = new PersonList();
personList.list = list;
String json = personCodec.encode(personList).toString();
setPersonList(json);
}
public static native void setPersonList(String personListJson)/*-{
$wnd.v = eval("(" + personListJson + ")").list;
alert($wnd.v[0].firstName); // Output: 'Bill'
}-*/;
}
You can create empty JavaScriptObject from Java but you cannot populate them from there, so use the dark side of the force:
private native JavaScriptObject putString(JavaScriptObject jso, String key, String value)/*-{
jso[key] = value;
return jso;
}-*/;
private native JavaScriptObject putObject(JavaScriptObject jso, String key, JavaScriptObject value)/*-{
jso[key] = value;
return jso;
}-*/;
void someJavaFunction() {
JavaScriptObject fromJava = JavaScriptObject.createObject();
fromJava = putString(fromJava, "foo", "bar");
fromJava = putObject(fromJava, "baz", fromJava);
}
How do I obtain values of an array that is located inside a java object in a jsp page?
I have set an object attribute so that in the jsp page I can call the object like so
${obj.property}
My question is how would I obtain property String [] example from Object obj?
<c:forEach var="prop" items="${obj.example}">
<td>${prop}</td>
</c:forEach>
I get Errors that tell me the class obj.Obj does not have the property property 'example'
and obviously I don't get the data out.
Actual errors:
org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'.
javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'
And my actual class:
package roommate;
public class Roommate{
public String firstname;
public String lastname;
public String gender;
public String place;
public String[] favProfessors;
public Roommate(String fname, String lname, String roommateGender, String hangout,String[] professors) {
firstname= fname;
lastname= lname;
gender= roommateGender;
place= hangout;
favProfessors= professors;
}
public String getFirstname()
{
return firstname;
}
public void setFirstname(String newFirstname)
{
this.firstname = newFirstname;
}
public String getLastname()
{
return lastname;
}
public void setLastname(String newLastname)
{
this.lastname = newLastname;
}
public String getGender()
{
return gender;
}
public void setGender(String newGender)
{
this.gender = newGender;
}
public String getHangout()
{
return place;
}
public void setHangout(String newPlace)
{
this.place = newPlace;
}
public String[] getProfessors()
{
return favProfessors;
}
public void setProfessors(final String[] newfavProfessors)
{
this.favProfessors = newfavProfessors;
}
public void addRoommate(String fname, String lname, String roommateGender, String hangout,String[] professors)
{
}
}
I create the object in my servlet as well ass the Atrribute
String [] profArray = request.getParameterValues("professor");
Roommate roommate= new Roommate(
session.getAttribute("fname").toString(),
session.getAttribute("lname").toString(),
session.getAttribute("gender").toString(),
session.getAttribute("hangout").toString(),
profArray);
session.setAttribute("roommate",roommate);
I asked this earlier but did not receive a clear answer. I think my issue is in pulling the data out in the jsp alone in my forEach that I mentioned at the top
javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'
Java is right. You do not have a getFavProfessors() method in that class. It's instead the following:
public String[] getProfessors()
{
return favProfessors;
}
You have 2 options: use ${roommate.professors} instead, or fix the getter method name to be getFavProfessors().
In contrary to what most starters think, EL does not access private properties directly. EL just calls the public getter/setter methods according the Javabeans specification. The real private property behind it can have a completely different name or even not exist at all.