Merge branch 'eugenp:master' into danielmcnally285_string_to_long
This commit is contained in:
commit
c9c82e9e33
|
@ -0,0 +1,49 @@
|
|||
package com.baeldung.aboutlength;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class StringLengthAndByteArrayLengthUnitTest {
|
||||
|
||||
@Test
|
||||
void whenStrWithAllAsciiChar_thenStrLengthAndBytesLengthAreEqual() {
|
||||
String s = "beautiful";
|
||||
assertEquals(9, s.length());
|
||||
assertEquals(9, s.getBytes().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenStrWithUnicodeChar_thenStrLengthAndBytesLengthAreNotEqual() {
|
||||
assertEquals("f6", Integer.toHexString('ö'));
|
||||
assertEquals("7f8e", Integer.toHexString('美'));
|
||||
assertEquals("4e3d", Integer.toHexString('丽'));
|
||||
|
||||
String de = "schöne";
|
||||
assertEquals(6, de.length());
|
||||
assertEquals(7, de.getBytes().length);
|
||||
|
||||
String cn = "美丽";
|
||||
assertEquals(2, cn.length());
|
||||
assertEquals(6, cn.getBytes().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingUTF_32_thenBytesLengthIs4TimesStrLength() {
|
||||
Charset UTF_32 = Charset.forName("UTF_32");
|
||||
|
||||
String en = "beautiful";
|
||||
assertEquals(9, en.length());
|
||||
assertEquals(9 * 4, en.getBytes(UTF_32).length);
|
||||
|
||||
String de = "schöne";
|
||||
assertEquals(6, de.length());
|
||||
assertEquals(6 * 4, de.getBytes(UTF_32).length);
|
||||
|
||||
String cn = "美丽";
|
||||
assertEquals(2, cn.length());
|
||||
assertEquals(2 * 4, cn.getBytes(UTF_32).length);
|
||||
}
|
||||
}
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -59,6 +59,8 @@
|
|||
|
||||
<properties>
|
||||
<faunadb.version>4.2.0</faunadb.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
<start-class>com.baeldung.faunablog.FaunaBlogApplication</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -5,15 +5,17 @@ import com.faunadb.client.FaunaClient;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
@EnableMethodSecurity
|
||||
public class WebSecurityConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
@ -21,13 +23,11 @@ public class WebSecurityConfiguration {
|
|||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http.csrf()
|
||||
.disable();
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/**")
|
||||
.permitAll()
|
||||
.and()
|
||||
.httpBasic();
|
||||
http.csrf(CsrfConfigurer::disable)
|
||||
.authorizeHttpRequests(requests -> requests
|
||||
.requestMatchers("/**")
|
||||
.permitAll())
|
||||
.httpBasic(Customizer.withDefaults());
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
|
|
@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
|
@ -6,6 +6,8 @@ import org.springframework.security.core.userdetails.User;
|
|||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
@ -30,8 +32,9 @@ public class FaunaUserDetailsService implements UserDetailsService {
|
|||
if (userData == null) {
|
||||
throw new UsernameNotFoundException("User not found");
|
||||
}
|
||||
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
|
||||
return User.withDefaultPasswordEncoder()
|
||||
return User.builder().passwordEncoder(encoder::encode)
|
||||
.username(userData.at("data", "username").to(String.class).orNull())
|
||||
.password(userData.at("data", "password").to(String.class).orNull())
|
||||
.roles("USER")
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.service.ServiceRegistry;
|
|||
import com.baeldung.hibernate.exception.persistentobject.entity.Article;
|
||||
import com.baeldung.hibernate.exception.persistentobject.entity.Author;
|
||||
import com.baeldung.hibernate.exception.persistentobject.entity.Book;
|
||||
import com.baeldung.hibernate.namedparameternotbound.Person;
|
||||
|
||||
public class HibernateUtil {
|
||||
private static SessionFactory sessionFactory;
|
||||
|
@ -34,6 +35,7 @@ public class HibernateUtil {
|
|||
configuration.addAnnotatedClass(Book.class);
|
||||
configuration.addAnnotatedClass(Author.class);
|
||||
configuration.addAnnotatedClass(Article.class);
|
||||
configuration.addAnnotatedClass(Person.class);
|
||||
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(configuration.getProperties()).build();
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.baeldung.hibernate.namedparameternotbound;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.baeldung.hibernate.namedparameternotbound;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.query.Query;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.baeldung.hibernate.exception.persistentobject.HibernateUtil;
|
||||
|
||||
class NamedParameterNotBoundExceptionUnitTest {
|
||||
|
||||
private static Session session;
|
||||
|
||||
@BeforeAll
|
||||
static void init() {
|
||||
session = HibernateUtil.getSessionFactory()
|
||||
.openSession();
|
||||
session.beginTransaction();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void clear() {
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenSettingValueToNamedParameter_thenDoNotThrowQueryException() {
|
||||
Query<Person> query = session.createQuery("FROM Person p WHERE p.firstName = :firstName", Person.class);
|
||||
query.setParameter("firstName", "Azhrioun");
|
||||
|
||||
assertNotNull(query.list());
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenNotSettingValueToNamedParameter_thenThrowQueryException() {
|
||||
Exception exception = assertThrows(QueryException.class, () -> {
|
||||
Query<Person> query = session.createQuery("FROM Person p WHERE p.firstName = :firstName", Person.class);
|
||||
query.list();
|
||||
});
|
||||
|
||||
String expectedMessage = "Named parameter not bound";
|
||||
String actualMessage = exception.getMessage();
|
||||
|
||||
assertTrue(actualMessage.contains(expectedMessage));
|
||||
}
|
||||
|
||||
}
|
12
pom.xml
12
pom.xml
|
@ -686,7 +686,6 @@
|
|||
<modules>
|
||||
<module>akka-modules</module>
|
||||
<module>algorithms-modules</module>
|
||||
<module>antlr</module>
|
||||
<module>apache-cxf-modules</module>
|
||||
<module>apache-httpclient-2</module>
|
||||
<module>apache-httpclient4</module>
|
||||
|
@ -700,9 +699,7 @@
|
|||
<module>apache-poi-3</module>
|
||||
<module>apache-poi</module>
|
||||
<module>apache-thrift</module>
|
||||
<module>apache-tika</module>
|
||||
<module>apache-velocity</module>
|
||||
<module>asciidoctor</module>
|
||||
<module>atomix</module>
|
||||
<module>aws-modules</module>
|
||||
<module>azure</module>
|
||||
|
@ -813,8 +810,6 @@
|
|||
<module>osgi</module>
|
||||
<module>parent-boot-3</module>
|
||||
<module>patterns-modules</module>
|
||||
<module>pdf-2</module>
|
||||
<module>pdf</module>
|
||||
<module>performance-tests</module>
|
||||
<module>persistence-modules</module>
|
||||
<!--<module>persistence-modules/java-harperdb</module>--> <!-- This module requires a library to download manually -->
|
||||
|
@ -896,6 +891,7 @@
|
|||
<module>tensorflow-java</module>
|
||||
<module>testing-modules</module>
|
||||
<module>testing-modules/mockito-simple</module>
|
||||
<module>text-processing-libraries-modules</module>
|
||||
<module>timefold-solver</module>
|
||||
<module>vaadin</module>
|
||||
<module>vavr-modules</module>
|
||||
|
@ -940,7 +936,6 @@
|
|||
<modules>
|
||||
<module>akka-modules</module>
|
||||
<module>algorithms-modules</module>
|
||||
<module>antlr</module>
|
||||
<module>apache-cxf-modules</module>
|
||||
<module>apache-httpclient-2</module>
|
||||
<module>apache-httpclient4</module>
|
||||
|
@ -954,9 +949,7 @@
|
|||
<module>apache-poi-3</module>
|
||||
<module>apache-poi</module>
|
||||
<module>apache-thrift</module>
|
||||
<module>apache-tika</module>
|
||||
<module>apache-velocity</module>
|
||||
<module>asciidoctor</module>
|
||||
<module>atomix</module>
|
||||
<module>aws-modules</module>
|
||||
<module>azure</module>
|
||||
|
@ -1067,8 +1060,6 @@
|
|||
<module>osgi</module>
|
||||
<module>parent-boot-3</module>
|
||||
<module>patterns-modules</module>
|
||||
<module>pdf-2</module>
|
||||
<module>pdf</module>
|
||||
<module>performance-tests</module>
|
||||
<module>persistence-modules</module>
|
||||
<module>persistence-modules/spring-data-neo4j</module>
|
||||
|
@ -1148,6 +1139,7 @@
|
|||
<module>tensorflow-java</module>
|
||||
<module>testing-modules</module>
|
||||
<module>testing-modules/mockito-simple</module>
|
||||
<module>text-processing-libraries-modules</module>
|
||||
<module>timefold-solver</module>
|
||||
<module>vaadin</module>
|
||||
<module>vavr-modules</module>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
## Text Processing Libraries
|
||||
|
||||
This module contains modules about Text Processing Libraries.
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>text-processing-libraries-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>text-processing-libraries-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>text-processing-libraries-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>text-processing-libraries-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
@ -9,7 +9,7 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>text-processing-libraries-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>text-processing-libraries-modules</artifactId>
|
||||
<name>text-processing-libraries-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>antlr</module>
|
||||
<module>apache-tika</module>
|
||||
<module>asciidoctor</module>
|
||||
<module>pdf</module>
|
||||
<module>pdf-2</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue