[Major] fixed rest unit tests due to changes in jersey 2.7
also had to replace eclipse.persistence with 2.5.1 due to a bug in namespace resolution.
This commit is contained in:
parent
316764a409
commit
a7bae4b9f5
22
pom.xml
22
pom.xml
|
@ -31,6 +31,7 @@
|
|||
|
||||
<properties>
|
||||
<jersey.version>2.7</jersey.version>
|
||||
<org.eclipse.persistence.version>2.5.1</org.eclipse.persistence.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -42,6 +43,17 @@
|
|||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- due to bug in persistence 2.5.0 -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>org.eclipse.persistence.moxy</artifactId>
|
||||
<version>${org.eclipse.persistence.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>org.eclipse.persistence.antlr</artifactId>
|
||||
<version>${org.eclipse.persistence.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@ -86,14 +98,14 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>1.18</version>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-grizzly2-http</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-grizzly2-http</artifactId>
|
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
||||
<artifactId>jersey-test-framework-provider-bundle</artifactId>
|
||||
<type>pom</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
|||
|
||||
import li.strolch.agent.api.ComponentContainer;
|
||||
import li.strolch.agent.api.StrolchComponent;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.runtime.configuration.ComponentConfiguration;
|
||||
import li.strolch.runtime.privilege.StrolchPrivilegeHandler;
|
||||
import ch.eitchnet.privilege.model.Certificate;
|
||||
|
@ -112,10 +113,10 @@ public class DefaultStrolchSessionHandler extends StrolchComponent implements St
|
|||
certificate = this.certificateMap.get(sessionId);
|
||||
|
||||
if (certificate == null)
|
||||
throw new RuntimeException("No certificate exists for sessionId " + sessionId);
|
||||
throw new StrolchException("No certificate exists for sessionId " + sessionId);
|
||||
|
||||
if (!certificate.getUsername().equals(username) || !certificate.getAuthToken().equals(sessionId)) {
|
||||
throw new RuntimeException("Illegal request for username " + username + " and sessionId " + sessionId);
|
||||
throw new StrolchException("Illegal request for username " + username + " and sessionId " + sessionId);
|
||||
}
|
||||
|
||||
this.privilegeHandler.isCertificateValid(certificate);
|
||||
|
|
|
@ -25,6 +25,7 @@ import javax.ws.rs.core.Context;
|
|||
import javax.ws.rs.core.GenericEntity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.rest.RestfulStrolchComponent;
|
||||
|
@ -37,6 +38,7 @@ import li.strolch.rest.model.LogoutResult;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.eitchnet.privilege.base.PrivilegeException;
|
||||
import ch.eitchnet.privilege.model.Certificate;
|
||||
import ch.eitchnet.utils.helper.StringHelper;
|
||||
|
||||
|
@ -72,7 +74,7 @@ public class AuthenticationService {
|
|||
|
||||
if (sb.length() != 0) {
|
||||
loginResult.setMsg("Could not log in due to: " + sb.toString());
|
||||
return Response.status(401).entity(loginResult).build();
|
||||
return Response.status(Status.UNAUTHORIZED).entity(loginResult).build();
|
||||
}
|
||||
|
||||
StrolchSessionHandler sessionHandler = RestfulStrolchComponent.getInstance().getComponent(
|
||||
|
@ -87,9 +89,11 @@ public class AuthenticationService {
|
|||
loginResult.setParameters(certificate.getPropertyMap());
|
||||
|
||||
return Response.ok().entity(entity).build();
|
||||
|
||||
} catch (StrolchException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
loginResult.setMsg("Could not log in due to: " + e.getMessage());
|
||||
return Response.status(401).entity(entity).build();
|
||||
return Response.status(Status.UNAUTHORIZED).entity(entity).build();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
String msg = e.getMessage();
|
||||
|
@ -125,7 +129,7 @@ public class AuthenticationService {
|
|||
}
|
||||
if (sb.length() != 0) {
|
||||
logoutResult.setMsg("Could not logout due to: " + sb.toString());
|
||||
return Response.status(401).entity(logoutResult).build();
|
||||
return Response.status(Status.UNAUTHORIZED).entity(logoutResult).build();
|
||||
}
|
||||
|
||||
StrolchSessionHandler sessionHandlerHandler = RestfulStrolchComponent.getInstance().getComponent(
|
||||
|
@ -136,6 +140,11 @@ public class AuthenticationService {
|
|||
sessionHandlerHandler.invalidateSession(origin, certificate);
|
||||
|
||||
return Response.ok().entity(entity).build();
|
||||
|
||||
} catch (StrolchException | PrivilegeException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
logoutResult.setMsg("Could not logout due to: " + e.getMessage());
|
||||
return Response.status(Status.UNAUTHORIZED).entity(entity).build();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
String msg = e.getMessage();
|
||||
|
|
|
@ -17,41 +17,37 @@ package li.strolch.rest.inspector.test;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Application;
|
||||
import javax.ws.rs.ext.ContextResolver;
|
||||
|
||||
import li.strolch.rest.StrolchRestfulClasses;
|
||||
import li.strolch.rest.StrolchRestfulExceptionMapper;
|
||||
import li.strolch.testbase.runtime.RuntimeMock;
|
||||
|
||||
import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
|
||||
import org.glassfish.grizzly.http.server.HttpServer;
|
||||
import org.glassfish.jersey.client.ClientConfig;
|
||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||
import org.glassfish.jersey.moxy.json.MoxyJsonConfig;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
import org.glassfish.jersey.test.TestProperties;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import com.sun.jersey.api.client.config.ClientConfig;
|
||||
import com.sun.jersey.api.client.config.DefaultClientConfig;
|
||||
import com.sun.jersey.api.representation.Form;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public abstract class AbstractRestfulTest {
|
||||
public abstract class AbstractRestfulTest extends JerseyTest {
|
||||
|
||||
protected static final String BASE_URI = "http://localhost:56789/tutorialwebapp";
|
||||
private static final URI BASE_URI = URI.create("http://localhost:8888/base");
|
||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractRestfulTest.class);
|
||||
|
||||
private static final String RUNTIME_PATH = "target/withPrivilegeRuntime/"; //$NON-NLS-1$
|
||||
private static final String CONFIG_SRC = "src/test/resources/withPrivilegeRuntime"; //$NON-NLS-1$
|
||||
private static RuntimeMock runtimeMock;
|
||||
private static HttpServer httpServer;
|
||||
private static HttpServer server;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
|
@ -62,46 +58,37 @@ public abstract class AbstractRestfulTest {
|
|||
runtimeMock.mockRuntime(rootPath, configSrc);
|
||||
runtimeMock.startContainer();
|
||||
|
||||
// create a resource config that scans for JAX-RS resources and providers
|
||||
// in com.example package
|
||||
final ResourceConfig rc = new ResourceConfig();
|
||||
for (Class<?> clazz : StrolchRestfulClasses.getRestfulClasses()) {
|
||||
rc.register(clazz);
|
||||
rc.register(StrolchRestfulExceptionMapper.class);
|
||||
}
|
||||
|
||||
httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
|
||||
server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
httpServer.shutdownNow();
|
||||
server.shutdownNow();
|
||||
runtimeMock.destroyRuntime();
|
||||
}
|
||||
|
||||
protected WebResource getResource() {
|
||||
ClientConfig cc = new DefaultClientConfig();
|
||||
cc.getClasses().add(MOXyJsonProvider.class);
|
||||
Client client = Client.create(cc);
|
||||
WebResource resource = client.resource(BASE_URI);
|
||||
return resource;
|
||||
@Override
|
||||
protected Application configure() {
|
||||
enable(TestProperties.LOG_TRAFFIC);
|
||||
enable(TestProperties.DUMP_ENTITY);
|
||||
|
||||
return createApp();
|
||||
}
|
||||
|
||||
protected ClientResponse doGet(String path) {
|
||||
WebResource resource = getResource();
|
||||
ClientResponse response = resource.path(path).accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
|
||||
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode())
|
||||
throw new RuntimeException("Failed to get from path " + path + " due to "
|
||||
+ response.getEntity(String.class));
|
||||
return response;
|
||||
@Override
|
||||
protected void configureClient(ClientConfig config) {
|
||||
config.register(createMoxyJsonResolver());
|
||||
}
|
||||
|
||||
protected <T> ClientResponse doPostForm(String path, Form form) {
|
||||
WebResource resource = getResource();
|
||||
ClientResponse response = resource.path(path).type(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.accept(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, form);
|
||||
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode())
|
||||
throw new RuntimeException("Failed to post to path " + path + " due to " + response.getEntity(String.class));
|
||||
return response;
|
||||
public static ResourceConfig createApp() {
|
||||
return new ResourceConfig().packages("li.strolch.rest.endpoint").register(createMoxyJsonResolver());
|
||||
}
|
||||
|
||||
public static ContextResolver<MoxyJsonConfig> createMoxyJsonResolver() {
|
||||
final MoxyJsonConfig moxyJsonConfig = new MoxyJsonConfig();
|
||||
Map<String, String> namespacePrefixMapper = new HashMap<String, String>(1);
|
||||
namespacePrefixMapper.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
|
||||
moxyJsonConfig.setNamespacePrefixMapper(namespacePrefixMapper).setNamespaceSeparator(':');
|
||||
return moxyJsonConfig.resolver();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,34 +18,39 @@ package li.strolch.rest.inspector.test;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.Form;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import li.strolch.rest.model.LoginResult;
|
||||
import li.strolch.rest.model.LogoutResult;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.representation.Form;
|
||||
//import com.sun.jersey.api.client.ClientResponse;
|
||||
//import com.sun.jersey.api.representation.Form;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class AuthenticationTest extends AbstractRestfulTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
private static final String ROOT_PATH = "strolch/authentication";
|
||||
|
||||
@Test
|
||||
public void shouldAuthenticate() {
|
||||
|
||||
Form loginForm = new Form();
|
||||
loginForm.add("username", "jill");
|
||||
loginForm.add("password", "jill");
|
||||
|
||||
// login
|
||||
ClientResponse loginResponse = doPostForm("/strolch/authentication/login", loginForm);
|
||||
LoginResult loginResult = loginResponse.getEntity(LoginResult.class);
|
||||
Form loginForm = new Form();
|
||||
loginForm.param("username", "jill");
|
||||
loginForm.param("password", "jill");
|
||||
Entity<Form> entity = Entity.entity(loginForm, MediaType.APPLICATION_FORM_URLENCODED);
|
||||
Response result = target().path(ROOT_PATH + "/login").request(MediaType.APPLICATION_JSON).post(entity);
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
LoginResult loginResult = result.readEntity(LoginResult.class);
|
||||
assertNotNull(loginResult);
|
||||
assertEquals("jill", loginResult.getUsername());
|
||||
assertEquals(64, loginResult.getSessionId().length());
|
||||
|
@ -53,10 +58,13 @@ public class AuthenticationTest extends AbstractRestfulTest {
|
|||
|
||||
// logout
|
||||
Form logoutForm = new Form();
|
||||
logoutForm.add("username", "jill");
|
||||
logoutForm.add("sessionId", loginResult.getSessionId());
|
||||
ClientResponse logoutResponse = doPostForm("/strolch/authentication/logout", logoutForm);
|
||||
LogoutResult logoutResult = logoutResponse.getEntity(LogoutResult.class);
|
||||
logoutForm.param("username", "jill");
|
||||
logoutForm.param("sessionId", loginResult.getSessionId());
|
||||
entity = Entity.entity(logoutForm, MediaType.APPLICATION_FORM_URLENCODED);
|
||||
result = target().path(ROOT_PATH + "/logout").request(MediaType.APPLICATION_JSON).post(entity);
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
assertNotNull(loginResult);
|
||||
LogoutResult logoutResult = result.readEntity(LogoutResult.class);
|
||||
assertNotNull(logoutResult);
|
||||
assertNull(logoutResult.getMsg());
|
||||
}
|
||||
|
@ -64,30 +72,29 @@ public class AuthenticationTest extends AbstractRestfulTest {
|
|||
@Test
|
||||
public void shouldNotAuthenticate() {
|
||||
|
||||
exception.expect(RuntimeException.class);
|
||||
exception.expectMessage("Authentication credentials are invalid");
|
||||
|
||||
Form loginForm = new Form();
|
||||
loginForm.add("username", "admin");
|
||||
loginForm.add("password", "blalba");
|
||||
|
||||
// login
|
||||
doPostForm("/strolch/authentication/login", loginForm);
|
||||
Form loginForm = new Form();
|
||||
loginForm.param("username", "admin");
|
||||
loginForm.param("password", "blalba");
|
||||
Entity<Form> entity = Entity.entity(loginForm, MediaType.APPLICATION_FORM_URLENCODED);
|
||||
Response result = target().path(ROOT_PATH + "/login").request(MediaType.APPLICATION_JSON).post(entity);
|
||||
assertEquals(Status.UNAUTHORIZED.getStatusCode(), result.getStatus());
|
||||
LogoutResult logoutResult = result.readEntity(LogoutResult.class);
|
||||
assertNotNull(logoutResult);
|
||||
assertEquals("Could not log in due to: Authentication credentials are invalid", logoutResult.getMsg());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailLogoutIllegalSession() {
|
||||
|
||||
exception.expect(RuntimeException.class);
|
||||
exception.expectMessage("Illegal request for username jill and sessionId blabla");
|
||||
|
||||
Form loginForm = new Form();
|
||||
loginForm.add("username", "jill");
|
||||
loginForm.add("password", "jill");
|
||||
|
||||
// login
|
||||
ClientResponse loginResponse = doPostForm("/strolch/authentication/login", loginForm);
|
||||
LoginResult loginResult = loginResponse.getEntity(LoginResult.class);
|
||||
Form loginForm = new Form();
|
||||
loginForm.param("username", "jill");
|
||||
loginForm.param("password", "jill");
|
||||
Entity<Form> entity = Entity.entity(loginForm, MediaType.APPLICATION_FORM_URLENCODED);
|
||||
Response result = target().path(ROOT_PATH + "/login").request(MediaType.APPLICATION_JSON).post(entity);
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
LoginResult loginResult = result.readEntity(LoginResult.class);
|
||||
assertNotNull(loginResult);
|
||||
assertEquals("jill", loginResult.getUsername());
|
||||
assertEquals(64, loginResult.getSessionId().length());
|
||||
|
@ -95,8 +102,14 @@ public class AuthenticationTest extends AbstractRestfulTest {
|
|||
|
||||
// logout
|
||||
Form logoutForm = new Form();
|
||||
logoutForm.add("username", "jill");
|
||||
logoutForm.add("sessionId", "blabla");
|
||||
doPostForm("/strolch/authentication/logout", logoutForm);
|
||||
logoutForm.param("username", "jill");
|
||||
logoutForm.param("sessionId", "blabla");
|
||||
entity = Entity.entity(logoutForm, MediaType.APPLICATION_FORM_URLENCODED);
|
||||
result = target().path(ROOT_PATH + "/logout").request(MediaType.APPLICATION_JSON).post(entity);
|
||||
assertEquals(Status.UNAUTHORIZED.getStatusCode(), result.getStatus());
|
||||
LogoutResult logoutResult = result.readEntity(LogoutResult.class);
|
||||
assertNotNull(logoutResult);
|
||||
assertEquals("Could not logout due to: Illegal request for username jill and sessionId blabla",
|
||||
logoutResult.getMsg());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import li.strolch.rest.model.AgentOverview;
|
||||
import li.strolch.rest.model.ElementMapOverview;
|
||||
import li.strolch.rest.model.ElementMapType;
|
||||
|
@ -33,14 +37,13 @@ import li.strolch.rest.model.TypeOverview;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.GenericType;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class InspectorTest extends AbstractRestfulTest {
|
||||
|
||||
private static final String ROOT_PATH = "strolch/inspector/";
|
||||
|
||||
@Test
|
||||
public void shouldGetAgent() {
|
||||
|
||||
|
@ -50,9 +53,9 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
AgentOverview expectedAgentOverview = new AgentOverview(realms);
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector");
|
||||
AgentOverview agentOverview = response.getEntity(new GenericType<AgentOverview>() {
|
||||
});
|
||||
Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
AgentOverview agentOverview = result.readEntity(AgentOverview.class);
|
||||
|
||||
// assertions
|
||||
assertEquals(expectedAgentOverview, agentOverview);
|
||||
|
@ -74,9 +77,9 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
RealmDetail expectedRealmDetail = new RealmDetail(elementMapOverviews);
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector/defaultRealm");
|
||||
RealmDetail realmDetail = response.getEntity(new GenericType<RealmDetail>() {
|
||||
});
|
||||
Response result = target().path(ROOT_PATH + "defaultRealm").request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
RealmDetail realmDetail = result.readEntity(RealmDetail.class);
|
||||
|
||||
// assertions
|
||||
assertEquals(expectedRealmDetail, realmDetail);
|
||||
|
@ -93,9 +96,9 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews);
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector/defaultRealm/resource");
|
||||
ElementMapOverview elementMapOverview = response.getEntity(new GenericType<ElementMapOverview>() {
|
||||
});
|
||||
Response result = target().path(ROOT_PATH + "defaultRealm/resource").request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
ElementMapOverview elementMapOverview = result.readEntity(ElementMapOverview.class);
|
||||
|
||||
// assertions
|
||||
assertEquals(expectedElementMapOverview, elementMapOverview);
|
||||
|
@ -112,9 +115,9 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews);
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector/defaultRealm/order");
|
||||
ElementMapOverview elementMapOverview = response.getEntity(new GenericType<ElementMapOverview>() {
|
||||
});
|
||||
Response result = target().path(ROOT_PATH + "defaultRealm/order").request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
ElementMapOverview elementMapOverview = result.readEntity(ElementMapOverview.class);
|
||||
|
||||
// assertions
|
||||
assertEquals(expectedElementMapOverview, elementMapOverview);
|
||||
|
@ -126,8 +129,10 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
public void shouldGetResourceTypeDetails() {
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector/defaultRealm/resource/Template");
|
||||
String entity = response.getEntity(String.class);
|
||||
Response result = target().path(ROOT_PATH + "defaultRealm/resource/Template")
|
||||
.request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
String entity = result.readEntity(String.class);
|
||||
String expected = "{\"type\":\"Template\",\"resources\":[{\"id\":\"TestType\",\"name\":\"TestType Template\",\"type\":\"Template\"}]}";
|
||||
assertEquals(expected, entity);
|
||||
}
|
||||
|
@ -136,8 +141,10 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
public void shouldGetOrderTypeDetails() {
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector/defaultRealm/order/Template");
|
||||
String entity = response.getEntity(String.class);
|
||||
Response result = target().path(ROOT_PATH + "defaultRealm/order/Template").request(MediaType.APPLICATION_JSON)
|
||||
.get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
String entity = result.readEntity(String.class);
|
||||
String expected = "{\"type\":\"Template\",\"orders\":[{\"id\":\"TestType\",\"name\":\"MyTestOrder Template\",\"type\":\"Template\",\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\"}]}";
|
||||
assertEquals(expected, entity);
|
||||
}
|
||||
|
@ -146,8 +153,10 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
public void shouldGetResource() {
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector/defaultRealm/resource/Template/TestType");
|
||||
String entity = response.getEntity(String.class);
|
||||
Response result = target().path(ROOT_PATH + "defaultRealm/resource/Template/TestType")
|
||||
.request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
String entity = result.readEntity(String.class);
|
||||
assertTrue(entity.contains("name\":\"TestType Template\",\"type\":\"Template\",\"parameterBags\":"));
|
||||
}
|
||||
|
||||
|
@ -155,8 +164,10 @@ public class InspectorTest extends AbstractRestfulTest {
|
|||
public void shouldGetOrder() {
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/inspector/defaultRealm/order/Template/TestType");
|
||||
String entity = response.getEntity(String.class);
|
||||
Response result = target().path(ROOT_PATH + "defaultRealm/order/Template/TestType")
|
||||
.request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
String entity = result.readEntity(String.class);
|
||||
assertTrue(entity
|
||||
.contains("\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\",\"parameterBags\""));
|
||||
}
|
||||
|
|
|
@ -19,28 +19,30 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import li.strolch.agent.api.AgentVersion;
|
||||
import li.strolch.agent.api.ComponentVersion;
|
||||
import li.strolch.agent.api.VersionQueryResult;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.GenericType;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class VersionQueryTest extends AbstractRestfulTest {
|
||||
|
||||
private static final String ROOT_PATH = "strolch/version";
|
||||
|
||||
@Test
|
||||
public void shouldQueryVersion() {
|
||||
|
||||
// query
|
||||
ClientResponse response = doGet("/strolch/version");
|
||||
VersionQueryResult versionQueryResult = response.getEntity(new GenericType<VersionQueryResult>() {
|
||||
});
|
||||
|
||||
Response result = target().path(ROOT_PATH).request(MediaType.APPLICATION_JSON).get();
|
||||
assertEquals(Status.OK.getStatusCode(), result.getStatus());
|
||||
VersionQueryResult versionQueryResult = result.readEntity(VersionQueryResult.class);
|
||||
if (versionQueryResult.hasErrors()) {
|
||||
for (String error : versionQueryResult.getErrors()) {
|
||||
logger.error(error);
|
||||
|
|
Loading…
Reference in New Issue