Skip to content

Commit e24041e

Browse files
committed
Update project
1 parent de873ed commit e24041e

File tree

6 files changed

+43
-38
lines changed

6 files changed

+43
-38
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
To build the project: mvn clean install
1+
##Run Unit Tests and start the Ticket Viewer Java App from Command Line:
2+
####mvn -X clean install exec:java

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@
1717
<target>7</target>
1818
</configuration>
1919
</plugin>
20+
<plugin>
21+
<groupId>org.codehaus.mojo</groupId>
22+
<artifactId>exec-maven-plugin</artifactId>
23+
<version>1.2.1</version>
24+
<executions>
25+
<execution>
26+
<goals>
27+
<goal>java</goal>
28+
</goals>
29+
</execution>
30+
</executions>
31+
<configuration>
32+
<includePluginDependencies>true</includePluginDependencies>
33+
<mainClass>TicketViewer</mainClass>
34+
</configuration>
35+
</plugin>
2036
</plugins>
2137
</build>
2238
<dependencies>

src/main/java/Ticket.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public String getTicketData(int ticketId) {
2323
return "ERROR: ID must be > 0";
2424
}
2525

26-
LOGGER.info("Processing your request, please wait...");
26+
LOGGER.info("Processing your request, please wait...\n");
2727
HttpRequest httpRequest = new HttpRequest();
2828
String url = route + "/" + ticketId + ".json";
2929
String response = httpRequest.get(url, null);
@@ -45,23 +45,19 @@ public String getTicketData(int ticketId) {
4545

4646
void displayTicketData(){
4747
System.out.format("\n %66s \n", "** Displaying ticket number " + this.id + " **");
48-
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------------");
49-
//Subject align left, createdAt align right
48+
System.out.println(" ------------------------------------------------------------------------------------------------------------------------");
5049
System.out.format("| Subject: %-82s Created at: %-25s |\n", this.subject, this.createdAt);
5150
System.out.format("|%-132s|\n| Description: %-116s |\n", " ","");
52-
//Handle Description content
5351
int length = this.description.length();
54-
//Description is short, and fit 1 row
5552
if(length <= 130) {
5653
System.out.format("| %-130s |\n", this.description);
5754
}
58-
//Description is too long, need text wrapping
5955
ArrayList<String> descWrapped = WrapTextFullWords(this.description, 130);
6056
for (int i=0; i< descWrapped.size(); i++) {
6157
System.out.format("| %-130s |\n", descWrapped.get(i));
6258
}
6359

64-
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------------");
60+
System.out.println(" ------------------------------------------------------------------------------------------------------------------------");
6561
}
6662

6763
private ArrayList<String> WrapTextFullWords (String str, int maxLength) {
@@ -82,5 +78,4 @@ private ArrayList<String> WrapTextFullWords (String str, int maxLength) {
8278
result.add(line);
8379
return result;
8480
}
85-
86-
}
81+
}

src/main/java/TicketList.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ String listTickets(int pageNumber, int ticketsPerPage) {
1919
return "ERROR: Number of Records in a request must be > 0";
2020
}
2121

22-
LOGGER.info("Processing your Request, Please Wait...");
22+
LOGGER.info("Processing your Request, Please Wait...\n");
2323
HttpRequest httpRequest = new HttpRequest();
2424
String parameters = "?page=" + pageNumber + "&per_page=" + ticketsPerPage;
2525
String response = httpRequest.get(ROUTE, parameters); // json string.
@@ -56,18 +56,17 @@ private void displayInformation(Ticket ticket) {
5656
if (str.length() >50) {
5757
str = str.substring(0, 46) + "...";
5858
}
59-
//Align left
6059
System.out.format("| %-10s | %-10s | %-50s | %-10s | %-25s |\n", ticket.id+"", ticket.type, str, ticket.priority, ticket.createdAt);
6160
}
6261

6362
private void displayHeadline() {
64-
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------------");
63+
System.out.println(" ------------------------------------------------------------------------------------------------------------------------");
6564
//Align left
6665
System.out.format("| %-10s | %-10s | %-50s | %-10s | %-25s |\n", "ID", "Type", "Subject", "Priority", "Created");
67-
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------------");
66+
System.out.println(" ------------------------------------------------------------------------------------------------------------------------");
6867
}
6968

7069
private void displayFooter() {
71-
System.out.println(" ------------------------------------------------------------------------------------------------------------------------------------");
70+
System.out.println(" ------------------------------------------------------------------------------------------------------------------------");
7271
}
7372
}

src/main/java/TicketViewer.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import java.io.BufferedReader;
22
import java.io.IOException;
33
import java.io.InputStreamReader;
4+
import java.util.logging.Logger;
45

