TaskGenerateConnect extends AbstractTaskConnectGenerator { @Override public void execute() throws ExecutionFailedException { File customConnectClient = new File(frontendDirectory, CUSTOM_CONNECT_CLIENT_NAME); String customName = customConnectClient.exists() ? ("../" + CUSTOM_CONNECT_CLIENT_NAME) : null; if (VaadinConnectTsGenerator.launch(openApi, outputFolder, customName)) { new VaadinConnectClientGenerator(readApplicationProperties()) .generateVaadinConnectClientFile(connectClientFile.toPath()); } } TaskGenerateConnect(File applicationProperties, File openApi,
                        File outputFolder, File frontendDirectory); @Override void execute();  }
@Test public void should_generate_Two_TypeScriptFiles() throws Exception { File ts1 = new File(outputDirectory, "FooBarEndpoint.ts"); File ts2 = new File(outputDirectory, "FooFooEndpoint.ts"); File client = new File(outputDirectory, "connect-client.default.ts"); File frontendDirectory = outputDirectory.getParentFile(); assertFalse(ts1.exists()); assertFalse(ts2.exists()); assertFalse(client.exists()); taskGenerateConnectTs = new TaskGenerateConnect(properties, openApiJson, outputDirectory, frontendDirectory); taskGenerateConnectTs.execute(); assertTrue(ts1.exists()); assertTrue(ts2.exists()); assertTrue(client.exists()); String output = FileUtils.readFileToString(client, "UTF-8"); assertTrue(output .contains("import {ConnectClient} from '@vaadin/flow-frontend/Connect';")); assertTrue(output.contains( "const client = new ConnectClient({prefix: 'connect'});")); assertTrue(output.contains("export default client;")); }
@Test public void should_use_custom_endpoint_name_when_connect_client_exists() throws Exception { File ts1 = new File(outputDirectory, "FooBarEndpoint.ts"); File ts2 = new File(outputDirectory, "FooFooEndpoint.ts"); File client = new File(outputDirectory, "connect-client.default.ts"); File frontendDirectory = outputDirectory.getParentFile(); File customConnectClient = temporaryFolder .newFile("connect-client.ts"); assertFalse(ts1.exists()); assertFalse(ts2.exists()); assertFalse(client.exists()); assertTrue(customConnectClient.exists()); taskGenerateConnectTs = new TaskGenerateConnect(properties, openApiJson, outputDirectory, frontendDirectory); taskGenerateConnectTs.execute(); assertTrue(ts1.exists()); assertTrue(ts2.exists()); assertTrue(client.exists()); String outputEndpoinTs1 = FileUtils.readFileToString(ts1, "UTF-8"); String outputEndpoinTs2 = FileUtils.readFileToString(ts2, "UTF-8"); assertThat(outputEndpoinTs1, containsString("import client from '../connect-client'")); assertThat(outputEndpoinTs1, containsString("import client from '../connect-client'")); }