Search in sources :

Example 11 with ListOfBooks

use of org.talend.types.test.library.common._1.ListOfBooks 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;
}
Also used : BookType(org.talend.types.test.library.common._1.BookType) SeekBookError(org.talend.services.test.library._1_0.SeekBookError) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) PersonType(org.talend.types.test.library.common._1.PersonType) ListOfBooks(org.talend.types.test.library.common._1.ListOfBooks)

Example 12 with ListOfBooks

use of org.talend.types.test.library.common._1.ListOfBooks in project tesb-rt-se by Talend.

the class LibraryTester method testRequestResponsePositive.

public void testRequestResponsePositive() throws SeekBookError {
    // Test the positive case where author(s) are found and we retrieve
    // a list of books
    System.out.println("***************************************************************");
    System.out.println("*** Request-Response operation ********************************");
    System.out.println("***************************************************************");
    System.out.println("\nSending request for authors named Icebear");
    SearchFor request = new SearchFor();
    request.getAuthorLastName().add("Icebear");
    ListOfBooks response = libraryHttp.seekBook(request);
    System.out.println("\nResponse received:");
    if (response.getBook().size() != 1) {
        System.out.println("An error occured: number of books found is not equal to 1");
    }
    if (!"Icebear".equals(response.getBook().get(0).getAuthor().get(0).getLastName())) {
        System.out.println("An error occured: the author of the found book is not Icebear");
    }
}
Also used : SearchFor(org.talend.types.test.library.common._1.SearchFor) ListOfBooks(org.talend.types.test.library.common._1.ListOfBooks)

Example 13 with ListOfBooks

use of org.talend.types.test.library.common._1.ListOfBooks 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");
    }
}
Also used : SeekBookError(org.talend.services.test.library._1_0.SeekBookError) SearchFor(org.talend.types.test.library.common._1.SearchFor) ListOfBooks(org.talend.types.test.library.common._1.ListOfBooks)

Example 14 with ListOfBooks

use of org.talend.types.test.library.common._1.ListOfBooks in project tesb-rt-se by Talend.

the class LibraryTester method testRequestResponsePositive.

/**
 * Test request response positive.
 *
 * @throws SeekBookError the seek book error
 */
public void testRequestResponsePositive() throws SeekBookError {
    // Test the positive case where author(s) are found and we retrieve
    // a list of books
    System.out.println("***************************************************************");
    System.out.println("*** Request-Response operation ********************************");
    System.out.println("***************************************************************");
    System.out.println("\nSending request for authors named Icebear");
    SearchFor request = new SearchFor();
    request.getAuthorLastName().add("Icebear");
    request.getAuthorLastName().add("Sykes");
    ListOfBooks response = libraryHttp.seekBook(request);
    System.out.println("\nResponse received:");
    Utils.showBooks(response);
    if (response.getBook().size() != 1) {
        System.out.println("An error occured: number of books found is not equal to 1");
    }
    if (!"Icebear".equals(response.getBook().get(0).getAuthor().get(0).getLastName()) && !"Sykes".equals(response.getBook().get(0).getAuthor().get(0).getLastName())) {
        System.out.println("An error occured: the author of the found book does not match the request");
    }
}
Also used : SearchFor(org.talend.types.demos.library.common._1.SearchFor) ListOfBooks(org.talend.types.demos.library.common._1.ListOfBooks)

Example 15 with ListOfBooks

use of org.talend.types.test.library.common._1.ListOfBooks in project tesb-rt-se by Talend.

the class LibraryTester method testRequestCallbackPositive.

/**
 * Test request callback positive.
 *
 * @throws SeekBookError the seek book error
 */
public void testRequestCallbackPositive() throws SeekBookError {
    // Test the positive case where author(s) are found and we retrieve
    // a list of books
    System.out.println("***************************************************************");
    System.out.println("*** Request-Callback operation ********************************");
    System.out.println("***************************************************************");
    System.out.println("\nSending request(callback) for authors named Stripycat");
    SearchFor request = new SearchFor();
    request.getAuthorLastName().add("Stripycat");
    Map<String, Object> rctx = ((BindingProvider) libraryJms).getRequestContext();
    Map<String, Object> correlationInfo = new HashMap<String, Object>();
    rctx.put(RequestCallbackFeature.CALL_INFO_PROPERTY_NAME, correlationInfo);
    libraryJms.seekBookInBasement(request);
    String correlationId = (String) correlationInfo.get(RequestCallbackFeature.CALL_ID_NAME);
    System.out.println("\nRequest sent.");
    System.out.println("Call ID is " + correlationId);
    try {
        boolean moreToCome = LibraryConsumerImpl.waitForResponse() instanceof ListOfBooks;
        System.out.println("\nProcessing of first callback response confirmed.\n");
        if (moreToCome) {
            LibraryConsumerImpl.waitForResponse();
            System.out.println("\nProcessing of second callback response confirmed.\n");
        }
    } catch (InterruptedException e) {
        throw new RuntimeException("Request-callback test interrupted: ", e);
    }
}
Also used : HashMap(java.util.HashMap) BindingProvider(javax.xml.ws.BindingProvider) SearchFor(org.talend.types.demos.library.common._1.SearchFor) ListOfBooks(org.talend.types.demos.library.common._1.ListOfBooks)

Aggregations

ListOfBooks (org.talend.types.test.library.common._1.ListOfBooks)21 SearchFor (org.talend.types.test.library.common._1.SearchFor)18 SeekBookError (org.talend.services.test.library._1_0.SeekBookError)16 Calendar (java.util.Calendar)7 GregorianCalendar (java.util.GregorianCalendar)7 Library (org.talend.services.test.library._1_0.Library)6 ListOfBooks (org.talend.types.demos.library.common._1.ListOfBooks)6 BookType (org.talend.types.test.library.common._1.BookType)5 PersonType (org.talend.types.test.library.common._1.PersonType)5 SeekBookError (org.talend.services.demos.library._1_0.SeekBookError)3 BookType (org.talend.types.demos.library.common._1.BookType)3 PersonType (org.talend.types.demos.library.common._1.PersonType)3 SearchFor (org.talend.types.demos.library.common._1.SearchFor)3 HashMap (java.util.HashMap)1 BindingProvider (javax.xml.ws.BindingProvider)1 CallContext (org.talend.esb.mep.requestcallback.feature.CallContext)1 CallContextStore (org.talend.esb.mep.requestcallback.impl.callcontext.CallContextStore)1 LibraryConsumer (org.talend.services.demos.library._1_0.LibraryConsumer)1