Skip to content

RESTEASY-1857 #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions resteasy-spring-boot-starter-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
</properties>

<dependencies>
<!-- rls tmp for testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<!-- rls end test -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.test.multicontexttest;
package com.test.resourcesprovidersperapp;

/**
* A simple echo message, containing the text to be echoed
Expand All @@ -24,4 +24,4 @@ public String getEchoText() {
return echoText;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.test.multicontexttest;
package com.test.resourcesprovidersperapp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand All @@ -15,11 +16,7 @@
* Created by facarvalho on 12/7/15.
*/
@Path("/echo")
@Component
public class Echo {

@Autowired
private EchoMessageCreator echoer;
public class EchoV1 {

/**
* Receives a simple POST request message containing as payload
Expand All @@ -34,7 +31,12 @@ public class Echo {
@Consumes({ MediaType.TEXT_PLAIN })
@Produces({ MediaType.APPLICATION_JSON })
public EchoMessage echo(String echoText) {
return echoer.createEchoMessage(echoText);
return new EchoMessage("echoed v1 -> " + echoText);
}

@GET
public String echo() {
return "foobar";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.test.resourcesprovidersperapp;

import org.springframework.stereotype.Component;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
* Echo REST endpoint class
*
* Created by facarvalho on 12/7/15.
*/
@Path("/echo2")
@Component
public class EchoV2 {

/**
* Receives a simple POST request message containing as payload
* a text, in text plain format, to be echoed by the service.
* It returns as response, in JSON, the text to be echoed plus a timestamp of the
* moment the echo response was created on the server side
*
* @param echoText
* @return
*/
@POST
@Consumes({ MediaType.TEXT_PLAIN })
@Produces({ MediaType.APPLICATION_JSON })
public EchoMessage echo(String echoText) {
return new EchoMessage("echoed v2 -> " + echoText);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.test.resourcesprovidersperapp;

import org.springframework.stereotype.Component;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;

@Component
@ApplicationPath("/resourcesproviders/")
public class JaxrsApplicationV1 extends Application {

@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(EchoV1.class);
return classes;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.test.multicontexttest;
package com.test.resourcesprovidersperapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
//import org.springframework.boot.web.support.SpringBootServletInitializer; // pre 2.0 ref

/**
* SpringBoot entry point application
*
* Created by facarvalho on 12/7/15.
*/
@SpringBootApplication
public class MultiContextTestApp extends SpringBootServletInitializer {
public class ResoucesAndProvidersPerApp extends SpringBootServletInitializer {

public static void main(String[] args) {
SpringApplication.run(MultiContextTestApp.class, args);
SpringApplication.run(ResoucesAndProvidersPerApp.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//package com.paypal.springboot.resteasy;
package com.test.resourcesprovidersperapp;

//import com.sample.app.Application;
//import com.test.resourcesprovidersperapp.JaxrsApplicationV1;
import com.test.resourcesprovidersperapp.ResoucesAndProvidersPerApp;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.springframework.boot.SpringApplication;
import org.springframework.util.SocketUtils;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;

/**
* This is an integration test based on a simple sample application and
* very common use cases (see sample-app project)
*
* @author facarvalho
*/
public class ResourcesAndProvidersPerAppIT {

@BeforeClass
public void startingApplicationUp() {
RestAssured.basePath = "/resourcesproviders/";
int port = SocketUtils.findAvailableTcpPort();
RestAssured.port = port;
System.out.println("::: " + port);
SpringApplication springApplication = new SpringApplication(ResoucesAndProvidersPerApp.class);
springApplication.run("--server.port=" + port).registerShutdownHook();
// try {
// Thread.currentThread().join();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}

@AfterClass
public void shuttingDownApplication() {
Response response = given().basePath("/").contentType("application/json").post("/actuator/shutdown");
response.then().statusCode(200).body("message", equalTo("Shutting down, bye...")); }

@Test
public void echoSucceeds() {
Response response = given().body("oh behave").post("/echo");
response.then().statusCode(200).body("timestamp", notNullValue()).body("echoText", equalTo
("echoed v1 -> oh behave"));
}

@Test
public void echoV2MustNotBeReachable() {
Response response = given().body("oh behave").post("/echo2");
Assert.assertNotEquals(200, response.getStatusCode(),"echo2 must not be reachable");
}
}

This file was deleted.

Loading