Introduce mock service

Change-Id: Ide981afc41020adbf1d1ee671bd397d40c9fdde8
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index 3f1e3bf..92937d4 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -97,6 +97,14 @@
   # Configure mail exception
   $self->plugin('MailException' => $self->config('MailException'));
 
+  # Start fixture
+  if ($self->mode eq 'test') {
+    $self->plugin(Mount => {
+      'http://*:3001/api/v0.1/' => $self->home->child('lib/Kalamar/Apps/test_backend.pl')
+    });
+    $self->config('Kalamar')->{api} = 'http://*:3001/api/v0.1/';
+  };
+
 
   # Configure documentation navigation
   my $navi = Mojo::File->new($self->home->child('templates','doc','navigation.json'))->slurp;
diff --git a/lib/Kalamar/Apps/test_backend.pl b/lib/Kalamar/Apps/test_backend.pl
new file mode 100644
index 0000000..237d566
--- /dev/null
+++ b/lib/Kalamar/Apps/test_backend.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/env perl
+use Mojolicious::Lite;
+use Mojo::ByteStream 'b';
+use Mojo::Date;
+
+# This is an API fake server with fixtures
+
+# Request API token
+get '/auth/apiToken' => sub {
+  my $c = shift;
+
+  # Get auth header
+  my $auth = $c->req->headers->authorization;
+
+  # Authorization missing or not basic
+  if (!$auth || $auth =~ s/\s*Basic\s+//gi) {
+    return $c->render(
+      json => {
+        error => [2, 'x']
+      }
+    );
+  };
+
+  # Decode header
+  my ($username, $pwd) = @{b($auth)->b64_decode->split(':')->to_array};
+
+  if ($pwd eq 'test') {
+
+    # Render info with token
+    return $c->render(
+      json => {
+        username => $username,
+        expires => Mojo::Date->new(time + (3 * 34 * 60 * 60)),
+        token => 'abcdefg',
+        token_type => 'api_token'
+      }
+    );
+  };
+
+  return $c->render(
+    json => {
+      error => []
+    }
+  );
+};
+
+app->start;
+
+1;