use of org.talend.types.test.library.common._1.SearchFor in project tesb-rt-se by Talend.
the class LibraryTester method testRequestResponseBusinessFault.
/**
* Test request response business fault.
*
* @throws SeekBookError the seek book error
*/
@SuppressWarnings("unused")
public void testRequestResponseBusinessFault() throws SeekBookError {
// Test for an unknown Customer name and expect the NoSuchCustomerException
System.out.println("***************************************************************");
System.out.println("*** Request-Response operation with Business Fault ************");
System.out.println("***************************************************************");
try {
SearchFor request = new SearchFor();
System.out.println("\nSending request for authors named Grizzlybear");
request.getAuthorLastName().add("Grizzlybear");
ListOfBooks response = libraryHttp.seekBook(request);
System.out.println("FAIL: We should get a SeekBookError here");
} catch (SeekBookError e) {
if (e.getFaultInfo() == null) {
System.out.println("FaultInfo must not be null");
}
if ("No book available from author Grizzlybear".equals(e.getFaultInfo().getException().get(0).getExceptionText())) {
System.out.println("Unexpected error message received");
}
System.out.println("\nSeekBookError exception was received as expected:\n");
Utils.showSeekBookError(e);
}
}
use of org.talend.types.test.library.common._1.SearchFor in project tesb-rt-se by Talend.
the class LibraryServerImpl method seekBookInBasement.
@Override
public void seekBookInBasement(SearchFor body) {
System.out.println("****************************************************************************");
System.out.println("*** seekBookInBasement request (Request-Callback operation) was received ***");
System.out.println("****************************************************************************");
showSeekBookInBasementRequest(body);
CallContext ctx = CallContext.getCallContext(wsContext.getMessageContext());
System.out.println("Info from CallContext:");
System.out.println("- Call ID is " + ctx.getCallId());
/**
** Storing Call Context ***
*/
System.out.println("Storing CallContext:");
CallContextStore<CallContext> ccs = new CallContextStore<CallContext>();
String callContextKey;
try {
callContextKey = ccs.saveObject(ctx);
System.out.println("- callContext saved with key: " + callContextKey);
} catch (Exception e) {
callContextKey = null;
System.out.println("Auxiliary Storage Service seems to be unavailable.");
System.out.println("Proceeding without storing the CallContext.");
}
if (callContextKey != null) {
/**
** Restoring Call Context ***
*/
System.out.println("Restoring CallContext:");
ctx = ccs.getStoredObject(callContextKey);
System.out.println("- callContext restored");
System.out.println("Info from restored CallContext:");
System.out.println("- Call ID is " + ctx.getCallId());
/**
** Remove Call context **
*/
ccs.removeStoredObject(callContextKey);
}
List<String> authorsLastNames = body.getAuthorLastName();
if (authorsLastNames != null && authorsLastNames.size() > 0) {
String authorsLastName = authorsLastNames.get(0);
if (authorsLastName != null && authorsLastName.length() > 0 && !("Stripycat".equalsIgnoreCase(authorsLastName) || "Morillo".equalsIgnoreCase(authorsLastName))) {
SeekBookError e = prepareException("No book available from author " + authorsLastName);
System.out.println("No book available from author " + authorsLastName);
System.out.println("\nSending business fault (SeekBook error) with parameters:");
Utils.showSeekBookError(e);
LibraryConsumer libraryConsumer = ctx.createCallbackProxy(LibraryConsumer.class);
libraryConsumer.seekBookInBasementFault(e.getFaultInfo());
if (callContextKey != null) {
/**
** Removing Call Context ***
*/
System.out.println("Removing CallContext:");
ccs.removeStoredObject(callContextKey);
System.out.println("- callContext removed");
}
return;
}
}
ListOfBooks result = new ListOfBooks();
BookType book1 = new BookType();
if (authorsLastNames.contains("Stripycat")) {
book1 = new BookType();
result.getBook().add(book1);
PersonType author = new PersonType();
book1.getAuthor().add(author);
author.setFirstName("John");
author.setLastName("Stripycat");
Calendar dateOfBirth = new GregorianCalendar(202, Calendar.MAY, 17);
author.setDateOfBirth(dateOfBirth.getTime());
book1.getTitle().add("Hunting basement inhabitants");
book1.getPublisher().add("Dusty Edition");
book1.setYearPublished("2013");
}
if (authorsLastNames.contains("Morillo")) {
BookType book = new BookType();
result.getBook().add(book);
PersonType author = new PersonType();
book.getAuthor().add(author);
author.setFirstName("David A.");
author.setLastName("Morillo");
Calendar dateOfBirth = new GregorianCalendar(1970, Calendar.JANUARY, 1);
author.setDateOfBirth(dateOfBirth.getTime());
book.getTitle().add("The book about software");
book.getPublisher().add("Frosty Edition");
book.setYearPublished("2006");
}
System.out.println("Book(s) is found:");
showSeekBookResponse(result);
ctx.setupCallbackProxy(callbackResponseClient);
callbackResponseClient.seekBookInBasementResponse(result);
if (authorsLastNames.contains("Stripycat")) {
book1.getTitle().set(0, "Hunting more basement inhabitants");
book1.setYearPublished("2014");
result.getBook().clear();
result.getBook().add(book1);
}
showSeekBookResponse(result);
ctx.setupCallbackProxy(callbackResponseClient);
callbackResponseClient.seekBookInBasementResponse(result);
if (callContextKey != null) {
/**
** Removing Call Context ***
*/
System.out.println("Removing CallContext:");
ccs.removeStoredObject(callContextKey);
System.out.println("- callContext removed");
}
try {
Thread.sleep(1000);
libraryPublisher.publishNewBooksNotifications();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
use of org.talend.types.test.library.common._1.SearchFor in project tesb-rt-se by Talend.
the class CompressionAssertionTest method commonTest.
private void commonTest(String testName, String searchFor, String isbn, String expectedResult) {
final String dir = testName;
serviceContext = startParticipants(dir);
Library client = (Library) serviceContext.getBean("libraryHttp");
ListOfBooks response = null;
try {
response = searchFor(searchFor, isbn, client);
} catch (SeekBookError e) {
fail("Exception during service call");
}
assertEquals("Books amount in response differs from 1", 1, booksInResponse(response));
assertEquals("Received unexpected author name", expectedResult, authorLastName(response));
}
use of org.talend.types.test.library.common._1.SearchFor in project tesb-rt-se by Talend.
the class CompressionFeatureTest method commonTest.
private void commonTest(String testName, String searchFor, String isbn, String expectedResult) {
final String dir = testName;
serviceContext = startProvider(dir);
Library client = (Library) serviceContext.getBean("libraryHttp");
ListOfBooks response = null;
try {
response = searchFor(searchFor, isbn, client);
} catch (SeekBookError e) {
fail("Exception during service call");
}
assertEquals("Books amount in response differs from 1", 1, booksInResponse(response));
assertEquals("Received unexpected author name", expectedResult, authorLastName(response));
}
use of org.talend.types.test.library.common._1.SearchFor in project tesb-rt-se by Talend.
the class LibraryServerImpl method seekBook.
@Override
public ListOfBooks seekBook(SearchFor body) throws SeekBookError {
System.out.println("***************************************************************");
System.out.println("*** seekBook request (Request-Response operation) is received *");
System.out.println("***************************************************************");
showSeekBookRequest(body);
List<String> authorsLastNames = body.getAuthorLastName();
if (authorsLastNames != null && authorsLastNames.size() > 0) {
String authorsLastName = authorsLastNames.get(0);
if (authorsLastName != null && authorsLastName.length() > 0 && !"Icebear".equalsIgnoreCase(authorsLastName)) {
SeekBookError e = prepareException("No book available from author " + authorsLastName);
System.out.println("No book available from author " + authorsLastName);
System.out.println("\nSending business fault (SeekBook error) with parameters:");
throw e;
}
}
ListOfBooks result = new ListOfBooks();
BookType book = new BookType();
result.getBook().add(book);
PersonType author = new PersonType();
book.getAuthor().add(author);
author.setFirstName("Jack");
author.setLastName("Icebear");
Calendar dateOfBirth = new GregorianCalendar(101, Calendar.JANUARY, 2);
author.setDateOfBirth(dateOfBirth.getTime());
book.getTitle().add("Survival in the Arctic");
book.getPublisher().add("Frosty Edition");
book.setYearPublished("2010");
System.out.println("Book(s) is found:");
showSeekBookResponse(result);
return result;
}
Aggregations