forked from eclipse-ee4j/jersey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManagedClientSimpleTest.java
61 lines (48 loc) · 2.08 KB
/
ManagedClientSimpleTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.glassfish.jersey.examples.managedclientsimple;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriBuilder;
import java.net.URI;
import org.glassfish.jersey.examples.managedclientsimple.resources.ManagedClientApplication;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Miroslav Fuksa
*
*/
public class ManagedClientSimpleTest extends JerseyTest {
@Override
protected ResourceConfig configure() {
return new ManagedClientApplication();
}
@Override
protected URI getBaseUri() {
final UriBuilder baseUriBuilder = UriBuilder.fromUri(super.getBaseUri()).path("managed-client-simple-webapp");
final boolean externalFactoryInUse = getTestContainerFactory() instanceof ExternalTestContainerFactory;
return externalFactoryInUse ? baseUriBuilder.path("app").build() : baseUriBuilder.build();
}
@Test
public void testManagedClientSimple() throws Exception {
final WebTarget resource = target("app").path("client");
Response response;
response = resource.path("animals").request(MediaType.TEXT_PLAIN).get();
assertEquals(200, response.getStatus());
assertEquals("Queried animals: Max and Lucy and Bobo", response.readEntity(String.class));
response = resource.path("car/1").request(MediaType.TEXT_PLAIN).get();
assertEquals(200, response.getStatus());
assertEquals("Response from resource/car/1: CAR with id=1", response.readEntity(String.class));
}
}