Search in sources :

Example 1 with TypeScriptGenerator

use of cz.habarta.typescript.generator.TypeScriptGenerator in project typescript-generator by vojtechhabarta.

the class AxiosClientExtensionTest method test.

@Test
public void test() {
    final Settings settings = TestUtils.settings();
    settings.outputFileType = TypeScriptFileType.implementationFile;
    settings.outputKind = TypeScriptOutputKind.module;
    settings.generateJaxrsApplicationClient = true;
    settings.jaxrsNamespacing = JaxrsNamespacing.perResource;
    settings.extensions.add(new AxiosClientExtension());
    final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(JaxrsApplicationTest.OrganizationApplication.class));
    final String errorMessage = "Unexpected output: " + output;
    Assert.assertTrue(errorMessage, output.contains("interface Organization"));
    Assert.assertTrue(errorMessage, output.contains("interface Address"));
    Assert.assertTrue(errorMessage, output.contains("interface Person"));
    Assert.assertTrue(errorMessage, output.contains("interface HttpClient"));
    Assert.assertTrue(errorMessage, output.contains("class OrganizationsResourceClient<O>"));
    Assert.assertTrue(errorMessage, output.contains("class PersonResourceClient<O>"));
    Assert.assertTrue(errorMessage, output.contains("type RestResponse<R> = Promise<Axios.GenericAxiosResponse<R>>"));
    Assert.assertTrue(errorMessage, output.contains("class AxiosHttpClient implements HttpClient<Axios.AxiosRequestConfig>"));
    Assert.assertTrue(errorMessage, output.contains("request<R>(requestConfig: { method: string; url: string; queryParams?: any; data?: any; copyFn?: (data: R) => R; options?: Axios.AxiosRequestConfig; }): RestResponse<R>"));
    Assert.assertTrue(errorMessage, output.contains("class AxiosOrganizationsResourceClient extends OrganizationsResourceClient<Axios.AxiosRequestConfig>"));
    Assert.assertTrue(errorMessage, output.contains("class AxiosPersonResourceClient extends PersonResourceClient<Axios.AxiosRequestConfig>"));
    Assert.assertTrue(errorMessage, output.contains("constructor(baseURL: string, axiosInstance: Axios.AxiosInstance = axios.create())"));
}
Also used : TypeScriptGenerator(cz.habarta.typescript.generator.TypeScriptGenerator) Settings(cz.habarta.typescript.generator.Settings) Test(org.junit.Test) JaxrsApplicationTest(cz.habarta.typescript.generator.JaxrsApplicationTest)

Aggregations

JaxrsApplicationTest (cz.habarta.typescript.generator.JaxrsApplicationTest)1 Settings (cz.habarta.typescript.generator.Settings)1 TypeScriptGenerator (cz.habarta.typescript.generator.TypeScriptGenerator)1 Test (org.junit.Test)1