Skip to content

Commit

Permalink
fix dependencies between JWT & Health
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert committed Jun 1, 2022
1 parent a724969 commit 322f448
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,35 @@ private void updateAngularFilesForHealth(Project project) {
String oldHtml = "// jhipster-needle-angular-route";
String newHtml =
"""
// jhipster-needle-angular-route
{
path: 'admin',
loadChildren: () => import('./admin/admin-routing.module').then(m => m.AdminRoutingModule),
},""";
},
// jhipster-needle-angular-route""";
projectRepository.replaceText(project, APP, APP_ROUTING_MODULE, oldHtml, newHtml);

oldHtml = "<!-- jhipster-needle-angular-menu -->";
newHtml =
"""
newHtml = """
<a routerLink="admin/health" mat-menu-item><span>Health</span></a>
<!-- jhipster-needle-angular-menu -->
""";
<!-- jhipster-needle-angular-menu -->""";
projectRepository.replaceText(project, APP, APP_COMPONENT_HTML, oldHtml, newHtml);

oldHtml = "// jhipster-needle-angular-health";
newHtml = """
oldHtml = "// jhipster-needle-angular-menu";
newHtml =
"""
it('should navigate on admin endpoint', () => {
router.navigateByUrl('/admin');
});
""";
// jhipster-needle-angular-menu""";
projectRepository.replaceText(project, APP, APP_ROUTING_MODULE_SPEC, oldHtml, newHtml);

