Skip to content

Commit

Permalink
Added new checkstyle guide and fixed issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
R4il committed Mar 13, 2018
1 parent 5afb644 commit bdc4366
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 254 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ contracts {
}

checkstyle {
toolVersion = "8.7"
configFile = new File(rootDir, "checkstyle.xml")
}

Expand Down
391 changes: 183 additions & 208 deletions checkstyle.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ public class TripEventHandler {
public TripEventHandler() {}

@EventHandler
public void on(TripCreatedEvent event){
public void on(TripCreatedEvent event) {
LOG.info("Trip created: {}", event.getId());
tripRepository.save(new Trip(event.getId(), event.getUserId(),
event.getOriginAddress(), event.getDestinationAddress(), TripStatus.CREATED));
}

@EventHandler
public void on(TripCanceledEvent event){
public void on(TripCanceledEvent event) {
LOG.info("Trip canceled: {}", event.getId());
Trip trip = tripRepository.findOne(event.getId());
trip.setStatus(TripStatus.CANCELED);
tripRepository.save(trip);
}

@EventHandler
public void on(TripStartedEvent event){
public void on(TripStartedEvent event) {
LOG.info("Trip started: {}", event.getId());
Trip trip = tripRepository.findOne(event.getId());
trip.setStatus(TripStatus.STARTED);
tripRepository.save(trip);
}

@EventHandler
public void on(TripCompletedEvent event){
public void on(TripCompletedEvent event) {
LOG.info("Trip completed: {}", event.getId());
Trip trip = tripRepository.findOne(event.getId());
trip.setStatus(TripStatus.COMPLETED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package org.aitesting.microservices.tripmanagement.query.domain.models;

import org.aitesting.microservices.tripmanagement.common.events.TripStatus;

import javax.validation.constraints.NotNull;
import java.util.UUID;
import javax.validation.constraints.NotNull;
import org.aitesting.microservices.tripmanagement.common.events.TripStatus;

public class Trip {
@NotNull
private UUID id;
private UUID userID;
private UUID userId;
private String originAddress;
private String destinationAddress;

private TripStatus status;

public Trip(UUID id, UUID userID, String originAddress, String destinationAddress, TripStatus status) {
public Trip(UUID id, UUID userId, String originAddress, String destinationAddress, TripStatus status) {
this.id = id;
this.userID = userID;
this.userId = userId;
this.originAddress = originAddress;
this.destinationAddress = destinationAddress;
this.status = status;
}

public UUID getId() {
return id;
}

public UUID getUserID() {
return userID;
public UUID getUserId() {
return userId;
}

public String getOriginAddress() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.aitesting.microservices.tripmanagement.query.service.controllers;

import java.util.List;
import java.util.UUID;
import org.aitesting.microservices.tripmanagement.common.exceptions.NotFoundException;
import org.aitesting.microservices.tripmanagement.query.domain.models.Trip;
import org.aitesting.microservices.tripmanagement.query.service.repositories.TripRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("api")
public class TripManagementController {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.aitesting.microservices.tripmanagement.query.service.repositories;

import java.util.UUID;
import org.aitesting.microservices.tripmanagement.query.domain.models.Trip;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.UUID;

public interface TripRepository extends MongoRepository<Trip, UUID>{
public interface TripRepository extends MongoRepository<Trip, UUID> {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.aitesting.microservices.tests.provider;

import static org.aitesting.microservices.tests.helpers.TestConstants.*;

import io.restassured.module.mockmvc.RestAssuredMockMvc;
import org.aitesting.microservices.tripmanagement.common.events.TripStatus;
import org.aitesting.microservices.tripmanagement.query.TripManagementQueryApplication;
import org.aitesting.microservices.tripmanagement.query.domain.models.Trip;
Expand All @@ -11,9 +14,6 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext;
import io.restassured.module.mockmvc.RestAssuredMockMvc;

import static org.aitesting.microservices.tests.helpers.TestConstants.*;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TripManagementQueryApplication.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.aitesting.microservices.tests.unit;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.UUID;
import org.aitesting.microservices.tripmanagement.common.events.*;
import org.aitesting.microservices.tripmanagement.query.domain.eventhandlers.TripEventHandler;
import org.aitesting.microservices.tripmanagement.query.domain.models.Trip;
Expand All @@ -11,13 +17,6 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.UUID;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class TripEventHandlerUnitTests {

Expand All @@ -43,12 +42,12 @@ public class TripEventHandlerUnitTests {
private static Trip trip;

@Before
public void setup(){
public void setup() {
when(tripRepository.findOne(any(UUID.class))).thenReturn(trip);
}

@Test
public void onTripCreatedEvent_SaveIsCalled(){
public void onTripCreatedEvent_SaveIsCalled() {
//arrange

//act
Expand All @@ -59,7 +58,7 @@ public void onTripCreatedEvent_SaveIsCalled(){
}

@Test
public void onTripCanceledEvent_FindOneIsCalled(){
public void onTripCanceledEvent_FindOneIsCalled() {
//arrange

//act
Expand All @@ -70,7 +69,7 @@ public void onTripCanceledEvent_FindOneIsCalled(){
}

@Test
public void onTripCanceledEvent_SaveIsCalled(){
public void onTripCanceledEvent_SaveIsCalled() {
//arrange

//act
Expand All @@ -81,7 +80,7 @@ public void onTripCanceledEvent_SaveIsCalled(){
}

@Test
public void onTripStartedEvent_SaveIsCalled(){
public void onTripStartedEvent_SaveIsCalled() {
//arrange

//act
Expand All @@ -92,7 +91,7 @@ public void onTripStartedEvent_SaveIsCalled(){
}

@Test
public void onTripCompletedEvent_SaveIsCalled(){
public void onTripCompletedEvent_SaveIsCalled() {
//arrange

//act
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.aitesting.microservices.tests.unit;

import static org.aitesting.microservices.tests.helpers.TestConstants.TRIP_ID1;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import org.aitesting.microservices.tripmanagement.common.exceptions.NotFoundException;
import org.aitesting.microservices.tripmanagement.query.service.controllers.TripManagementController;
import org.aitesting.microservices.tripmanagement.query.service.repositories.TripRepository;
Expand All @@ -9,12 +13,6 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.UUID;

import static org.aitesting.microservices.tests.helpers.TestConstants.TRIP_ID1;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class TripManagementControllerUnitTests {

Expand All @@ -25,7 +23,7 @@ public class TripManagementControllerUnitTests {
private TripRepository tripRepository;

@Test
public void onGetTripsCall_FindAllIsCalled(){
public void onGetTripsCall_FindAllIsCalled() {
//arrange

//act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ Contract.make {
[
{
"id": "f849769e-2534-84a6-d475-5c2d701343ab",
"userID": "123e4567-e89b-12d3-a456-426655440000",
"userId": "123e4567-e89b-12d3-a456-426655440000",
"originAddress": "from some place over there",
"destinationAddress": "to this other place",
"status": "STARTED"
},
{
"id": "5b842415-9447-4b9b-85c6-2e1075214cc4",
"userID": "123e4567-e89b-12d3-a456-426655440000",
"userId": "123e4567-e89b-12d3-a456-426655440000",
"originAddress": "from some place over there",
"destinationAddress": "to this other place",
"status": "CREATED"
},
{
"id": "7a7d1e99-4823-4aa5-9d3b-2307e88cee0d",
"userID": "123e4567-e89b-12d3-a456-426655440000",
"userId": "123e4567-e89b-12d3-a456-426655440000",
"originAddress": "from some place over there",
"destinationAddress": "to this other place",
"status": "COMPLETED"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tripmanagement.query
import org.springframework.cloud.contract.spec.*

Contract.make {
description("When a Get request with a TripID is made, the corresponding trip is returned")
description("When a Get request with a TripId is made, the corresponding trip is returned")
request {
method 'GET'
url '/api/trip/f849769e-2534-84a6-d475-5c2d701343ab'
Expand All @@ -12,7 +12,7 @@ Contract.make {
status 200
body(
"id": "f849769e-2534-84a6-d475-5c2d701343ab",
"userID": "123e4567-e89b-12d3-a456-426655440000",
"userId": "123e4567-e89b-12d3-a456-426655440000",
"originAddress": "from some place over there",
"destinationAddress": "to this other place",
"status": "STARTED"
Expand Down

0 comments on commit bdc4366

Please sign in to comment.