fixed local conflict
This commit is contained in:
commit
7a627dff4a
@ -1,57 +1,36 @@
|
||||
package com.baeldung.string;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Created by smatt on 26/05/2017.
|
||||
*/
|
||||
public class StringToCharStream {
|
||||
|
||||
public StringToCharStream() {
|
||||
|
||||
//let's use the Stream API to manipulate a string
|
||||
//this will count the occurrence of each character in the test string
|
||||
|
||||
private StringToCharStream() {
|
||||
String testString = "tests";
|
||||
|
||||
//first get an IntStream
|
||||
IntStream intStream = testString.chars();
|
||||
IntStream intStream1 = testString.codePoints();
|
||||
|
||||
//now let's map them
|
||||
Stream<Character> characterStream = intStream.mapToObj(c -> (char) c);
|
||||
Stream<Character> characterStream1 = intStream1.mapToObj(c -> (char) c);
|
||||
|
||||
System.out.println("Counting Occurrence of Letter");
|
||||
testString = "Noww";
|
||||
|
||||
//we don't want to use foreach, so . . .
|
||||
|
||||
Map<Character, Integer> map = new HashMap<>();
|
||||
|
||||
testString.codePoints()
|
||||
Map<Character, Integer> map = "Noww".codePoints()
|
||||
.mapToObj(c -> (char) c)
|
||||
.filter(c -> Character.isLetter(c))
|
||||
.forEach(c -> {
|
||||
if(map.containsKey(c)) {
|
||||
map.put(c, map.get(c) + 1);
|
||||
} else {
|
||||
map.put(c, 1);
|
||||
}
|
||||
});
|
||||
.filter(Character::isLetter)
|
||||
.collect(Collectors.toMap(c -> c, c -> 1, Integer::sum));
|
||||
|
||||
//printing out the result here
|
||||
System.out.println(map.toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
new StringToCharStream();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,9 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by smatt on 09/06/2017.
|
||||
*/
|
||||
public class StringToCharStreamUnitTest {
|
||||
|
||||
String testString = "Tests";
|
||||
private String testString = "Tests";
|
||||
|
||||
@Test
|
||||
public void givenTestString_whenChars_thenReturnIntStream() {
|
||||
|
@ -11,6 +11,10 @@ public class Application {
|
||||
public static void main(String[] args) {
|
||||
applicationContext = SpringApplication.run(Application.class, args);
|
||||
|
||||
displayAllBeans();
|
||||
}
|
||||
|
||||
public static void displayAllBeans() {
|
||||
String[] allBeanNames = applicationContext.getBeanDefinitionNames();
|
||||
for(String beanName : allBeanNames) {
|
||||
System.out.println(beanName);
|
||||
|
@ -1,19 +0,0 @@
|
||||
package com.baeldung.displayallbeans;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import com.baeldung.displayallbeans.model.Person;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "com.baeldung.displayallbeans")
|
||||
public class SpringConfig {
|
||||
@Bean
|
||||
public Person person() {
|
||||
Person person = new Person();
|
||||
person.setName("Jon Doe");
|
||||
return person;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.baeldung.displayallbeans.controller;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.baeldung.displayallbeans.service.FooService;
|
||||
|
||||
@Controller
|
||||
public class FooController {
|
||||
@Autowired
|
||||
private FooService fooService;
|
||||
|
||||
@RequestMapping(value="/displayallbeans")
|
||||
public String getHeaderAndBody (Map<String, Object> model){
|
||||
model.put("header", fooService.getHeader());
|
||||
model.put("message", fooService.getBody());
|
||||
return "displayallbeans";
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.baeldung.displayallbeans.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.baeldung.displayallbeans.model.Person;
|
||||
|
||||
@Controller
|
||||
public class PersonController {
|
||||
@Autowired
|
||||
Person person;
|
||||
|
||||
@RequestMapping("/getPerson")
|
||||
public @ResponseBody Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.baeldung.displayallbeans.model;
|
||||
|
||||
public class Person {
|
||||
String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung.displayallbeans.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class FooService {
|
||||
|
||||
public String getHeader() {
|
||||
return "Display All Beans";
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return "This is a sample application that displays all beans "
|
||||
+ "in Spring IoC container using ListableBeanFactory interface "
|
||||
+ "and Spring Boot Actuators.";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
||||
<title>Baeldung</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2 th:text="${header}"></h2>
|
||||
<p th:text="${message}"></p>
|
||||
</body>
|
||||
</html>
|
@ -44,9 +44,8 @@ public class DisplayBeanIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenRestTemplate_whenAccessServerUrl_thenHttpStatusOK() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = this.testRestTemplate.getForEntity(
|
||||
"http://localhost:" + this.port + "/getPerson", Map.class);
|
||||
ResponseEntity<String> entity = this.testRestTemplate.getForEntity(
|
||||
"http://localhost:" + this.port + "/displayallbeans", String.class);
|
||||
|
||||
then(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
@ -69,8 +68,8 @@ public class DisplayBeanIntegrationTest {
|
||||
List<Map<String, Object>> allBeans = (List) ((Map) entity.getBody().get(0)).get("beans");
|
||||
List<String> beanNamesList = allBeans.stream().map(x -> (String) x.get("bean")).collect(Collectors.toList());
|
||||
|
||||
assertThat( beanNamesList, hasItem("personController"));
|
||||
assertThat( beanNamesList, hasItem("person"));
|
||||
assertThat( beanNamesList, hasItem("fooController"));
|
||||
assertThat( beanNamesList, hasItem("fooService"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -78,7 +77,7 @@ public class DisplayBeanIntegrationTest {
|
||||
String[] beanNames = context.getBeanDefinitionNames();
|
||||
|
||||
List<String> beanNamesList = Arrays.asList(beanNames);
|
||||
assertTrue(beanNamesList.contains("personController"));
|
||||
assertTrue(beanNamesList.contains("person"));
|
||||
assertTrue(beanNamesList.contains("fooController"));
|
||||
assertTrue(beanNamesList.contains("fooService"));
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
|
||||
|
||||
@Override
|
||||
public void registerStompEndpoints(final StompEndpointRegistry registry) {
|
||||
registry.addEndpoint("/chat");
|
||||
registry.addEndpoint("/chat").withSockJS();
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-core</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-web</artifactId>
|
||||
@ -70,6 +65,23 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
<exclude>**/*ManualTest.java</exclude>
|
||||
<exclude>**/JdbcTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
</excludes>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -16,8 +16,9 @@ public class VertxSpringApplicationIntegrationTest {
|
||||
private TestRestTemplate restTemplate = new TestRestTemplate();
|
||||
|
||||
@Test
|
||||
public void givenUrl_whenReceivedArticles_thenSuccess() {
|
||||
public void givenUrl_whenReceivedArticles_thenSuccess() throws InterruptedException {
|
||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://localhost:8080/api/baeldung/articles", String.class);
|
||||
|
||||
assertEquals(200, responseEntity.getStatusCodeValue());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user