I'm a newbie to mashape unirest, and I can't seem to figure out what I'm doing wrong.
I'm using maven to use unirest as a dependency, as so:
<dependencies>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.3.27</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
Next, I'm trying to use unirest to make an asyncronous call to my server using java anonymous callbacks.
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.lang.*;
import java.io.*;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.async.Callback;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.http.options.Options;
public class CRDTClient {
private ArrayList<String> servers;
public AtomicInteger successCount;
public CRDTClient() {
servers = new ArrayList(3);
servers.add("http://localhost:3000");
servers.add("http://localhost:3001");
servers.add("http://localhost:3002");
}
public boolean put(long key, String value) {
final CountDownLatch countDownLatch = new CountDownLatch(servers.size());
successCount = new AtomicInteger();
for (final String serverUrl : servers) {
Future<HttpResponse<JsonNode>> future = Unirest.post(serverUrl + "/cache/{key}/{value}")
.header("accept", "application/json")
.routeParam("key", Long.toString(key))
.routeParam("value", value).asJson()
.asJsonAsync(new Callback<JsonNode>() {
public void failed(UnirestException e) {
System.out.println("The request has failed: " + serverUrl);
countDownLatch.countDown();
}
public void completed(HttpResponse<JsonNode> response) {
int code = response.getStatus();
if (code == 200) {
successCount.incrementAndGet();
}
countDownLatch.countDown();
}
public void cancelled() {
System.out.println("The request has been cancelled");
}
});
}
// Block the thread until all responses gotten
countDownLatch.await();
return (Math.round(successCount.floatValue() / servers.size()) == 1);
}
The error I get when I run
mvn clean package -e
is
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project client: Compilation failure
[ERROR] /Users/jonguan/Documents/SJSU/cmpe273/cmpe273-lab4/client/src/main/java/edu/sjsu/cmpe/cache/client/CRDTClient.java:[40,20] error: cannot find symbol
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project client: Compilation failure
.../cmpe/cache/client/CRDTClient.java:[40,20] error: cannot find symbol
which turns out to be the line on .asJsonAsync
I tried importing all sorts of classes, but it doesn't seem to work.
I figured it out. Stupid me.
On the line previous, there is an extra .asJson
.routeParam("value", value).asJson()
should just be
.routeParam("value", value)
Related
As a RPGLE programmer I was asked to convert an IMAP mail poller to EWS. So I'm a bit out of my comfort zone.
With all documentation I managed to cobble a lot of pieces together, but it looks like I'm missing a vital piece because the program keep crashing at Folder folder = service.bindToFolder(folderId, propertySet);
It first I thought it had something to do with authorization. But then I found a little program EwsEditor at Github which works just fine.
Could someone point me to what I am missing?
With all documentation I managed to cobble a lot of pieces together. My testing code:
package test.ewstest;
import com.microsoft.aad.msal4j.ClientCredentialFactory;
import com.microsoft.aad.msal4j.ClientCredentialParameters;
import com.microsoft.aad.msal4j.ConfidentialClientApplication;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.util.Collections;
import java.util.Properties;
import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.PropertySet;
import microsoft.exchange.webservices.data.core.enumeration.misc.ConnectingIdType;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.core.enumeration.property.BasePropertySet;
import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName;
import microsoft.exchange.webservices.data.core.enumeration.search.FolderTraversal;
import microsoft.exchange.webservices.data.core.service.schema.FolderSchema;
import microsoft.exchange.webservices.data.credential.TokenCredentials;
import microsoft.exchange.webservices.data.misc.ImpersonatedUserId;
import microsoft.exchange.webservices.data.property.complex.FolderId;
import microsoft.exchange.webservices.data.property.complex.Mailbox;
import microsoft.exchange.webservices.data.search.FindFoldersResults;
import microsoft.exchange.webservices.data.search.FolderView;
import microsoft.exchange.webservices.data.core.service.folder.Folder;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
public class EwsTest {
static String exchangeUser;
static String exchangeTenant;
static String exchangeClientId;
static String exchangeClientSecret;
static ExchangeService service;
static Logger logger = LogManager.getLogger(EwsTest.class.getName());
static Properties properties = new Properties();
public static void main(String[] args) {
try {
properties.load(new FileInputStream(System.getProperty("user.dir") + File.separator + "EwsTest.properties"));
exchangeUser = properties.getProperty("user");
exchangeTenant = properties.getProperty("tenant");
exchangeClientId = properties.getProperty("client");
exchangeClientSecret = properties.getProperty("secret");
createConnection();
displayFolders();
}
catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
}
static void createConnection() throws Exception {
service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.getHttpHeaders().put("X-AnchorMailbox",exchangeUser);
service.getHttpHeaders().put("X-PublicFolderMailbox",exchangeUser);
service.setCredentials(new TokenCredentials(createOauthToken()));
service.setImpersonatedUserId(new ImpersonatedUserId(ConnectingIdType.SmtpAddress, exchangeUser));
service.setUrl(new URI("https://outlook.office365.com/EWS/Exchange.asmx"));
}
static String createOauthToken() throws Exception {
ConfidentialClientApplication app = ConfidentialClientApplication.builder(
exchangeClientId,
ClientCredentialFactory.createFromSecret(exchangeClientSecret))
.authority("https://login.microsoftonline.com/" + exchangeTenant + "/")
.build();
ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(
Collections.singleton("https://outlook.office365.com/.default"))
.build();
return app.acquireToken(clientCredentialParam).get().accessToken();
}
static void displayFolders() throws Exception {
PropertySet propertySet = new PropertySet(BasePropertySet.IdOnly);
propertySet.add(FolderSchema.DisplayName);
FolderView view = new FolderView(100);
view.setPropertySet(propertySet);
view.setTraversal(FolderTraversal.Deep);
Mailbox mailbox = new Mailbox(exchangeUser);
FolderId folderId = new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox);
logger.info("service.bindToFolder");
Folder folder = service.bindToFolder(folderId, propertySet);
logger.info("Ok");
logger.info("service.findFolders");
FindFoldersResults findFolderResults = service.findFolders(folder.getId(), view);
logger.info("Ok");
// find specific folder
for (Folder f : findFolderResults)
{
logger.info(f.getId());
}
}
}
And my Netbeans maven dependencies:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>EwsTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.13.3</version>
</dependency>
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<exec.mainClass>test.ewstest.EwsTest</exec.mainClass>
</properties>
</project>
I created my EwsTest.properties file and filled it with the keys:
user=example#example.nl
client=9999x9xx-xx99-x99x-xx99-xx99x9999x9x
tenant=x99x9999-xx99-9999-xx99-9999xx9x9999
secret=XXxxX!9xx-...-
When I run the program, I see that the connection is being build and a token is being exchanged. But it crashes at the statement:
Folder folder = service.bindToFolder(folderId, propertySet);
With an error: The request failed. An internal server error occurred. The operation failed.
microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. An internal server error occurred. The operation failed.
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74) ~[ews-java-api-2.0.jar:?]
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158) ~[ews-java-api-2.0.jar:?]
at microsoft.exchange.webservices.data.core.ExchangeService.bindToFolder(ExchangeService.java:504) ~[ews-java-api-2.0.jar:?]
at test.ewstest.EwsTest.displayFolders(EwsTest.java:91) ~[classes/:?]
at test.ewstest.EwsTest.main(EwsTest.java:49) [classes/:?]
Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: An internal server error occurred. The operation failed.
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.processWebException(ServiceRequestBase.java:548) ~[ews-java-api-2.0.jar:?]
at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:641) ~[ews-java-api-2.0.jar:?]
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:62) ~[ews-java-api-2.0.jar:?]
... 4 more
I tried several folders like inbox and root but they all give that same error:
FolderId folderId = new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox);
But since EwsEditor seems to work, I'm clearly missing something. I tried looking at the code of EwsEditor but that's C# which is even harder to understand for me.
i am trying to embed a HTTP-Server into an existing java Application. My goal is to create a small rest API as an interface to send commands to the server application it runs in.
I planned using Jakarta and Jersey 3 with Jetty as embeded HTTP-Server. My starting point was the following topic which was for Jersey 2 but i tried my luck: Embed jersey in java application
My problem is that i get 404 Not Found back when i try to call http://localhost/login/status in my browser. The page is blank. When i switch to using Grizzly2 as embedded HTTP-Server and type the url in the browser, the result is the same. The only difference in Grizzly2 i could spot is when i only call http://localhost/ i get an error page additionally to the 404 Not Found response back. As soon as i add /login to the url, i get the 404 Not Found response without an error page. What could be the reason the server does not pick up my resources?
I am using the Eclipse IDE. First i created a clean Maven project, added the following dependencies and created my test code:
org.glassfish.jersey.core -> jersey-server
org.glassfish.jersey.containers -> jersey-container-jetty-http
On my first startup i got some missing class errors, searched for the dependencies they are in and added them to the pom. Following is my current test code.
<!-- pom.xml -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test-ee</groupId>
<artifactId>test-ee-embed</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>3.0.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-bom</artifactId>
<version>3.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
</dependency>
</dependencies>
</project>
// LoginserverRestApi.java
package de.l2d;
import org.glassfish.jersey.server.ResourceConfig;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
#ApplicationPath("/login")
public class LoginserverRestApi extends ResourceConfig {
#GET #Path("/status")
public String status() {
// TODO Return real server statistics.
return "{\"status\":\"ok\"}";
}
}
// RestApiServer.java
package de.l2d;
import java.net.URI;
import org.eclipse.jetty.server.Server;
import org.glassfish.jersey.jetty.JettyHttpContainerFactory;
import jakarta.ws.rs.core.UriBuilder;
public class RestApiServer {
private Server server;
private RestApiServer() {
URI baseUri = UriBuilder.fromUri("http://localhost/").build();
server = JettyHttpContainerFactory.createServer(baseUri, new LoginserverRestApi(), false);
}
public void start() throws Exception {
server.start();
}
public void stop() throws Exception {
server.stop();
}
private static final class SingletonHolder {
protected static RestApiServer instance = new RestApiServer();
}
public static RestApiServer getInstance() {
return SingletonHolder.instance;
}
}
// Main.java
package de.l2d;
public class Main {
public static void main(String[] args) throws Exception {
RestApiServer.getInstance().start();
Thread.currentThread().join();
RestApiServer.getInstance().stop();
}
}
I found the solution to my problem. However, i do not know why it behaves like this.
I had to use the Path annotation instead of the ApplicationPath annotation on the LoginserverRestApi class and additionally construct a ResourceConfig with LoginserverRestApi.class as parameter and pass that Object to the JettyHttpContainerFactory.createServer static method. Following are the two files which differ from the initial post:
// LoginserverRestApi.java
package de.l2d;
import org.glassfish.jersey.server.ResourceConfig;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
#Path("/login")
public class LoginserverRestApi extends ResourceConfig {
#GET #Path("/status")
public String status() {
// TODO Return real server statistics.
return "{\"status\":\"ok\"}";
}
}
// RestApiServer.java
package de.l2d;
import java.net.URI;
import org.eclipse.jetty.server.Server;
import org.glassfish.jersey.jetty.JettyHttpContainerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import jakarta.ws.rs.core.UriBuilder;
public class RestApiServer {
private Server server;
private RestApiServer() {
URI baseUri = UriBuilder.fromUri("http://localhost/").build();
ResourceConfig config = new ResourceConfig(LoginserverRestApi.class);
server = JettyHttpContainerFactory.createServer(baseUri, config, false);
}
public void start() throws Exception {
server.start();
}
public void stop() throws Exception {
server.stop();
}
private static final class SingletonHolder {
protected static RestApiServer instance = new RestApiServer();
}
public static RestApiServer getInstance() {
return SingletonHolder.instance;
}
}
I have trying selenium code with #Test, but eclipse is not running it and asking for Main method.
I've added Maven Project and added Selenium & TestNG dependencies to pom.xml
Please help with the issue I'm facing
Sample code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class BaseTest {
#Test
public void openBrowser() {
File file = new File("./src/test/resources/config.properties");
FileInputStream fileInput = null;
try {
fileInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("File not found");
}
Properties prop = new Properties();
//load properties file
try {
prop.load(fileInput);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Values not found");
}
System.setProperty("webdriver.chrome.driver","./src/test/resources/drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get(prop.getProperty("baseURL"));
}
}
On running it,I'm facing
Error: Main method not found in class com.digivalsolutions.digiassess.LoginTest, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
My pom.xml file:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
I think you should install TestNG for your IDE. You can check this link for more details.
I am following many examples of serenity bdd testing API. Mainly (https://github.com/serenity-bdd/serenity-core/blob/master/serenity-screenplay-rest/src/test/java/net/serenitybdd/screenplay/rest/examples/WhenRetrievingUserDetails.java)
But when I run my code I am always getting:
TEST FAILED WITH ERROR: User attempts to recover the password
---------------------------------------------------------------------
[main] ERROR net.serenitybdd.core.Serenity - TEST FAILED AT STEP Rest
[main] ERROR net.serenitybdd.core.Serenity - SERENITY_DISABLE_REST_CALLS_AFTER_FAILURES
net.serenitybdd.core.exceptions.SerenityManagedException: SERENITY_DISABLE_REST_CALLS_AFTER_FAILURES
at net.serenitybdd.rest.utils.RestExecutionHelper.restCallsAreDisabled(RestExecutionHelper.java:28)
at net.serenitybdd.rest.utils.RestSpecificationFactory.getInstrumentedRequestSpecification(RestSpecificationFactory.java:105)
at net.serenitybdd.rest.utils.RestDecorationHelper.decorate(RestDecorationHelper.java:20)
at net.serenitybdd.rest.SerenityRest.given(SerenityRest.java:220)
at net.serenitybdd.screenplay.rest.interactions.RestInteraction.rest(RestInteraction.java:32)
at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.CGLIB$rest$3(<generated>)
at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9$$FastClassByCGLIB$$49fc3d71.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at net.thucydides.core.steps.BaseMethodRunner.invokeMethod(BaseMethodRunner.java:10)
at net.thucydides.core.steps.NormalMethodRunner.invokeMethodAndNotifyFailures(NormalMethodRunner.java:20)
at net.thucydides.core.steps.StepInterceptor.runNormalMethod(StepInterceptor.java:361)
at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:132)
at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:68)
at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.rest(<generated>)
at net.serenitybdd.screenplay.rest.interactions.Post.performAs(Post.java:24)
at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.CGLIB$performAs$0(<generated>)
at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9$$FastClassByCGLIB$$49fc3d71.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:449)
at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:434)
at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:409)
at net.thucydides.core.steps.StepInterceptor.runOrSkipMethod(StepInterceptor.java:150)
at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:137)
at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:68)
at net.serenitybdd.screenplay.rest.interactions.Post$$EnhancerByCGLIB$$6437c6d9.performAs(<generated>)
at net.serenitybdd.screenplay.Actor.perform(Actor.java:100)
at net.serenitybdd.screenplay.Actor.attemptsTo(Actor.java:84)
at jarv.serenity.carnival.features.steps.steps.RecoverUserNameSteps.he_attemps_to_recover_password(RecoverUserNameSteps.java:40)
at ✽.he sends the required information to recover his password(src/test/resources/features/ProfileManagement.feature:7)
I have the following test steps:
package jarv.serenity.carnival.features.steps.steps;
import net.serenitybdd.screenplay.rest.abilities.CallAnApi;
import net.serenitybdd.screenplay.rest.interactions.Post;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import net.serenitybdd.screenplay.Actor;
import static org.hamcrest.Matchers.equalTo;
import static net.serenitybdd.screenplay.rest.questions.ResponseConsequence.seeThatResponse;
public class RecoverUserNameSteps {
private String theRestApiBaseUrl = "https://www.carnival.com/ProfileManagement/api/v1.0";
private Actor jorge;
private String userName;
#Before
public void set_the_test(){
jorge = Actor.named("Jorge, learning serenity rest").whoCan(CallAnApi.at(theRestApiBaseUrl));
}
#Given("^Jorge is not a registered user$")
public void jorge_is_not_registered() throws Throwable {
//TODO: Investigate what should be done here???
}
#Given("^he wants to recover his password$")
public void jorge_wants_to_recover_the_password() throws Throwable {
//I am setting this as blank cause the service to retrieve the password will only failed if request parameter is blank!!!
//When sending any other kind of string response is 202 Accepted, only blanks generate 400 Bad request
//Test may need to be changed to recover username instead, which has more options to get the error code
userName = "";
}
#When("^he sends the required information to recover his password$")
public void he_attemps_to_recover_password() throws Throwable {
//TODO: Create Object Model for Request Body and send it. Anyway example is way too simple to do that and I am running out of time Julian.
jorge.attemptsTo(
Post.to("/Accounts/Password/Forgot")
.with(request -> request.header("Content-Type", "application/json")
.body("{\"username\": \"joe\"}")
)
);
}
#Then("^he should be informed that operation could not be done$")
public void he_must_see_a_failed_response() throws Throwable {
jorge.should(
seeThatResponse( "Recover for password was denied",
response -> response.statusCode(400)
)
);
}
}
This is my maven with rest related dependencies
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>2.0.34</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay-rest</artifactId>
<version>2.0.34</version>
<scope>test</scope>
</dependency>
This is my fork git hub repo: https://github.com/jarvcol/CarnivalTest/tree/addApiTesting
Any idea on this???
Because you are not using the matching serenity-core dependency. Try adding following dependency in pom.xml and update project:
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>2.0.34</version>
</dependency>
This question already has answers here:
What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?
(18 answers)
Closed 6 years ago.
I have 3 maven projects:
project-A
project-B
project-C
The second project (B) requires the dependency for the first project (A).
The third project (C) requires the dependencies for the first and second project (A, B).
I have defined these dependencies in the respective projects pom files:
project-B pom.xml :
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
project-C pom.xml :
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-B</artifactId>
<version>${project.version}</version>
</dependency>
Everything works OK on SpringToolSuite. I have tested the second project (which depends on the first project) and also tested the third project (which depends on both first and second project) and everything works OK from STS.
When I try to execute:
mvn clean install -U -DskipTests=true
it works perfectly well for project-A and project-B, but for project-C I get a:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] MyClassOnProjectC.java:[12,38] package XXX does not exist
[ERROR] MyClassOnProjectC.java:[22,17] cannot find symbol
symbol: class MyClassOnProjectB
location: class MyClassOnProjectC
Below there are 3 classes extracted from each of the projects:
Project-A:
User.java
package com.neweraed.datamodel;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "UserType", propOrder = {
"name",
"description",
})
public class User implements Serializable {
private static final long serialVersionUID = -876063526825526098L;
private String name;
private String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Project-B:
UserOperations.java
package com.neweraed.services.midpoint;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestOperations;
import com.neweraed.datamodel.User;
import com.neweraed.services.midpoint.utils.Constants;
import com.neweraed.services.midpoint.utils.Utils;
#Component
public class UserOperations {
private static final Logger logger = LoggerFactory.getLogger(UserOperations.class);
public User getUser(User user) {
RestOperations restOperations = Utils.createGenericRestTemplate();
ResponseEntity<User> response = null;
try {
response = restOperations.exchange(Constants.ENDPOIT_SEARCH_USER, HttpMethod.GET, new HttpEntity<Object>(Utils.createHeaders()), User.class);
logger.info("=== RESPONSE ===" + response + " === ");
} catch (Exception e) {
logger.error("=== ERROR === " + e.getMessage() + " === ");
}
return user;
}
}
Project-C:
UserService.java
package com.neweraed.rest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.neweraed.datamodel.User;
import com.neweraed.services.midpoint.UserOperations;
#RestController
#RequestMapping(value="/api/v1/users")
public class UserService {
#RequestMapping(value="/", method=RequestMethod.POST)
public User addUser(#RequestBody User user) {
UserOperations userOperations = new UserOperations();
return userOperations.addUser(user);
}
}
It seems like everything is OK on my pom.xml files. How can I solve this?
According to your premises, pom.xml of the project B must be:
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
And project C doesn't need the dependency with A because it is defined on B