my code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beans;
import clients.NewJerseyClient;
import entities.ReservationItem;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.ws.rs.core.GenericType;
import parameters.ReservationParam;
import org.glassfish.jersey.client.ClientResponse;
/**
*
* #author subhi2
*/
#ManagedBean
#SessionScoped
public class PageController implements Serializable {
public String moveToPage2() {
NewJerseyClient client = new NewJerseyClient();
ClientResponse response = client.findInsertedReservationItem(ClientResponse.class, "22", "2010-07-26T11:15:51", "2014-07-26T11:15:51");
GenericType<List<ReservationItem>> genericType = new GenericType<List<ReservationItem>>() {
};
// Returns an ArrayList of Players from the web service
List<ReservationItem> data = new ArrayList<ReservationItem>();
data = (response.getEntity(genericType));
return data.toString();
}
}
the line
data = (response.getEntity(genericType));
cause the error
this code was working with old jersey but now what should I do to solve this error ?
You can change response.getEntity(genericType) by response.readEntity(genericType)
For what you are asking I've replaced this
response.getEntity(String.class);
by this
response.getEntityStream().toString();
But there could be another problems related with Jersey 2, I could get it working by replacing these imports
import jersey.spi.container.servlet.ServletContainer;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
By these
import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.client.ClientResponse;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
and in the code (as I was using Jetty) I had to replace this
servletHolder.setInitParameter("com.sun.jersey.config.property.packages",
"resources");
by this
servletHolder.setInitParameter("jersey.config.server.provider.packages",
"resources");
and this
WebResource webResource = client.resource("http://url_u_want_to_connect");
ClientResponse response = webResource.accept("application/json")
by this
WebTarget webTarget = client.target("http://url_u_want_to_connect");
ClientResponse response = webTarget.request("application/json")
Finally here is a link for "latest" docs (It's about Jersey 2.x, at 2013)
https://jersey.java.net/documentation/latest/user-guide.html
Related
I have the below Karate Runner File Content. When I executed this file on Eclipse, nothing is shownup on Console. Can Someone please help on this issue for me.
package com.accounting.apirunner;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import com.intuit.karate.junit5.Karate;
import cucumber.api.CucumberOptions;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
#CucumberOptions(features = { "classpath:Accountspayables", "classpath:Accountsreceivables", "classpath:company",
"classpath:generalLedger", "classpath: SpendManagement" }, tags = {
"~#ignore" }, plugin = { "pretty", "html:target/cucumber-html-reports" }, monochrome = true)
public class TestCaseRunner {
#BeforeClass
public static void beforeClass() throws Exception {
System.setProperty("karate.env", "SAT");
#Test
public void testParallel() {
Results results = Runner.path("classpath:Accountspayables", "classpath:Accountsreceivables",
"classpath:company", "classpath:generalLedger", "classpath: SpendManagement").tags("~#ignore")
.parallel(1);
generateReport(results.getReportDir());
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
String karateOutputPath = "target/surefire-reports";
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] { "json" }, true);
List<String> jsonPaths = new ArrayList(jsonFiles.size());
for (File file : jsonFiles) {
jsonPaths.add(file.getAbsolutePath());
}
Configuration config = new Configuration(new File("target"), "Accounting XMLGW Regression Test Suite");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
And no Executions shown up on Junit Explorer.
I'm writing script to scroll mobile application up and down but Appium studio code with testng framework not working in Eclipse.
I'm new with this kind of script and testing please help to fix it.
I tried Appium studio code.
but it need to fix to run script.
//package <set your test package>;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.TouchAction;
import java.time.Duration;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.testng.annotations.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.logging.Level;
public class scrollandsave {
private String reportDirectory = "reports";
private String reportFormat = "xml";
private String testName = "scrollandsave";
protected AndroidDriver<AndroidElement> driver = null;
DesiredCapabilities dc = new DesiredCapabilities();
#BeforeMethod
public void setUp() throws MalformedURLException {
dc.setCapability("reportDirectory", reportDirectory);
dc.setCapability("reportFormat", reportFormat);
dc.setCapability("testName", testName);
dc.setCapability(MobileCapabilityType.UDID, "330033acecf394bd");
driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), dc);
driver.setLogLevel(Level.INFO);
}
#Test
public void testscrollandsave() {
new TouchAction(driver).press(480, 1348).waitAction(Duration.ofMillis(624)).moveTo(338, 312).release().perform();
new TouchAction(driver).press(591, 1376).waitAction(Duration.ofMillis(592)).moveTo(421, 138).release().perform();
driver.findElement(By.xpath("(//*[#id='listAllImgByCat']/*/*/*/*[#id='icPlayVideo'])[1]")).click();
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#text='EDIT']")));
driver.findElement(By.xpath("//*[#text='EDIT']")).click();
new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[#text='SAVE']")));
driver.findElement(By.xpath("//*[#text='SAVE']")).click();
driver.findElement(By.xpath("//*[#text='Export as GIF']")).click();
driver.findElement(By.xpath("//*[#id='btnHome']")).click();
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
I expect screen should scroll down whenever I execute above code.
you can try this code driver.executeScript("seetest:client.swipe(\"Down\", 1000, 500)");
. This code would swipe from Down, from the offset 1000 for 500ms.
Visit here for more information
I am trying to run the following code with eclipse but it will give me the error: "The method when() is undefined for the type LastLabTest". I have imported the libraries but still it gives me that error. I am using eclipse with junit5.
import io.restassured.RestAssured;
import io.restassured.RestAssured.*;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.http.ContentType;
import io.restassured.matcher.RestAssuredMatchers.*;
import io.restassured.specification.RequestSpecification;
import org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.BeforeClass;
import org.junit.jupiter.api.Test;
class LastLabTest {
private RequestSpecification specification;
#BeforeClass
public void inItSpec() {
specification = new RequestSpecBuilder()
.setContentType(ContentType.JSON)
.setBaseUri("http://openlibrary.org/")
.addFilter(new RequestLoggingFilter())
.addFilter(new ResponseLoggingFilter())
.build();
}
#Test
public void getByName() {
when().get("https://swapi.co/api/people/1")
.then().log().all()
.statusCode(200)
.and()
.body("name", equals("Luke Skywalker"));
}
}
The keyword static is missing in the line
import io.restassured.RestAssured.*;
=>
import static io.restassured.RestAssured.*;
keyword static is missing in import io.restassured.RestAssured.;
correct : import static io.restassured.RestAssured.;
I have a Spring Boot (V 1.3.5) Web Application with JSPs packaged as jar. The views are located in src/main/resources/META-INF/resources/WEB-INF/views.
See http://hillert.blogspot.lu/2016/03/spring-boot-with-jsp-in-executable-jar.html on that subject.
This works well on my Fedora dev. workstation, and as well on a colleague's with Windows 7, both using Eclipse Mars.
But on another Windows 8 PC, the same sourcecode run in Eclipse or STS, produces a 404 because no view can be found, and this starts aching my head seriously.
I append my configuration class here, maybe someone has an idea what could go wrong here.
package our.base.package;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
#Configuration
#EnableScheduling
#EnableCaching
//#EnableWebMvc
#ComponentScan(basePackages = { "our.base.package" })
public class SpringConfigRootApplication extends WebMvcConfigurerAdapter {
#Bean
public LocaleResolver localeResolver() {
final CookieLocaleResolver slr = new CookieLocaleResolver();
slr.setCookieMaxAge(86400 * 365 * 5);
slr.setCookieName("lang");
slr.setDefaultLocale(Locale.GERMAN);
return slr;
}
#Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
final LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
lci.setIgnoreInvalidLocale(true);
return lci;
}
#Override
public void addInterceptors(final InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
#Override
public void addViewControllers(final ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
#Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setRequestContextAttribute("requestContext");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
#Bean(initMethod = "init", destroyMethod = "shutdown")
#Order(value = Ordered.LOWEST_PRECEDENCE)
public Application application() {
return new Application();
}
}
I've created a new workflow model in the workflow console and trying to access it using a service. From the jsp I'm passing the workflow name as /etc/workflow/models/DeleteNode/jcr:content/model, followed the format mentioned in the AEM docs. But the WorkFlowModel is throwing null value while I try to get the model from the path that I've passed.
below is the service that I've written:
package com.aem.sample.workflow;
import java.util.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
import java.io.InputStream;
import javax.jcr.Repository;
import javax.jcr.SimpleCredentials;
import javax.jcr.Node;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.jackrabbit.commons.JcrUtils;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Reference;
import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.api.SlingRepository;
import javax.jcr.Session;
import javax.jcr.Node;
//Adobe CQ Workflow APIs
import com.day.cq.workflow.model.WorkflowModel ;
import com.day.cq.workflow.WorkflowService ;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkflowData;
//Sling Imports
import org.apache.sling.api.resource.ResourceResolverFactory ;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.Resource;
//This is a component so it can provide or consume services
#Component
#Service
public class InvokeAEMWorkflowImp implements InvokeAEMWorkflow {
#Reference
private WorkflowService workflowService;
private Session session;
#Reference
private ResourceResolverFactory resolverFactory;
#Override
public String StartWorkflow(String workflowName, String workflowContent) {
try
{
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
//Create a workflow session
WorkflowSession wfSession = workflowService.getWorkflowSession(session);
// Get the workflow model
WorkflowModel wfModel = wfSession.getModel(workflowName);
// Get the workflow data
// The first param in the newWorkflowData method is the payloadType. Just a fancy name to let it know what type of workflow it is working with.
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", workflowContent);
// Run the Workflow.
wfSession.startWorkflow(wfModel, wfData);
return workflowName +" has been successfully invoked on this content: "+workflowContent ;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
}