oldHtml = "// jhipster-needle-angular-health";
newHtml = """
oldHtml = "// jhipster-needle-angular-menu";
newHtml =
"""
it('should navigate on health endpoint', () => {
router.navigateByUrl('/health');
});
""";
// jhipster-needle-angular-menu""";
projectRepository.replaceText(project, APP, ADMIN_ROUTING_MODULE_SPEC, oldHtml, newHtml);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void addAllowedCommonJsDependenciesAngularJson(Project project, String li
public List<String> getAngularModules() {
return List.of(
"BrowserAnimationsModule",
"HttpClientModule",
"MatMenuModule",
"MatToolbarModule",
"MatIconModule",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Map<String, String> scripts() {
}

public static List<String> files() {
return List.of("angular.json", "jest.conf.js", "tsconfig.app.json", "tsconfig.json", "tsconfig.spec.json");
return List.of("angular.json", "jest.conf.js", "proxy.conf.json", "tsconfig.app.json", "tsconfig.json", "tsconfig.spec.json");
}

public static Map<String, String> angularFiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ public static List<String> jwtDependencies() {
return List.of("ngx-webstorage");
}

public static Map<String, String> jwtFiles() {
return Map.ofEntries(Map.entry("proxy.conf.json", ""));
}

public static Map<String, String> angularJwtFiles() {
String primaryAppAuth = "app/auth";
String primaryAppLogin = "app/login";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public void addAppJwtFiles(Project project) {

addJwtDependencies(project);
addAngularJwtFiles(project);
addJwtFiles(project);
updateAngularFilesForJwt(project);
}

Expand All @@ -62,7 +61,6 @@ public void updateAngularFilesForJwt(Project project) {
oldHtml = "import \\{ NgModule \\} from '@angular/core';";
newHtml =
"""
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { NgxWebstorageModule } from 'ngx-webstorage';""";
Expand All @@ -80,7 +78,7 @@ public void updateAngularFilesForJwt(Project project) {
newHtml =
"imports: \\[" +
angularCommonService.getAngularModules().stream().collect(Collectors.joining(", ")) +
", HttpClientModule, ReactiveFormsModule, NgxWebstorageModule.forRoot()\\],";
", ReactiveFormsModule, NgxWebstorageModule.forRoot()\\],";
projectRepository.replaceText(project, APP, APP_MODULE, oldHtml, newHtml);

oldHtml = "bootstrap: \\[AppComponent\\],";
Expand All @@ -95,30 +93,6 @@ public void updateAngularFilesForJwt(Project project) {
},
],""";
projectRepository.replaceText(project, APP, APP_MODULE, oldHtml, newHtml);

oldHtml = "9000";
newHtml = """
9000,
"proxyConfig": "proxy.conf.json" """;
projectRepository.replaceText(project, "", "angular.json", oldHtml, newHtml);
}

public void addJwtFiles(Project project) {
project.addConfig("serverPort", 8080);

List<ProjectFile> files = AngularJwt
.jwtFiles()
.entrySet()
.stream()
.map(entry ->
ProjectFile
.forProject(project)
.withSource(getPath(SOURCE, entry.getValue()), entry.getKey())
.withDestinationFolder(getPath("", entry.getValue()))
)
.toList();

projectRepository.template(files);
}

public void addAngularJwtFiles(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ private void updateAppModuleTsFile(Project project) {
project,
APP_MODULE_TS_FILE_PATH,
"""
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LoginComponent } from './login/login.component';
import { Oauth2AuthService } from './auth/oauth2-auth.service';
import { HttpAuthInterceptor } from './auth/http-auth.interceptor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ describe('AdminRoutingModule', () => {
expect(AdminRoutingModule).toBeDefined();
});

// jhipster-needle-angular-health
// jhipster-needle-angular-menu
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
},
"serve": {
"options": {
"port": 9000
"port": 9000,
"proxyConfig": "proxy.conf.json"
},
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/generator/client/angular/core/proxy.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"/api": {
"target": "http://localhost:8080",
"secure": false
},
"/management": {
"target": "http://localhost:8080",
"secure": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ describe('AppRoutingModule', () => {
expect(AppRoutingModule).toBeDefined();
});

// jhipster-needle-angular-health
// jhipster-needle-angular-menu
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

export const routes: Routes = [
// jhipster-needle-angular-route
// jhipster-needle-angular-route
];

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand All @@ -13,7 +14,7 @@ import { MatMenuModule } from '@angular/material/menu';

@NgModule({
declarations: [AppComponent],
imports: [BrowserAnimationsModule, MatMenuModule, MatToolbarModule, MatIconModule, MatButtonModule, MatButtonToggleModule, BrowserModule, AppRoutingModule],
imports: [BrowserAnimationsModule, HttpClientModule, MatMenuModule, MatToolbarModule, MatIconModule, MatButtonModule, MatButtonToggleModule, BrowserModule, AppRoutingModule],
bootstrap: [AppComponent],
})
export class AppModule {}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public static void assertUpdatedFiles(Project project) throws IOException {
{
path: 'admin',
loadChildren: () => import('./admin/admin-routing.module').then(m => m.AdminRoutingModule),
},""".lines()
},
// jhipster-needle-angular-route""".lines()
.toList();
assertThat(appRoutingModuleTsLines).containsAll(expectedContentLines);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ void shouldGetAngularModules() {
.isEqualTo(
List.of(
"BrowserAnimationsModule",
"HttpClientModule",
"MatMenuModule",
"MatToolbarModule",
"MatIconModule",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static void assertConfigFiles(Project project) {
assertFileExist(project, "angular.json");
assertFileContent(project, "angular.json", "\"port\": 9000");
assertFileExist(project, "jest.conf.js");
assertFileExist(project, "proxy.conf.json");
assertFileExist(project, "tsconfig.app.json");
assertFileExist(project, "tsconfig.json");
assertFileExist(project, "tsconfig.spec.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void shouldAddFiles() {

angularDomainService.addFiles(project);

verify(projectRepository).add(filesCountArgument(5));
verify(projectRepository).add(filesCountArgument(6));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ void shouldNotAddJwtDependencies() {
assertThatThrownBy(() -> angularJwtDomainService.addJwtDependencies(project)).isExactlyInstanceOf(GeneratorException.class);
}

@Test
void shouldAddJwtFiles() {
Project project = tmpProjectWithPackageJson();

angularJwtDomainService.addJwtFiles(project);

verify(projectRepository).template(ProjectFilesAsserter.filesCountArgument(1));
}

@Test
void shouldAddAngularJwtFiles() {
Project project = tmpProjectWithPackageJson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void assertUpdatedFiles(Project project) throws IOException {
"""
import { NgModule, APP_INITIALIZER} from '@angular/core';
import { MatButtonToggleModule } from '@angular/material/button-toggle';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { LoginComponent } from './login/login.component';
import { Oauth2AuthService } from './auth/oauth2-auth.service';
import { HttpAuthInterceptor } from './auth/http-auth.interceptor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ private void verifyUpdatedFiles(Project project) {
project,
APP_MODULE_TS_FILE_PATH,
"""
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LoginComponent } from './login/login.component';
import { Oauth2AuthService } from './auth/oauth2-auth.service';
import { HttpAuthInterceptor } from './auth/http-auth.interceptor';
Expand Down

0 comments on commit 322f448

Please sign in to comment.