Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-15959
This commit is contained in:
commit
805e6b7d5b
|
@ -0,0 +1,34 @@
|
|||
package com.baeldung.java_8_features.groupingby;
|
||||
|
||||
public class Tuple {
|
||||
|
||||
private BlogPostType type;
|
||||
private String author;
|
||||
|
||||
public Tuple(BlogPostType type, String author) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public BlogPostType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(BlogPostType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tuple [type=" + type + ", author=" + author + ", getType()=" + getType() + ", getAuthor()=" + getAuthor() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";
|
||||
}
|
||||
}
|
|
@ -165,7 +165,7 @@ public class JacksonSerializationIgnoreUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public final void givenIgnoringNullFieldsOnClass_whenWritingObjectWithNullField_thenFieldIsIgnored() throws JsonProcessingException {
|
||||
public final void givenNullsIgnoredOnClass_whenWritingObjectWithNullField_thenIgnored() throws JsonProcessingException {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
final MyDtoIgnoreNull dtoObject = new MyDtoIgnoreNull();
|
||||
|
||||
|
@ -178,7 +178,7 @@ public class JacksonSerializationIgnoreUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public final void givenIgnoringNullFieldsGlobally_whenWritingObjectWithNullField_thenIgnored() throws JsonProcessingException {
|
||||
public final void givenNullsIgnoredGlobally_whenWritingObjectWithNullField_thenIgnored() throws JsonProcessingException {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||
final MyDto dtoObject = new MyDto();
|
||||
|
|
|
@ -13,9 +13,9 @@ public class GetterLazy {
|
|||
private static final String DELIMETER = ",";
|
||||
|
||||
@Getter(lazy = true)
|
||||
private final Map<String, Long> transactions = readTxnsFromFile();
|
||||
private final Map<String, Long> transactions = getTransactions();
|
||||
|
||||
private Map<String, Long> readTxnsFromFile() {
|
||||
private Map<String, Long> getTransactions() {
|
||||
|
||||
final Map<String, Long> cache = new HashMap<>();
|
||||
List<String> txnRows = readTxnListFromFile();
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.baeldung.lombok.intro;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.Synchronized;
|
||||
|
||||
public class Utility {
|
||||
|
||||
@SneakyThrows
|
||||
public String resourceAsString() throws IOException {
|
||||
try (InputStream is = this.getClass().getResourceAsStream("sure_in_my_jar.txt")) {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
return br.lines().collect(Collectors.joining("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
public void putValueInCache(String key, String value) {
|
||||
System.out.println("Thread safe here with key : [" + key + "] and value[" + value + "]");
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Hello
|
|
@ -12,7 +12,7 @@ public class ScopesIntegrationTest {
|
|||
private static final String NAME_OTHER = "Anna Jones";
|
||||
|
||||
@Test
|
||||
public void testScopeSingleton() {
|
||||
public void givenSingletonScope_whenSetName_thenEqualNames() {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
|
||||
|
||||
final Person personSingletonA = (Person) applicationContext.getBean("personSingleton");
|
||||
|
@ -25,7 +25,7 @@ public class ScopesIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testScopePrototype() {
|
||||
public void givenPrototypeScope_whenSetNames_thenDifferentNames() {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
|
||||
|
||||
final Person personPrototypeA = (Person) applicationContext.getBean("personPrototype");
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.web.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
|
||||
public class BadRequestException extends RuntimeException {
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.web.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(value = HttpStatus.NOT_FOUND)
|
||||
public class ResourceNotFoundException extends RuntimeException {
|
||||
}
|
|
@ -10,7 +10,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class BasicAuthConfiguration extends WebSecurityConfigurerAdapter {
|
||||
public class BasicConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
@ -1,27 +1,26 @@
|
|||
package com.baeldung.springbootsecurity.basic_auth;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringBootSecurityApplication.class)
|
||||
public class BasicAuthConfigurationIntegrationTest {
|
||||
public class BasicConfigurationIntegrationTest {
|
||||
|
||||
TestRestTemplate restTemplate;
|
||||
URL base;
|
||||
|
@ -45,7 +44,7 @@ public class BasicAuthConfigurationIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenUserWithWrongCredentialsRequestsHomePage_ThenUnauthorizedPage() throws IllegalStateException, IOException {
|
||||
public void whenUserWithWrongCredentials_thenUnauthorizedPage() throws IllegalStateException, IOException {
|
||||
restTemplate = new TestRestTemplate("user", "wrongpassword");
|
||||
ResponseEntity<String> response = restTemplate.getForEntity(base.toString(), String.class);
|
||||
|
|
@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -77,7 +78,7 @@ public class SpringResourceIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void whenResourceUtils_thenReadSuccessful() throws IOException {
|
||||
final File employeeFile = ResourceUtils.getFile("classpath:data/employees.dat");
|
||||
final File employeeFile = loadEmployeesWithSpringInternalClass();
|
||||
final String employees = new String(Files.readAllBytes(employeeFile.toPath()));
|
||||
assertEquals(EMPLOYEES_EXPECTED, employees);
|
||||
}
|
||||
|
@ -112,4 +113,8 @@ public class SpringResourceIntegrationTest {
|
|||
final String employees = new String(Files.readAllBytes(resource.toPath()));
|
||||
assertEquals(EMPLOYEES_EXPECTED, employees);
|
||||
}
|
||||
|
||||
public File loadEmployeesWithSpringInternalClass() throws FileNotFoundException {
|
||||
return ResourceUtils.getFile("classpath:data/employees.dat");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,39 +29,36 @@ public class KafkaConsumerConfig {
|
|||
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
|
||||
return new DefaultKafkaConsumerFactory<>(props);
|
||||
}
|
||||
|
||||
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(String groupId) {
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory(groupId));
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConcurrentKafkaListenerContainerFactory<String, String> fooKafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory("foo"));
|
||||
return factory;
|
||||
return kafkaListenerContainerFactory("foo");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConcurrentKafkaListenerContainerFactory<String, String> barKafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory("bar"));
|
||||
return factory;
|
||||
return kafkaListenerContainerFactory("bar");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConcurrentKafkaListenerContainerFactory<String, String> headersKafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory("headers"));
|
||||
return factory;
|
||||
return kafkaListenerContainerFactory("headers");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConcurrentKafkaListenerContainerFactory<String, String> partitionsKafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory("partitions"));
|
||||
return factory;
|
||||
return kafkaListenerContainerFactory("partitions");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConcurrentKafkaListenerContainerFactory<String, String> filterKafkaListenerContainerFactory() {
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||
factory.setConsumerFactory(consumerFactory("filter"));
|
||||
ConcurrentKafkaListenerContainerFactory<String, String> factory = kafkaListenerContainerFactory("filter");
|
||||
factory.setRecordFilterStrategy(record -> record.value()
|
||||
.contains("World"));
|
||||
return factory;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class MockitoInjectIntoSpyUnitTest {
|
|||
private MyDictionary spyDic;
|
||||
|
||||
@Test
|
||||
public void whenUseInjectMocksAnnotation_thenCorrect2() {
|
||||
public void whenUseInjectMocksAnnotation_thenCorrect() {
|
||||
Mockito.when(wordMap.get("aWord")).thenReturn("aMeaning");
|
||||
|
||||
assertEquals("aMeaning", spyDic.getMeaning("aWord"));
|
||||
|
|
Loading…
Reference in New Issue