Added a README for the UI2 archetype

Change-Id: I7e0b40a5c34610b3e4d97eef59cbf545426fce06
diff --git a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/BUILD.rename b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/BUILD.rename
index b0eafd4..0d28862 100644
--- a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/BUILD.rename
+++ b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/BUILD.rename
@@ -65,7 +65,7 @@
 """
     Run ng build to create ${artifactId} GUI 2 library in production mode
     The output file ${artifactId}-gui-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/
-    See bazel-genfiles/web/${artifactId}-gui-lib/${artifactId}-gui-lib.log for details of the Angular CLI output
+    See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib.log for details of the Angular CLI output
 """
 
 genrule(
@@ -91,37 +91,37 @@
           " export XDG_CONFIG_HOME=$(@D)/config &&" +
           " NODE=$(location @nodejs//:bin/node) &&" +
           " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" +  # An array of filenames - sorted by time created
-          " ${appNameAllCaps}_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" +  # An array of filenames - sorted by time created
-          " mkdir -p web/${artifactId}-gui-lib &&" +
-          " cd web/${artifactId}-gui-lib &&" +
+          " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" +  # An array of filenames - sorted by time created
+          " mkdir -p apps/${artifactId}/web/${artifactId}-gui &&" +
+          " cd apps/${artifactId}/web/${artifactId}-gui &&" +
           " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
-          " tar xf $$ROOT/$${${appNameAllCaps}_FILES[0]} &&" +
+          " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
           " mv package/ node_modules/gui2-fw-lib/ &&" +
           " mkdir -p projects/${artifactId}-gui-lib/fw &&" +
           " (cd projects/${artifactId}-gui-lib/fw &&" +
           "  jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
           " chmod +x node_modules/@angular/cli/bin/ng &&" +
-          " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/${artifactId}-gui-lib/node_modules/@angular/cli/bin:$$PATH &&" +
+          " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/apps/${artifactId}/web/${artifactId}-gui/node_modules/@angular/cli/bin:$$PATH &&" +
           " ng build ${artifactId}-gui-lib >> $$ROOT/$(location ${artifactId}-gui-lib.log) 2>&1 ||" +
           " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
           " else " +
-          "   echo 'Error running \'ng build ${artifactId}-gui-lib\' on \'//web/${artifactId}-gui-lib:${artifactId}-gui-lib-build\'. \\\n" +
-          "     See bazel-genfiles/web/${artifactId}-gui-lib/${artifactId}-gui-lib.log for more details' >&2;" +
-          #"   tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
+          "   echo 'Error running \'ng build ${artifactId}-gui-lib\' on \'//apps/${artifactId}/web/${artifactId}-gui:${artifactId}-gui-lib-build\'. \\\n" +
+          "     See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib.log for more details' >&2;" +
+          #"   tail -n 100 ../../../../$(location onos-gui2-ng-test.log) >&2;" +
           "   exit 1;" +
           " fi;" +
           " cp README.md LICENSE dist/${artifactId}-gui-lib && " +
           " npm pack ./dist/${artifactId}-gui-lib >> $$ROOT/$(location ${artifactId}-gui-lib.log) 2>&1 &&" +
           " mv ${artifactId}-gui-lib-*.tgz $$ROOT/$(location ${artifactId}-gui-lib-ver.tgz) &&" +
           " touch $$ROOT/$(location ${artifactId}-gui-lib.log)",  # to get the log always as the 2nd file,
-    message = "Angular ${artifactId} GUI2 build",
+    message = "Angular ${artifactId} Lib build",
     visibility = ["//visibility:public"],
 )
 
 """
     Run 'ng test' to run Angular test and 'ng lint' for checkstyle
-    See bazel-genfiles/web/${artifactId}-gui-lib/${artifactId}-gui-lib-lint.log or
-    bazel-genfiles/web/${artifactId}-gui-lib/${artifactId}-gui-lib-test.log for details of the Angular CLI output
+    See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-lint.log or
+    bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-test.log for details of the Angular CLI output
 """
 
 genrule(
@@ -149,25 +149,25 @@
           " NODE=$(location @nodejs//:bin/node) &&" +
           " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" +  # An array of filenames - sorted by time created
           " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" +  # An array of filenames - sorted by time created
-          " mkdir -p web/${artifactId}-gui-lib &&" +
-          " cd web/${artifactId}-gui-lib &&" +
-          " jar xf ../../$(location :_${artifactId}_lib_src_tests) &&" +
+          " mkdir -p apps/${artifactId}/web/${artifactId}-gui &&" +
+          " cd apps/${artifactId}/web/${artifactId}-gui &&" +
+          " jar xf ../../../../$(location :_${artifactId}_lib_src_tests) &&" +
           " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
           " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
           " mv package/ node_modules/gui2-fw-lib/ &&" +
           " mkdir -p projects/${artifactId}-gui-lib/fw &&" +
           " (cd projects/${artifactId}-gui-lib/fw &&" +
           "  jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
-          " chmod +x $$ROOT/web/${artifactId}-gui-lib/node_modules/@angular/cli/bin/ng &&" +
+          " chmod +x $$ROOT/apps/${artifactId}/web/${artifactId}-gui/node_modules/@angular/cli/bin/ng &&" +
           " export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" +
-          " node -v > ../../$(location ${artifactId}-gui-lib-ver.log) &&" +
-          " npm -v >> ../../$(location ${artifactId}-gui-lib-ver.log) &&" +
-          " ng version >> ../../$(location ${artifactId}-gui-lib-ver.log) &&" +
-          " ng lint ${artifactId}-gui-lib > ../../$(location ${artifactId}-gui-lib-lint.log)  2>&1 ||" +
+          " node -v > ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
+          " npm -v >> ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
+          " ng version >> ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
+          " ng lint ${artifactId}-gui-lib > ../../../../$(location ${artifactId}-gui-lib-lint.log)  2>&1 ||" +
           " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
           " else " +
-          "   echo 'Error running \'ng lint\' on \'//web/${artifactId}-gui-lib:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
-          "     See bazel-genfiles/web/${artifactId}-gui-lib/${artifactId}-gui-lib-lint.log for more details' >&2;" +
+          "   echo 'Error running \'ng lint\' on \'//apps/${artifactId}/web/${artifactId}-gui:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
+          "     See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-lint.log for more details' >&2;" +
           "   exit 1;" +
           " fi;" +
           " if [ -f /usr/bin/chromium-browser ]; then " +  # Add to this for Mac and Chrome
@@ -179,18 +179,18 @@
           "   no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
           "   Install Google Chrome or Chromium Browser to allow this step to run.';" +
           "   echo -e $$MSG >&2;" +
-          "   echo -e $$MSG > ../../$(location ${artifactId}-gui-lib-test.log);" +
+          "   echo -e $$MSG > ../../../../$(location ${artifactId}-gui-lib-test.log);" +
           "   exit 0;" +
           " fi;" +
           " ng test ${artifactId}-gui-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
-          "     --watch=false > ../../$(location ${artifactId}-gui-lib-test.log) 2>&1 ||" +
+          "     --watch=false > ../../../../$(location ${artifactId}-gui-lib-test.log) 2>&1 ||" +
           " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
           " else " +
-          "   echo 'Error running \'ng test ${artifactId}-gui-lib\' on \'//web/${artifactId}-gui-lib:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
-          "     See bazel-genfiles/web/${artifactId}-gui-lib/${artifactId}-gui-lib-test.log for more details' >&2;" +
+          "   echo 'Error running \'ng test ${artifactId}-gui-lib\' on \'//apps/${artifactId}/web/${artifactId}-gui:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
+          "     See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-test.log for more details' >&2;" +
           "   exit 1;" +
           " fi;",
-    message = "Angular Topo GUI2 Lib lint and test",
+    message = "Angular ${appNameCap}${appNameEnd} Lib lint and test",
 )
 
 """
@@ -250,8 +250,8 @@
         ],
     ),
     outs = ["${artifactId}_gui_lib_src_tests.jar"],
-    cmd = "cd web/${artifactId}-gui-lib &&" +
-          " jar Mcf ../../$@ .",
+    cmd = "cd apps/${artifactId}/web/${artifactId}-gui &&" +
+          " jar Mcf ../../../../$@ .",
 )
 
 """
