diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2.java b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2.java index 4f326bbb53d..8314117ea51 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2.java +++ b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2.java @@ -11,6 +11,7 @@ private AngularOauth2() { protected static final String APP_MODULE_TS_FILE_PATH = "src/main/webapp/app/app.module.ts"; protected static final String ENVIRONMENT_TS_FILE_PATH = "src/main/webapp/environments/environment.ts"; + protected static final String ENVIRONMENT_PROD_TS_FILE_PATH = "src/main/webapp/environments/environment.prod.ts"; protected static final String APP_COMPONENT_HTML_FILE_PATH = "src/main/webapp/app/app.component.html"; protected static final String APP_COMPONENT_SPEC_TS_FILE_PATH = "src/main/webapp/app/app.component.spec.ts"; diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainService.java b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainService.java index 9a737e13d8e..bbd1b037011 100644 --- a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainService.java +++ b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainService.java @@ -4,6 +4,7 @@ import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.APP_COMPONENT_HTML_FILE_PATH; import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.APP_COMPONENT_SPEC_TS_FILE_PATH; import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.APP_MODULE_TS_FILE_PATH; +import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.ENVIRONMENT_PROD_TS_FILE_PATH; import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.ENVIRONMENT_TS_FILE_PATH; import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_WEBAPP; import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME; @@ -107,17 +108,16 @@ private void updateAppModuleTsFile(Project project) { } private void addEnvVariables(Project project) { - angularCommonService.addEnvVariables( - project, - ENVIRONMENT_TS_FILE_PATH, + String envVariables = """ keycloak: { url: 'http://localhost:9080/auth', realm: 'jhipster', client_id: 'web_app' } - """ - ); + """; + angularCommonService.addEnvVariables(project, ENVIRONMENT_TS_FILE_PATH, envVariables); + angularCommonService.addEnvVariables(project, ENVIRONMENT_PROD_TS_FILE_PATH, envVariables); } private void addKeycloakJsAllowedCommonJsDependency(Project project) { diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/application/AngularOauth2Assert.java b/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/application/AngularOauth2Assert.java index 879400b1190..bf5571f8a3e 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/application/AngularOauth2Assert.java +++ b/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/application/AngularOauth2Assert.java @@ -69,7 +69,7 @@ public static void assertUpdatedFiles(Project project) throws IOException { .toList(); assertThat(appModuleTsLines).containsAll(expectedContentLines); - // ENvironnement.ts + // Environnement.ts assertFileContent( project, "src/main/webapp/environments/environment.ts", @@ -86,6 +86,23 @@ public static void assertUpdatedFiles(Project project) throws IOException { .toList() ); + // Environnement-prod.ts + assertFileContent( + project, + "src/main/webapp/environments/environment.prod.ts", + """ + export const environment = { + production: true, + keycloak: { + url: 'http://localhost:9080/auth', + realm: 'jhipster', + client_id: 'web_app' + } + }; + """.lines() + .toList() + ); + // Angular.json List angularJsonTsLines = Files.readAllLines(Path.of(getPath(project.getFolder(), "angular.json"))); expectedContentLines = diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainServiceTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainServiceTest.java index b0fc71a3d77..47b2fed6de2 100644 --- a/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainServiceTest.java +++ b/src/test/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2DomainServiceTest.java @@ -11,6 +11,7 @@ import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.APP_COMPONENT_HTML_FILE_PATH; import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.APP_COMPONENT_SPEC_TS_FILE_PATH; import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.APP_MODULE_TS_FILE_PATH; +import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.ENVIRONMENT_PROD_TS_FILE_PATH; import static tech.jhipster.lite.generator.client.angular.security.oauth2.domain.AngularOauth2.ENVIRONMENT_TS_FILE_PATH; import java.util.Optional; @@ -106,7 +107,7 @@ private void verifyUpdatedFiles(Project project) { verify(angularCommonService, times(1)).addConstants(any(Project.class), anyString(), anyString()); verify(angularCommonService, times(2)).addDeclarations(any(Project.class), anyString(), anyString()); verify(angularCommonService, times(1)).addProviders(any(Project.class), anyString(), anyString()); - verify(angularCommonService, times(1)).addEnvVariables(any(Project.class), anyString(), anyString()); + verify(angularCommonService, times(2)).addEnvVariables(any(Project.class), anyString(), anyString()); verify(angularCommonService, times(1)).addAllowedCommonJsDependenciesAngularJson(any(Project.class), anyString()); verify(angularCommonService, times(1)).addHtml(any(Project.class), anyString(), anyString(), anyString()); verify(angularCommonService, times(1)).addTest(any(Project.class), anyString(), anyString(), anyString()); @@ -152,18 +153,16 @@ private void verifyUpdatedFiles(Project project) { """ ); - verify(angularCommonService) - .addEnvVariables( - project, - ENVIRONMENT_TS_FILE_PATH, - """ + String envVariables = + """ keycloak: { url: 'http://localhost:9080/auth', realm: 'jhipster', client_id: 'web_app' } - """ - ); + """; + verify(angularCommonService).addEnvVariables(project, ENVIRONMENT_TS_FILE_PATH, envVariables); + verify(angularCommonService).addEnvVariables(project, ENVIRONMENT_PROD_TS_FILE_PATH, envVariables); verify(angularCommonService).addAllowedCommonJsDependenciesAngularJson(project, " \"keycloak-js\"");