MockWebServer with JUnit: Test Spring WebClient Calls
Test Spring WebClient with MockWebServer and JUnit. Queue responses, route with a Dispatcher, verify requests, and simulate errors, delays and timeouts.
Test Spring WebClient with MockWebServer and JUnit. Queue responses, route with a Dispatcher, verify requests, and simulate errors, delays and timeouts.
Learn Spring Boot with the following in-depth tutorials, covering from basic to advanced concepts such as packaging and monitoring.
WireMock 3 tutorial for Java. Stub REST APIs in JUnit 5 tests, match requests, simulate delays and faults, verify calls and use stateful scenarios.
Learn about Spring profiles, @Profile, profile-specific beans and properties, profile groups and activating a certain profile during startup.
Learn to use @PropertySource, @Value and @ConfigurationProperties annotations to register property files and inject configuration properties.
Learn to configure OAuth2 authorization-based login security in a Spring boot and spring security application with custom handlers.
Learn to partially or fully disable the Spring security in Spring boot applications based on selected runtime @Profile or using properties.
Learn to enable DEBUG and TRACE level logging for spring security configuration, request processing and filter chain proxy using simple switches.
Learn to configure and test a spring security login form based authentication that fetches the username, password and roles from the database.
Learn to pass the Spring SecurityContext instance to new threads either spawned by Spring @Async or created explicitly using new Runnable or Callable instances. 1. Default Strategy is ThreadLocal Once the AuthenticationManager completes the authentication process successfully, it stores the Authentication instance for the rest of the request in the …
Learn to create, plug in and test a custom Authentication Provider into the spring security and register with the authentication manager.
Learn the contract spring security expects from PasswordEncoder interface, inbuilt implementations and DelegatingPasswordEncoder with examples.
Log4j2 provides significant improvements over its predecessor Log4j. Read about its xml and properties configuration and various examples.
Hibernate tutorials for Hibernate 7.4, Jakarta Persistence 3.2 and Java 25, grouped as a learning path: setup, entities, entity states, associations, queries, caching, validation, search and fixes for common errors.
Test code that looks up a JNDI DataSource without an application server: register a small in-memory JNDI provider or Simple-JNDI, bind an H2 DataSource under the production name, bootstrap Hibernate 7 with it and run CRUD in JUnit 6. Or skip JNDI and pass the DataSource object.
Hibernate sends inserts, updates and deletes in JDBC batches once hibernate.jdbc.batch_size is set. Measured on Hibernate 7.4: why IDENTITY ids stop batching, how flush() and clear() keep memory flat, and when to use order_inserts, StatelessSession or a JPQL bulk statement.
Call a stored procedure from Hibernate with StoredProcedureQuery: IN and OUT parameters, result sets mapped to entities, named procedures and Spring Data @Procedure.
Hibernate aggregate functions compute one value from many rows. Learn count, min, max, sum and avg in HQL, JPQL and the Criteria API, their Java return types, group by, having, null handling and Hibernate’s listagg, filter and window functions.
Hibernate Search adds full-text search to Hibernate entities. Map fields with @FullTextField, @KeywordField and @GenericField, let the index follow every commit, rebuild it with the MassIndexer, and search with match, phrase, bool, range, sorting, paging and highlighting on Hibernate Search 8.4 and Lucene.
A Hibernate interceptor gets a callback when an entity is persisted, changed, removed or loaded, with the old and new property values. Build an audit trail with onPersist, onFlushDirty and onRemove in Hibernate 7, pick the right scope, and rewrite SQL with a StatementInspector.
Hibernate pagination loads a query result one page at a time with setFirstResult() and setMaxResults(). See the SQL for offset and keyset pages, page counts, the ORDER BY trap, join fetch paging and ScrollableResults on Hibernate 7.4.
Sort Hibernate query results with JPQL order by, Criteria orderBy and Hibernate 7 SelectionSpecification, and sort collections with @OrderBy, @OrderColumn, @SortNatural and @SortComparator.
Delete an entity in Hibernate 7 with em.remove() after find() or getReference(), fix the detached entity error, and use a JPQL bulk delete without leaving stale objects or hitting foreign key errors.
The seven JPA lifecycle callbacks in Hibernate 7.4, when each one runs relative to persist(), flush and commit, entity listeners and default listeners in orm.xml, what a callback must not do, and Hibernate’s own event listeners.
Create one EntityManagerFactory per database in Hibernate 7.4, from persistence.xml, from Java code with PersistenceConfiguration or HibernatePersistenceConfiguration, or from a PersistenceUnitInfo, then open one EntityManager per unit of work with runInTransaction() and callInTransaction().
Hibernate maps LocalDate, LocalDateTime, Instant, OffsetDateTime and ZonedDateTime to SQL date, time and timestamp columns without annotations. See the DDL and stored values on Hibernate 7.4 and how @TimeZoneStorage keeps or drops the offset.
Set up Ehcache 3 as the Hibernate 6 and 7 second level cache: the hibernate-jcache and jakarta Ehcache dependencies, the JCache properties, a minimal ehcache.xml, @Cacheable and @Cache, hit statistics, and the startup error each missing piece causes.
“Unable to locate persister” (Unknown entity type in Hibernate 7) means Hibernate has no mapping for the class it received. See each cause reproduced on Hibernate 7.4 and Spring Boot 4.1, from javax imports and missing registration to DTOs, proxies and entity scanning, with a tested fix for each.
Copy an InputStream to OutputStream in Java with transferTo(), a custom loop, Files.copy(), Guava or Commons IO, plus the closing and flushing rules.
Convert a Reader to InputStream in Java with a String, OutputStreamWriter or Commons IO ReaderInputStream, and back with InputStreamReader and a charset.
Java create directory examples with Files.createDirectories() and createDirectory(), parent folders, permissions, mkdirs() pitfalls and race-free checks.
Count lines in a file in Java with Files.lines(), LineNumberReader, readAllLines() or a fast byte counter, with edge cases like a missing final newline.
Java check if directory is empty with Files.list() or newDirectoryStream(), closing the stream, files and missing paths, hidden files and subfolders.
Read the file creation date in Java with BasicFileAttributes, format the FileTime, and see which platforms and JDK versions return the real value.
Create, detect and read symbolic links in Java with Files, control link following with NOFOLLOW_LINKS, compare hard links and switch releases atomically.
Learn to delete the contents of a file in Java without deleting it, with Files.write, FileChannel.truncate and writers, plus partial truncation.
Write a byte array to file in Java with Files.write, FileOutputStream and Files.copy, covering overwrite, append, parent folders and atomic writes.
Java streams tutorial hub with every Stream API guide grouped by task, from creating and filtering streams to collectors, sorting, numbers and debugging.
Read a specific line from a file in Java by line number with Files.lines(), readAllLines() or BufferedReader, handle missing lines and index large files.
Rename or move a file in Java with Files.move(), replace targets, use ATOMIC_MOVE, move folders across disks and avoid File.renameTo() pitfalls.
Get the file size in Java with Files.size(), compute a directory size with Files.walk(), convert bytes to KB, MB and GB, and check free disk space.
Learn the Java Cleaner API with a native memory example, the mistakes that stop cleanup, and how to migrate deprecated finalize() code in Java 25.
Primitive type streams in Java with IntStream, LongStream and DoubleStream, covering creation, sum and average, overflow, summary statistics and boxing.
How to work with dates and times in Java using java.time: a tested quick example, a table of which class to use when, and every date-time tutorial grouped by task.
Add or subtract hours, minutes and seconds in Java with LocalDateTime, ZonedDateTime, Instant and Duration, including DST changes and midnight rollover.
Get the year, month and day from a date in Java with getYear(), getMonthValue() and getDayOfMonth(), plus month names, time zones and YearMonth.
Set the JVM default time zone with -Duser.timezone, TZ or TimeZone.setDefault(). Learn the precedence, the GMT fallback and Docker and Kubernetes setup.
Get the day of week from a date in Java with getDayOfWeek(), read its number, handle time zones and strings, and convert java.util.Date values.
Get the start and end of day in Java with atStartOfDay(zone) and LocalTime.MAX, handle days that skip midnight and select a day with a half-open range.
ZonedDateTime vs OffsetDateTime in Java. See how each handles DST, which one to store in a database or send in JSON, and how to convert between them.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.