We have a bunch of Spring Boot apps running in various Docker containers and wanted a centralised place to view the logs
function setJavaHome | |
{ | |
javaVersions=($(/usr/libexec/java_home -V 2>&1 | grep x86 | awk -F ":" '{print $1}' | awk -F "," '{print $1}' | xargs echo -n)) | |
newJava="" | |
while [[ $newJava = "" ]]; do | |
echo "Select your Java version for this shell" | |
select newJava in ${javaVersions[@]}; do | |
if [[ $newJava = "" ]]; then | |
echo "Please enter a valid option." |
import java.math.BigInteger; | |
import java.util.Collections; | |
import java.util.UUID; | |
import java.util.stream.Stream; | |
public class ShorterUuid { | |
private static void doit() { | |
String original = UUID.randomUUID().toString(); | |
String hex = original.replaceAll("-", ""); | |
String s = new BigInteger(hex, 16).toString(36); |
I just started writing an app using Spring Boot/Angular 2 combo. Once I had the initial demo up and working and cracked wiring in Spring security (another blog entirely), my attention turned to writing some tests that would drive the next phases.
My Spring Boot back-end can be unit/integration tested on it's own. I was interested in making sure the user experience was tested. Tradionally I might have turned to Geb for a full server side project, but this is mostly just javascript and I know how fast Jasmine/Karma tests run, so there must be a nice way of doing this?
Indeed I was not disappointed to find that Angular ng new webapp
had already created me a e2e folder with a skeleton Protractor test to point the way.
But how to stub out the back-end? I have used many mocking frameworks before; Sinon, for example, is excellent in unit tests. There must by a simple way of doing it for Protractor/An
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Pipeline Status</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script> | |
<link rel="stylesheet" href="/plugin/build-monitor-plugin/styles/normalize.css"> |
@Grab(group='joda-time', module='joda-time', version='2.0') | |
public class UsedToExposeAnnotationToComplier {} | |
import org.joda.time.* | |
[new LocalTime(8,0),new LocalTime(7,0)].min() |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Docker Monitor</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.2/ui-bootstrap-tpls.min.js"></script> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.css"/> |
import java.util.Random | |
Random rand = new Random() | |
def colours = ['blue', 'green', 'red', 'yellow'] | |
def likihood = [blue: 25, green: 22, red: 22, yellow: 5] | |
def views = [blue: 1, green: 1, red: 1, yellow: 1] | |
def clicks = [blue: 1, green: 1, red: 1, yellow: 1] | |
def percentages | |
for (def i = 0; i < 10000; i++) { |
Here's how we were able to reduce our functional testing and greatly speed up our build times by generating fully rendered [Velocity] (http://velocity.apache.org/) templates on demand and testing their interaction with our JavaScript.
The conventional wisdom is that unit testing views is hard, then therefore best left to functional tests, but these tests tend to be slow and not really designed for testing error scenarios/multiple cases/etc. In our case unit testing the JavaScript without the views would be largly pointless as most of the logic is directly linked to elements on the page. We could have just had some fixture data that emulated our views, but then you get into a maintenance nightmare trying to keep them both in sync. The ideal solution would be to test against the real views.