merge conflict
This commit is contained in:
commit
6528ce5356
@ -19,7 +19,5 @@ public class CyclicBarrierExample {
|
||||
t2.start();
|
||||
t3.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,5 +21,4 @@ public class Task implements Runnable {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ public class Rectangle extends Shape {
|
||||
private double width;
|
||||
private double length;
|
||||
|
||||
public Rectangle(double width, double length) {
|
||||
Rectangle(double width, double length) {
|
||||
this.width = width;
|
||||
this.length = length;
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.baeldung.executable;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.*;
|
||||
|
||||
public class ExecutableMavenJar {
|
||||
|
||||
public static void main(String[] args) {
|
||||
JOptionPane.showMessageDialog(null, "It worked!", "Executable Jar with Maven", 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.baeldung.destructuringdeclarations
|
||||
|
||||
import com.baeldung.destructuringdeclarations.Person
|
||||
import com.baeldung.destructuringdeclarations.Result
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
@ -13,20 +12,15 @@ fun main(args: Array<String>) {
|
||||
println(name) //Jon Snow
|
||||
println(age) //20
|
||||
|
||||
//The equivalent of line 10
|
||||
/* val id = person.component1();
|
||||
val name = person.component2();
|
||||
val age = person.component3();*/
|
||||
|
||||
//2.2. Functions
|
||||
fun getPersonInfo() = Person(2, "Ned Stark", 45)
|
||||
val(idf, namef, agef) = getPersonInfo()
|
||||
|
||||
fun twoValuesReturn(): Result {
|
||||
fun twoValuesReturn(): Pair<Int, String> {
|
||||
|
||||
// needed code
|
||||
|
||||
return Result(1, "success")
|
||||
return Pair(1, "success")
|
||||
}
|
||||
|
||||
// Now, to use this function:
|
||||
@ -41,15 +35,10 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
//2.4. Underscore and Destructuring in Lambdas
|
||||
val (_, status2) = twoValuesReturn()
|
||||
val (_, name2, age2) = person
|
||||
val (id3, name3) = person
|
||||
|
||||
map.mapValues { entry -> "${entry.value}!" }
|
||||
map.mapValues { (key, value) -> "$value!" }
|
||||
|
||||
//A pair of parameters vs. a destructuring pair
|
||||
/* { a -> ... } // one parameter
|
||||
{ a, b -> ... } // two parameters
|
||||
{ (a, b) -> ... } // a destructured pair
|
||||
{ (a, b), c -> ... } // a destructured pair and another parameter*/
|
||||
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
package com.baeldung.circularfifoqueue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.collections4.queue.CircularFifoQueue;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CircularFifoQueueTest {
|
||||
|
||||
private static final int DEFAULT_SIZE = 32;
|
||||
|
||||
private static final int FIXED_SIZE = 5;
|
||||
|
||||
private static final int COLLECTION_SIZE = 7;
|
||||
|
||||
private static final String TEST_COLOR = "Red";
|
||||
|
||||
private static final String TEST_COLOR_BY_INDEX = "Blue";
|
||||
|
||||
@Test
|
||||
public void whenUsingDefualtConstructor_correctSizeQueue() {
|
||||
CircularFifoQueue<String> bits = new CircularFifoQueue<>();
|
||||
|
||||
Assert.assertEquals(DEFAULT_SIZE, bits.maxSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAddElements_whenUsingIntConstructor_correctSizeQueue() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
Assert.assertEquals(FIXED_SIZE, colors.maxSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingCollectionConstructor_correctSizeQueue() {
|
||||
List<String> days = new ArrayList<>();
|
||||
days.add("Monday");
|
||||
days.add("Tuesday");
|
||||
days.add("Wednesday");
|
||||
days.add("Thursday");
|
||||
days.add("Friday");
|
||||
days.add("Saturday");
|
||||
days.add("Sunday");
|
||||
|
||||
CircularFifoQueue<String> daysOfWeek = new CircularFifoQueue<>(days);
|
||||
|
||||
Assert.assertEquals(COLLECTION_SIZE, daysOfWeek.maxSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAddElements_whenGetElement_correctElement() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
Assert.assertEquals(TEST_COLOR_BY_INDEX, colors.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAddElements_whenPollElement_correctElement() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
Assert.assertEquals(TEST_COLOR, colors.poll());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAddElements_whenPeekQueue_correctElement() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
Assert.assertEquals(TEST_COLOR, colors.peek());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAddElements_whenElementQueue_correctElement() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
Assert.assertEquals(TEST_COLOR, colors.element());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAddElements_whenRemoveElement_correctElement() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
Assert.assertEquals(TEST_COLOR, colors.remove());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFullQueue_whenClearQueue_getIsEmpty() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
colors.clear();
|
||||
|
||||
Assert.assertEquals(true, colors.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFullQueue_whenCheckFull_getIsFull() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
Assert.assertEquals(false, colors.isFull());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFullQueue_whenAddMoreElements_getIsAtFullCapacity() {
|
||||
CircularFifoQueue<String> colors = new CircularFifoQueue<>(5);
|
||||
colors.add("Red");
|
||||
colors.add("Blue");
|
||||
colors.add("Green");
|
||||
colors.offer("White");
|
||||
colors.offer("Black");
|
||||
|
||||
colors.add("Orange");
|
||||
colors.add("Violet");
|
||||
colors.add("Pink");
|
||||
|
||||
Assert.assertEquals(true, colors.isAtFullCapacity());
|
||||
}
|
||||
|
||||
}
|
@ -44,10 +44,9 @@ public class PCollectionsUnitTest {
|
||||
Map map = new HashMap();
|
||||
map.put("key2", "val2");
|
||||
map.put("key3", "val3");
|
||||
|
||||
HashPMap<String, String> pmap1 = pmap0.plusAll(map);
|
||||
|
||||
HashPMap<String, String> pmap2 = pmap1.minus("key1");
|
||||
|
||||
HashPMap<String, String> pmap3 = pmap2.minusAll(map.keySet());
|
||||
|
||||
assertEquals(pmap0.size(), 1);
|
||||
@ -79,6 +78,7 @@ public class PCollectionsUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenMapPSetMethods_thenPerformOperations() {
|
||||
|
||||
MapPSet pSet = HashTreePSet.empty()
|
||||
.plusAll(Arrays.asList("e1","e2","e3","e4"));
|
||||
assertEquals(pSet.size(), 4);
|
||||
|
9
pom.xml
9
pom.xml
@ -12,6 +12,9 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<gib.referenceBranch>refs/heads/master</gib.referenceBranch>
|
||||
<gib.skipTestsForNotImpactedModules>true</gib.skipTestsForNotImpactedModules>
|
||||
<gib.failOnMissingGitDir>false</gib.failOnMissingGitDir>
|
||||
<gib.failOnError>false</gib.failOnError>
|
||||
<!-- <gib.enabled>false</gib.enabled>-->
|
||||
<junit.version>4.12</junit.version>
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
@ -328,11 +331,11 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
<extensions>
|
||||
<!--<extension>
|
||||
<extension>
|
||||
<groupId>com.vackosar.gitflowincrementalbuilder</groupId>
|
||||
<artifactId>gitflow-incremental-builder</artifactId>
|
||||
<version>3.1</version>
|
||||
</extension>-->
|
||||
<version>3.4</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -12,6 +12,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<ratpack.version>1.4.6</ratpack.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
@ -21,20 +22,28 @@
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ratpack</groupId>
|
||||
<artifactId>ratpack-spring-boot-starter</artifactId>
|
||||
<version>${ratpack.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.ratpack</groupId>
|
||||
<artifactId>ratpack-core</artifactId>
|
||||
<version>1.4.5</version>
|
||||
<version>${ratpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.ratpack</groupId>
|
||||
<artifactId>ratpack-hikari</artifactId>
|
||||
<version>1.4.5</version>
|
||||
<version>${ratpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.ratpack</groupId>
|
||||
<artifactId>ratpack-test</artifactId>
|
||||
<version>1.4.5</version>
|
||||
<version>${ratpack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
|
11
ratpack/src/main/java/com/baeldung/spring/ArticleList.java
Normal file
11
ratpack/src/main/java/com/baeldung/spring/ArticleList.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public interface ArticleList {
|
||||
|
||||
List<String> articles();
|
||||
}
|
24
ratpack/src/main/java/com/baeldung/spring/Config.java
Normal file
24
ratpack/src/main/java/com/baeldung/spring/Config.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@Configuration
|
||||
public class Config {
|
||||
|
||||
@Bean
|
||||
public Content content() {
|
||||
return () -> "hello baeldung!";
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ArticleList articles() {
|
||||
return () -> Arrays.asList("Introduction to Ratpack", "Ratpack Google Guice Integration", "Ratpack Spring Boot Integration");
|
||||
}
|
||||
|
||||
}
|
10
ratpack/src/main/java/com/baeldung/spring/Content.java
Normal file
10
ratpack/src/main/java/com/baeldung/spring/Content.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public interface Content {
|
||||
|
||||
String body();
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import ratpack.func.Action;
|
||||
import ratpack.handling.Chain;
|
||||
import ratpack.server.ServerConfig;
|
||||
import ratpack.spring.config.EnableRatpack;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableRatpack
|
||||
public class EmbedRatpackApp {
|
||||
|
||||
@Autowired private Content content;
|
||||
@Autowired private ArticleList list;
|
||||
|
||||
@Bean
|
||||
public Action<Chain> hello() {
|
||||
return chain -> chain.get("hello", ctx -> ctx.render(content.body()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Action<Chain> list() {
|
||||
return chain -> chain.get("list", ctx -> ctx.render(list
|
||||
.articles()
|
||||
.toString()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServerConfig ratpackServerConfig() {
|
||||
return ServerConfig
|
||||
.builder()
|
||||
.findBaseDir("public")
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EmbedRatpackApp.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import ratpack.server.RatpackServer;
|
||||
|
||||
import static ratpack.spring.Spring.spring;
|
||||
|
||||
public class EmbedSpringBootApp {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
RatpackServer.start(server -> server
|
||||
.registry(spring(Config.class))
|
||||
.handlers(chain -> chain.get(ctx -> ctx.render(ctx
|
||||
.get(Content.class)
|
||||
.body()))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
10
ratpack/src/main/resources/public/index.html
Normal file
10
ratpack/src/main/resources/public/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Special Static Resource</title>
|
||||
</head>
|
||||
<body>
|
||||
This page is static.
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,41 @@
|
||||
package com.baeldung.spring;
|
||||
|
||||
import org.junit.Test;
|
||||
import ratpack.test.MainClassApplicationUnderTest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
public class EmbedRatpackAppIntegrationTest {
|
||||
|
||||
MainClassApplicationUnderTest appUnderTest = new MainClassApplicationUnderTest(EmbedRatpackApp.class);
|
||||
|
||||
@Test
|
||||
public void whenSayHello_thenGotWelcomeMessage() {
|
||||
assertEquals("hello baeldung!", appUnderTest
|
||||
.getHttpClient()
|
||||
.getText("/hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestList_thenGotArticles() throws IOException {
|
||||
assertEquals(3, appUnderTest
|
||||
.getHttpClient()
|
||||
.getText("/list")
|
||||
.split(",").length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestStaticResource_thenGotStaticContent() {
|
||||
assertThat(appUnderTest
|
||||
.getHttpClient()
|
||||
.getText("/"), containsString("page is static"));
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<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>
|
||||
<groupId>org.baeldung.springboot.rest</groupId>
|
||||
<artifactId>difference-uri-url-rest</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.2.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@ -1,21 +0,0 @@
|
||||
package com.baeldung.springboot.rest;
|
||||
|
||||
public class Greeting {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id = null;
|
||||
private String content = null;
|
||||
|
||||
public Greeting(Integer id) {
|
||||
this.id = id;
|
||||
this.content = "Hello World";
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.baeldung.springboot.rest;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("/")
|
||||
@Component
|
||||
public class GreetingController {
|
||||
|
||||
private final AtomicLong counter = new AtomicLong();
|
||||
|
||||
@RequestMapping(value = "/greetings", method = RequestMethod.GET)
|
||||
public Greeting greeting() {
|
||||
|
||||
return new Greeting(new Integer((int) counter.incrementAndGet()));
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.baeldung.springboot.rest;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootApplication
|
||||
public class SpringBootWebApplication extends SpringBootServletInitializer {
|
||||
|
||||
// method for explicit deployment on Application Server
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(SpringBootWebApplication.class);
|
||||
}
|
||||
|
||||
// run it as standalone JAVA application
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SpringBootWebApplication.class, args);
|
||||
}
|
||||
|
||||
//Samples
|
||||
// http://localhost:8080/greetings
|
||||
// http://localhost:8989/difference-uri-url-rest/greetings
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.baeldung.springboot.rest.client;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
public class ApplicationClient {
|
||||
//private static final Logger log = LoggerFactory.getLogger(ApplicationClient.class);
|
||||
final static String URI_STRING = "http://localhost:8080/difference-uri-url-rest/greetings";
|
||||
|
||||
|
||||
public ApplicationClient() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Greeting init() {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
Greeting greeting = restTemplate.getForObject(ApplicationClient.URI_STRING, Greeting.class);
|
||||
//log.info(greeting.toString());
|
||||
return greeting;
|
||||
}
|
||||
public static void main(String args[]) {
|
||||
Greeting greeting = new ApplicationClient().init();
|
||||
System.out.println(greeting.toString());
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.baeldung.springboot.rest.client;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Greeting implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id = null;
|
||||
private String content = null;
|
||||
|
||||
/** Default constructor is mandatory for client */
|
||||
public Greeting() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Greeting(Integer id) {
|
||||
this.id = id;
|
||||
this.content = "Hello World";
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Id: " + getId().toString() + " Content: " + getContent();
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.baeldung.springboot.rest.test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.baeldung.springboot.rest.client.Greeting;
|
||||
|
||||
public class DifferenceURIURLRESTTest {
|
||||
final static String URI_STRING = "http://localhost:8080/difference-uri-url-rest/greetings";
|
||||
static RestTemplate restTemplate;
|
||||
Greeting greeting;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupTest() {
|
||||
restTemplate = new RestTemplate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRestTenplate_whenIsNotNull_thenSuccess() {
|
||||
assertNotNull("Rest Template not null", restTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWiredConstructorParam_whenIsNotNull_thenSuccess() {
|
||||
greeting = restTemplate.getForObject(URI_STRING, Greeting.class);
|
||||
assertNotNull("Greeting class is not null", greeting);
|
||||
}
|
||||
|
||||
}
|
@ -17,7 +17,7 @@ public class DataProducerController {
|
||||
return "Hello world";
|
||||
}
|
||||
|
||||
@GetMapping(value = "/get-image")
|
||||
@GetMapping("/get-image")
|
||||
public @ResponseBody byte[] getImage() throws IOException {
|
||||
final InputStream in = getClass().getResourceAsStream("/com/baeldung/produceimage/image.jpg");
|
||||
return IOUtils.toByteArray(in);
|
||||
|
@ -14,5 +14,4 @@ public class Application extends SpringBootServletInitializer {
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -14,11 +14,11 @@ import com.baeldung.web.log.util.RequestLoggingUtil;
|
||||
@Component
|
||||
public class TaxiFareRequestInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
Logger LOGGER = LoggerFactory.getLogger(TaxiFareRequestInterceptor.class);
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(TaxiFareRequestInterceptor.class);
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
String postData = null;
|
||||
String postData;
|
||||
HttpServletRequest requestCacheWrapperObject = null;
|
||||
try {
|
||||
// Uncomment to produce the stream closed issue
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.baeldung.web.log.config;
|
||||
|
||||
import com.baeldung.web.log.app.TaxiFareRequestInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import com.baeldung.web.log.app.TaxiFareRequestInterceptor;
|
||||
|
||||
@Configuration
|
||||
public class TaxiFareMVCConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
|
@ -6,16 +6,17 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.baeldung.web.log.data.RateCard;
|
||||
import com.baeldung.web.log.data.TaxiRide;
|
||||
import com.baeldung.web.log.service.TaxiFareCalculatorService;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
public class TaxiFareController {
|
||||
|
||||
@Autowired
|
||||
@ -23,15 +24,13 @@ public class TaxiFareController {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaxiFareController.class);
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/taxifare/get/")
|
||||
@ResponseBody
|
||||
@GetMapping("/taxifare/get/")
|
||||
public RateCard getTaxiFare() {
|
||||
LOGGER.debug("getTaxiFare() - START");
|
||||
return new RateCard();
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/taxifare/calculate/")
|
||||
@ResponseBody
|
||||
@PostMapping("/taxifare/calculate/")
|
||||
public String calculateTaxiFare(@RequestBody @Valid TaxiRide taxiRide) {
|
||||
LOGGER.debug("calculateTaxiFare() - START");
|
||||
String totalFare = taxiFareCalculatorService.calculateFare(taxiRide);
|
||||
|
@ -14,12 +14,15 @@ public class RateCard {
|
||||
public String getNightSurcharge() {
|
||||
return nightSurcharge;
|
||||
}
|
||||
|
||||
public void setNightSurcharge(String nightSurcharge) {
|
||||
this.nightSurcharge = nightSurcharge;
|
||||
}
|
||||
|
||||
public String getRatePerMile() {
|
||||
return ratePerMile;
|
||||
}
|
||||
|
||||
public void setRatePerMile(String ratePerMile) {
|
||||
this.ratePerMile = ratePerMile;
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ public class TaxiRide {
|
||||
private Boolean isNightSurcharge;
|
||||
private Long distanceInMile;
|
||||
|
||||
public TaxiRide(){}
|
||||
public TaxiRide() {
|
||||
}
|
||||
|
||||
public TaxiRide(Boolean isNightSurcharge, Long distanceInMile) {
|
||||
this.isNightSurcharge = isNightSurcharge;
|
||||
|
@ -1,20 +1,14 @@
|
||||
package com.baeldung.web.log.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.web.log.data.TaxiRide;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TaxiFareCalculatorService {
|
||||
|
||||
public String calculateFare(TaxiRide taxiRide) {
|
||||
Long fare = 0l;
|
||||
if (taxiRide.getIsNightSurcharge()) {
|
||||
fare = taxiRide.getDistanceInMile() * 10 + 100;
|
||||
} else {
|
||||
fare = taxiRide.getDistanceInMile() * 10;
|
||||
return String.valueOf((Long) (taxiRide.getIsNightSurcharge()
|
||||
? taxiRide.getDistanceInMile() * 10 + 100
|
||||
: taxiRide.getDistanceInMile() * 10));
|
||||
}
|
||||
return String.valueOf(fare);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,5 +12,4 @@ public class MainApplication extends WebMvcConfigurerAdapter {
|
||||
public static void main(final String[] args) {
|
||||
SpringApplication.run(MainApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package org.baeldung.repository;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.baeldung.web.dto.HeavyResource;
|
||||
import org.baeldung.web.dto.HeavyResourceAddressOnly;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HeavyResourceRepository {
|
||||
|
||||
public void save(HeavyResource heavyResource) {
|
||||
@ -21,6 +21,7 @@ public class HeavyResourceRepository {
|
||||
public void save(HeavyResource heavyResource, String id) {
|
||||
|
||||
}
|
||||
|
||||
public void save(HeavyResourceAddressOnly partialUpdate, String id) {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user