@@ -273,9 +273,9 @@
         ],
     ),
     outs = ["${artifactId}_gui_lib_tests.jar"],
-    cmd = "cd web/${artifactId}-gui-lib &&" +
+    cmd = "cd apps/${artifactId}/web/${artifactId}-gui &&" +
           " find projects/${artifactId}-gui-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" +
-          " jar Mcf ../../$@ projects/${artifactId}-gui-lib/src/lib",
+          " jar Mcf ../../../../$@ projects/${artifactId}-gui-lib/src/lib",
 )
 
 """
diff --git a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/ng-test.sh b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/ng-test.sh
new file mode 100755
index 0000000..1c3d95a
--- /dev/null
+++ b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/ng-test.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+set -euo pipefail
+# --- begin runfiles.bash initialization ---
+if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+    if [[ -f "$0.runfiles_manifest" ]]; then
+      export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
+    elif [[ -f "$0.runfiles/MANIFEST" ]]; then
+      export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
+    elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+      export RUNFILES_DIR="$0.runfiles"
+    fi
+fi
+
+if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
+  source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
+elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
+  source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
+            "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
+else
+  echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
+  exit 1
+fi
+
+# --- end runfiles.bash initialization ---
+
+
diff --git a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/package.json b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/package.json
index d90d0d7..11f711e 100644
--- a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/package.json
+++ b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/package.json
@@ -12,6 +12,8 @@
   },
   "peerDependencies": {
     "@angular/common": "^7.0.0",
-    "@angular/core": "^7.0.0"
+    "@angular/core": "^7.0.0",
+    "gui2-fw-lib": "^2.1.1",
+    "d3": "^5.9.2"
   }
-}
\ No newline at end of file
+}
diff --git a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.spec.ts b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.spec.ts
index 1aa7d04..5d0c76a 100644
--- a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.spec.ts
+++ b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.spec.ts
@@ -16,16 +16,68 @@
 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { ${appNameCap}${appNameEnd}Component } from './${artifactId}.component';
+import {ActivatedRoute, Params} from '@angular/router';
+import { of } from 'rxjs';
+import { } from 'jasmine';
+import {
+    FnService,
+    IconService,
+    IconComponent,
+    LogService,
+    TableFilterPipe, LoadingComponent,
+} from 'gui2-fw-lib';
+import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
+import {FormsModule} from '@angular/forms';
+import {RouterTestingModule} from '@angular/router/testing';
+
+class MockActivatedRoute extends ActivatedRoute {
+    constructor(params: Params) {
+        super();
+        this.queryParams = of(params);
+    }
+}
+
+class MockIconService {
+    loadIconDef() { }
+}
 
 describe('${appNameCap}${appNameEnd}Component', () => {
+    let fs: FnService;
+    let ar: MockActivatedRoute;
+    let windowMock: Window;
+    let logServiceSpy: jasmine.SpyObj<LogService>;
     let component: ${appNameCap}${appNameEnd}Component;
     let fixture: ComponentFixture<${appNameCap}${appNameEnd}Component>;
 
     beforeEach(async(() => {
+        const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
+        ar = new MockActivatedRoute({ 'debug': 'txrx' });
+
+        windowMock = <any>{
+            location: <any>{
+                hostname: 'foo',
+                host: 'foo',
+                port: '80',
+                protocol: 'http',
+                search: { debug: 'true' },
+                href: 'ws://foo:123/onos/ui/websock/path',
+                absUrl: 'ws://foo:123/onos/ui/websock/path'
+            }
+        };
+        fs = new FnService(ar, logSpy, windowMock);
+
         TestBed.configureTestingModule({
-            declarations: [ ${appNameCap}${appNameEnd}Component ]
+            imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
+            declarations: [ ${appNameCap}${appNameEnd}Component ],
+            providers: [
+                { provide: FnService, useValue: fs },
+                { provide: LogService, useValue: logSpy },
+                { provide: IconService, useClass: MockIconService },
+                { provide: 'Window', useValue: windowMock },
+            ]
         })
         .compileComponents();
+        logServiceSpy = TestBed.get(LogService);
     }));
 
     beforeEach(() => {
diff --git a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.ts b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.ts
index 5177356..d510867 100644
--- a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.ts
+++ b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/__artifactId__/__artifactId__.component.ts
@@ -38,7 +38,7 @@
     ngOnInit() {
         this.wss.bindHandlers(new Map<string, (data) => void>([
             [SAMPLE_CUSTOM_DATA_RESP, (data) => {
-                this.log.debug(SAMPLE_CUSTOM_DATA_RESP, data)
+                this.log.debug(SAMPLE_CUSTOM_DATA_RESP, data);
             }
             ]
         ]));
diff --git a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/welcome/welcome.component.spec.ts b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/welcome/welcome.component.spec.ts
index 28c59a9..103e29f 100644
--- a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/welcome/welcome.component.spec.ts
+++ b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/src/lib/welcome/welcome.component.spec.ts
@@ -16,16 +16,68 @@
 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { WelcomeComponent } from './welcome.component';
+import {ActivatedRoute, Params} from '@angular/router';
+import { of } from 'rxjs';
+import { } from 'jasmine';
+import {
+    FnService,
+    IconService,
+    IconComponent,
+    LogService,
+    TableFilterPipe, LoadingComponent,
+} from 'gui2-fw-lib';
+import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
+import {FormsModule} from '@angular/forms';
+import {RouterTestingModule} from '@angular/router/testing';
+
+class MockActivatedRoute extends ActivatedRoute {
+    constructor(params: Params) {
+        super();
+        this.queryParams = of(params);
+    }
+}
+
+class MockIconService {
+    loadIconDef() { }
+}
 
 describe('WelcomeComponent', () => {
+    let fs: FnService;
+    let ar: MockActivatedRoute;
+    let windowMock: Window;
+    let logServiceSpy: jasmine.SpyObj<LogService>;
     let component: WelcomeComponent;
     let fixture: ComponentFixture<WelcomeComponent>;
 
     beforeEach(async(() => {
+        const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
+        ar = new MockActivatedRoute({ 'debug': 'txrx' });
+
+        windowMock = <any>{
+            location: <any>{
+                hostname: 'foo',
+                host: 'foo',
+                port: '80',
+                protocol: 'http',
+                search: { debug: 'true' },
+                href: 'ws://foo:123/onos/ui/websock/path',
+                absUrl: 'ws://foo:123/onos/ui/websock/path'
+            }
+        };
+        fs = new FnService(ar, logSpy, windowMock);
+
         TestBed.configureTestingModule({
-            declarations: [ WelcomeComponent ]
+            imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
+            declarations: [ WelcomeComponent ],
+            providers: [
+                { provide: FnService, useValue: fs },
+                { provide: LogService, useValue: logSpy },
+                { provide: IconService, useClass: MockIconService },
+                { provide: 'Window', useValue: windowMock },
+            ]
         })
         .compileComponents();
+        logServiceSpy = TestBed.get(LogService);
     }));
 
     beforeEach(() => {
diff --git a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/tslint.json b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/tslint.json
index 6b8354e..ee5daee 100644
--- a/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/tslint.json
+++ b/tools/package/archetypes/ui2/src/main/resources/archetype-resources/web/__artifactId__-gui/projects/__artifactId__-gui-lib/tslint.json
@@ -4,13 +4,13 @@
     "directive-selector": [
       true,
       "attribute",
-      "sample-app",
+      "${artifactId}",
       "camelCase"
     ],
     "component-selector": [
       true,
       "element",
-      "sample-app",
+      "${artifactId}",
       "kebab-case"
     ]
   }