org.gradle.testfixtures.ProjectBuilder Java Examples
The following examples show how to use
org.gradle.testfixtures.ProjectBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValidateStructureTaskTest.java From scaffold-clean-architecture with MIT License | 6 votes |
@Before public void init() throws IOException, CleanException { File projectDir = new File("build/unitTest"); Files.createDirectories(projectDir.toPath()); writeString(new File(projectDir, "settings.gradle"), ""); writeString(new File(projectDir, "build.gradle"), "plugins {" + " id('co.com.bancolombia.cleanArchitecture')" + "}"); Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build(); project.getTasks().create("testStructure", GenerateStructureTask.class); GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("testStructure"); taskStructure.generateStructureTask(); project.getTasks().create("test", ValidateStructureTask.class); task = (ValidateStructureTask) project.getTasks().getByName("test"); }
Example #2
Source File: PropertyOverridesTest.java From ya-cf-app-gradle-plugin with Apache License 2.0 | 6 votes |
@Test public void testPropertyOverridesForAppName() { Project project = ProjectBuilder.builder().build(); project.getPluginManager().apply("cf-app"); setPropsInExtension((CfPluginExtension) project.getExtensions().getByName("cfConfig")); CfPushTask cfPushTask = (CfPushTask) project.getTasks().getAt("cf-push"); CfProperties props = cfPushTask.getCfProperties(); assertThat(props.name()).isEqualTo("name-fromplugin"); assertThat(props.ccHost()).isEqualTo("cchost-fromplugin"); assertThat(props.ccPassword()).isEqualTo("ccpassword-fromplugin"); assertThat(props.buildpack()).isEqualTo("buildpack-fromplugin"); assertThat(props.org()).isEqualTo("org-fromplugin"); assertThat(props.space()).isEqualTo("space-fromplugin"); assertThat(props.instances()).isEqualTo(3); assertThat(props.memory()).isEqualTo(12); assertThat(props.stagingTimeout()).isEqualTo(15); assertThat(props.startupTimeout()).isEqualTo(5); }
Example #3
Source File: MinikubePluginTest.java From minikube-build-tools-for-java with Apache License 2.0 | 6 votes |
@Test public void testMinikubeExtensionSetProperties() { Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build(); project.getPluginManager().apply(MinikubePlugin.class); MinikubeExtension ex = (MinikubeExtension) project.getExtensions().getByName("minikube"); ex.setMinikube("/custom/minikube/path"); TaskContainer t = project.getTasks(); TaskCollection<MinikubeTask> tc = t.withType(MinikubeTask.class); Assert.assertEquals(3, tc.size()); tc.forEach( minikubeTask -> { Assert.assertEquals(minikubeTask.getMinikube(), "/custom/minikube/path"); }); }
Example #4
Source File: MinikubeExtensionTest.java From minikube-build-tools-for-java with Apache License 2.0 | 6 votes |
@Before public void setUp() { Project project = ProjectBuilder.builder().build(); // Mocks the CommandExecutor. commandExecutorMock = mock(CommandExecutor.class); commandExecutorFactoryMock = mock(CommandExecutorFactory.class); when(commandExecutorFactoryMock.newCommandExecutor()).thenReturn(commandExecutorMock); // Creates an extension to test on. minikube = new MinikubeExtension(project, commandExecutorFactoryMock); minikube.setMinikube("/test/path/to/minikube"); expectedCommand = new ArrayList<>(Arrays.asList("/test/path/to/minikube", "docker-env", "--shell=none")); }
Example #5
Source File: PropertyEnvironmentOverridesTest.java From ya-cf-app-gradle-plugin with Apache License 2.0 | 6 votes |
@Test public void testPropertyOverridesForAppName() { Project project = ProjectBuilder.builder().build(); project.getPluginManager().apply("cf-app"); setPropsInExtension((CfPluginExtension) project.getExtensions().getByName("cfConfig")); overrideProjectProperties(project); CfPushTask cfPushTask = (CfPushTask) project.getTasks().getAt("cf-push"); CfProperties props = cfPushTask.getCfProperties(); assertThat(props.name()).isEqualTo("appName-new"); assertThat(props.ccHost()).isEqualTo("cchost-new"); assertThat(props.ccPassword()).isEqualTo("ccpassword-new"); assertThat(props.org()).isEqualTo("org-new"); assertThat(props.space()).isEqualTo("space-new"); assertThat(props.domain()).isEqualTo("domain-new"); assertThat(props.services()).containsExactlyInAnyOrder("mysql-new", "redis-new"); }
Example #6
Source File: MinikubeTaskTest.java From minikube-build-tools-for-java with Apache License 2.0 | 6 votes |
@Test public void testBuildCommand() { Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build(); MinikubeTask testTask = project .getTasks() .create( "minikubeTestTask", MinikubeTask.class, minikubeTask -> { minikubeTask.setMinikube("/test/path/to/minikube"); minikubeTask.setCommand("testCommand"); minikubeTask.setFlags(new String[] {"testFlag1", "testFlag2"}); }); Assert.assertEquals( Arrays.asList("/test/path/to/minikube", "testCommand", "testFlag1", "testFlag2"), testTask.buildMinikubeCommand()); }
Example #7
Source File: UpdateIntelliJSdksTaskTest.java From curiostack with MIT License | 6 votes |
@BeforeEach void setUserHome() throws Exception { oldUserHome = System.getProperty("user.home"); testUserHome = GradleTempDirectories.create("home"); testGradleHome = GradleTempDirectories.create("gradlehome"); System.setProperty("user.home", testUserHome.toAbsolutePath().toString()); // Add an unrelated folder to make it look just a little more like a user home. Files.writeString( Files.createDirectories(testUserHome.resolve("curiotest")).resolve("foo.txt"), "bar"); var project = ProjectBuilder.builder().withGradleUserHomeDir(testGradleHome.toFile()).build(); var properties = project.getExtensions().getByType(ExtraPropertiesExtension.class); properties.set("org.curioswitch.curiostack.tools.openjdk", "zulu13.28.11-ca-jdk13.0.1"); properties.set("org.curioswitch.curiostack.tools.openjdk8", "zulu8.42.0.21-ca-jdk8.0.232"); project.getPlugins().apply(CuriostackRootPlugin.class); project.getPlugins().apply(GolangSetupPlugin.class); task = project .getTasks() .withType(UpdateIntelliJSdksTask.class) .getByName(UpdateIntelliJSdksTask.NAME); }
Example #8
Source File: ShowConfigurationTaskTest.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
@Test public void testGetAllFields_NestedExtensions() throws IllegalAccessException { String expected = "" + "root {\n" + " x {\n" + " y {\n" + " (int) yy = 0\n" + " z {\n" + " (String) zz = hello\n" + " (Map<String, List<String>>) zzNested = {a=[a1, a2], b=[b1, b2]}\n" + " }\n" + " }\n" + " }\n" + "}\n"; Project p = ProjectBuilder.builder().build(); ExtensionAware root = (ExtensionAware) p.getExtensions().create("root", ExtX.class); ExtensionAware x = (ExtensionAware) root.getExtensions().create("x", ExtX.class); ExtensionAware y = (ExtensionAware) x.getExtensions().create("y", ExtY.class); y.getExtensions().create("z", ExtZ.class); String result = ShowConfigurationTask.getExtensionData("root", root, 0); Assert.assertEquals(expected, result); }
Example #9
Source File: GenerateDrivenAdapterTaskTest.java From scaffold-clean-architecture with MIT License | 6 votes |
private void setup(GenerateStructureTask.ProjectType type) throws IOException, CleanException { Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build(); ProjectBuilder.builder() .withName("app-service") .withProjectDir(new File("build/unitTest/applications/app-service")) .withParent(project) .build(); project.getTasks().create("ca", GenerateStructureTask.class); GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("ca"); taskStructure.setType(type); taskStructure.generateStructureTask(); project.getTasks().create("test", GenerateDrivenAdapterTask.class); task = (GenerateDrivenAdapterTask) project.getTasks().getByName("test"); }
Example #10
Source File: RuntimeClassoaderFactoryTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Before public void setup() throws IOException { // TODO address dependency resolution issues GeneratorPlugin.APPLY_DOCLET_BY_DEFAULT = false; testProjectDir.newFolder("src", "main", "java"); File outputDir = testProjectDir.getRoot(); Project project = ProjectBuilder.builder().withName("crnk-gen-typescript-test").withProjectDir(outputDir).build(); project.setVersion("0.0.1"); project.getPluginManager().apply(JavaPlugin.class); project.getPluginManager().apply(GeneratorPlugin.class); GeneratorExtension config = project.getExtensions().getByType(GeneratorExtension.class); config.getRuntime().setConfiguration("test"); TSGeneratorModule module = new TSGeneratorModule(); factory = new RuntimeClassLoaderFactory(project, module); ClassLoader parentClassLoader = getClass().getClassLoader(); classLoader = factory.createClassLoader(parentClassLoader, true); sharedClassLoader = (RuntimeClassLoaderFactory.SharedClassLoader) classLoader.getParent(); }
Example #11
Source File: DeployAllTaskTest.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
/** Setup DeployAllTaskTest. */ @Before public void setup() throws IOException { Project tempProject = ProjectBuilder.builder().build(); deployExtension = new DeployExtension(tempProject); deployExtension.setDeployTargetResolver(deployTargetResolver); deployCapture = ArgumentCaptor.forClass(DeployConfiguration.class); stageDir = tempFolder.newFolder("staging"); deployAllTask = tempProject.getTasks().create("tempDeployAllTask", DeployAllTask.class); deployAllTask.setDeployExtension(deployExtension); deployAllTask.setGcloud(gcloud); deployAllTask.setStageDirectory(stageDir); when(gcloud.newDeployment(Mockito.any(ProcessHandler.class))).thenReturn(deploy); }
Example #12
Source File: GeneratePipelineTaskTest.java From scaffold-clean-architecture with MIT License | 6 votes |
@Before public void init() throws IOException, CleanException { File projectDir = new File("build/unitTest"); Files.createDirectories(projectDir.toPath()); writeString(new File(projectDir, "build.gradle"), "plugins {" + " id('co.com.bancolombia.cleanArchitecture')" + "}"); Project project = ProjectBuilder.builder().withName("cleanArchitecture") .withProjectDir(new File("build/unitTest")).build(); project.getTasks().create("testStructure", GenerateStructureTask.class); GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("testStructure"); taskStructure.generateStructureTask(); project.getTasks().create("test", GeneratePipelineTask.class); task = (GeneratePipelineTask) project.getTasks().getByName("test"); }
Example #13
Source File: MultiModuleTestProject.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
/** * Build and evaluate multi-module project. * * @return root project */ public Project build() throws IOException { Project rootProject = ProjectBuilder.builder().withProjectDir(projectRoot).build(); for (String module : modules) { Project p = ProjectBuilder.builder().withName(module).withParent(rootProject).build(); // Create an appengine-web.xml for each module Path webInf = p.getProjectDir().toPath().resolve("src/main/webapp/WEB-INF"); Files.createDirectories(webInf); File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile(); Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8)); p.getPluginManager().apply(JavaPlugin.class); p.getPluginManager().apply(WarPlugin.class); p.getPluginManager().apply(AppEngineStandardPlugin.class); DeployExtension deploy = p.getExtensions().getByType(AppEngineStandardExtension.class).getDeploy(); deploy.setProjectId("project"); deploy.setVersion("version"); } ((ProjectInternal) rootProject).evaluate(); return rootProject; }
Example #14
Source File: GenerateEntryPointTaskTest.java From scaffold-clean-architecture with MIT License | 6 votes |
@Before public void setup() throws IOException, CleanException { Project project = ProjectBuilder.builder().withProjectDir(new File("build/unitTest")).build(); project.getTasks().create("ca", GenerateStructureTask.class); GenerateStructureTask caTask = (GenerateStructureTask) project.getTasks().getByName("ca"); caTask.generateStructureTask(); ProjectBuilder.builder() .withProjectDir(new File("build/unitTest/applications/app-service")) .withName("app-service") .withParent(project) .build(); project.getTasks().create("test", GenerateEntryPointTask.class); task = (GenerateEntryPointTask) project.getTasks().getByName("test"); }
Example #15
Source File: ModuleBuilderTest.java From scaffold-clean-architecture with MIT License | 6 votes |
@Before public void init() throws IOException, CleanException { File projectDir = new File("build/unitTest"); Files.createDirectories(projectDir.toPath()); writeString(new File(projectDir, "build.gradle"), "plugins {" + " id('co.com.bancolombia.cleanArchitecture')" + "}"); Project project = ProjectBuilder.builder().withName("cleanArchitecture") .withProjectDir(new File("build/unitTest")).build(); project.getTasks().create("testStructure", GenerateStructureTask.class); GenerateStructureTask taskStructure = (GenerateStructureTask) project.getTasks().getByName("testStructure"); taskStructure.generateStructureTask(); builder = new ModuleBuilder(project); }
Example #16
Source File: TestProject.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
private Project applyProjectBuilder(Class<?>... plugins) { Project p = ProjectBuilder.builder().withProjectDir(projectRoot).build(); for (Class<?> clazz : plugins) { p.getPluginManager().apply(clazz); } Object appengineExt = p.getExtensions().getByName(APPENGINE_EXTENSION); DeployExtension deploy = ((ExtensionAware) appengineExt).getExtensions().getByType(DeployExtension.class); deploy.setProjectId("test-project"); deploy.setVersion("test-version"); ((ProjectInternal) p).evaluate(); return p; }
Example #17
Source File: AppEngineStandardExtensionTest.java From app-gradle-plugin with Apache License 2.0 | 6 votes |
private Project setUpTestProject(String buildFileName) throws IOException { Path buildFile = testProjectDir.getRoot().toPath().resolve("build.gradle"); InputStream buildFileContent = getClass() .getClassLoader() .getResourceAsStream( "projects/AppEnginePluginTest/Extension/" + buildFileName + ".gradle"); Files.copy(buildFileContent, buildFile); Path webInf = testProjectDir.getRoot().toPath().resolve("src/main/webapp/WEB-INF"); Files.createDirectories(webInf); File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile(); Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8)); Project p = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build(); p.getPluginManager().apply(JavaPlugin.class); p.getPluginManager().apply(WarPlugin.class); p.getPluginManager().apply(AppEngineStandardPlugin.class); ((ProjectInternal) p).evaluate(); return p; }
Example #18
Source File: CompileJavaTaskMutatorTest.java From gradle-modules-plugin with MIT License | 5 votes |
@Test void modularizeJavaCompileTask() { // given Project project = ProjectBuilder.builder().withProjectDir(new File("test-project/")).build(); project.getPlugins().apply("java"); JavaCompile compileJava = (JavaCompile) project.getTasks().getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME); FileCollection classpath = project.files("dummy dir"); // we need anything on classpath compileJava.setClasspath(classpath); CompileModuleOptions moduleOptions = compileJava.getExtensions() .create("moduleOptions", CompileModuleOptions.class, project); project.getExtensions().add("moduleName", getClass().getName()); project.getExtensions().create("patchModules", PatchModuleExtension.class); project.getExtensions().create("modularity", DefaultModularityExtension.class, project); CompileJavaTaskMutator mutator = new CompileJavaTaskMutator(project, compileJava.getClasspath(), moduleOptions); // when mutator.modularizeJavaCompileTask(compileJava); // then List<String> twoLastArguments = twoLastCompilerArgs(compileJava); assertEquals( Arrays.asList("--module-path", classpath.getAsPath()), twoLastArguments, "Two last arguments should be setting module path to the current compileJava task classpath"); }
Example #19
Source File: ModuleNameTest.java From gradle-modules-plugin with MIT License | 5 votes |
@Test void findModuleName_ParentProjectWithWithJava() { Project project = ProjectBuilder.builder().withProjectDir(new File("test-project/")).build(); project.getPlugins().apply("java"); Optional<String> result = new ModuleName().findModuleName(project); assertTrue(result.isEmpty(), "Found a module in the parent project. It doesn't have any modules or java code so it should not find anything."); }
Example #20
Source File: AzureFunctionsPluginTest.java From azure-gradle-plugins with MIT License | 5 votes |
@Test public void greeterPluginAddsGreetingTaskToProject() { Project project = ProjectBuilder.builder().build(); project.getPluginManager().apply("lenala.azure.azurefunctions"); assertTrue(project.getTasks().findByPath("package") instanceof PackageTask); }
Example #21
Source File: MinikubePluginTest.java From minikube-build-tools-for-java with Apache License 2.0 | 5 votes |
@Test public void testDefaultMinikubeTasks() { Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build(); project.getPluginManager().apply(MinikubePlugin.class); ((ProjectInternal) project).evaluate(); TaskContainer t = project.getTasks(); TaskCollection<MinikubeTask> tc = t.withType(MinikubeTask.class); Assert.assertEquals(3, tc.size()); AssertMinikubeTaskConfig(tc, "minikubeStart", "start"); AssertMinikubeTaskConfig(tc, "minikubeStop", "stop"); AssertMinikubeTaskConfig(tc, "minikubeDelete", "delete"); }
Example #22
Source File: FileUtilsTest.java From scaffold-clean-architecture with MIT License | 5 votes |
@Test public void readFile() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(new File("src/test/resources")).build(); String response = FileUtils.readFile(project, "temp.txt").collect(Collectors.joining()); assertEquals("hello", response); }
Example #23
Source File: MinikubePluginTest.java From minikube-build-tools-for-java with Apache License 2.0 | 5 votes |
@Test public void testUserAddedMinikubeTaskConfigured() { Project project = ProjectBuilder.builder().withProjectDir(tmp.getRoot()).build(); project.getPluginManager().apply(MinikubePlugin.class); MinikubeExtension ex = (MinikubeExtension) project.getExtensions().getByName("minikube"); ex.setMinikube("/custom/minikube/path"); MinikubeTask custom = project.getTasks().create("minikubeCustom", MinikubeTask.class); custom.setCommand("custom"); Assert.assertEquals(custom.getMinikube(), "/custom/minikube/path"); Assert.assertEquals(custom.getCommand(), "custom"); Assert.assertArrayEquals(custom.getFlags(), new String[] {}); }
Example #24
Source File: StageAppYamlExtensionTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Before public void setUpFiles() throws IOException { stagingDirectory = testProjectDir.newFolder("stage"); appEngineDirectory = testProjectDir.newFolder("app"); artifact = testProjectDir.newFile("artifact"); dockerDirectory = testProjectDir.newFolder("docker"); extraFilesDirectories = Arrays.asList(testProjectDir.newFolder("extra1"), testProjectDir.newFolder("extra2")); testContextProject = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build(); }
Example #25
Source File: DownloadCloudSdkTaskTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
/** Setup DownloadCloudSdkTaskTest. */ @Before public void setup() { Project tempProject = ProjectBuilder.builder().build(); downloadCloudSdkTask = tempProject.getTasks().create("tempDownloadTask", DownloadCloudSdkTask.class); when(managedCloudSdk.newInstaller()).thenReturn(installer); when(managedCloudSdk.newComponentInstaller()).thenReturn(componentInstaller); when(managedCloudSdk.newUpdater()).thenReturn(updater); }
Example #26
Source File: GitUtilsTest.java From gradle-plugins with MIT License | 5 votes |
@BeforeEach void setUp() { project = ProjectBuilder.builder() .withProjectDir(new File(".")) .build(); }
Example #27
Source File: CheckCloudSdkTaskTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
/** Setup CheckCloudSdkTaskTest. */ @Before public void setup() { Project tempProject = ProjectBuilder.builder().build(); checkCloudSdkTask = tempProject.getTasks().create("tempCheckCloudSdk", CheckCloudSdkTask.class); checkCloudSdkTask.setCloudSdk(sdk); }
Example #28
Source File: DeployExtensionTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Before public void setUp() { Mockito.when(deployTargetResolver.getProject("test-project-id")) .thenReturn("processed-project-id"); Mockito.when(deployTargetResolver.getVersion("test-version")).thenReturn("processed-version"); testProject = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build(); }
Example #29
Source File: WarOverlayPluginTest.java From gradle-plugins with MIT License | 5 votes |
@Test public void testProperties() { Project project = ProjectBuilder.builder().build(); project.getPlugins().apply(WarPlugin.class); project.getPlugins().apply(WarOverlayPlugin.class); Task warTask = project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); assertThat(warTask.hasProperty("overlays")).isTrue(); assertThat(warTask.property("overlays")).isInstanceOf(DomainObjectCollection.class); }
Example #30
Source File: SourceContextPluginTest.java From app-gradle-plugin with Apache License 2.0 | 5 votes |
@Test public void testDefaultConfiguration() throws IOException { File appengineWebXml = new File(testProjectDir.getRoot(), "src/main/webapp/WEB-INF/appengine-web.xml"); appengineWebXml.getParentFile().mkdirs(); appengineWebXml.createNewFile(); Files.write(appengineWebXml.toPath(), "<web-app/>".getBytes()); Project project = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build(); project.getPluginManager().apply(JavaPlugin.class); project.getPluginManager().apply(WarPlugin.class); project.getPluginManager().apply(AppEngineStandardPlugin.class); project.getPluginManager().apply(SourceContextPlugin.class); DeployExtension deploy = project.getExtensions().getByType(AppEngineStandardExtension.class).getDeploy(); deploy.setProjectId("project"); deploy.setVersion("version"); ((ProjectInternal) project).evaluate(); ExtensionAware ext = (ExtensionAware) project.getExtensions().getByName(AppEngineCorePluginConfiguration.APPENGINE_EXTENSION); GenRepoInfoFileExtension genRepoInfoExt = new ExtensionUtil(ext).get(SourceContextPlugin.SOURCE_CONTEXT_EXTENSION); Assert.assertEquals( new File(project.getBuildDir(), "sourceContext"), genRepoInfoExt.getOutputDirectory()); }