diff --git a/magellan-nbi/src/main/java/global/packet/magellan/controller/ApplicationServiceController.java b/magellan-nbi/src/main/java/global/packet/magellan/controller/ApplicationServiceController.java new file mode 100644 index 0000000..9984a2f --- /dev/null +++ b/magellan-nbi/src/main/java/global/packet/magellan/controller/ApplicationServiceController.java @@ -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(); + } + +} diff --git a/magellan-nbi/src/main/java/global/packet/magellan/controller/ForwardingController.java b/magellan-nbi/src/main/java/global/packet/magellan/controller/ForwardingController.java index 442aa45..f4d7d00 100644 --- a/magellan-nbi/src/main/java/global/packet/magellan/controller/ForwardingController.java +++ b/magellan-nbi/src/main/java/global/packet/magellan/controller/ForwardingController.java @@ -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; @@ -24,7 +16,7 @@ public class ForwardingController { @Autowired - ApplicationService applicationService; + ForwardingService forwardingService; //@GET //@Path("/health") @@ -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(); } } diff --git a/magellan-nbi/src/main/java/global/packet/magellan/service/ForwardingService.java b/magellan-nbi/src/main/java/global/packet/magellan/service/ForwardingService.java new file mode 100644 index 0000000..107e992 --- /dev/null +++ b/magellan-nbi/src/main/java/global/packet/magellan/service/ForwardingService.java @@ -0,0 +1,6 @@ +package global.packet.magellan.service; + +public interface ForwardingService { + + String forward(); +} diff --git a/magellan-nbi/src/main/java/global/packet/magellan/service/ForwardingServiceImpl.java b/magellan-nbi/src/main/java/global/packet/magellan/service/ForwardingServiceImpl.java new file mode 100644 index 0000000..3eac2d6 --- /dev/null +++ b/magellan-nbi/src/main/java/global/packet/magellan/service/ForwardingServiceImpl.java @@ -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"; + } + +} diff --git a/magellan-nbi/src/test/java/global/packet/magellan/ApplicationServiceControllerTest.java b/magellan-nbi/src/test/java/global/packet/magellan/ApplicationServiceControllerTest.java new file mode 100644 index 0000000..e3df2a9 --- /dev/null +++ b/magellan-nbi/src/test/java/global/packet/magellan/ApplicationServiceControllerTest.java @@ -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); + } + + +} + + + diff --git a/magellan-nbi/src/test/java/global/packet/magellan/ForwardingControllerTest.java b/magellan-nbi/src/test/java/global/packet/magellan/ForwardingControllerTest.java index ef76d1b..8ac2c47 100644 --- a/magellan-nbi/src/test/java/global/packet/magellan/ForwardingControllerTest.java +++ b/magellan-nbi/src/test/java/global/packet/magellan/ForwardingControllerTest.java @@ -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); }