Skip to content

Commit

Permalink
Merge pull request #160 from UMM-CSci-3601/s21-updates
Browse files Browse the repository at this point in the history
Spring 2021 Updates 2: Electric Boogaloo
  • Loading branch information
NicMcPhee authored Feb 9, 2021
2 parents 44edb54 + 97386b7 commit 7bc3de4
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 125 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/server-gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Check out the repository
uses: actions/checkout@v2

- name: Cache Gradle artifacts (downloaded JARs, the wrapper, and any downloaded JDKs)
uses: actions/cache@v2
with:
java-version: 1.8
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.gradle/jdks
key: ${{ runner.os }}-gradle-${{ hashFiles('**/.gradle/') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: |
cd server
./gradlew build
run: ./gradlew build
working-directory: ./server
16 changes: 14 additions & 2 deletions LABTASKS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# Lab Tasks
# Lab Tasks <!-- omit in toc -->

* [Notes on notation and structure](#notes-on-notation-and-structure)
* [Exploring the project](#exploring-the-project)
* [Exploring the server](#exploring-the-server)
* [Exploring the client](#exploring-the-client)
* [Use ZenHub to support Agile development](#use-zenhub-to-support-agile-development)
* [Setting up the project ZenHub board](#setting-up-the-project-zenhub-board)
* [Using the board](#using-the-board)
* [The epics/features](#the-epicsfeatures)
* [Questions](#questions)

## Notes on notation and structure

* Questions that you need to answer (as a group!) are indicated with question mark symbols (:question:).
* The [Questions](./LABTASKS.md#questions) section is at the end of this document.
Expand Down Expand Up @@ -32,7 +44,7 @@ Run it according to the instructions in the
[README](./README.md), including running the JUnit tests. Answer
the following questions.

> Protip: Using Google to gain additional knowledge or support your conjectures
> Pro-tip: Using Google to gain additional knowledge or support your conjectures
about how something works is great! It's important that you think about how everything
fits together and works, though, so don't use Google as a replacement for
building your understanding or you will regret it!
Expand Down
82 changes: 39 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# CSCI 3601 Lab #2 - Building a web server in Java with Javalin
# CSCI 3601 Lab #2 - Building a web server in Java with Javalin <!-- omit in toc -->

[![Server Build Status](../../workflows/Server%20Java/badge.svg?branch=master)](../../actions?query=workflow%3A"Server+Java")

- [Overview of the project](#overview-of-the-project)
- [Setup](#setup)
- [Cloning the project in GitKraken](#cloning-the-project-in-gitkraken)
- [Open the project in VS Code](#open-the-project-in-vs-code)
- [JSONView browser extension](#jsonview-browser-extension)
- [Running Your project](#running-your-project)
- [Testing Your Project](#testing-your-project)
- [Checking your code coverage](#checking-your-code-coverage)
- [Continuous Integration with GitHub Actions](#continuous-integration-with-github-actions)
- [Go do the lab!](#go-do-the-lab)
- [Resources](#resources)

Here you will explore serving up a simple website that you create,
using a server written with the [Javalin framework][javalin-io] server.
Javalin is a micro framework for
Expand Down Expand Up @@ -89,13 +101,12 @@ Don't worry if you don't get the dialog, it is probably because you already have

Like in previous labs, click "Install All" to automatically install them.

### Install JSONView browser extension
### JSONView browser extension

You'll also want the JSONView extension for either Firefox or Chrome installed.
This will make JSON in the browser look pretty and actually be readable.
If you use Chrome, you may find it helpful to install the [JSONView][jsonview-chrome] extension.
This will make JSON in the browser look pretty and actually be readable when you visit the different API endpoints.

* Firefox: [JSONView][jsonview-firefox]
* Chrome: [JSONView][jsonview-chrome]
If you use Firefox, this functionality is built-in, so there is no need to install an extension.

## Running Your project

Expand All @@ -122,14 +133,6 @@ run on.
Visit it at [http://localhost:4567][local] in your web browser. The
server will continue to run indefinitely until you stop it

To run the JUnit tests:

```bash
./gradlew test
```

You can also run your tests right in VS Code by clicking the "Run Test" link above them.

## Testing Your Project

There's very little meaningful logic in the client component of this
Expand All @@ -140,22 +143,25 @@ labs.
The server-side portion of this project will be tested using JUnit.
Server-side tests are located in the `src/test/java` directory.

To run your server-side tests, you have a few options:
To run your server-side tests: while in the `server` directory, run:

```bash
./gradlew test
```

You can run `./gradlew test` from the `server` directory in the terminal to run all tests and output info about the run to an HTML file.
This will run all tests and output info about the run to a test report "website". To see the report open the file in your browser:

Additionally, you can go to the Test pane on the left side of VS Code and run all or individual tests from there.
The test pane looks like this:
```text
server/build/reports/tests/test/index.html
```

![VS Code test pane](https://i.vgy.me/TAfWcG.png)
It will look something like this:

You can also run your tests right in the code editor by clicking the "Run Test" link above them.
![image](https://user-images.githubusercontent.com/1300395/107262491-3cf57780-6a06-11eb-9e5b-68d4491cde47.png)

![VS Code inline testing](https://i.vgy.me/SxWfWh.png)
These test reports are especially helpful when a test fails because you will get the full stack trace there.

This last two options are particularly nice because it gives you better
integrated feedback in VS Code and the ability to just run single
tests or files of tests when you're trying to debug a complex problem.
When a test fails, you will get a notice in the terminal that there were failing tests along with a path to the report. You can copy that path into your browser to see the report.

## Checking your code coverage

Expand All @@ -166,15 +172,20 @@ so you can see how well your tests cover (i.e., exercise) your code. The command
./gradlew test jacocoTestReport
```

will run the tests followed by the test coverage report generator. The report is in fact
a small "website" composed of a collection of HTML files. To see the report open the file
will run the tests followed by the test coverage report generator. This report is a "website" like the one from JUnit above. To see the report open the file in your browser:

```bash
```text
server/build/jacocoHtml/index.html
```

It will look something like this:

![image](https://user-images.githubusercontent.com/1300395/107262605-5c8ca000-6a06-11eb-9844-f7b5d1265eb2.png)

If you generate and look at that report at the start of the lab, you'll see that you start
with 100% coverage of all the `user` files. You'd like to keep it that way, so check your
with 100% coverage of everything but the `Server.java`
file, e.g., we're great on all the `user` files.
You'd like to keep it that way, so check your
code coverage after major stories are finished and look for areas that you're not yet testing.

:bangbang: The server file itself currently has 0% coverage, although we think we could
Expand Down Expand Up @@ -202,16 +213,6 @@ most of the actual work of the lab is described.

## Resources

### Running in the command line

We include a Gradle wrapper which lets you run gradle tasks from the command line. So, you can run tasks like:

```bash
./gradlew test
```

### Handling requests in Javalin

* [Getting started in Javalin](https://javalin.io/documentation#getting-started)
* [Javalin tutorials](https://javalin.io/tutorials/)
* [Testing Javalin](https://javalin.io/tutorials/testing)
Expand All @@ -221,12 +222,7 @@ We include a Gradle wrapper which lets you run gradle tasks from the command lin

[javalin-io]: https://javalin.io
[gradle]: https://gradle.org/
[intellij-idea]: https://www.jetbrains.com/idea/
[jasmine]: https://jasmine.github.io/
[jasmine-introduction]: http://jasmine.github.io/2.0/introduction.html
[jsonview-chrome]: https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc?hl=en
[jsonview-firefox]: https://addons.mozilla.org/en-us/firefox/addon/jsonview/
[karma]: https://karma-runner.github.io/1.0/index.html
[labtasks]: LABTASKS.md
[local]: http://localhost:4567/
[rest-best-practices]: https://medium.com/@mwaysolutions/10-best-practices-for-better-restful-api-cbe81b06f291
Expand Down
3 changes: 2 additions & 1 deletion client/javascript/todos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// gets todos from the api.
// It adds the values of the various inputs to the requested URl to filter and order the returned todos.
function getFilteredTodos() {
console.log("Getting all the todos.");
console.log("Getting todos");

var url = "/api/todos?";
if(document.getElementById("owner").value != "") {
Expand All @@ -24,6 +24,7 @@ function getFilteredTodos() {
}

get(url, function(returned_json){
document.getElementById("requestUrl").innerHTML = url;
document.getElementById('jsonDump').innerHTML = syntaxHighlight(JSON.stringify(returned_json, null, 2));
});
}
24 changes: 2 additions & 22 deletions client/javascript/users.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
/**
* Function to get all the users!
*/
function getAllUsers() {
console.log("Getting all the users.");

get("/api/users", function (returned_json) {
document.getElementById('jsonDump').innerHTML = returned_json;
});
}

function getAllUsersByAge() {
console.log("Getting all the users.");

get("/api/users?age=" + document.getElementById("age").value, function (returned_json) {
document.getElementById('jsonDump').innerHTML = returned_json;
});
}



// gets users from the api.
// It adds the values of the various inputs to the requested URl to filter and order the returned users.
function getFilteredUsers() {
console.log("Getting all the users.");
console.log("Getting users");

var url = "/api/users?";
if(document.getElementById("age").value != "") {
Expand All @@ -34,6 +13,7 @@ function getFilteredUsers() {


get(url, function(returned_json){
document.getElementById("requestUrl").innerHTML = url;
document.getElementById('jsonDump').innerHTML = syntaxHighlight(JSON.stringify(returned_json, null, 2));
});
}
10 changes: 4 additions & 6 deletions client/todos.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@
</select><br>
Limit: <input id="limit" type="text" name="limit"><br>

<button type="button" id="getTodos"> Get Todos </button>
<button type="button" id="getTodos">Get Todos</button>

<pre id="jsonDump"> Json will go here </pre>
<div style="margin-top: 20px;">Requested URL: <code id="requestUrl">(the requested API URL will appear here)</code></div>
<pre id="jsonDump">JSON will go here</pre>

<script>
window.onload = function() {
console.log("The page is loaded now!");

var element = document.getElementById('getTodos');
element.addEventListener("click", getFilteredTodos, true);
document.getElementById('getTodos').addEventListener("click", getFilteredTodos, true);
}
</script>
</body>
Expand Down
9 changes: 3 additions & 6 deletions client/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
<br>
<button type="button" id="getUsers">Get Users</button>


<pre id="jsonDump" > Json will go here</pre>
<div style="margin-top: 20px;">Requested URL: <code id="requestUrl">(the requested API URL will appear here)</code></div>
<pre id="jsonDump">JSON will go here</pre>


<script>
window.onload = function () {
console.log("The page is loaded now!");

var element = document.getElementById('getUsers');
element.addEventListener("click", getFilteredUsers, true);
document.getElementById('getUsers').addEventListener("click", getFilteredUsers, true);
}
</script>
</body>
Expand Down
27 changes: 14 additions & 13 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// Builds the server side of the project

plugins {
// Apply the java plugin to add support for Java
id 'java'

// Apply the application plugin to add support for building a CLI application
id 'application'

Expand All @@ -13,6 +10,13 @@ plugins {
id 'jacoco'
}

// Build and run the project with Java 11
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
Expand All @@ -26,41 +30,38 @@ mainClassName = 'umm3601.Server'
// External dependencies that our application utilizes
dependencies {
// Google core libraries for Java, various useful utilities
implementation 'com.google.guava:guava:28.2-jre'
implementation 'com.google.guava:guava:30.1-jre'

// Javalin, a simple web framework for Java
compile 'io.javalin:javalin:3.7.0'
implementation 'io.javalin:javalin:3.13.3'

// Jackson, a JSON library for Java
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.1'
// Simple Logging Facade for Java
implementation 'org.slf4j:slf4j-simple:1.7.30'

implementation 'com.google.code.gson:gson:2.8.6'

// JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'

// JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1'

// Mockito for testing
testImplementation 'org.mockito:mockito-core:3.2.4'
testImplementation 'org.mockito:mockito-core:3.7.7'
}

application {
// Define the main class for the application
mainClassName = 'umm3601.Server'
mainClass = 'umm3601.Server'
}

test {
// Use junit platform for unit tests
useJUnitPlatform()
}

// We want our source code to be compatible with Java 1.8
sourceCompatibility = '1.8'

wrapper {
distributionType = Wrapper.DistributionType.ALL
}
Expand Down
Binary file modified server/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion server/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions server/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
Loading

0 comments on commit 7bc3de4

Please sign in to comment.