From 5dae00e9513919b5f26fd13e00364b0c9821d95e Mon Sep 17 00:00:00 2001 From: Yevhen Vydolob Date: Fri, 21 Dec 2018 12:38:40 +0200 Subject: [PATCH] #12132 fix review comments Signed-off-by: Yevhen Vydolob --- .../dto/TypeScriptDTOGeneratorMojoITest.java | 19 ++++++++++++++++++- .../src/it/resources/dto.spec.ts | 9 +++++++++ .../che/plugin/typescript/dto/DTOHelper.java | 2 +- .../typescript/dto/typescript.d.ts.template | 4 ++-- .../dto/TypeScriptDTOGeneratorMojoTest.java | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java b/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java index 360aa605d7f..1930a4ec1aa 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java +++ b/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java @@ -48,11 +48,15 @@ public class TypeScriptDTOGeneratorMojoITest { */ private static final String GENERATED_DTO_NAME = "my-typescript-test-module.ts"; + private static final String GENERATED_DTO_DTS_NAME = "my-typescript-test-module.d.ts"; + /** * DTO new name */ private static final String DTO_FILENAME = "dto.ts"; + private static final String DTO_DTS_FILENAME = "dtoD.d.ts"; + /** * DTO test name */ @@ -251,7 +255,7 @@ public void compileDTOAndLaunchTests() throws IOException, InterruptedException // search DTO Path p = this.buildDirectory; final int maxDepth = 10; - Stream matches = java.nio.file.Files.find(p, maxDepth, (path, basicFileAttributes) -> path.getFileName().toString().equals(GENERATED_DTO_NAME)); + Stream matches = java.nio.file.Files.find( p, maxDepth, (path, basicFileAttributes) -> path.getFileName().toString().equals(GENERATED_DTO_NAME)); // take first Optional optionalPath = matches.findFirst(); @@ -264,6 +268,19 @@ public void compileDTOAndLaunchTests() throws IOException, InterruptedException //copy it in test resources folder where package.json is java.nio.file.Files.copy(generatedDtoPath, this.rootPath.resolve(DTO_FILENAME), StandardCopyOption.REPLACE_EXISTING); + matches = java.nio.file.Files.find( p, maxDepth, (path, basicFileAttributes) -> path.getFileName().toString().equals(GENERATED_DTO_DTS_NAME)); + + // take first + optionalPath = matches.findFirst(); + if (!optionalPath.isPresent()) { + throw new IllegalStateException("Unable to find generated DTO file named '" + GENERATED_DTO_DTS_NAME + "'. Check it has been generated first"); + } + + generatedDtoPath = optionalPath.get(); + + //copy it in test resources folder where package.json is + java.nio.file.Files.copy(generatedDtoPath, this.rootPath.resolve(DTO_DTS_FILENAME), StandardCopyOption.REPLACE_EXISTING); + // setup command line List command = getDockerExec(); diff --git a/core/che-core-typescript-dto-maven-plugin/src/it/resources/dto.spec.ts b/core/che-core-typescript-dto-maven-plugin/src/it/resources/dto.spec.ts index d9d3a666ede..6fe6330bc1d 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/it/resources/dto.spec.ts +++ b/core/che-core-typescript-dto-maven-plugin/src/it/resources/dto.spec.ts @@ -11,6 +11,8 @@ */ import {org} from './dto'; +import {che} from './dtoD' + let expect = require('chai').expect; class DTOBuilder { @@ -103,6 +105,13 @@ describe("DTO serialization tests", () => { expect(myCustomDTO.toJson()).to.eql(myCustomDTOFromSource.toJson()); }); + it("check d.ts types", () => { + const customDto: che.plugin.typescript.MySimple = { + id: 1 + } + + expect(customDto).to.eql({id: 1} as che.plugin.typescript.MySimple) + }); diff --git a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/DTOHelper.java b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/DTOHelper.java index 16234d4eeea..32985006e1d 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/DTOHelper.java +++ b/core/che-core-typescript-dto-maven-plugin/src/main/java/org/eclipse/che/plugin/typescript/dto/DTOHelper.java @@ -201,7 +201,7 @@ public static String convertTypeForDTS(Type containerType, Type type) { return typePackage + "." + convertToDTSName((Class) type); } - /** Remove 'Dto' suffix from class nam */ + /** Remove 'Dto' suffix from class name */ public static String convertToDTSName(Class type) { String name = type.getSimpleName(); if (name.toLowerCase().endsWith("dto")) { diff --git a/core/che-core-typescript-dto-maven-plugin/src/main/resources/org/eclipse/che/plugin/typescript/dto/typescript.d.ts.template b/core/che-core-typescript-dto-maven-plugin/src/main/resources/org/eclipse/che/plugin/typescript/dto/typescript.d.ts.template index 8544200c226..e6345df967d 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/main/resources/org/eclipse/che/plugin/typescript/dto/typescript.d.ts.template +++ b/core/che-core-typescript-dto-maven-plugin/src/main/resources/org/eclipse/che/plugin/typescript/dto/typescript.d.ts.template @@ -9,7 +9,7 @@ export namespace { + // export interface { { }> \} }>\} -}> \ No newline at end of file +}> diff --git a/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoTest.java b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoTest.java index de301121207..77bef32caef 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoTest.java +++ b/core/che-core-typescript-dto-maven-plugin/src/test/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoTest.java @@ -84,7 +84,7 @@ public void testCheckTypeScriptGenerated() throws Exception { } @Test - public void checkD_TS_fileCreated() throws Exception { + public void checkDTSFileCreated() throws Exception { File projectCopy = this.resources.getBasedir("project-d-ts"); File pom = new File(projectCopy, "pom.xml"); assertNotNull(pom);