Skip to content

Commit

Permalink
fix angular project build (missing keycloak config in env prod)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bolo89 committed May 15, 2022
1 parent 2d1db18 commit d891c24
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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<String> angularJsonTsLines = Files.readAllLines(Path.of(getPath(project.getFolder(), "angular.json")));
expectedContentLines =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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\"");

Expand Down

0 comments on commit d891c24

Please sign in to comment.