Skip to content

Commit

Permalink
changes for reiview suggestions
Browse files Browse the repository at this point in the history
before int test script change

before int test script change for commas

remove commented lines

remove a comment in the scripts
  • Loading branch information
slahirucd7 committed Oct 20, 2022
1 parent 7f35947 commit fde1644
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 43 deletions.
1 change: 0 additions & 1 deletion dev-scripts/code-coverage/prepare-files-after-int-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# limitations under the License.
# -----------------------------------------------------------------------

# Sets the Choreo Connect version
echo "Preparing code coverage files after integration tests...."
rm -f ../../resources/enforcer/dropins/aggregate.exec
rm ../../.github/workflows/coverage.yml
Expand Down
10 changes: 5 additions & 5 deletions dev-scripts/code-coverage/prepare-files-before-int-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# limitations under the License.
# -----------------------------------------------------------------------

# Sets the Choreo Connect version
echo "Preparing code coverage files before integration tests..."
mkdir ../../resources/enforcer/dropins/
chmod 777 ../../enforcer-parent/enforcer/target/coverage-aggregate-reports/aggregate.exec
sed -i 's/JAVA_OPTS.*/JAVA_OPTS=${JAVA_OPTS} -javaagent:\/home\/wso2\/lib\/org.jacoco.agent-0.8.8-runtime.jar=destfile=\/home\/wso2\/lib\/dropins\/aggregate.exec,append=true/g' ../../resources/docker-compose/docker-compose.yaml
sed -i 's/JAVA_OPTS.*/JAVA_OPTS=${JAVA_OPTS} -javaagent:\/home\/wso2\/lib\/org.jacoco.agent-0.8.8-runtime.jar=destfile=\/home\/wso2\/lib\/dropins\/aggregate.exec,append=true -Dhttpclient.hostnameVerifier=AllowAll/g' ../../resources/docker-compose/apim/docker-compose.yaml
sed -i 's/JAVA_OPTS.*/JAVA_OPTS=${JAVA_OPTS} -javaagent:\/home\/wso2\/lib\/org.jacoco.agent-0.8.8-runtime.jar=destfile=\/home\/wso2\/lib\/dropins\/aggregate.exec,append=true/g' ../../integration/test-integration/src/test/resources/dockerCompose/cc-cacert-mounted-mtls.yaml
sed -i 's/JAVA_OPTS.*/JAVA_OPTS=${JAVA_OPTS} -javaagent:\/home\/wso2\/lib\/org.jacoco.agent-0.8.8-runtime.jar=destfile=\/home\/wso2\/lib\/dropins\/aggregate.exec,append=true -Dhttpclient.hostnameVerifier=AllowAll/g' ../../integration/test-integration/src/test/resources/dockerCompose/cc-in-common-network-docker-compose.yaml
export JAVA_AGENT_ARG="-javaagent:\/home\/wso2\/lib\/org.jacoco.agent-0.8.8-runtime.jar=destfile=\/home\/wso2\/lib\/dropins\/aggregate.exec,append=true"
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG}/g" ../../resources/docker-compose/docker-compose.yaml
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG} -Dhttpclient.hostnameVerifier=AllowAll/g" ../../resources/docker-compose/apim/docker-compose.yaml
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG}/g" ../../integration/test-integration/src/test/resources/dockerCompose/cc-cacert-mounted-mtls.yaml
sed -i "s/JAVA_OPTS.*/JAVA_OPTS=\${JAVA_OPTS} ${JAVA_AGENT_ARG} -Dhttpclient.hostnameVerifier=AllowAll/g" ../../integration/test-integration/src/test/resources/dockerCompose/cc-in-common-network-docker-compose.yaml
echo "Preparing code coverage files before integration tests completed successfully..."
13 changes: 0 additions & 13 deletions integration/test-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
<root_pom_path>${ccBaseDir}</root_pom_path>
<is_code_coverage_enabled>${skip.code.coverage}</is_code_coverage_enabled>
<apictl_version>${apictl.version}</apictl_version>
<!-- <jacoco_exec_location>-->
<!-- ${ccBaseDir}/enforcer-parent/enforcer/target/coverage-aggregate-reports/aggregate.exec-->
<!-- </jacoco_exec_location>-->
<!-- allowRestrictedHeaders enabled for allowing to send host header with requests, for testing vhost feature -->
<sun.net.http.allowRestrictedHeaders>true</sun.net.http.allowRestrictedHeaders>
<jacoco-agent.destfile>**/jacoco.exec</jacoco-agent.destfile>
Expand Down Expand Up @@ -171,16 +168,6 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<!-- <execution>-->
<!-- <phase>compile</phase>-->
<!-- <goals>-->
<!-- <goal>exec</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <skip>${skip.code.coverage}</skip>-->
<!-- <executable>${ccBaseDir}/dev-scripts/code-coverage/prepare-files-before-int-tests.sh</executable>-->
<!-- </configuration>-->
<!-- </execution>-->
<execution>
<id>after-integration-tests</id>
<phase>verify</phase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ private CcInstance(String dockerComposeFile, String confFileName, String backend
boolean isClientCertValidationRequired, boolean isInitialStartup
) throws IOException, CCTestException {
boolean isCodeCovAllowedToSkip = true;
if (System.getProperty("is_code_coverage_enabled") != null) {
String codeCovProperty = System.getProperty("is_code_coverage_enabled");
String codeCoverageEnabled = System.getProperty("is_code_coverage_enabled");
if (codeCoverageEnabled != null) {
String codeCovProperty = codeCoverageEnabled;
isCodeCovAllowedToSkip = Boolean.valueOf(codeCovProperty);
}
createTmpMgwSetup(isInitialStartup, isCodeCovAllowedToSkip);
Expand Down Expand Up @@ -133,6 +134,7 @@ public static class Builder {
boolean withAnalyticsMetricImpl = false;
boolean isInterceptorCertRequired = false;
boolean isClientCertValidationRequired = false;
boolean isInitialStartUp = false;

public Builder withNewDockerCompose(String dockerComposeFile) {
this.dockerComposeFile = dockerComposeFile;
Expand Down Expand Up @@ -186,12 +188,17 @@ public Builder withClientCertValidation() {
return this;
}

public CcInstance build(boolean isInitialStartUp) throws IOException, CCTestException {
// to indicate Choreo-Connect initial startup during the integration tests
public Builder markInitialCCStartup(boolean isInitialStartUp) {
this.isInitialStartUp = isInitialStartUp;
return this;
}

public CcInstance build() throws IOException, CCTestException {
instance = new CcInstance(this.dockerComposeFile, this.confFileName, this.backendServiceFile,
this.gitServiceFile, this.withCustomJwtTransformer, this.withAnalyticsMetricImpl,
this.startupAPIProjectFiles, this.isInterceptorCertRequired, this.enforcerTrustCertsDir,
this.volumeMountDir, this.isClientCertValidationRequired, isInitialStartUp
);
this.volumeMountDir, this.isClientCertValidationRequired, this.isInitialStartUp);
return instance;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ private Boolean checkForBackendAvailability() throws IOException {
*/
void createTmpMgwSetup(boolean isInitialStartup, boolean isCodeCovAllowedToSkip) throws CCTestException {
if (!isCodeCovAllowedToSkip && !isInitialStartup) {
File myObj = new File(System.getProperty("root_pom_path") + "/enforcer-parent/enforcer/target/coverage-aggregate-reports/aggregate.exec");
File myObj = new File(System.getProperty("root_pom_path") + Utils.getEnforcerCodeCovExecPath());
if (myObj.delete()) {
log.debug("Deleted the aggregate.exec file");
} else {
log.debug("Failed to delete aggregate.exec file");
}
Utils.copyFileWithAttributes(Utils.getTargetDirPath() + TestConstant.CC_TEMP_PATH + TestConstant.DROPINS_FOLDER_PATH + File.separator + "aggregate.exec",
System.getProperty("root_pom_path")+"/enforcer-parent/enforcer/target/coverage-aggregate-reports/aggregate.exec");
Utils.copyFileWithAttributes(Utils.getTargetDirPath() + TestConstant.CC_TEMP_PATH + TestConstant.DROPINS_FOLDER_PATH + File.separator + TestConstant.JACOCO_EXEC_NAME,
System.getProperty("root_pom_path")+ Utils.getEnforcerCodeCovExecPath());
}
Utils.deleteQuietly(ccTempPath);
Utils.copyDirectory(ccExtractedPath, ccTempPath);
Expand Down Expand Up @@ -194,9 +194,9 @@ public static void addCustomJwtTransformer() throws CCTestException {

// adds aggregated jacoco exec (relevant to the enforcer) into the cc-temp dropins directory
public static void addCodeCovExec() throws CCTestException {
Utils.copyFileWithAttributes(System.getProperty("root_pom_path")+"/enforcer-parent/enforcer/target/coverage-aggregate-reports/aggregate.exec",
Utils.copyFileWithAttributes(System.getProperty("root_pom_path")+ Utils.getEnforcerCodeCovExecPath(),
Utils.getTargetDirPath() + TestConstant.CC_TEMP_PATH + TestConstant.DROPINS_FOLDER_PATH
+ File.separator + "aggregate.exec");
+ File.separator + TestConstant.JACOCO_EXEC_NAME);
}

public static void addInterceptorCertToRouterTruststore() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void start() throws Exception {
.withEnforcerTrustCertsDir("enforcer-truststore-opa-certs")
.withVolumeMountDir("opa-volume")
.withAllCustomImpls() // for custom OPA request generator
.build(false);
.build();
ccInstance.start();
Awaitility.await().pollDelay(5, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS)
.atMost(2, TimeUnit.MINUTES).until(ccInstance.isHealthy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CcWithClientCertEncodeDisabled {

@BeforeTest(description = "initialise the setup")
void start() throws Exception {
ccInstance = new CcInstance.Builder().withNewConfig("client-cert-not-encode-config.toml").build(false);
ccInstance = new CcInstance.Builder().withNewConfig("client-cert-not-encode-config.toml").build();
ccInstance.start();

ApictlUtils.addEnv("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CcWithClientCertEncodeEnabled {

@BeforeTest(description = "initialise the setup")
void start() throws Exception {
ccInstance = new CcInstance.Builder().withNewConfig("client-cert-encode-config.toml").build(false);
ccInstance = new CcInstance.Builder().withNewConfig("client-cert-encode-config.toml").build();
ccInstance.start();

ApictlUtils.addEnv("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ void start() throws Exception {
.withStartupAPI(Utils.getTargetDirPath() + ApictlUtils.API_PROJECTS_PATH +
"openAPI_startup_zipped.zip")
.withStartupAPI(Utils.getTargetDirPath() + ApictlUtils.API_PROJECTS_PATH + "openAPI_startup")
.build(true);
.markInitialCCStartup(true)
.build();
ccInstance.start();
Awaitility.await().pollDelay(5, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS)
.atMost(2, TimeUnit.MINUTES).until(ccInstance.isHealthy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void start() throws Exception {
ApictlUtils.createProject( "timeout_endpoint_openAPI.yaml", "timeout_endpoint");

ccInstance = new CcInstance.Builder().withBackendServiceFile("backend-service-gql.yaml")
.withNewConfig("jwt-generator-config.toml").build(false);
.withNewConfig("jwt-generator-config.toml").build();
ccInstance.start();

ApictlUtils.addEnv("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CcWithJwtConfigAndTransformer {

@BeforeTest(description = "initialise the setup")
void start() throws Exception {
ccInstance = new CcInstance.Builder().withNewConfig("jwt-generator-config.toml").withAllCustomImpls().build(false);
ccInstance = new CcInstance.Builder().withNewConfig("jwt-generator-config.toml").withAllCustomImpls().build();
ccInstance.start();
//TODO: (SuKSW) Check why this fails
// Awaitility.await().pollDelay(20, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CcWithMtlsDefault {
void start() throws Exception {

ccInstance = new CcInstance.Builder().withNewConfig("mtls-enabled-config.toml").
withNewDockerCompose("cc-cacert-mounted-mtls.yaml").withClientCertValidation().build(false);
withNewDockerCompose("cc-cacert-mounted-mtls.yaml").withClientCertValidation().build();
ccInstance.start();

ApictlUtils.createProject("mutual_ssl_openAPI.yaml", "MutualSSL", null, null, null, "mutual_ssl_api.yaml", false, "client_certificate.crt", "client_certificates.yaml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CcWithMultipleEnv {
@BeforeTest(description = "initialise the setup")
void start() throws Exception {

ccInstance = new CcInstance.Builder().withNewConfig("multiple-env-config.toml").build(false);
ccInstance = new CcInstance.Builder().withNewConfig("multiple-env-config.toml").build();
ccInstance.start();
Awaitility.await().pollDelay(5, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS)
.atMost(2, TimeUnit.MINUTES).until(ccInstance.isHealthy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void start() throws Exception {
.withGitServiceFile("git-service.yaml")
.withNewConfig("cc-with-source-control.toml")
.withVolumeMountDir("gitea")
.build(false);
.build();
ccInstance.start();

Awaitility.await().pollDelay(10, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void startChoreoConnect() throws Exception {
ccInstance = new CcInstance.Builder().withNewDockerCompose("cc-in-common-network-docker-compose.yaml")
.withNewConfig("controlplane-enabled-config.toml")
.withBackendServiceFile("backend-service-with-tls-and-network.yaml")
.withAllCustomImpls().build(false);
.withAllCustomImpls().build();
ccInstance.start();
Awaitility.await().pollDelay(20, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS)
.atMost(2, TimeUnit.MINUTES).until(ccInstance.isHealthy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void startChoreoConnect() throws Exception {
.withNewConfig("cc-special-scenarios-with-apim.toml")
.withBackendServiceFile("backend-service-with-tls-and-network.yaml")
.withInterceptorCertInRouterTruststore()
.withAllCustomImpls().build(false);
.withAllCustomImpls().build();
ccInstance.start();
Awaitility.await().pollDelay(20, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS)
.atMost(2, TimeUnit.MINUTES).until(ccInstance.isHealthy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,22 @@ public class TestConstant {
public static final String DOCKER_COMPOSE_YAML_PATH = File.separator + "docker-compose.yaml";
public static final String CA_CERTS_FILE = File.separator + "ca-certificates.crt";

public static final String ENFORCER_DIR_NAME = "enforcer";
public static final String ROUTER_TRUSTSTORE_DIR = RESOURCES_DIR + File.separator + "router"
+ SECURITY_DIR + File.separator + "truststore";
public static final String ENFORCER_TRUSTSTORE_DIR = RESOURCES_DIR + File.separator + "enforcer"
public static final String ENFORCER_TRUSTSTORE_DIR = RESOURCES_DIR + File.separator + ENFORCER_DIR_NAME
+ SECURITY_DIR + File.separator + "truststore";
public static final String DOCKER_COMPOSE_CC_DIR = DOCKER_COMPOSE_DIR + File.separator + "choreo-connect";
public static final String DROPINS_FOLDER_PATH = DOCKER_COMPOSE_DIR + RESOURCES_DIR
+ File.separator + "enforcer" + File.separator + "dropins";
+ File.separator + ENFORCER_DIR_NAME + File.separator + "dropins";
public static final String STARTUP_APIS_DIR = RESOURCES_DIR + File.separator
+ "adapter" + File.separator + "artifacts" + File.separator + "apis";
public static final String JACOCO_EXEC_NAME = "aggregate.exec";
public static final String ENFORCER_PARENT_DIR_NAME = "enforcer-parent";
public static final String TARGET_DIR_NAME = "target";
public static final String CODECOV_AGGREGATE_REPORT_DIR_NAME = "coverage-aggregate-reports";



public static final String HEALTH_ENDPOINT_RESPONSE = "{\"status\": \"healthy\"}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ public static void copyFileWithAttributes(String sourceLocation, String destLoca
}
}


/**
* Delay the program for a given time period
*
Expand Down Expand Up @@ -658,6 +657,17 @@ public static JSONObject changeHeadersToLowerCase(JSONObject headers) {
return headersCaseInsensitive;
}

/**
* Gives jacoco aggregate.exec file containing path relevant to the Enforcer
*
* @return jacoco aggregate.exec file path
*/
public static String getEnforcerCodeCovExecPath() {
return File.separator + TestConstant.ENFORCER_PARENT_DIR_NAME + File.separator + TestConstant.ENFORCER_DIR_NAME
+ File.separator + TestConstant.TARGET_DIR_NAME + File.separator +
TestConstant.CODECOV_AGGREGATE_REPORT_DIR_NAME + File.separator + TestConstant.JACOCO_EXEC_NAME;
}

public static String getTargetDirPath() {
File targetClassesDir = new File(Utils.class.getProtectionDomain().getCodeSource().
getLocation().getPath());
Expand Down

0 comments on commit fde1644

Please sign in to comment.