Skip to content

Commit

Permalink
Update & improve site content & logging (#58)
Browse files Browse the repository at this point in the history
- [x] Improve log statements
- [x] Update project carousel with booking-sys
- [x] Increase memory for app instance
- [x] Update Unit tests (strict)
  • Loading branch information
conorheffron authored Sep 9, 2024
1 parent 54872a4 commit 6bd85d2
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .aws/task-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "ironoc",
"image": "345594590074.dkr.ecr.eu-north-1.amazonaws.com/conorheffron/ironoc:latest",
"memory": "512",
"memory": "1024 ",
"portMappings": [
{
"name": "ironoc-80-tcp",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Build / Run (spin-up) Docker container:
```
docker image build -t ironoc .
docker compose up -d
docker logs ironoc-portfolio-1 -f
```
![image](screen-grabs/cli-docker.png)

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/ironoc/portfolio/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,3 @@ public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> enableDef
return (factory) -> factory.setRegisterDefaultServlet(true);
}
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ironoc.portfolio.controller;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
Expand All @@ -13,16 +13,16 @@
@Slf4j
public class CustomErrorController implements ErrorController {

private static final String PATH = "/error";
protected static final String PATH = "/error";

@RequestMapping(value = PATH)
public RedirectView error(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
log.error("Bad request - redirect to home");
return new RedirectView("/", false);
public RedirectView error(HttpServletRequest request) {
log.error("Unexpected error occurred. {}, The HTTP status is: {}",
request.getAttribute(RequestDispatcher.ERROR_MESSAGE),
request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE));
RedirectView redirectView = new RedirectView("/", false);
log.error("Bad request for {}. Redirecting to home",
request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI));
return redirectView;
}

public String getErrorPath() {
return PATH;
}

}
12 changes: 10 additions & 2 deletions src/main/java/com/ironoc/portfolio/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
import jakarta.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;
import org.apache.logging.slf4j.Log4jLogger;
import org.springframework.stereotype.Controller;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.function.ServerRequest;

import java.util.Enumeration;

@Controller
@Slf4j
public class HomeController {

@RequestMapping( {"/"} )
public String index(HttpServletRequest httpServletRequest) {
log.info(httpServletRequest.getRequestURI() + " page request");
public String index(HttpServletRequest request) {
log.info("Home page request details, host={}, uri={}, user-agent={}",
request.getHeader("host"),
request.getRequestURI(),
request.getHeader("user-agent"));
return "index";
}
}
26 changes: 14 additions & 12 deletions src/main/webapp/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,14 @@ <h1>iRonoc</h1>
<div class="row">
<div class="col-sm-8">
<h2>About</h2>
<h4>Welcome, my name is Conor. I am a software developer from
Ireland who loves to write software and build great products. I
appreciate clean code and applications that perform well. I have
worked professionally in software development since 2010 in the web
and mobile spaces with a variety of experience. I am a server-side
developer (primarily Java/Spring) but looking to increase my full
stack experience with other languages and frameworks such as
AngularJS, React and Scala - everything web app related. See below
for contact details.</h4>
<h4>Welcome, I'm Conor Heffron, a Software Engineer hailing from County Meath, Ireland.
With over ten years of professional experience, I specialize in writing clean code and
developing high-performance applications. As a passionate Full Stack Developer, I am constantly
expanding my technical expertise across various tech stacks, languages, frameworks, and
tools in the realm of Software, Data, and DevOps. Let's connect and explore exciting
opportunities together! See below for contact details.</h4>

<a href="https://uk.linkedin.com/pub/conor-heffron/17/7a5/8a2"
<a href="https://www.linkedin.com/in/conorheffron"
target="_blank"> <img
src="https://static.licdn.com/scds/common/u/img/webpromo/btn_viewmy_160x33.png"
width="160" height="33" border="0"
Expand All @@ -95,8 +92,8 @@ <h4>Welcome, my name is Conor. I am a software developer from
<div id="portfolio" class="container-fluid text-center bg-grey">
<h2>Portfolio</h2>
<h4>
Technologies: <br> Server-side: Java / Spring Boot 3, Python, R, & MySQL <br> Front-end: HTML5+CSS,
JQUERY, JSP<br> and more...
Technologies: <br> Server-side: Java / Spring Boot 3, Python3, Django 5, R, & MySQL <br> Front-end: HTML5+CSS,
JQUERY, JSP, angularJS<br> and more...
</h4>
<br>
<br>
Expand All @@ -111,6 +108,7 @@ <h4>
<li data-target="#myCarousel" data-slide-to="3"></li>
<li data-target="#myCarousel" data-slide-to="4"></li>
<li data-target="#myCarousel" data-slide-to="5"></li>
<li data-target="#myCarousel" data-slide-to="6"></li>
</ol>

<!-- Wrapper for slides -->
Expand All @@ -119,6 +117,10 @@ <h4>
<a href="https://github.com/conorheffron/ironoc-db" target="_blank">Sample Data Manager Service with
UI</a>
</div>
<div class="item">
<a href="https://github.com/conorheffron/booking-sys" target="_blank">Sample Resrvations & View
System</a>
</div>
<div class="item">
<a href="https://github.com/cph33/nba-stats" target="_blank">NBA Analytics (2015 - 2023): Player
Statistics</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.ironoc.portfolio.controller;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -11,6 +12,8 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
Expand All @@ -22,23 +25,25 @@ public class CustomErrorControllerTest {
@Mock
private HttpServletRequest httpServletRequestMock;

@Mock
private HttpServletResponse httpServletResponseMock;

@Test
public void test_error_view_success() {
// when
RedirectView result = customErrorController.error(httpServletRequestMock, httpServletResponseMock);
RedirectView result = customErrorController.error(httpServletRequestMock);

// then
verify(httpServletRequestMock, times(3)).getAttribute(anyString());
verify(httpServletRequestMock).getAttribute(RequestDispatcher.ERROR_MESSAGE);
verify(httpServletRequestMock).getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
verify(httpServletRequestMock).getAttribute(RequestDispatcher.ERROR_REQUEST_URI);

assertThat(result, is(notNullValue()));
assertThat(result, isA(RedirectView.class));
}

@Test
public void test_getErrorPath_success() {
// when
String result = customErrorController.getErrorPath();
String result = CustomErrorController.PATH;

// then
assertThat(result, is("/error"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ public class HomeControllerTest {

@Test
public void test_index_success() {
// given
String homeView = "index";

// when
String result = homeController.index(httpServletRequestMock);

// then
verify(httpServletRequestMock).getRequestURI();
verify(httpServletRequestMock, times(2)).getHeader(anyString());

assertThat(result, is("index"));
assertThat(result, is(homeView));
}
}

0 comments on commit 6bd85d2

Please sign in to comment.