use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class AbstractFailoverTest method strategyTest.
protected void strategyTest(String inactiveReplica, FailoverFeature feature, String activeReplica1, String activeReplica2, boolean expectServerException, boolean expectRandom, boolean singleProxy) throws Exception {
boolean randomized = false;
String prevEndpoint = null;
BookStore bookStore = null;
if (singleProxy) {
bookStore = getBookStore(inactiveReplica, feature);
}
for (int i = 0; i < 20; i++) {
if (!singleProxy) {
feature.getTargetSelector().close();
bookStore = getBookStore(inactiveReplica, feature);
}
verifyStrategy(bookStore, expectRandom ? RandomStrategy.class : SequentialStrategy.class);
Exception ex = null;
try {
if (expectServerException) {
bookStore.getBook("9999");
fail("Exception expected");
} else {
Book book = bookStore.echoBookElementJson(new Book("CXF", 123));
assertNotNull("expected non-null response", book);
assertEquals("unexpected id", 123L, book.getId());
}
} catch (Exception error) {
if (!expectServerException) {
// assertTrue(currEndpoint.equals(inactiveReplica));
throw error;
}
ex = error;
}
String currEndpoint = getCurrentEndpointAddress(bookStore);
assertFalse(currEndpoint.equals(inactiveReplica));
if (expectRandom) {
assertTrue(currEndpoint.equals(activeReplica1) || currEndpoint.equals(activeReplica2));
} else {
assertEquals(activeReplica1, currEndpoint);
}
if (expectServerException) {
assertNotNull(ex);
throw ex;
}
if (!(prevEndpoint == null || currEndpoint.equals(prevEndpoint))) {
randomized = true;
}
prevEndpoint = currEndpoint;
}
if (!singleProxy) {
assertEquals("unexpected random/sequential distribution of failovers", expectRandom, randomized);
}
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class JAXRSClientServerWebSocketTest method testGetBookHTTPFromWebSocketEndpoint.
@Test
public void testGetBookHTTPFromWebSocketEndpoint() throws Exception {
String address = "http://localhost:" + getPort() + getContext() + "/websocket/web/bookstore/books/1";
WebClient wc = WebClient.create(address);
wc.accept("application/xml");
Book book = wc.get(Book.class);
assertEquals(1L, book.getId());
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class LoadDistributorTest method strategyTest.
protected void strategyTest(String initialAddress, FailoverFeature feature) throws Exception {
assertEquals(Server.ADDRESS1, initialAddress);
int address2Count = 0;
int address3Count = 0;
for (int i = 0; i < 20; i++) {
BookStore bookStore = getBookStore(initialAddress, feature);
verifyStrategy(bookStore, SequentialStrategy.class);
String bookId = "123";
Book book = bookStore.getBook(bookId);
assertNotNull("expected non-null response", book);
assertEquals("unexpected id", 123L, book.getId());
String address = getCurrentEndpointAddress(bookStore);
if (Server.ADDRESS2.equals(address)) {
address2Count++;
} else if (Server.ADDRESS3.equals(address)) {
address3Count++;
}
}
assertEquals(10, address2Count);
assertEquals(10, address3Count);
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class LoadDistributorWebClientTest method testLoadDistributor.
@Test
public void testLoadDistributor() throws Exception {
URL busFile = LoadDistributorWebClientTest.class.getResource("cxf-client.xml");
String address = "http://localhost:" + PORT1 + "/bookstore";
LoadDistributorFeature feature = new LoadDistributorFeature();
SequentialStrategy strategy = new SequentialStrategy();
List<String> addresses = new ArrayList<>();
addresses.add(address);
addresses.add("http://localhost:" + PORT2 + "/bookstore");
strategy.setAlternateAddresses(addresses);
feature.setStrategy(strategy);
WebClient webClient = WebClient.create(address, null, Collections.singletonList(feature), busFile.toString()).accept("application/xml");
Book b = webClient.get(Book.class);
assertEquals(124L, b.getId());
assertEquals("root", b.getName());
b = webClient.get(Book.class);
assertEquals(124L, b.getId());
assertEquals("root", b.getName());
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class BookStoreSoapRestImpl method init.
private void init() {
Book book = new Book();
book.setId(new Long(123));
book.setName("CXF in Action");
books.put(book.getId(), book);
}
Aggregations