Skip to content

Commit

Permalink
[WIP] Automate MTA-404 custom rules with source technology
Browse files Browse the repository at this point in the history
Signed-off-by: Karishma Punwatkar <[email protected]>

	modified:   cypress/e2e/tests/administration/custom-migration-targets/crud.test.ts
	modified:   cypress/fixtures/custom-rules.json
	new file:   cypress/fixtures/xml/corporate-framework-config.windup.xml

	modified:   cypress/e2e/models/administration/custom-migration-targets/custom-migration-target.ts
	modified:   cypress/e2e/tests/administration/custom-migration-targets/crud.test.ts
	modified:   cypress/e2e/views/custom-migration-target.view.ts
	modified:   cypress/fixtures/custom-rules.json
	new file:   cypress/fixtures/xml/corporate-framework-config.windup.xml

	modified:   cypress/e2e/models/administration/custom-migration-targets/custom-migration-target.ts
  • Loading branch information
kpunwatk committed Mar 18, 2024
1 parent af241ee commit 103fa9d
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
SEC,
} from "../../../types/constants";
import { navMenu } from "../../../views/menu.view";
import { CustomMigrationTargetView } from "../../../views/custom-migration-target.view";
import {
CustomMigrationTargetView,
sourcesList,
sourcesToggle,
} from "../../../views/custom-migration-target.view";
import { RulesManualFields, RulesRepositoryFields } from "../../../types/types";
import { actionSelectToggle, submitButton } from "../../../views/common.view";

Expand All @@ -28,6 +32,7 @@ export interface CustomMigrationTarget {
imagePath?: string;
ruleTypeData: RulesRepositoryFields | RulesManualFields;
language: Languages;
sources?: string;
}

export class CustomMigrationTarget {
Expand All @@ -36,15 +41,17 @@ export class CustomMigrationTarget {
description: string,
imagePath: string,
ruleTypeData: RulesRepositoryFields | RulesManualFields,
language = Languages.Java
language = Languages.Java,
sources?: string
) {
this.name = name;
this.description = description;
this.ruleTypeData = ruleTypeData;
this.language = language;
this.sources = sources;
}

public static fullUrl = Cypress.env("tackleUrl") + "migration-targets";
public static fullUrl = Cypress.env("tackleUrl") + "/migration-targets";

public static open(forceReload = false) {
if (forceReload) {
Expand Down Expand Up @@ -184,4 +191,9 @@ export class CustomMigrationTarget {
});
});
}

validateSourceTechnology(sources: string): void {
click(sourcesToggle);
cy.get(sourcesList).should("contain", sources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,51 @@ describe(["@tier1", "@dc", "@interop"], "Custom Migration Targets CRUD operation
application.delete();
});
});

Object.values(Languages).forEach((language) => {
it(`${language} | custom rule with source technology`, function () {
const targetData = this.customMigrationTargets["rules_with_source_element"];
const target = new CustomMigrationTarget(
data.getRandomWord(8),
data.getDescription(),
targetData.image,
getRulesData(targetData),
language,
targetData.sources
);
target.create();

const application = new Analysis(
getRandomApplicationData("bookserverApp", {
sourceData: this.appData["bookserver-app"],
}),
getRandomAnalysisData(this.analysisData["source_analysis_on_bookserverapp"])
);
application.create();

Analysis.open();
selectItemsPerPage(100);
application.selectApplication();
cy.contains(button, analyzeButton, { timeout: 20 * SEC })
.should("be.enabled")
.click();

application.selectSourceofAnalysis(application.source);
cy.contains(button, "Next", { timeout: 200 }).click();

Analysis.selectLanguage(language);
cy.get(".pf-v5-c-card__body", { timeout: 12 * SEC })
.first()
.should("contain", target.name)
.click();
cy.contains(button, "Next", { timeout: 200 }).click();
cy.contains(button, "Next", { timeout: 200 }).click();
cy.contains(button, "Next", { timeout: 200 }).click();
target.validateSourceTechnology(targetData.sources);
clickByText(button, "Cancel");

target.delete();
application.delete();
});
});
});
2 changes: 2 additions & 0 deletions cypress/e2e/views/custom-migration-target.view.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const sourcesToggle = "#sources-toggle";
export const sourcesList = "ul#formSources-id.pf-v5-c-select__menu";
export enum CustomMigrationTargetView {
createSubmitButton = "button[id='identity-form-submit']:contains('Create')",
editSubmitButton = "button[id='identity-form-submit']:contains('Save')",
Expand Down
6 changes: 6 additions & 0 deletions cypress/fixtures/custom-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
"hazelcast_target": {
"image": "img/cloud.png",
"rulesFiles": ["xml/hazelcast.windup.xml"]
},

"rules_with_source_element": {
"image": "img/cloud.png",
"rulesFiles": ["xml/corporate-framework-config.windup.xml"],
"sources": "traditional-corporate-framework"
}
}
64 changes: 64 additions & 0 deletions cypress/fixtures/xml/corporate-framework-config.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<ruleset id="corporate-configuration"
xmlns="http://windup.jboss.org/schema/jboss-ruleset"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<metadata>
<description>
This ruleset provides rules related to the corporate configuration frameworks.
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final"/>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/>
</dependencies>
<sourceTechnology id="traditional-corporate-framework"/>
<targetTechnology id="cloud-corporate-framework"/>
<tag>configuration</tag>
</metadata>
<rules>
<rule id="corporate-config-01000" xmlns="http://windup.jboss.org/schema/jboss-ruleset">
<when>
<javaclass references="io.konveyor.demo.config.ApplicationConfiguration">
<location>VARIABLE_DECLARATION</location>
</javaclass>
</when>
<perform>
<hint title="Legacy configuration with io.konveyor.demo.config.ApplicationConfiguration" effort="1" category-id="cloud-mandatory">
<message>
The legacy ApplicationConfiguration class is being used in this application. This is discouraged by the migration
guidelines, and should be replaced by a more standard approach using Spring's @PropertySource annotation and Environment class:


```java
@PropertySource("classpath:persistence.properties")
public class PersistenceConfig {
@Autowired
private Environment env;

@Bean
public DataSource dataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
dataSource.setUrl(env.getProperty("jdbc.url"));
dataSource.setUsername(env.getProperty("jdbc.user"));
dataSource.setPassword(env.getProperty("jdbc.password"));

return dataSource;
}
}
```



This allows externalizing the configuration in Kubernetes by injecting it as a ConfigMap or a Secret in the lib directory from the
container running the Tomcat instance.
</message>
<link title="Spring Documentation - PropertySource javadoc" href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html"/>
<link title="Mkyong - Spring @PropertySource example" href="https://mkyong.com/spring/spring-propertysources-example/"/>
<link title="Baeldung - Properties with Spring and Spring Boot" href="https://www.baeldung.com/properties-with-spring" />
<tag>configuration</tag>
</hint>
</perform>
</rule>
</rules>
</ruleset>

0 comments on commit 103fa9d

Please sign in to comment.