Skip to content

Commit

Permalink
Angular oauth2 / clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bolo89 committed May 18, 2022
1 parent 647e752 commit d89dda9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
4 changes: 4 additions & 0 deletions src/main/java/tech/jhipster/lite/common/domain/WordUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class WordUtils {
public static final String OB = "\\{";
public static final String CB = "\\}";

public static final String COMA = ",";
public static final String O_BRACKET = "[";
public static final String C_BRACKET = "]";

private static final String VALUE_FIELD = "value";

private WordUtils() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public class AngularCommon {
"^([\\s]+\"allowedCommonJsDependencies\": [^\\]]+)\\]"
);

protected static final String COMA = ",";
protected static final String O_BRACKET = "[";
protected static final String C_BRACKET = "]";

private AngularCommon() {
// Cannot be instantiated
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package tech.jhipster.lite.generator.client.angular.common.domain;

import static tech.jhipster.lite.common.domain.WordUtils.COMA;
import static tech.jhipster.lite.common.domain.WordUtils.C_BRACKET;
import static tech.jhipster.lite.common.domain.WordUtils.O_BRACKET;
import static tech.jhipster.lite.common.domain.WordUtils.indent;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.ALLOWED_COMMON_JS_DEPENDENCIES_REGEX_LIST;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.ANGULAR_JSON_FILE_NAME;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.COMA;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.C_BRACKET;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.DECLARATIONS_REGEX;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.DECLARATIONS_WITH_ARRAY_VALUES_REGEX_LIST;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.DECORATOR_REGEX_LIST;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.ENV_VARIABLES_WITH_VALUES_REGEX_LIST;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.EXISTING_IMPORT_PATTERN;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.O_BRACKET;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.PROVIDERS_WITH_ARRAY_VALUES_REGEX_LIST;
import static tech.jhipster.lite.generator.client.angular.common.domain.AngularCommon.TEST_REGEX_FORMAT;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package tech.jhipster.lite.generator.client.angular.security.oauth2.domain;

import static tech.jhipster.lite.common.domain.FileUtils.*;
import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_WEBAPP;

import java.util.List;
import java.util.Map;

Expand All @@ -9,11 +12,11 @@ private AngularOauth2() {
// Cannot be instantiated
}

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";
protected static final String APP_MODULE_TS_FILE_PATH = getPath(MAIN_WEBAPP, "app/app.module.ts");
protected static final String ENVIRONMENT_TS_FILE_PATH = getPath(MAIN_WEBAPP, "environments/environment.ts");
protected static final String ENVIRONMENT_PROD_TS_FILE_PATH = getPath(MAIN_WEBAPP, "environments/environment.prod.ts");
protected static final String APP_COMPONENT_HTML_FILE_PATH = getPath(MAIN_WEBAPP, "app/app.component.html");
protected static final String APP_COMPONENT_SPEC_TS_FILE_PATH = getPath(MAIN_WEBAPP, "app/app.component.spec.ts");

protected static List<String> getDependencies() {
return List.of("keycloak-js");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static tech.jhipster.lite.TestUtils.tmpProject;
import static tech.jhipster.lite.common.domain.FileUtils.getPath;
import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_WEBAPP;
import static tech.jhipster.lite.generator.project.domain.DefaultConfig.BASE_NAME;

import java.io.IOException;
Expand All @@ -19,11 +20,11 @@
@IntegrationTest
class AngularCommonApplicationServiceIT {

private static final String APP_MODULE_TS_FILE_PATH = "src/main/webapp/app/app.module.ts";
private static final String ENVIRONMENT_TS_FILE_PATH = "src/main/webapp/environments/environment.ts";
private static final String APP_COMPONENT_HTML_FILE_PATH = "src/main/webapp/app/app.component.html";
private static final String APP_COMPONENT_SPEC_TS_FILE_PATH = "src/main/webapp/app/app.component.spec.ts";
private static final String ANGULAR_JSON_FILE_PATH = "angular.json";
private static final String APP_MODULE_TS_FILE_PATH = getPath(MAIN_WEBAPP, "app/app.module.ts");
private static final String ENVIRONMENT_TS_FILE_PATH = getPath(MAIN_WEBAPP, "environments/environment.ts");
private static final String APP_COMPONENT_HTML_FILE_PATH = getPath(MAIN_WEBAPP, "app/app.component.html");
private static final String APP_COMPONENT_SPEC_TS_FILE_PATH = getPath(MAIN_WEBAPP, "app/app.component.spec.ts");
private static final String ANGULAR_JSON_FILE_NAME = "angular.json";

@Autowired
AngularCommonApplicationService angularCommonApplicationService;
Expand Down Expand Up @@ -265,7 +266,7 @@ void shouldAddAllowedCommonJsDependenciesAngularJson() throws IOException {
angularCommonApplicationService.addAllowedCommonJsDependenciesAngularJson(project, lib);

// Then
List<String> allLinesFile = Files.readAllLines(Path.of(getPath(project.getFolder(), ANGULAR_JSON_FILE_PATH)));
List<String> allLinesFile = Files.readAllLines(Path.of(getPath(project.getFolder(), ANGULAR_JSON_FILE_NAME)));
List<String> expectedContentLines =
"""
"allowedCommonJsDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static tech.jhipster.lite.TestUtils.assertFileExist;
import static tech.jhipster.lite.common.domain.FileUtils.getPath;
import static tech.jhipster.lite.common.domain.WordUtils.DQ;
import static tech.jhipster.lite.generator.project.domain.Constants.MAIN_WEBAPP;
import static tech.jhipster.lite.generator.project.domain.Constants.PACKAGE_JSON;

import java.io.IOException;
Expand All @@ -16,13 +17,13 @@
public class AngularOauth2Assert {

private static final List<String> ADDED_FILES_PATHS = List.of(
"src/main/webapp/app/auth/oauth2-auth.service.ts",
"src/main/webapp/app/auth/oauth2-auth.service.spec.ts",
"src/main/webapp/app/auth/http-auth.interceptor.ts",
"src/main/webapp/app/auth/http-auth.interceptor.spec.ts",
"src/main/webapp/app/login/login.component.html",
"src/main/webapp/app/login/login.component.ts",
"src/main/webapp/app/login/login.component.spec.ts"
getPath(MAIN_WEBAPP, "app/auth/oauth2-auth.service.ts"),
getPath(MAIN_WEBAPP, "app/auth/oauth2-auth.service.spec.ts"),
getPath(MAIN_WEBAPP, "app/auth/http-auth.interceptor.ts"),
getPath(MAIN_WEBAPP, "app/auth/http-auth.interceptor.spec.ts"),
getPath(MAIN_WEBAPP, "app/login/login.component.html"),
getPath(MAIN_WEBAPP, "app/login/login.component.ts"),
getPath(MAIN_WEBAPP, "app/login/login.component.spec.ts")
);

private static final List<String> ADDED_DEPENDENCIES = List.of("keycloak-js");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AngularOauth2ResourceIT {
InitApplicationService initApplicationService;

@Test
void shouldAddJwtAngular() throws Exception {
void shouldAddOauth2() throws Exception {
ProjectDTO projectDTO = readFileToObject("json/chips.json", ProjectDTO.class).folder(tmpDirForTest());
Project project = ProjectDTO.toProject(projectDTO);
initApplicationService.init(project);
Expand Down

0 comments on commit d89dda9

Please sign in to comment.