-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move BuildNewCommandTest to project api
- Loading branch information
1 parent
d0b3fac
commit 1d6406b
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
project-api-tests/src/test/java/org/ballerina/projectapi/BuildNewCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.ballerina.projectapi; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.ballerina.projectapi.CentralTestUtils.createSettingToml; | ||
import static org.ballerina.projectapi.CentralTestUtils.deleteFiles; | ||
import static org.ballerina.projectapi.CentralTestUtils.getEnvVariables; | ||
import static org.ballerina.projectapi.CentralTestUtils.getString; | ||
import static org.ballerina.projectapi.TestUtils.addEnvVariables; | ||
import static org.ballerina.projectapi.TestUtils.executeBuildCommand; | ||
import static org.ballerina.projectapi.TestUtils.executeNewCommand; | ||
|
||
/** | ||
* Tests related new command compiling. | ||
*/ | ||
public class BuildNewCommandTest { | ||
public static final Path MAVEN_VERSION = Paths.get(System.getProperty("maven.version")); | ||
public static final Path CODE_NAME = Paths.get(System.getProperty("code.name")); | ||
public static final String DISTRIBUTION_FILE_NAME = "ballerina-" + MAVEN_VERSION + "-" + CODE_NAME; | ||
|
||
private Path tempHomeDirectory; | ||
private Path tempWorkspaceDirectory; | ||
Map<String, String> envProperties; | ||
|
||
@BeforeClass() | ||
public void setUp() throws IOException { | ||
TestUtils.setupDistributions(); | ||
tempHomeDirectory = Files.createTempDirectory("bal-test-integration-packaging-home-"); | ||
tempWorkspaceDirectory = Files.createTempDirectory("bal-test-integration-packaging-workspace-"); | ||
createSettingToml(tempHomeDirectory); | ||
envProperties = addEnvVariables(getEnvVariables(), tempHomeDirectory); | ||
} | ||
|
||
@Test(description = "Build package created from new command with default template") | ||
public void testCompilingNewCommandDefaultTempProject() throws IOException, InterruptedException { | ||
List<String> args = new LinkedList<>(); | ||
String projectName = "project_sample"; | ||
args.add(projectName); | ||
executeNewCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, args, envProperties); | ||
Path projectPath = tempWorkspaceDirectory.resolve(projectName); | ||
Assert.assertTrue(Files.isDirectory(projectPath)); | ||
Assert.assertTrue(Files.exists(projectPath.resolve("Ballerina.toml"))); | ||
|
||
List<String> buildArgs = new LinkedList<>(); | ||
Process build = executeBuildCommand(DISTRIBUTION_FILE_NAME, projectPath, buildArgs, envProperties); | ||
String buildOutput = getString(build.getInputStream()); | ||
Assert.assertTrue(buildOutput.contains("Compiling source")); | ||
Assert.assertTrue(buildOutput.contains("Generating executable")); | ||
} | ||
|
||
@Test(description = "Build package created from new command with main template") | ||
public void testCompilingNewCommandMainTempProject() throws IOException, InterruptedException { | ||
List<String> args = new LinkedList<>(); | ||
String projectName = "main_sample"; | ||
args.add(projectName); | ||
args.add("-t"); | ||
args.add("main"); | ||
executeNewCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, args, envProperties); | ||
Path projectPath = tempWorkspaceDirectory.resolve(projectName); | ||
Assert.assertTrue(Files.isDirectory(projectPath)); | ||
Assert.assertTrue(Files.exists(projectPath.resolve("Ballerina.toml"))); | ||
|
||
List<String> buildArgs = new LinkedList<>(); | ||
Process build = executeBuildCommand(DISTRIBUTION_FILE_NAME, projectPath, buildArgs, envProperties); | ||
String buildOutput = getString(build.getInputStream()); | ||
Assert.assertTrue(buildOutput.contains("Compiling source")); | ||
Assert.assertTrue(buildOutput.contains("Generating executable")); | ||
} | ||
|
||
@Test(description = "Build package created from new command with service template") | ||
public void testCompilingNewCommandServiceTempProject() throws IOException, InterruptedException { | ||
List<String> args = new LinkedList<>(); | ||
String projectName = "service_sample"; | ||
args.add(projectName); | ||
args.add("-t"); | ||
args.add("service"); | ||
executeNewCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, args, envProperties); | ||
Path projectPath = tempWorkspaceDirectory.resolve(projectName); | ||
Assert.assertTrue(Files.isDirectory(projectPath)); | ||
Assert.assertTrue(Files.exists(projectPath.resolve("Ballerina.toml"))); | ||
|
||
List<String> buildArgs = new LinkedList<>(); | ||
Process build = executeBuildCommand(DISTRIBUTION_FILE_NAME, projectPath, buildArgs, envProperties); | ||
String buildOutput = getString(build.getInputStream()); | ||
Assert.assertTrue(buildOutput.contains("Compiling source")); | ||
Assert.assertTrue(buildOutput.contains("Generating executable")); | ||
} | ||
|
||
@Test(description = "Build package created from new command with lib template") | ||
public void testCompilingNewCommandLibTempProject() throws IOException, InterruptedException { | ||
List<String> args = new LinkedList<>(); | ||
String projectName = "lib_sample"; | ||
args.add(projectName); | ||
args.add("-t"); | ||
args.add("lib"); | ||
executeNewCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, args, envProperties); | ||
Path projectPath = tempWorkspaceDirectory.resolve(projectName); | ||
Assert.assertTrue(Files.isDirectory(projectPath)); | ||
Assert.assertTrue(Files.exists(projectPath.resolve("Ballerina.toml"))); | ||
|
||
List<String> buildArgs = new LinkedList<>(); | ||
Process build = executeBuildCommand(DISTRIBUTION_FILE_NAME, projectPath, buildArgs, envProperties); | ||
String buildOutput = getString(build.getInputStream()); | ||
Assert.assertTrue(buildOutput.contains("Compiling source")); | ||
Assert.assertTrue(buildOutput.contains("Generating executable")); | ||
} | ||
|
||
@AfterClass | ||
private void cleanup() throws IOException { | ||
deleteFiles(tempHomeDirectory); | ||
deleteFiles(tempWorkspaceDirectory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters