-
Notifications
You must be signed in to change notification settings - Fork 2
Client service #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client service #12
Changes from all commits
e755cc7
8cb326a
491ebaf
77781c1
cf49023
a6e14ea
c492f40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?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> | ||
|
||
<groupId>com.lohika.jclub.client</groupId> | ||
<artifactId>client-service</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Client service</name> | ||
<description>Client service for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.5.3.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-eureka</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.16.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-feign</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.lohika.jclub.storage.client</groupId> | ||
<artifactId>storage-service-client</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
<version>1.3.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>${spring-cloud.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.spotify</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<version>1.0.0</version> | ||
<executions> | ||
<execution> | ||
<id>build-image</id> | ||
<phase>install</phase> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<imageName>client-service</imageName> | ||
<baseImage>java</baseImage> | ||
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint> | ||
<resources> | ||
<resource> | ||
<targetPath>/</targetPath> | ||
<directory>${project.build.directory}</directory> | ||
<include>${project.build.finalName}.jar</include> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.lohika.jclub.client; | ||
|
||
import com.lohika.jclub.storage.client.Apartment; | ||
import com.lohika.jclub.storage.client.StorageServiceClient; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.hateoas.PagedResources; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestController | ||
public class ClientController { | ||
|
||
@Autowired | ||
private StorageServiceClient storageServiceClient; | ||
|
||
@GetMapping("/apartments") | ||
public PagedResources<Apartment> getApartments() { | ||
PagedResources<Apartment> list = storageServiceClient.list(); | ||
return new PagedResources<>(list.getContent(), list.getMetadata()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.lohika.jclub.client; | ||
|
||
import com.lohika.jclub.storage.client.EnableStorageServiceClient; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.loadbalancer.LoadBalanced; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@SpringBootApplication | ||
@EnableStorageServiceClient | ||
public class ClientServiceApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ClientServiceApplication.class, args); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
spring.application.name=client-service | ||
server.port=8083 | ||
eureka.instance.prefer-ip-address=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
_________ __ _ | ||
/ ____/ (_)__ ____ / /_ ________ ______ __(_)_______ | ||
/ / / / / _ \/ __ \/ __/ / ___/ _ \/ ___/ | / / / ___/ _ \ | ||
/ /___/ / / __/ / / / /_ (__ ) __/ / | |/ / / /__/ __/ | ||
\____/_/_/\___/_/ /_/\__/ /____/\___/_/ |___/_/\___/\___/ | ||
|
||
v.${application.version} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.lohika.jclub.client; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class ClientServiceApplicationTests { | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.lohika.jclub.client; | ||
|
||
import com.lohika.jclub.storage.client.Apartment; | ||
import com.lohika.jclub.storage.client.StorageServiceClient; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.util.EnvironmentTestUtils; | ||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.LogMessageWaitStrategy; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = ClientServiceApplication.class) | ||
@ContextConfiguration(initializers = ClientServiceTest.Initializer.class) | ||
@AutoConfigureMockMvc | ||
public class ClientServiceTest { | ||
|
||
@ClassRule | ||
public static GenericContainer discoveryService = new GenericContainer("discovery-service:latest") | ||
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started EurekaServerApplication in.*\\s")) | ||
.withExposedPorts(8761); | ||
|
||
@Rule | ||
public GenericContainer storageService = new GenericContainer("storage-service:latest") | ||
.withExposedPorts(8091) | ||
.withEnv("eureka.client.serviceUrl.defaultZone", "http://" + discoveryService.getContainerIpAddress() + ":" + discoveryService.getMappedPort(8761) + "/eureka") | ||
.withEnv("eureka.instance.preferIpAddress", "true") | ||
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*DiscoveryClient_STORAGE-SERVICE.*registration status: 204.*\\s")); | ||
|
||
@Autowired | ||
private StorageServiceClient storageServiceClient; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
@Override | ||
public void initialize(ConfigurableApplicationContext configurableApplicationContext) { | ||
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(), | ||
"eureka.client.serviceUrl.defaultZone=http://" + discoveryService.getContainerIpAddress() + | ||
":" + discoveryService.getMappedPort(8761) + "/eureka", | ||
"storage-service.ribbon.servers=http://"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetApartments() throws Exception { | ||
// Given | ||
Apartment lviv = storageServiceClient.create( | ||
Apartment.builder() | ||
.location("LVIV") | ||
.mail("asfafs@asf.com") | ||
.phone("02510505001") | ||
.price(5225) | ||
.realtorName("Bariga") | ||
.sqft(55) | ||
.build()); | ||
|
||
// When | ||
mockMvc.perform(MockMvcRequestBuilders.get("/apartments")) | ||
.andDo(print()); | ||
|
||
// Then | ||
//TODO storageServiceClient does not creating the records. | ||
// fallback is working with 0 paging | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
feign.hystrix.enabled=true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
spring.application.name=realtor-service | ||
feign.hystrix.enabled=true | ||
feign.hystrix.enabled=true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, to separate different types of configuration and keep clean code, but lets @banadiga answer this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will affect next changes. In a case when we add a new property to the end of the file, we will get a diff with 2 line (but we changed only one.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would like to see some integration tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will create tests in next change-set using test-containers.