Skip to content

Commit

Permalink
#12132 fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Dec 21, 2018
1 parent 5cefbf6 commit 5dae00e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -251,7 +255,7 @@ public void compileDTOAndLaunchTests() throws IOException, InterruptedException
// search DTO
Path p = this.buildDirectory;
final int maxDepth = 10;
Stream<Path> matches = java.nio.file.Files.find(p, maxDepth, (path, basicFileAttributes) -> path.getFileName().toString().equals(GENERATED_DTO_NAME));
Stream<Path> matches = java.nio.file.Files.find( p, maxDepth, (path, basicFileAttributes) -> path.getFileName().toString().equals(GENERATED_DTO_NAME));

// take first
Optional<Path> optionalPath = matches.findFirst();
Expand All @@ -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<String> command = getDockerExec();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
import {org} from './dto';

import {che} from './dtoD'

let expect = require('chai').expect;

class DTOBuilder {
Expand Down Expand Up @@ -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)
});



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export namespace <namespaces.namespace> {

<! BEGIN declare interfaces !>
<namespaces.dtoInterfaces: { dto |
//<dto.name>
// <dto.name>
export interface <dto.dtsName> {
<! BEGIN declare fields !>
<dto.fieldAttributeModels:{ field |
<field.name>?: <if(field.map)> { [key: <field.mapKeyType>]: <field.mapValueType>; \}<else><field.dtsType><endif>;
}> \} <! END declare interface !>

}>\} <! END declare dto module !>
}>
}>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5dae00e

Please sign in to comment.