diff --git a/README.md b/README.md index 15d8f685..2095f91e 100644 --- a/README.md +++ b/README.md @@ -1,76 +1,89 @@ -# Show me the code +# Springboot + Eureka + Zuul + Feign -### # DESAFIO: +API REST for Expense Management! -API REST para Gestão de Gastos! +###Enviroment Configuration +Redis: https://redis.io/download +Lombok: https://projectlombok.org/setup/eclipse +Lombok Tutorial: https://projectlombok.org/setup/eclipse +MySQL: https://dev.mysql.com/downloads/ +Postman: https://www.getpostman.com/downloads/ +Order to run the applications: 1. eurekaserver / 2. category-management / 3. expense-management / 4. zuul + +Note: Before you use all endpoints, I personally suggest to add some expenses first and use the same as well to search for what you need. +I didn't populated the base and all of the values below are merely illustrative. + +How to use cURL code: ``` -Funcionalidade: Integração de gastos por cartão - Apenas sistemas credenciados poderão incluir novos gastos - É esperado um volume de 100.000 inclusões por segundo - Os gastos, serão informados atraves do protoloco JSON, seguindo padrão: - { "descricao": "alfanumerico", "valor": double americano, "codigousuario": numerico, "data": Data dem formato UTC } -``` -``` -Funcionalidade: Listagem de gastos* - Dado que acesso como um cliente autenticado que pode visualizar os gastos do cartão - Quando acesso a interface de listagem de gastos - Então gostaria de ver meus gastos mais atuais. - -*Para esta funcionalidade é esperado 2.000 acessos por segundo. -*O cliente espera ver gastos realizados a 5 segundos atrás. -``` -``` -Funcionalidade: Filtro de gastos - Dado que acesso como um cliente autenticado - E acessei a interface de listagem de gastos - E configure o filtro de data igual a 27/03/1992 - Então gostaria de ver meus gastos apenas deste dia. -``` -``` -Funcionalidade: Categorização de gastos - Dado que acesso como um cliente autenticado - Quando acesso o detalhe de um gasto - E este não possui uma categoria - Então devo conseguir incluir uma categoria para este -``` -``` -Funcionalidade: Sugestão de categoria - Dado que acesso como um cliente autenticado - Quando acesso o detalhe do gasto que não possui categoria - E começo a digitar a categoria que desejo - Então uma lista de sugestões de categoria deve ser exibida, estas baseadas em categorias já informadas por outro usuários. -``` +1. Open postman.exe +2. CTRL + O +3. Choose: Past Raw Text +4. Paste the cURL code below. +5. Click on button send to run the endpoint. ``` -Funcionalidade: Categorização automatica de gasto - No processo de integração de gastos, a categoria deve ser incluida automaticamente - caso a descrição de um gasto seja igual a descrição de qualquer outro gasto já categorizado pelo cliente - o mesmo deve receber esta categoria no momento da inclusão do mesmo + +Endpoints: +Expense: ``` -### # Avaliação +* Add a new expense +POST http:localhost:8762/expense-management/expenses +cURL: +curl -X POST \ + http://http:localhost:8762/expense-management/expenses \ + -H 'Postman-Token: c79ad816-5fe0-4ea2-8647-cb4251931543' \ + -H 'cache-control: no-cache' \ + -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ + -F 'description=O homem mais rico da babilonia' \ + -F cost=30.4 \ + -F category=Leitura -Você será avaliado pela usabilidade, por respeitar o design e pela arquitetura da API. -É esperado que você consiga explicar as decisões que tomou durante o desenvolvimento através de commits. +* Update a new expense +PUT http:localhost:8762/expense-management/expenses/1 +cURL: +curl -X POST \ + http://http:localhost:8762/expense-management/expenses/1 \ + -H 'Postman-Token: de311b6c-9101-4133-ae76-05f9efc6578c' \ + -H 'cache-control: no-cache' \ + -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ + -F codUser=1 \ + -F 'description=O homem mais rico da babilonia' \ + -F cost=30.4 \ + -F category=Leitura -* Springboot - Java - Maven (preferêncialmente) ([https://projects.spring.io/spring-boot/](https://projects.spring.io/spring-boot/)) -* RESTFul ([https://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/](https://blog.mwaysolutions.com/2014/06/05/10-best-practices-for-better-restful-api/)) -* DDD ([https://airbrake.io/blog/software-design/domain-driven-design](https://airbrake.io/blog/software-design/domain-driven-design)) -* Microservices ([https://martinfowler.com/microservices/](https://martinfowler.com/microservices/)) -* Testes unitários, teste o que achar importante (De preferência JUnit + Mockito). Mas pode usar o que você tem mais experiência, só nos explique o que ele tem de bom. -* SOAPUI para testes de carga ([https://www.soapui.org/load-testing/concept.html](https://www.soapui.org/load-testing/concept.html)) -* Uso de diferentes formas de armazenamento de dados (REDIS, Cassandra, Solr/Lucene) -* Uso do git -* Diferencial: Criptografia de comunicação, com troca de chaves. ([http://noiseprotocol.org/](http://noiseprotocol.org/)) -* Diferencial: CQRS ([https://martinfowler.com/bliki/CQRS.html](https://martinfowler.com/bliki/CQRS.html)) -* Diferencial: Docker File + Docker Compose (com dbs) para rodar seus jars. +* Search for expenses by user +GET http:localhost:8762/expense-management/expenses/1 + +* Search for expenses by user in a specific date +http:localhost:8762/expense-management/expenses/1/2019-04-06 +``` -### # Observações gerais -Adicione um arquivo [README.md](http://README.md) com os procedimentos para executar o projeto. -Pedimos que trabalhe sozinho e não divulgue o resultado na internet. -Faça um fork desse desse repositório em seu Github e nos envie um Pull Request com o resultado, por favor informe por qual empresa você esta se candidatando. +Category: +``` +* Searching for similar name: Autocomplete usability +GET http:localhost:8762/category-management/categories/suggest?name=Roup +* Search by exact name +GET http:localhost:8762/category-management/category/Comida +* Add Category +POST http:localhost:8762/category-management/categories +cURL: +curl -X POST \ + http://http:localhost:8762/category-management/categories \ + -H 'Postman-Token: 87f38883-4711-4d4a-a185-87425fa7b2ac' \ + -H 'cache-control: no-cache' \ + -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ + -F name=Saques -### # Importante: não há prazo de entrega, faça com qualidade! +* Update category +http:localhost:8762/category-management/categories/1 +cURL: +curl -X POST \ + http://http:localhost:8762/category-management/categories/1 \ + -H 'Postman-Token: 86de2127-2c50-4e35-9094-af4c07bbf4e8' \ + -H 'cache-control: no-cache' \ + -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ + -F name=Saques +``` -# BOA SORTE! diff --git a/category-management/.gitignore b/category-management/.gitignore new file mode 100644 index 00000000..579cb537 --- /dev/null +++ b/category-management/.gitignore @@ -0,0 +1,4 @@ +/target/ +*.classpath +*.project +.settings/ diff --git a/category-management/pom.xml b/category-management/pom.xml new file mode 100644 index 00000000..2a9dce6f --- /dev/null +++ b/category-management/pom.xml @@ -0,0 +1,98 @@ + + 4.0.0 + br.com.camaroti.alex.rest.api + category-management + 0.0.1-SNAPSHOT + category-management + + + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.projectlombok + lombok + provided + + + + org.springframework.data + spring-data-redis + + + + redis.clients + jedis + jar + + + + mysql + mysql-connector-java + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.jayway.jsonpath + json-path + test + + + + org.springframework.boot + spring-boot-devtools + true + runtime + + + + org.mockito + mockito-all + 1.10.19 + test + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + 2.1.1.RELEASE + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/configuration/Application.java b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/configuration/Application.java new file mode 100644 index 00000000..88aad49f --- /dev/null +++ b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/configuration/Application.java @@ -0,0 +1,48 @@ +package br.com.camaroti.alex.rest.api.category.configuration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@SpringBootApplication +@EnableAutoConfiguration +@EntityScan(basePackages = { "br.com.camaroti.alex.rest.api.category.domain" }) +@ComponentScan(basePackages = { "br.com.camaroti.alex.rest.api.category.controller", + "br.com.camaroti.alex.rest.api.category.service", "class br.com.camaroti.alex.rest.api.category.domain" }) +@EnableJpaRepositories("br.com.camaroti.alex.rest.api.category.repository") +@EnableRedisRepositories("br.com.camaroti.alex.rest.api.category.service") +@EnableDiscoveryClient +public class Application { + + @Bean + JedisConnectionFactory jedisConnectionFactory() { + RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); + return new JedisConnectionFactory(config); + } + + @Bean + public RedisTemplate redisTemplate() { + final RedisTemplate template = new RedisTemplate(); + template.setConnectionFactory(jedisConnectionFactory()); + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(new StringRedisSerializer()); + template.setHashValueSerializer(new StringRedisSerializer()); + template.afterPropertiesSet(); + return template; + + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/controller/CategoryController.java b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/controller/CategoryController.java new file mode 100644 index 00000000..e9cb2e5a --- /dev/null +++ b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/controller/CategoryController.java @@ -0,0 +1,39 @@ +package br.com.camaroti.alex.rest.api.category.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import br.com.camaroti.alex.rest.api.category.domain.Category; +import br.com.camaroti.alex.rest.api.category.service.CategoryService; + +@RestController +public class CategoryController { + + @Autowired + private CategoryService categoryService; + + @GetMapping(path="/categories/suggest") + public @ResponseBody List suggestCategory(@RequestParam(value="name", required = false, defaultValue = "") String name) throws Exception { + return categoryService.findByNameContaining(name); + } + + @GetMapping(path="/category/{name}") + public @ResponseBody Category findByNameIgnoreCase(@PathVariable(value="name", required = true) String name) throws Exception { + return categoryService.findByNameIgnoreCase(name); + } + + @PostMapping(path="/categories") + public @ResponseBody Category addCategory(@RequestParam(value="name") String name) throws Exception { + Category category = new Category(); + category.setName(name); + return categoryService.save(category); + } + +} diff --git a/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/domain/Category.java b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/domain/Category.java new file mode 100644 index 00000000..c61bb6cf --- /dev/null +++ b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/domain/Category.java @@ -0,0 +1,115 @@ +package br.com.camaroti.alex.rest.api.category.domain; + +import java.io.IOException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisHash; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import br.com.camaroti.alex.rest.api.category.repository.CategoryRepository; +import lombok.AccessLevel; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Table(name = "category") +@RedisHash("category") +public @Data class Category implements Serializable { + + private final String KEY = "category"; + + /** + * + */ + private static final long serialVersionUID = 1L; + + public Category() { + + } + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int cod; + private String name; + + @Transient + @Getter(value = AccessLevel.NONE) + @Setter(value = AccessLevel.NONE) + private CategoryRepository categoryRepository; + + @Transient + @Getter(value = AccessLevel.NONE) + @Setter(value = AccessLevel.NONE) + private HashOperations hashOperations; + + public Category(CategoryRepository categoryRepository, HashOperations hashOperations) { + this.categoryRepository = categoryRepository; + this.hashOperations = hashOperations; + } + + public Category(CategoryRepository categoryRepository) { + this.categoryRepository = categoryRepository; + } + + public Category save(Category category) throws IOException { + Category newCategory = categoryRepository.save(category); + updateRedisCategoriesList(newCategory); + return newCategory; + } + + public Category findByNameIgnoreCase(String name) { + return categoryRepository.findByNameIgnoreCase(name); + } + + public List findByNameContaining(String name) throws IOException { + ObjectMapper objectMapper = checkIfRedisIsEmpty(); + Object listCategories = hashOperations.get(KEY, "1"); + List categoriesFound = new ArrayList<>(); + List categories = Arrays.asList(objectMapper.readValue(listCategories.toString(), Category[].class)); + for (Category category : categories) { + if (category.getName().trim().toLowerCase().contains(name.trim().toLowerCase())) { + categoriesFound.add(category); + } + } + return categoriesFound; + } + + private void updateRedisCategoriesList(Category newCategory) + throws IOException, JsonParseException, JsonMappingException, JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + String redisCategories = hashOperations.get(KEY, "1").toString(); + List categories = new ArrayList<>( + Arrays.asList(objectMapper.readValue(redisCategories, Category[].class))); + categories.add(newCategory); + String categoriesUpdated = objectMapper.writeValueAsString(categories); + hashOperations.put(KEY, "1", categoriesUpdated); + } + + private ObjectMapper checkIfRedisIsEmpty() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + if (hashOperations.size(KEY) == null || hashOperations.size(KEY) == 0) { + Iterable categories = categoryRepository.findAll(); + String json = objectMapper.writeValueAsString(categories); + hashOperations.put(KEY, "1", json); + } + + return objectMapper; + } + +} diff --git a/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/repository/CategoryRepository.java b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/repository/CategoryRepository.java new file mode 100644 index 00000000..1d67b775 --- /dev/null +++ b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/repository/CategoryRepository.java @@ -0,0 +1,13 @@ +package br.com.camaroti.alex.rest.api.category.repository; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; + +import br.com.camaroti.alex.rest.api.category.domain.Category; + +public interface CategoryRepository extends CrudRepository { + + Category findByNameIgnoreCase(String name); + List findByNameContainingIgnoreCase(String name); +} diff --git a/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/service/CategoryService.java b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/service/CategoryService.java new file mode 100644 index 00000000..a8b973b8 --- /dev/null +++ b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/service/CategoryService.java @@ -0,0 +1,13 @@ +package br.com.camaroti.alex.rest.api.category.service; + +import java.io.IOException; +import java.util.List; + +import br.com.camaroti.alex.rest.api.category.domain.Category; + +public interface CategoryService { + + Category findByNameIgnoreCase(String name); + List findByNameContaining(String name) throws IOException; + Category save(Category category) throws IOException; +} diff --git a/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/service/CategoryServiceImpl.java b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/service/CategoryServiceImpl.java new file mode 100644 index 00000000..ec46a6d6 --- /dev/null +++ b/category-management/src/main/java/br/com/camaroti/alex/rest/api/category/service/CategoryServiceImpl.java @@ -0,0 +1,54 @@ +package br.com.camaroti.alex.rest.api.category.service; + +import java.io.IOException; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import br.com.camaroti.alex.rest.api.category.domain.Category; +import br.com.camaroti.alex.rest.api.category.repository.CategoryRepository; + +@Service +public class CategoryServiceImpl implements CategoryService { + + + @Autowired + private RedisTemplate redisTemplate; + @Resource(name = "redisTemplate") + private HashOperations hashOperations; + + @PostConstruct + private void init() { + hashOperations = redisTemplate.opsForHash(); + } + + @Autowired + private CategoryRepository categoryRepository; + + @Override + public List findByNameContaining(String name) throws IOException { + return new Category(categoryRepository, hashOperations).findByNameContaining(name); + } + + + @Override + public Category save(Category category) throws IOException { + return new Category(categoryRepository, hashOperations).save(category); + } + + + @Override + public Category findByNameIgnoreCase(String name) { + return new Category(categoryRepository).findByNameIgnoreCase(name); + } + + + + +} diff --git a/category-management/src/main/resources/application.properties b/category-management/src/main/resources/application.properties new file mode 100644 index 00000000..4d3dd09d --- /dev/null +++ b/category-management/src/main/resources/application.properties @@ -0,0 +1,21 @@ + +#mysql config +spring.jpa.hibernate.ddl-auto=update +spring.datasource.driverClassName=com.mysql.jdbc.Driver +spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect +spring.datasource.url=jdbc:mysql://localhost:3306/db_example?useLegacyDatetimeCode=false&serverTimezone=UTC +spring.datasource.username=root +spring.datasource.password=password + + +#Pools +spring.datasource.tomcat.max-active=100000 +spring.datasource.tomcat.max-wait=10000 + +#redis +spring.redis.host=localhost +spring.redis.port=6379 + +#Spring +spring.application.name=category-management + diff --git a/eurekaserver/.gitignore b/eurekaserver/.gitignore new file mode 100644 index 00000000..153c9335 --- /dev/null +++ b/eurekaserver/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/eurekaserver/.mvn/wrapper/MavenWrapperDownloader.java b/eurekaserver/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 00000000..72308aa4 --- /dev/null +++ b/eurekaserver/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/eurekaserver/.mvn/wrapper/maven-wrapper.jar b/eurekaserver/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..01e67997 Binary files /dev/null and b/eurekaserver/.mvn/wrapper/maven-wrapper.jar differ diff --git a/eurekaserver/.mvn/wrapper/maven-wrapper.properties b/eurekaserver/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..cd0d451c --- /dev/null +++ b/eurekaserver/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/eurekaserver/mvnw b/eurekaserver/mvnw new file mode 100644 index 00000000..8b9da3b8 --- /dev/null +++ b/eurekaserver/mvnw @@ -0,0 +1,286 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/eurekaserver/mvnw.cmd b/eurekaserver/mvnw.cmd new file mode 100644 index 00000000..fef5a8f7 --- /dev/null +++ b/eurekaserver/mvnw.cmd @@ -0,0 +1,161 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/eurekaserver/pom.xml b/eurekaserver/pom.xml new file mode 100644 index 00000000..2688f7a2 --- /dev/null +++ b/eurekaserver/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + br.com.camaroti.alex + eurekaserver + 0.0.1-SNAPSHOT + eurekaserver + Eureka project for Spring Boot + + + 1.8 + Greenwich.SR1 + + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/eurekaserver/src/main/java/br/com/camaroti/alex/eurekaserver/EurekaserverApplication.java b/eurekaserver/src/main/java/br/com/camaroti/alex/eurekaserver/EurekaserverApplication.java new file mode 100644 index 00000000..03a71c75 --- /dev/null +++ b/eurekaserver/src/main/java/br/com/camaroti/alex/eurekaserver/EurekaserverApplication.java @@ -0,0 +1,15 @@ +package br.com.camaroti.alex.eurekaserver; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + +@SpringBootApplication +@EnableEurekaServer +public class EurekaserverApplication { + + public static void main(String[] args) { + SpringApplication.run(EurekaserverApplication.class, args); + } + +} diff --git a/eurekaserver/src/main/resources/application.properties b/eurekaserver/src/main/resources/application.properties new file mode 100644 index 00000000..b02576c9 --- /dev/null +++ b/eurekaserver/src/main/resources/application.properties @@ -0,0 +1,4 @@ +server.port=8761 +spring.application.name=eureka-server +eureka.client.registerWithEureka=false +eureka.client.fetchRegistry=false diff --git a/eurekaserver/src/test/java/br/com/camaroti/alex/eurekaserver/EurekaserverApplicationTests.java b/eurekaserver/src/test/java/br/com/camaroti/alex/eurekaserver/EurekaserverApplicationTests.java new file mode 100644 index 00000000..c9f69b8b --- /dev/null +++ b/eurekaserver/src/test/java/br/com/camaroti/alex/eurekaserver/EurekaserverApplicationTests.java @@ -0,0 +1,16 @@ +package br.com.camaroti.alex.eurekaserver; + +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 EurekaserverApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/expense-management/.gitignore b/expense-management/.gitignore new file mode 100644 index 00000000..579cb537 --- /dev/null +++ b/expense-management/.gitignore @@ -0,0 +1,4 @@ +/target/ +*.classpath +*.project +.settings/ diff --git a/expense-management/pom.xml b/expense-management/pom.xml new file mode 100644 index 00000000..da8dad46 --- /dev/null +++ b/expense-management/pom.xml @@ -0,0 +1,104 @@ + + 4.0.0 + br.com.camaroti.alex.rest.api + expense-management + 0.0.1-SNAPSHOT + expense-management + + + + org.springframework.boot + spring-boot-starter-parent + 2.1.3.RELEASE + + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.projectlombok + lombok + provided + + + + org.springframework.data + spring-data-redis + + + + redis.clients + jedis + jar + + + + mysql + mysql-connector-java + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.jayway.jsonpath + json-path + test + + + + org.springframework.boot + spring-boot-devtools + true + runtime + + + + org.mockito + mockito-all + 1.10.19 + test + + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + 2.1.1.RELEASE + + + + org.springframework.cloud + spring-cloud-starter-openfeign + 2.1.1.RELEASE + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/client/CategoryClient.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/client/CategoryClient.java new file mode 100644 index 00000000..0ac62301 --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/client/CategoryClient.java @@ -0,0 +1,20 @@ +package br.com.camaroti.alex.rest.api.expense.client; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import br.com.camaroti.alex.rest.api.expense.domain.Category; + +@FeignClient("category-management") +public interface CategoryClient { + + @PostMapping(path="/categories") + @ResponseBody Category save(@RequestParam(value="name") String name) throws Exception; + + @GetMapping(path="/category/{name}") + @ResponseBody Category findByNameIgnoreCase(@PathVariable(value="name", required = true) String name)throws Exception; + +} \ No newline at end of file diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/configuration/Application.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/configuration/Application.java new file mode 100644 index 00000000..0a3ac14e --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/configuration/Application.java @@ -0,0 +1,50 @@ +package br.com.camaroti.alex.rest.api.expense.configuration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@SpringBootApplication +@EnableAutoConfiguration +@EntityScan(basePackages = { "br.com.camaroti.alex.rest.api.expense.domain" }) +@ComponentScan(basePackages = { "br.com.camaroti.alex.rest.api.expense.client", + "br.com.camaroti.alex.rest.api.expense.controller", "br.com.camaroti.alex.rest.api.expense.service" }) +@EnableJpaRepositories("br.com.camaroti.alex.rest.api.expense.repository") +@EnableRedisRepositories("br.com.camaroti.alex.rest.api.expense.service") +@EnableFeignClients(basePackages = { "br.com.camaroti.alex.rest.api.expense.client" }) +@EnableDiscoveryClient +public class Application { + + @Bean + JedisConnectionFactory jedisConnectionFactory() { + RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); + return new JedisConnectionFactory(config); + } + + @Bean + public RedisTemplate redisTemplate() { + final RedisTemplate template = new RedisTemplate(); + template.setConnectionFactory(jedisConnectionFactory()); + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(new StringRedisSerializer()); + template.setHashValueSerializer(new StringRedisSerializer()); + template.afterPropertiesSet(); + return template; + + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/controller/ExpenseController.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/controller/ExpenseController.java new file mode 100644 index 00000000..ee828b2d --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/controller/ExpenseController.java @@ -0,0 +1,45 @@ +package br.com.camaroti.alex.rest.api.expense.controller; + +import java.util.Date; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import br.com.camaroti.alex.rest.api.expense.domain.Expense; +import br.com.camaroti.alex.rest.api.expense.helper.ExpenseHelper; +import br.com.camaroti.alex.rest.api.expense.service.ExpenseService; + +@RestController +public class ExpenseController { + + @Autowired + private ExpenseService expenseService; + + @PostMapping(path="/expenses") + public @ResponseBody Expense addExpense(@RequestParam int codUser + , @RequestParam String description, @RequestParam double cost, @RequestParam(value = "category", required = false) String category) throws Exception { + Expense expense = ExpenseHelper.convertExpense(codUser, description, cost, category); + return expenseService.save(expense); + } + + @GetMapping(path="/expenses/{codUser}") + public @ResponseBody Iterable findByCodUserOrderByDateDesc(@PathVariable int codUser) { + return expenseService.findByCodUserOrderByDateDesc(codUser); + } + + @GetMapping(path="/expenses/{codUser}/{date}") + public @ResponseBody Iterable findByCodUserAndDateOrderByDateDesc(@PathVariable int codUser, + @PathVariable @DateTimeFormat(pattern="yyyy-MM-dd") Long date) { + Date start = new Date(date); + Date end = new Date(date + 86399999L); + return expenseService.findByCodUserAndDateBetweenOrderByDateDesc(codUser, start, end); + } + + +} diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/domain/Category.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/domain/Category.java new file mode 100644 index 00000000..7e2594fb --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/domain/Category.java @@ -0,0 +1,11 @@ +package br.com.camaroti.alex.rest.api.expense.domain; + +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +public class Category { + + private int cod; + private String name; +} diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/domain/Expense.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/domain/Expense.java new file mode 100644 index 00000000..2cbbf56c --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/domain/Expense.java @@ -0,0 +1,102 @@ +package br.com.camaroti.alex.rest.api.expense.domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.Transient; + +import org.springframework.data.redis.core.RedisHash; + +import br.com.camaroti.alex.rest.api.expense.client.CategoryClient; +import br.com.camaroti.alex.rest.api.expense.repository.ExpenseRepository; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@RedisHash("expense") +@Getter @Setter @NoArgsConstructor +public class Expense implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int cod; + private String description; + private double value; + private int codUser; + private Date date; + @ManyToOne(optional = true) + private Category category; + + @Transient @Getter(value = AccessLevel.NONE) @Setter(value = AccessLevel.NONE) + private ExpenseRepository expenseRepository; + + @Transient @Getter(value = AccessLevel.NONE) @Setter(value = AccessLevel.NONE) + private CategoryClient categoryClient; + + public Expense(ExpenseRepository expenseRepository, CategoryClient categoryClient) { + this.expenseRepository = expenseRepository; + this.categoryClient = categoryClient; + } + + public Expense save(Expense expense) throws Exception { + checkCategoryInformation(expense); + return expenseRepository.save(expense); + } + + public List findByCodUserOrderByDateDesc(int codUser) { + return expenseRepository.findByCodUserOrderByDateDesc(codUser); + } + + public List findByCodUserAndDateBetweenOrderByDateDesc(int codUser, Date start, Date end) { + return expenseRepository.findByCodUserAndDateBetweenOrderByDateDesc(codUser, start, end); + } + + public Expense findFirstByDescriptionContainingIgnoreCaseAndCategoryNotNullOrderByDateDesc( + String description) { + return expenseRepository + .findFirstByDescriptionContainingIgnoreCaseAndCategoryNotNullOrderByDateDesc(description); + } + + private void checkCategoryInformation(Expense expense) throws Exception { + Category category = expense.getCategory(); + if (category != null && !category.getName().isEmpty()) { + saveCategoryIfNotExists(category.getName(), expense); + } else { + setSameCategoryBySimilarExpenseDescription(expense); + } + } + + private void setSameCategoryBySimilarExpenseDescription(Expense expense) { + Expense similarExpense = expenseRepository + .findFirstByDescriptionContainingIgnoreCaseAndCategoryNotNullOrderByDateDesc(expense.getDescription()); + if (similarExpense != null) { + expense.setCategory(similarExpense.getCategory()); + } else { + expense.setCategory(null); + } + } + + private void saveCategoryIfNotExists(String category, Expense expense) throws Exception { + Category categoryObj = categoryClient.findByNameIgnoreCase(category); + if (categoryObj != null) { + expense.setCategory(categoryObj); + } else { + setSameCategoryBySimilarExpenseDescription(expense); + if (expense.getCategory() == null) { + Category newCategory = categoryClient.save(category); + expense.setCategory(newCategory); + } + } + } + +} diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/helper/ExpenseHelper.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/helper/ExpenseHelper.java new file mode 100644 index 00000000..c77d90ca --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/helper/ExpenseHelper.java @@ -0,0 +1,22 @@ +package br.com.camaroti.alex.rest.api.expense.helper; + +import java.util.Date; + +import br.com.camaroti.alex.rest.api.expense.domain.Category; +import br.com.camaroti.alex.rest.api.expense.domain.Expense; + +public class ExpenseHelper { + + public static Expense convertExpense(int codUser, String description, double cost, String category) { + Expense expense = new Expense(); + Category categoryObj = new Category(); + expense.setCodUser(codUser); + expense.setDate(new Date()); + expense.setDescription(description); + expense.setValue(cost); + categoryObj.setName(category); + expense.setCategory(categoryObj); + return expense; + } + +} diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/repository/ExpenseRepository.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/repository/ExpenseRepository.java new file mode 100644 index 00000000..1c603618 --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/repository/ExpenseRepository.java @@ -0,0 +1,18 @@ +package br.com.camaroti.alex.rest.api.expense.repository; + +import java.util.Date; +import java.util.List; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import br.com.camaroti.alex.rest.api.expense.domain.Expense; + +@Repository +public interface ExpenseRepository extends CrudRepository { + + ListfindByCodUserOrderByDateDesc(int codUser); + ListfindByCodUserAndDateBetweenOrderByDateDesc(int codUser, Date start, Date end); + Expense findFirstByDescriptionContainingIgnoreCaseAndCategoryNotNullOrderByDateDesc(String description); + +} diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseService.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseService.java new file mode 100644 index 00000000..66db5ef5 --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseService.java @@ -0,0 +1,14 @@ +package br.com.camaroti.alex.rest.api.expense.service; + +import java.util.Date; +import java.util.List; + +import br.com.camaroti.alex.rest.api.expense.domain.Expense; + +public interface ExpenseService { + + Expense save(Expense expense) throws Exception; + List findByCodUserOrderByDateDesc(int codUser); + List findByCodUserAndDateBetweenOrderByDateDesc(int codUser, Date start, Date end); + +} diff --git a/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseServiceImpl.java b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseServiceImpl.java new file mode 100644 index 00000000..b89ca32b --- /dev/null +++ b/expense-management/src/main/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseServiceImpl.java @@ -0,0 +1,39 @@ +package br.com.camaroti.alex.rest.api.expense.service; + +import java.util.Date; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import br.com.camaroti.alex.rest.api.expense.client.CategoryClient; +import br.com.camaroti.alex.rest.api.expense.domain.Expense; +import br.com.camaroti.alex.rest.api.expense.repository.ExpenseRepository; + +@Service +public class ExpenseServiceImpl implements ExpenseService{ + + @Autowired + private ExpenseRepository expenseRepository; + + @Autowired + private CategoryClient categoryClient; + + + @Override + public Expense save(Expense expense) throws Exception { + return new Expense(expenseRepository, categoryClient).save(expense); + } + + @Override + public List findByCodUserOrderByDateDesc(int codUser) { + return new Expense(expenseRepository, categoryClient).findByCodUserOrderByDateDesc(codUser); + } + + @Override + public List findByCodUserAndDateBetweenOrderByDateDesc(int codUser, Date start, Date end) { + return new Expense(expenseRepository, categoryClient).findByCodUserAndDateBetweenOrderByDateDesc(codUser, start, end); + } + + +} diff --git a/expense-management/src/main/resources/application.properties b/expense-management/src/main/resources/application.properties new file mode 100644 index 00000000..479b8c86 --- /dev/null +++ b/expense-management/src/main/resources/application.properties @@ -0,0 +1,21 @@ +server.port=8081 +#mysql config +spring.jpa.hibernate.ddl-auto=update +spring.datasource.driverClassName=com.mysql.jdbc.Driver +spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect +spring.datasource.url=jdbc:mysql://localhost:3306/db_example?useLegacyDatetimeCode=false&serverTimezone=UTC +spring.datasource.username=root +spring.datasource.password=password + + +#Pools +spring.datasource.tomcat.max-active=100000 +spring.datasource.tomcat.max-wait=10000 + +#redis +spring.redis.host=localhost +spring.redis.port=6379 + +#Spring +spring.application.name=expense-management + diff --git a/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/builder/CategoryBuilder.java b/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/builder/CategoryBuilder.java new file mode 100644 index 00000000..3fbf73f0 --- /dev/null +++ b/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/builder/CategoryBuilder.java @@ -0,0 +1,34 @@ +package br.com.camaroti.alex.rest.api.expense.builder; + +import br.com.camaroti.alex.rest.api.expense.domain.Category; + +public class CategoryBuilder { + + public static final int DEFAULT_COD = 1; + public static final String DEFAULT_NAME = "Category Name"; + + private int cod = DEFAULT_COD; + private String name = DEFAULT_NAME; + + public static CategoryBuilder aCategory() { + return new CategoryBuilder(); + } + + public CategoryBuilder withCod(int cod) { + this.cod = cod; + return this; + } + + public CategoryBuilder withName(String name) { + this.name = name; + return this; + } + + public Category build() { + Category c = new Category(); + c.setCod(cod); + c.setName(name); + return c; + } + +} diff --git a/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/builder/ExpenseBuilder.java b/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/builder/ExpenseBuilder.java new file mode 100644 index 00000000..00adbf32 --- /dev/null +++ b/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/builder/ExpenseBuilder.java @@ -0,0 +1,70 @@ +package br.com.camaroti.alex.rest.api.expense.builder; + +import java.util.Date; + +import br.com.camaroti.alex.rest.api.expense.domain.Category; +import br.com.camaroti.alex.rest.api.expense.domain.Expense; + +public class ExpenseBuilder { + + public static final int DEFAULT_COD = 1; + public static final int DEFAULT_CODUSER = 1; + public static final Date DEFAULT_DATE = new Date(); + public static final String DEFAULT_DESCRIPTION = "Expense Description Test"; + public static final double DEFAULT_VALUE = 20.5; + public static final Category DEFAULT_CATEGORY = CategoryBuilder.aCategory().build(); + + private int cod = DEFAULT_COD; + private int codUser = DEFAULT_CODUSER; + private Date date = DEFAULT_DATE; + private String description = DEFAULT_DESCRIPTION; + private double value = DEFAULT_VALUE; + private Category category = DEFAULT_CATEGORY; + + public static ExpenseBuilder anExpense() { + return new ExpenseBuilder(); + } + + public ExpenseBuilder withCod(int cod) { + this.cod = cod; + return this; + } + + public ExpenseBuilder withCodUser(int codUser) { + this.codUser = codUser; + return this; + } + + public ExpenseBuilder withDescription(String description) { + this.description = description; + return this; + } + + public ExpenseBuilder withValue(double value) { + this.value = value; + return this; + } + + public ExpenseBuilder withCategory(Category category) { + this.category = category; + return this; + } + + public ExpenseBuilder withoutCategory() { + this.category = null; + return this; + } + + public Expense build() { + Expense e = new Expense(); + e.setCod(cod); + e.setCodUser(codUser); + e.setDate(date); + e.setDescription(description); + e.setValue(value); + e.setCategory(category); + return e; + } + + +} diff --git a/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseServiceImplTest.java b/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseServiceImplTest.java new file mode 100644 index 00000000..a4661391 --- /dev/null +++ b/expense-management/src/test/java/br/com/camaroti/alex/rest/api/expense/service/ExpenseServiceImplTest.java @@ -0,0 +1,77 @@ +package br.com.camaroti.alex.rest.api.expense.service; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import br.com.camaroti.alex.rest.api.expense.builder.CategoryBuilder; +import br.com.camaroti.alex.rest.api.expense.builder.ExpenseBuilder; +import br.com.camaroti.alex.rest.api.expense.client.CategoryClient; +import br.com.camaroti.alex.rest.api.expense.domain.Category; +import br.com.camaroti.alex.rest.api.expense.domain.Expense; +import br.com.camaroti.alex.rest.api.expense.repository.ExpenseRepository; + +@RunWith(MockitoJUnitRunner.class) +public class ExpenseServiceImplTest { + + @InjectMocks + private ExpenseServiceImpl expenseService; + + @Mock + private CategoryClient categoryClient; + + @Mock + private ExpenseRepository expenseRepository; + + private Expense expense1, expense2, expense4; + private Category category3; + + @Before + public void setUp() { + expense1 = ExpenseBuilder.anExpense() + .withDescription("Mc Lanche Feliz") + .withValue(25.90) + .withCategory( + CategoryBuilder.aCategory() + .withName("Food").build()) + .build(); + expense2 = ExpenseBuilder.anExpense().withoutCategory().build(); + category3 = CategoryBuilder.aCategory().withCod(2).withName("Entertainment").build(); + expense4 = ExpenseBuilder.anExpense().withCod(4).withDescription("Cinema: Shazam!").withValue(35.0).withCategory( + CategoryBuilder.aCategory().withCod(3).withName("Entertainment").build()).build(); + } + + @Test + public void saveExpenseWithNewCategory() throws Exception { + Mockito.when(categoryClient.findByNameIgnoreCase(expense1.getCategory().getName())).thenReturn(null); + Mockito.when(expenseRepository.save(expense1)).thenReturn(expense1); + Mockito.when(categoryClient.save(expense1.getCategory().getName())).thenReturn(expense1.getCategory()); + Expense expenseSaved = expenseService.save(expense1); + assertEquals(expense1, expenseSaved); + Mockito.verify(categoryClient, Mockito.times(1)).save(expense1.getCategory().getName()); + } + + @Test + public void saveExpenseBySimilarDescription() throws Exception { + Mockito.when(expenseRepository + .findFirstByDescriptionContainingIgnoreCaseAndCategoryNotNullOrderByDateDesc(expense2.getDescription())) + .thenReturn(expense1); + Mockito.when(expenseRepository.save(expense2)).thenReturn(expense2); + Expense expenseSavedWithoutCategory = expenseService.save(expense2); + assertEquals(expense1.getCategory(), expenseSavedWithoutCategory.getCategory()); + } + + @Test + public void saveExpenseBySimilarCategoryDescription() throws Exception { + Mockito.when(categoryClient.findByNameIgnoreCase(expense4.getCategory().getName())).thenReturn(category3); + expenseService.save(expense4); + Mockito.verify(categoryClient, Mockito.times(1)).findByNameIgnoreCase(expense4.getCategory().getName()); + assertEquals(category3, expense4.getCategory()); + } +} diff --git a/zuul/.gitignore b/zuul/.gitignore new file mode 100644 index 00000000..153c9335 --- /dev/null +++ b/zuul/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/zuul/.mvn/wrapper/MavenWrapperDownloader.java b/zuul/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 00000000..72308aa4 --- /dev/null +++ b/zuul/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,114 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/zuul/.mvn/wrapper/maven-wrapper.jar b/zuul/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..01e67997 Binary files /dev/null and b/zuul/.mvn/wrapper/maven-wrapper.jar differ diff --git a/zuul/.mvn/wrapper/maven-wrapper.properties b/zuul/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..cd0d451c --- /dev/null +++ b/zuul/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip diff --git a/zuul/mvnw b/zuul/mvnw new file mode 100644 index 00000000..8b9da3b8 --- /dev/null +++ b/zuul/mvnw @@ -0,0 +1,286 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/zuul/mvnw.cmd b/zuul/mvnw.cmd new file mode 100644 index 00000000..fef5a8f7 --- /dev/null +++ b/zuul/mvnw.cmd @@ -0,0 +1,161 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/zuul/pom.xml b/zuul/pom.xml new file mode 100644 index 00000000..1b5ee6f6 --- /dev/null +++ b/zuul/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.4.RELEASE + + + br.com.camaroti.alex + zuul + 0.0.1-SNAPSHOT + zuul + Demo project for Spring Boot + + + 1.8 + Greenwich.SR1 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.cloud + spring-cloud-starter-netflix-zuul + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/zuul/src/main/java/br/com/camaroti/alex/zuul/ZuulApplication.java b/zuul/src/main/java/br/com/camaroti/alex/zuul/ZuulApplication.java new file mode 100644 index 00000000..641e1061 --- /dev/null +++ b/zuul/src/main/java/br/com/camaroti/alex/zuul/ZuulApplication.java @@ -0,0 +1,17 @@ +package br.com.camaroti.alex.zuul; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; + +@EnableZuulProxy +@SpringBootApplication +@EnableDiscoveryClient +public class ZuulApplication { + + public static void main(String[] args) { + SpringApplication.run(ZuulApplication.class, args); + } + +} diff --git a/zuul/src/main/resources/application.properties b/zuul/src/main/resources/application.properties new file mode 100644 index 00000000..02314828 --- /dev/null +++ b/zuul/src/main/resources/application.properties @@ -0,0 +1,12 @@ +server.port=8762 +#Spring +spring.application.name=zuul + +#eureka +eureka.instance.preferIpAddress=false +eureka.serviceurl.defaultzone=http://localhost:8761/ +eureka.client.fetchRegistry=true +eureka.instance.hostname=localhost + +#actuator endpoint +management.endpoints.web.exposure.include=* \ No newline at end of file diff --git a/zuul/src/test/java/br/com/camaroti/alex/zuul/ZuulApplicationTests.java b/zuul/src/test/java/br/com/camaroti/alex/zuul/ZuulApplicationTests.java new file mode 100644 index 00000000..dd1c44bc --- /dev/null +++ b/zuul/src/test/java/br/com/camaroti/alex/zuul/ZuulApplicationTests.java @@ -0,0 +1,16 @@ +package br.com.camaroti.alex.zuul; + +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 ZuulApplicationTests { + + @Test + public void contextLoads() { + } + +}