Search in sources :

Example 41 with Book

use of com.google.example.library.v1.Book in project kripton by xcesco.

the class TestCustomBeanRuntimeErr1 method testContraintViolation.

@Test
public void testContraintViolation() throws InterruptedException, InstantiationException, IllegalAccessException {
    this.expectedException(KriptonRuntimeException.class);
    BindAppDataSource dataSource = BindAppDataSource.build(DataSourceOptions.builder().inMemory(true).build());
    dataSource.getLoanDao().findAllWithUserAndBook().observeForever(new Observer<List<LoanWithUserAndBook>>() {

        @Override
        public void onChanged(List<LoanWithUserAndBook> t) {
            if (t.size() > 0) {
                LoanWithUserAndBook bean = t.get(0);
                log("Found %s elements", t.size());
                assertTrue(bean.bookTitle != null);
                assertTrue(bean.userName != null);
                assertTrue(bean.startTime != null);
                assertTrue(bean.id != null);
            }
        }
    });
    dataSource.execute(new Transaction() {

        @Override
        public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
            User user = createUser(daoFactory);
            Book book = createBook(daoFactory);
            insertLoan(daoFactory, user, book);
            insertLoan(daoFactory, user, book);
            return TransactionResult.COMMIT;
        }

        private void insertLoan(BindAppDaoFactory daoFactory, User user, Book book) {
            Loan loan = new Loan();
            loan.id = UUID.randomUUID().toString();
            loan.bookId = book.id;
            loan.userId = user.id;
            loan.startTime = new Date();
            daoFactory.getLoanDao().insertLoan(loan);
        }

        private Book createBook(BindAppDaoFactory daoFactory) {
            Book book = new Book();
            book.id = UUID.randomUUID().toString();
            book.title = "Never Ending Story #" + (counter++);
            daoFactory.getBookDao().insertBook(book);
            return book;
        }

        private User createUser(BindAppDaoFactory daoFactory) {
            User user = new User();
            user.id = UUID.randomUUID().toString();
            user.age = 24;
            user.name = "Fox";
            user.lastName = "Mulder";
            daoFactory.getUserDao().insertUser(user);
            return user;
        }
    });
    KriptonLibrary.getExecutorService().awaitTermination(4, TimeUnit.SECONDS);
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) User(sqlite.feature.custombean.case1.User) LoanWithUserAndBook(sqlite.feature.custombean.case1.LoanWithUserAndBook) Date(java.util.Date) Transaction(sqlite.feature.custombean.case1.BindAppDataSource.Transaction) Loan(sqlite.feature.custombean.case1.Loan) BindAppDataSource(sqlite.feature.custombean.case1.BindAppDataSource) Book(sqlite.feature.custombean.case1.Book) LoanWithUserAndBook(sqlite.feature.custombean.case1.LoanWithUserAndBook) BindAppDaoFactory(sqlite.feature.custombean.case1.BindAppDaoFactory) List(java.util.List) BaseAndroidTest(base.BaseAndroidTest) Test(org.junit.Test)

Example 42 with Book

use of com.google.example.library.v1.Book in project java_1_sunday_january_2022_online by javagurulv.

the class BookDemo method main.

public static void main(String[] args) {
    Book myBook = new Book("Principles");
    String bookTitle = myBook.getTitle();
    System.out.println("Book title = " + bookTitle);
}
Also used : Book(student_stanislav_astafjev.lesson_2.Task_3.Book)

Example 43 with Book

use of com.google.example.library.v1.Book in project pgr112oop by bogdanmarculescu.

the class SomeExplanations method forEachExample.

public void forEachExample() {
    BookRegister br = initializeBookRegister();
    ArrayList<Book> books = br.allRegisteredBooks();
    ArrayList<String> authorNames = new ArrayList<>();
    for (Book bok : books) {
        authorNames.add(bok.getAuthor());
        books.indexOf(bok);
    }
}
Also used : BookRegister(org.pgr112.solutions.sol4.BookRegister) Book(org.pgr112.solutions.sol4.Book) ArrayList(java.util.ArrayList)

Example 44 with Book

use of com.google.example.library.v1.Book in project pgr112oop by bogdanmarculescu.

the class SomeExplanations method initializeBookRegister.

public BookRegister initializeBookRegister() {
    BookRegister br = new BookRegister();
    br.addBook(new Book("Dune", "Frank Herbert", 750, Genre.OTHER));
    br.addBook(new Book("Fellowship of the Ring", "J.R.R. Tolkien", 750, Genre.FANTASY));
    br.addBook(new Book("The Two Towers", "J.R.R. Tolkien", 750, Genre.FANTASY));
    br.addBook(new Book("Return of the King", "J.R.R. Tolkien", 750, Genre.FANTASY));
    br.addBook(new Book("Guards! Guards!", "Terry Pratchett", 750, Genre.FANTASY));
    return br;
}
Also used : BookRegister(org.pgr112.solutions.sol4.BookRegister) Book(org.pgr112.solutions.sol4.Book)

Example 45 with Book

use of com.google.example.library.v1.Book in project gapic-generator-java by googleapis.

the class SyncGetBook method syncGetBook.

public static void syncGetBook() throws Exception {
    // It may require modifications to work in your environment.
    try (LibraryServiceClient libraryServiceClient = LibraryServiceClient.create()) {
        GetBookRequest request = GetBookRequest.newBuilder().setName(BookName.of("[SHELF]", "[BOOK]").toString()).build();
        Book response = libraryServiceClient.getBook(request);
    }
}
Also used : GetBookRequest(com.google.example.library.v1.GetBookRequest) LibraryServiceClient(com.google.cloud.example.library.v1.LibraryServiceClient) Book(com.google.example.library.v1.Book)

Aggregations

Book (com.google.example.library.v1.Book)33 Test (org.junit.Test)25 LibraryServiceClient (com.google.cloud.example.library.v1.LibraryServiceClient)22 Book (student_arturs_melnikovs.lesson_10.level_02.Book)16 BookName (com.google.example.library.v1.BookName)12 AbstractMessage (com.google.protobuf.AbstractMessage)12 ShelfName (com.google.example.library.v1.ShelfName)9 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 MoveBookRequest (com.google.example.library.v1.MoveBookRequest)6 DeleteBookRequest (com.google.example.library.v1.DeleteBookRequest)5 Scanner (java.util.Scanner)5 CreateBookRequest (com.google.example.library.v1.CreateBookRequest)4 GetBookRequest (com.google.example.library.v1.GetBookRequest)4 Page (org.apache.wicket.Page)4 Book (org.apache.wicket.core.util.tester.apps_1.Book)4 WebPage (org.apache.wicket.markup.html.WebPage)4 AccessDeniedPage (org.apache.wicket.markup.html.pages.AccessDeniedPage)4 DummyPage (org.apache.wicket.resource.DummyPage)4 Book (org.apache.wicket.util.tester.apps_1.Book)4