Search in sources :

Example 11 with FileHeaderView

use of com.google.api.codegen.viewmodel.FileHeaderView in project toolkit by googleapis.

the class PhpGapicSurfaceTestTransformer method createUnitTestFileView.

private ClientTestFileView createUnitTestFileView(GapicInterfaceContext context) {
    addUnitTestImports(context.getImportTypeTable());
    String outputPath = PhpGapicCodePathMapper.newBuilder().setPrefix("tests/unit").build().getOutputPath(context.getInterfaceModel().getFullName(), context.getProductConfig());
    SurfaceNamer namer = context.getNamer();
    String name = namer.getUnitTestClassName(context.getInterfaceConfig());
    ClientTestClassView.Builder testClass = ClientTestClassView.newBuilder();
    testClass.apiSettingsClassName(namer.getNotImplementedString("PhpGapicSurfaceTestTransformer.generateTestView - apiSettingsClassName"));
    testClass.apiClassName(namer.getApiWrapperClassName(context.getInterfaceConfig()));
    testClass.name(name);
    testClass.apiName(PhpPackageMetadataNamer.getApiNameFromPackageName(namer.getPackageName()).toLowerUnderscore());
    testClass.testCases(createTestCaseViews(context));
    testClass.apiHasLongRunningMethods(context.getInterfaceConfig().hasLongRunningOperations());
    // Add gRPC client imports.
    for (InterfaceModel grpcInterface : mockServiceTransformer.getGrpcInterfacesForService(context.getApiModel(), context.getProductConfig(), context.getInterfaceModel()).values()) {
        context.getImportTypeTable().getAndSaveNicknameFor(namer.getGrpcClientTypeName(grpcInterface));
    }
    testClass.mockServices(mockServiceTransformer.createMockServices(context.getNamer(), context.getApiModel(), context.getProductConfig()));
    testClass.missingDefaultServiceAddress(!context.getInterfaceConfig().hasDefaultServiceAddress());
    testClass.missingDefaultServiceScopes(!context.getInterfaceConfig().hasDefaultServiceScopes());
    ClientTestFileView.Builder testFile = ClientTestFileView.newBuilder();
    testFile.testClass(testClass.build());
    testFile.outputPath(namer.getSourceFilePath(outputPath, name));
    testFile.templateFileName(UNIT_TEST_TEMPLATE_FILE);
    ImportSectionView importSection = importSectionTransformer.generateImportSection(context.getImportTypeTable().getImports());
    SurfaceNamer testPackageNamer = namer.cloneWithPackageName(namer.getTestPackageName(SurfaceNamer.TestKind.UNIT));
    FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context.getProductConfig(), importSection, testPackageNamer);
    testFile.fileHeader(fileHeader);
    return testFile.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ClientTestClassView(com.google.api.codegen.viewmodel.testing.ClientTestClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) FileHeaderView(com.google.api.codegen.viewmodel.FileHeaderView) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

FileHeaderView (com.google.api.codegen.viewmodel.FileHeaderView)11 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)10 MethodModel (com.google.api.codegen.config.MethodModel)5 SmokeTestClassView (com.google.api.codegen.viewmodel.testing.SmokeTestClassView)5 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)4 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)4 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)3 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)3 ClientTestFileView (com.google.api.codegen.viewmodel.testing.ClientTestFileView)3 MethodContext (com.google.api.codegen.transformer.MethodContext)2 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)2 StaticLangApiMethodView (com.google.api.codegen.viewmodel.StaticLangApiMethodView)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 TestCaseTransformer (com.google.api.codegen.transformer.TestCaseTransformer)1 SymbolTable (com.google.api.codegen.util.SymbolTable)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 MockServiceImplFileView (com.google.api.codegen.viewmodel.testing.MockServiceImplFileView)1 MockServiceView (com.google.api.codegen.viewmodel.testing.MockServiceView)1 ArrayList (java.util.ArrayList)1