Skip to content

Commit

Permalink
#4 - add 2nd forwarding controller
Browse files Browse the repository at this point in the history
  • Loading branch information
obriensystems committed Jul 18, 2021
1 parent 84a2179 commit da64a43
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package global.packet.magellan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import global.packet.magellan.service.ApplicationService;

//import com.wordnik.swagger.annotations.ApiOperation;
//import com.wordnik.swagger.annotations.ApiResponse;
//import com.wordnik.swagger.annotations.ApiResponses;

@RestController
@RequestMapping("/app")
public class ApplicationServiceController {

@Autowired
ApplicationService applicationService;

//@GET
//@Path("/health")
//@Produces(MediaType.TEXT_HTML)
//@RequestMapping("/test")
/*@ApiOperation(value="health check", notes="health check for auto scaling")
@ApiResponses (value= {
@ApiResponse(code=200, message="OK - success"),
@ApiResponse(code=400, message="Bad Request"),
@ApiResponse(code=401, message="Unauthorized"),
@ApiResponse(code=403, message="Forbidden"),
@ApiResponse(code=404, message="NotFound"),
@ApiResponse(code=409, message="Conflict"),
@ApiResponse(code=500, message="Internal Server Error")
})*/
@GetMapping("/health")
public String getHealth() {
return applicationService.health().toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package global.packet.magellan.controller;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import global.packet.magellan.service.ApplicationService;
import global.packet.magellan.service.ApplicationServiceLocal;
import global.packet.magellan.service.ForwardingService;

//import com.wordnik.swagger.annotations.ApiOperation;
//import com.wordnik.swagger.annotations.ApiResponse;
Expand All @@ -24,7 +16,7 @@
public class ForwardingController {

@Autowired
ApplicationService applicationService;
ForwardingService forwardingService;

//@GET
//@Path("/health")
Expand All @@ -40,9 +32,9 @@ public class ForwardingController {
@ApiResponse(code=409, message="Conflict"),
@ApiResponse(code=500, message="Internal Server Error")
})*/
@GetMapping("/health")
public String getHealth() {
return applicationService.health().toString();
@GetMapping("/packet")
public String getPacket() {
return forwardingService.forward().toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package global.packet.magellan.service;

public interface ForwardingService {

String forward();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package global.packet.magellan.service;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class ForwardingServiceImpl implements ForwardingService {

@Override
public String forward() {
return "OK";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package global.packet.magellan;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import global.packet.magellan.controller.ApplicationServiceController;

public class ApplicationServiceControllerTest {
// controller is unmocked, but service bean inside is mocked
private @InjectMocks ApplicationServiceController controller
= Mockito.mock(ApplicationServiceController.class);
// if controller is InjectMocked then Mock service bean will be injected
//@Mock ForwardingController controller;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}

@Test
public void testForwardRequest() {
String expected = "ok";
Mockito.when(controller.getHealth())
.thenReturn(expected);
String response = controller.getHealth();
Assertions.assertNotNull(response);
Assert.assertEquals(expected, response);
}


}



Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public void setup() {
@Test
public void testForwardRequest() {
String expected = "ok";
Mockito.when(controller.getHealth())
Mockito.when(controller.getPacket())
.thenReturn(expected);
String response = controller.getHealth();
String response = controller.getPacket();
Assertions.assertNotNull(response);
Assert.assertEquals(expected, response);
}
Expand Down

0 comments on commit da64a43

Please sign in to comment.