56
public class TicketViewer {
67
public static final int PER_PAGE = 25;
@@ -9,6 +10,7 @@ public class TicketViewer {
910
public static String response;
1011
public static boolean hasNext = false, hasPrev = false;
1112
public static boolean displayOptions = true;
13+
static final Logger LOGGER = Logger.getLogger(HttpRequest.class.getName());
1214

1315
public static void main(String[] args) {
1416
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
@@ -23,46 +25,41 @@ public static void main(String[] args) {
2325
switch(userInput) {
2426

2527
case "1": {
26-
//Gate ticket list of 25 tickets
2728
showTickets(page);
2829
break;
2930
}
3031
case "n": {
3132
if(hasNext != false) {
3233
page++;
33-
//Gate ticket list of 25 tickets
3434
showTickets(page);
35-
}
36-
else {
37-
System.out.println("INPUT ERROR: Cannot navigate to the next page");
35+
} else {
36+
LOGGER.info("INPUT ERROR: Cannot navigate to the next page\n");
37+
System.out.println("Type 'p' to move to the previous page");
38+
System.out.println("Type 'quit' to exit");
3839
}
3940
break;
4041
}
41-
//Navigate to previous page, available only in list view
4242
case "p": {
4343
if(hasPrev != false && page>1) {
4444
page--;
45-
//Gate ticket list of 25 tickets
4645
showTickets(page);
47-
}
48-
else {
49-
System.out.println("INPUT ERROR: Cannot navigate to the previous page");
46+
} else {
47+
LOGGER.info("INPUT ERROR: Cannot navigate to the previous page");
48+
System.out.println("Type 'n' to move to the next page");
49+
System.out.println("Type 'quit' to exit");
5050
}
5151
break;
5252
}
53-
//Exit
5453
case "quit": {
55-
System.out.println("Thank you for using Ticket Viewer. Hope you enjoyed our service");
54+
LOGGER.info("Thank you for using Ticket Viewer. Hope you enjoyed our service");
5655
return;
5756
}
5857
default:
59-
System.out.println("INVALID INPUT: Please Try Again");
58+
LOGGER.info("INVALID INPUT: Please Try Again");
6059
}
6160
}
6261
catch (IOException e) {
63-
System.out.println("ERROR: An error occured while reading input");
64-
System.out.println(e.getMessage());
65-
System.out.println(e.getStackTrace());
62+
LOGGER.severe("ERROR: An error occurred while reading input " + e);
6663
}
6764
}
6865
}

src/test/java/HttpRequestTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import static org.junit.Assert.assertEquals;
33

44
public class HttpRequestTest {
5+
HttpRequest httpRequest = new HttpRequest();
56

67
@Test
78
public void getRequest(){
8-
HttpRequest httpRequest = new HttpRequest();
99
httpRequest.get("/api/v2/tickets.json", null);
1010
String result = httpRequest.get("/api/v2/tickets.json", "?page=2&per_page=2");
1111
System.out.println("Result is : " + result);
@@ -14,38 +14,35 @@ public void getRequest(){
1414

1515
@Test
1616
public void getRequestWithParameters(){
17-
HttpRequest httpRequest = new HttpRequest();
1817
httpRequest.get("/api/v2/tickets.json", "?page=1&per_page=2");
1918
assertEquals(200, httpRequest.getResponseCode());
2019
}
2120

2221
@Test
2322
public void getRequestWithNonExistingRoute(){
24-
HttpRequest httpRequest = new HttpRequest();
2523
String response = httpRequest.get("/api/v2/tickets00000.json", "?page=1&per_page=2");
2624
assertEquals(404, httpRequest.getResponseCode());
2725
assertEquals("Not Found: Requested resource cannot be found", response);
2826
}
2927

3028
@Test
3129
public void invalidCredentials(){
32-
HttpRequest httpRequest = new HttpRequest("abc", "def".toCharArray(), "https://codewithcs.zendesk.com");
30+
httpRequest = new HttpRequest("abc", "def".toCharArray(), "https://codewithcs.zendesk.com");
3331
String response = httpRequest.get("/api/v2/tickets.json", null);
3432
assertEquals(403, httpRequest.getResponseCode());
3533
assertEquals("Forbidden: Not enough permissions", response);
3634
}
3735

38-
//@Test
36+
@Test
3937
public void invalidURL(){
40-
HttpRequest httpRequest = new HttpRequest("abc", "def".toCharArray(), "xyz");
38+
httpRequest = new HttpRequest("abc", "def".toCharArray(), "xyz");
4139
String response = httpRequest.get("/api/v2/tickets.json", null);
4240
assertEquals(0, httpRequest.getResponseCode());
4341
assertEquals("IOException occurred : java.net.MalformedURLException: no protocol: xyz/api/v2/tickets.jsonnull", response);
4442
}
4543

4644
@Test
4745
public void badClientRequest(){
48-
HttpRequest httpRequest = new HttpRequest();
4946
httpRequest.get("/api/v2/tickets.json?page=2&per_page=2", null);
5047
assertEquals(400, httpRequest.getResponseCode());
5148
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy