* Fix: Github reports security vulnerabilities #933 Upgrade camel and spring-data * -Fix github security vulnerabilities in spring-data and camel * -Code changes for review comments
This commit is contained in:
committed by
Ilkka Seppälä
parent
f5455f9887
commit
84c4b034a9
@ -23,6 +23,7 @@
|
||||
package com.iluwatar.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -84,17 +85,17 @@ public class App {
|
||||
nasta.setSurname("Spotakova");
|
||||
repository.save(nasta);
|
||||
|
||||
LOGGER.info("Find by id 2: {}", repository.findOne(2L));
|
||||
LOGGER.info("Find by id 2: {}", repository.findById(2L).get());
|
||||
|
||||
// Remove record from Person
|
||||
repository.delete(2L);
|
||||
repository.deleteById(2L);
|
||||
|
||||
// count records
|
||||
LOGGER.info("Count Person records: {}", repository.count());
|
||||
|
||||
// find by name
|
||||
Person p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
|
||||
LOGGER.info("Find by John is {}", p);
|
||||
Optional<Person> p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
|
||||
LOGGER.info("Find by John is {}", p.get());
|
||||
|
||||
// find by age
|
||||
persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
|
||||
|
@ -24,6 +24,7 @@ package com.iluwatar.repository;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@ -32,6 +33,7 @@ import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
@ -44,6 +46,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
*
|
||||
*/
|
||||
@EnableJpaRepositories
|
||||
@SpringBootConfiguration
|
||||
public class AppConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AppConfig.class);
|
||||
@ -60,7 +63,7 @@ public class AppConfig {
|
||||
basicDataSource.setUrl("jdbc:h2:~/databases/person");
|
||||
basicDataSource.setUsername("sa");
|
||||
basicDataSource.setPassword("sa");
|
||||
return (DataSource) basicDataSource;
|
||||
return basicDataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,17 +137,17 @@ public class AppConfig {
|
||||
nasta.setSurname("Spotakova");
|
||||
repository.save(nasta);
|
||||
|
||||
LOGGER.info("Find by id 2: {}", repository.findOne(2L));
|
||||
LOGGER.info("Find by id 2: {}", repository.findById(2L).get());
|
||||
|
||||
// Remove record from Person
|
||||
repository.delete(2L);
|
||||
repository.deleteById(2L);
|
||||
|
||||
// count records
|
||||
LOGGER.info("Count Person records: {}", repository.count());
|
||||
|
||||
// find by name
|
||||
Person p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
|
||||
LOGGER.info("Find by John is {}", p);
|
||||
Optional<Person> p = repository.findOne(new PersonSpecifications.NameEqualSpec("John"));
|
||||
LOGGER.info("Find by John is {}", p.get());
|
||||
|
||||
// find by age
|
||||
persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
|
||||
|
@ -49,7 +49,7 @@
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="packagesToScan" value="com.iluwatar" />
|
||||
<property name="persistenceProvider">
|
||||
<bean class="org.hibernate.ejb.HibernatePersistence" />
|
||||
<bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
|
||||
</property>
|
||||
<property name="jpaProperties">
|
||||
<map>
|
||||
|
@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@ -35,9 +36,8 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@ -47,7 +47,7 @@ import com.google.common.collect.Lists;
|
||||
*
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@SpringBootTest(classes = { AppConfig.class })
|
||||
public class AnnotationBasedRepositoryTest {
|
||||
|
||||
@Resource
|
||||
@ -66,7 +66,7 @@ public class AnnotationBasedRepositoryTest {
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
|
||||
repository.save(persons);
|
||||
repository.saveAll(persons);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -119,8 +119,8 @@ public class AnnotationBasedRepositoryTest {
|
||||
@Test
|
||||
public void testFindOneByNameEqualSpec() {
|
||||
|
||||
Person actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
|
||||
assertEquals(terry, actual);
|
||||
Optional<Person> actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
|
||||
assertEquals(terry, actual.get());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@ -25,9 +25,8 @@ package com.iluwatar.repository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@ -42,7 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
*
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@SpringBootTest(classes = { AppConfig.class })
|
||||
public class AppConfigTest {
|
||||
|
||||
@Autowired
|
||||
|
@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@ -35,7 +36,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@ -45,7 +46,7 @@ import com.google.common.collect.Lists;
|
||||
* by {@link org.springframework.data.jpa.domain.Specification} are also test.
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
|
||||
@SpringBootTest(properties = { "locations=classpath:applicationContext.xml" })
|
||||
public class RepositoryTest {
|
||||
|
||||
@Resource
|
||||
@ -64,7 +65,7 @@ public class RepositoryTest {
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
|
||||
repository.save(persons);
|
||||
repository.saveAll(persons);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -115,8 +116,8 @@ public class RepositoryTest {
|
||||
@Test
|
||||
public void testFindOneByNameEqualSpec() {
|
||||
|
||||
Person actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
|
||||
assertEquals(terry, actual);
|
||||
Optional<Person> actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
|
||||
assertEquals(terry, actual.get());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
Reference in New Issue
Block a user