Skip to content

Commit ea2a494

Browse files
committed
Fixed bug with tests and added a new one
1 parent f9d0a37 commit ea2a494

File tree

4 files changed

+224
-1
lines changed

4 files changed

+224
-1
lines changed

plugins/codemodder-plugin-maven/src/test/java/io/codemodder/plugins/maven/operator/AbstractTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected ProjectModel performAndAssertPomOperation(
5959
String testName, ProjectModel context, final OperationType operationType) throws Exception {
6060

6161
String resultFile = "pom-" + testName + "-result.xml";
62-
URL resource = AbstractTestBase.class.getClass().getResource(resultFile);
62+
URL resource = AbstractTestBase.class.getResource(resultFile);
6363

6464
if (resource != null) {
6565
Document outcome = new SAXReader().read(resource);

plugins/codemodder-plugin-maven/src/test/java/io/codemodder/plugins/maven/operator/POMOperatorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,18 @@ void modify_adds_dependency_to_file_with_tabs()
581581
"\n\t\t<dependency>\n\t\t\t<groupId>org.dom4j</groupId>\n\t\t\t<artifactId>dom4j</artifactId>\n\t\t</dependency>\n");
582582
}
583583

584+
@Test
585+
void modify_adds_dependency_to_pom_with_empty_elements_with_multiple_attributes() throws Exception {
586+
Dependency dependencyToUpgrade =
587+
new Dependency("io.github.pixee", "java-security-toolkit", "1.0.2", null, null, null);
588+
589+
performAndAssertModifyPomOperation(
590+
"trimmed-roller",
591+
ProjectModelFactory.load(POMOperatorTest.class.getResource("pom-trimmed-roller.xml"))
592+
.withDependency(dependencyToUpgrade)
593+
.withUseProperties(true));
594+
}
595+
584596
/**
585597
* Tests a scenario with an empty element from a customer's POM file and validates the resultant
586598
* POM.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.instancio</groupId>
25+
<artifactId>instancio-junit</artifactId>
26+
<version>5.0.1</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.github.pixee</groupId>
31+
<artifactId>java-security-toolkit</artifactId>
32+
</dependency>
33+
</dependencies>
34+
35+
<build>
36+
37+
<finalName>roller</finalName>
38+
39+
<plugins>
40+
41+
<plugin>
42+
<artifactId>maven-antrun-plugin</artifactId>
43+
<version>3.1.0</version>
44+
<dependencies>
45+
<dependency>
46+
<groupId>ant-contrib</groupId>
47+
<artifactId>ant-contrib</artifactId>
48+
<version>${maven-antrun.version}</version>
49+
<exclusions>
50+
<exclusion>
51+
<groupId>ant</groupId>
52+
<artifactId>ant</artifactId>
53+
</exclusion>
54+
</exclusions>
55+
</dependency>
56+
<!-- last velocity version which had the Ant TexenTask -->
57+
<dependency>
58+
<groupId>org.apache.velocity</groupId>
59+
<artifactId>velocity</artifactId>
60+
<version>1.7</version>
61+
</dependency>
62+
</dependencies>
63+
64+
<executions>
65+
<execution>
66+
<id>gen-db-scripts</id>
67+
<phase>generate-resources</phase>
68+
<goals>
69+
<goal>run</goal>
70+
</goals>
71+
<configuration>
72+
<target>
73+
<!-- Workaround for git distribution that doesn't keep empty directories.
74+
For detail check [ROL-2086] -->
75+
<taskdef resource="net/sf/antcontrib/antlib.xml" />
76+
<property file="${basedir}/src/main/resources/sql/dbscripts.properties" />
77+
<for list="${databases}" param="database" delimiter=" ">
78+
<sequential>
79+
<mkdir dir="${basedir}/target/classes/dbscripts/@{database}" />
80+
</sequential>
81+
</for>
82+
83+
<taskdef name="texen"
84+
classname="org.apache.velocity.texen.ant.TexenTask"
85+
classpathref="maven.plugin.classpath"/>
86+
<texen
87+
controlTemplate ="control.vm"
88+
contextProperties="${basedir}/src/main/resources/sql/dbscripts.properties"
89+
templatePath ="${basedir}/src/main/resources/sql"
90+
outputDirectory ="${basedir}/target/classes/dbscripts"
91+
outputFile ="README.txt"/>
92+
</target>
93+
</configuration>
94+
</execution>
95+
</executions>
96+
</plugin>
97+
98+
</plugins>
99+
100+
</build>
101+
<dependencyManagement>
102+
<dependencies>
103+
<dependency>
104+
<groupId>io.github.pixee</groupId>
105+
<artifactId>java-security-toolkit</artifactId>
106+
<version>${versions.java-security-toolkit}</version>
107+
</dependency>
108+
</dependencies>
109+
</dependencyManagement>
110+
<properties>
111+
<versions.java-security-toolkit>1.0.2</versions.java-security-toolkit>
112+
</properties>
113+
</project>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.instancio</groupId>
25+
<artifactId>instancio-junit</artifactId>
26+
<version>5.0.1</version>
27+
<scope>test</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
33+
<finalName>roller</finalName>
34+
35+
<plugins>
36+
37+
<plugin>
38+
<artifactId>maven-antrun-plugin</artifactId>
39+
<version>3.1.0</version>
40+
<dependencies>
41+
<dependency>
42+
<groupId>ant-contrib</groupId>
43+
<artifactId>ant-contrib</artifactId>
44+
<version>${maven-antrun.version}</version>
45+
<exclusions>
46+
<exclusion>
47+
<groupId>ant</groupId>
48+
<artifactId>ant</artifactId>
49+
</exclusion>
50+
</exclusions>
51+
</dependency>
52+
<!-- last velocity version which had the Ant TexenTask -->
53+
<dependency>
54+
<groupId>org.apache.velocity</groupId>
55+
<artifactId>velocity</artifactId>
56+
<version>1.7</version>
57+
</dependency>
58+
</dependencies>
59+
60+
<executions>
61+
<execution>
62+
<id>gen-db-scripts</id>
63+
<phase>generate-resources</phase>
64+
<goals>
65+
<goal>run</goal>
66+
</goals>
67+
<configuration>
68+
<target>
69+
<!-- Workaround for git distribution that doesn't keep empty directories.
70+
For detail check [ROL-2086] -->
71+
<taskdef resource="net/sf/antcontrib/antlib.xml" />
72+
<property file="${basedir}/src/main/resources/sql/dbscripts.properties" />
73+
<for list="${databases}" param="database" delimiter=" ">
74+
<sequential>
75+
<mkdir dir="${basedir}/target/classes/dbscripts/@{database}" />
76+
</sequential>
77+
</for>
78+
79+
<taskdef name="texen"
80+
classname="org.apache.velocity.texen.ant.TexenTask"
81+
classpathref="maven.plugin.classpath"/>
82+
<texen
83+
controlTemplate ="control.vm"
84+
contextProperties="${basedir}/src/main/resources/sql/dbscripts.properties"
85+
templatePath ="${basedir}/src/main/resources/sql"
86+
outputDirectory ="${basedir}/target/classes/dbscripts"
87+
outputFile ="README.txt"/>
88+
</target>
89+
</configuration>
90+
</execution>
91+
</executions>
92+
</plugin>
93+
94+
</plugins>
95+
96+
</build>
97+
98+
</project>

0 commit comments

Comments
 (0)