Skip to content

Commit a6cf214

Browse files
committed
Split BuilderTest into multiple files
One per Builder implementation.
1 parent 23c177f commit a6cf214

File tree

5 files changed

+269
-142
lines changed

5 files changed

+269
-142
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*-
2+
* #%L
3+
* Appose: multi-language interprocess cooperation with shared memory.
4+
* %%
5+
* Copyright (C) 2023 - 2025 Appose developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package org.apposed.appose.builder;
31+
32+
import org.apposed.appose.Appose;
33+
import org.apposed.appose.Environment;
34+
import org.apposed.appose.TestBase;
35+
import org.junit.jupiter.api.Test;
36+
37+
import java.io.File;
38+
39+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
40+
import static org.junit.jupiter.api.Assertions.assertTrue;
41+
42+
/** End-to-end tests for {@link MambaBuilder}. */
43+
public class MambaBuilderTest extends TestBase {
44+
45+
/** Tests explicit mamba builder selection using {@code .builder()} method. */
46+
@Test
47+
public void testExplicitMambaBuilder() throws Exception {
48+
Environment env = Appose
49+
.file("src/test/resources/envs/cowsay.yml")
50+
.builder("mamba")
51+
.base("target/envs/mamba-cowsay")
52+
.logDebug()
53+
.build();
54+
55+
assertInstanceOf(MambaBuilder.class, env.builder());
56+
57+
// Verify it actually used mamba by checking for conda-meta directory.
58+
File envBase = new File(env.base());
59+
File condaMeta = new File(envBase, "conda-meta");
60+
assertTrue(condaMeta.exists() && condaMeta.isDirectory(),
61+
"Environment should have conda-meta directory when using mamba builder");
62+
63+
cowsayAndAssert(env, "yay");
64+
}
65+
}

src/test/java/org/apposed/appose/BuilderTest.java renamed to src/test/java/org/apposed/appose/builder/PixiBuilderTest.java

Lines changed: 6 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,22 @@
2727
* #L%
2828
*/
2929

30-
package org.apposed.appose;
30+
package org.apposed.appose.builder;
3131

32-
import org.apposed.appose.Service.Task;
33-
import org.apposed.appose.builder.MambaBuilder;
34-
import org.apposed.appose.builder.PixiBuilder;
35-
import org.apposed.appose.builder.UvBuilder;
32+
import org.apposed.appose.Appose;
33+
import org.apposed.appose.Environment;
34+
import org.apposed.appose.TestBase;
3635
import org.apposed.appose.util.FilePaths;
3736
import org.junit.jupiter.api.Test;
3837

3938
import java.io.File;
4039
import java.io.IOException;
41-
import java.util.List;
4240

43-
import static org.junit.jupiter.api.Assertions.assertEquals;
44-
import static org.junit.jupiter.api.Assertions.assertFalse;
4541
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
46-
import static org.junit.jupiter.api.Assertions.assertNotNull;
4742
import static org.junit.jupiter.api.Assertions.assertThrows;
48-
import static org.junit.jupiter.api.Assertions.assertTrue;
4943

50-
/** End-to-end tests for the Appose builder subsystem and implementations. */
51-
public class BuilderTest extends TestBase {
44+
/** End-to-end tests for {@link PixiBuilder}. */
45+
public class PixiBuilderTest extends TestBase {
5246

5347
/** Tests the builder-agnostic API with an environment.yml file. */
5448
@Test
@@ -125,60 +119,6 @@ public void testPixiPyproject() throws Exception {
125119
cowsayAndAssert(env, "pixi-pyproject");
126120
}
127121

128-
/** Tests explicit mamba builder selection using {@code .builder()} method. */
129-
@Test
130-
public void testExplicitMambaBuilder() throws Exception {
131-
Environment env = Appose
132-
.file("src/test/resources/envs/cowsay.yml")
133-
.builder("mamba")
134-
.base("target/envs/mamba-cowsay")
135-
.logDebug()
136-
.build();
137-
138-
assertInstanceOf(MambaBuilder.class, env.builder());
139-
140-
// Verify it actually used mamba by checking for conda-meta directory.
141-
File envBase = new File(env.base());
142-
File condaMeta = new File(envBase, "conda-meta");
143-
assertTrue(condaMeta.exists() && condaMeta.isDirectory(),
144-
"Environment should have conda-meta directory when using mamba builder");
145-
146-
cowsayAndAssert(env, "yay");
147-
}
148-
149-
@Test
150-
public void testUv() throws Exception {
151-
Environment env = Appose
152-
.uv("src/test/resources/envs/cowsay-requirements.txt")
153-
.base("target/envs/uv-cowsay")
154-
.logDebug()
155-
.build();
156-
assertInstanceOf(UvBuilder.class, env.builder());
157-
cowsayAndAssert(env, "uv");
158-
}
159-
160-
@Test
161-
public void testUvBuilderAPI() throws Exception {
162-
Environment env = Appose
163-
.uv()
164-
.include("cowsay==6.1")
165-
.base("target/envs/uv-cowsay-builder")
166-
.logDebug()
167-
.build();
168-
assertInstanceOf(UvBuilder.class, env.builder());
169-
cowsayAndAssert(env, "fast");
170-
}
171-
172-
@Test
173-
public void testUvPyproject() throws Exception {
174-
Environment env = Appose
175-
.uv("src/test/resources/envs/cowsay-pyproject.toml")
176-
.base("target/envs/uv-cowsay-pyproject")
177-
.logDebug()
178-
.build();
179-
cowsayAndAssert(env, "pyproject");
180-
}
181-
182122
/** Tests building environment from content string using type-specific builder.*/
183123
@Test
184124
public void testContentAPI() throws Exception {
@@ -251,75 +191,4 @@ public void testContentPixiToml() throws Exception {
251191
assertInstanceOf(PixiBuilder.class, env.builder());
252192
cowsayAndAssert(env, "toml!");
253193
}
254-
255-
/**
256-
* Tests fluent chaining from base Builder methods to SimpleBuilder methods.
257-
* This verifies that the recursive generics enable natural method chaining.
258-
*/
259-
@Test
260-
public void testCustom() throws Exception {
261-
Environment env = Appose.custom()
262-
.env("CUSTOM_VAR", "test_value") // Base Builder method
263-
.inheritRunningJava() // SimpleBuilder method
264-
.appendSystemPath() // SimpleBuilder method
265-
.build();
266-
267-
assertNotNull(env);
268-
assertNotNull(env.binPaths());
269-
assertFalse(env.binPaths().isEmpty(),
270-
"Custom environment should have binary paths configured");
271-
assertTrue(env.launchArgs().isEmpty(),
272-
"Custom environment should have no special launcher");
273-
274-
// Verify environment variables are propagated.
275-
assertNotNull(env.envVars());
276-
assertEquals("test_value", env.envVars().get("CUSTOM_VAR"));
277-
278-
// Verify inheritRunningJava() sets JAVA_HOME.
279-
String javaHome = System.getProperty("java.home");
280-
if (javaHome != null) {
281-
assertEquals(javaHome, env.envVars().get("JAVA_HOME"));
282-
// Verify Java bin directory is in binPaths.
283-
String javaBin = new File(javaHome, "bin").getAbsolutePath();
284-
assertTrue(env.binPaths().contains(javaBin),
285-
"Java bin directory should be in binPaths");
286-
}
287-
288-
// Verify that the custom environment can execute Python tasks.
289-
try (Service service = env.python()) {
290-
maybeDebug(service);
291-
Task task = service.task("2 + 2");
292-
task.waitFor();
293-
assertComplete(task);
294-
Number result = (Number) task.result();
295-
assertEquals(4, result.intValue());
296-
}
297-
298-
// Test custom environment with specific base directory.
299-
File customDir = new File("target/test-custom");
300-
customDir.mkdirs();
301-
try {
302-
Environment customEnv = Appose.custom()
303-
.base(customDir)
304-
.appendSystemPath()
305-
.build();
306-
307-
assertEquals(customDir.getAbsolutePath(), customEnv.base());
308-
assertNotNull(customEnv.binPaths());
309-
}
310-
finally {
311-
customDir.delete();
312-
}
313-
314-
// Test custom environment with specific binary paths.
315-
Environment pathEnv = Appose.custom()
316-
.binPaths("/usr/bin", "/usr/local/bin")
317-
.build();
318-
319-
List<String> binPaths = pathEnv.binPaths();
320-
assertTrue(binPaths.contains("/usr/bin"),
321-
"Custom binPaths should include /usr/bin");
322-
assertTrue(binPaths.contains("/usr/local/bin"),
323-
"Custom binPaths should include /usr/local/bin");
324-
}
325194
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*-
2+
* #%L
3+
* Appose: multi-language interprocess cooperation with shared memory.
4+
* %%
5+
* Copyright (C) 2023 - 2025 Appose developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package org.apposed.appose.builder;
31+
32+
import org.apposed.appose.Appose;
33+
import org.apposed.appose.Environment;
34+
import org.apposed.appose.Service;
35+
import org.apposed.appose.Service.Task;
36+
import org.apposed.appose.TestBase;
37+
import org.junit.jupiter.api.Test;
38+
39+
import java.io.File;
40+
import java.util.List;
41+
42+
import static org.junit.jupiter.api.Assertions.assertEquals;
43+
import static org.junit.jupiter.api.Assertions.assertFalse;
44+
import static org.junit.jupiter.api.Assertions.assertNotNull;
45+
import static org.junit.jupiter.api.Assertions.assertTrue;
46+
47+
/** End-to-end tests for {@link SimpleBuilder}. */
48+
public class SimpleBuilderTest extends TestBase {
49+
50+
/**
51+
* Tests fluent chaining from base Builder methods to SimpleBuilder methods.
52+
* This verifies that the recursive generics enable natural method chaining.
53+
*/
54+
@Test
55+
public void testCustom() throws Exception {
56+
Environment env = Appose.custom()
57+
.env("CUSTOM_VAR", "test_value") // Base Builder method
58+
.inheritRunningJava() // SimpleBuilder method
59+
.appendSystemPath() // SimpleBuilder method
60+
.build();
61+
62+
assertNotNull(env);
63+
assertNotNull(env.binPaths());
64+
assertFalse(env.binPaths().isEmpty(),
65+
"Custom environment should have binary paths configured");
66+
assertTrue(env.launchArgs().isEmpty(),
67+
"Custom environment should have no special launcher");
68+
69+
// Verify environment variables are propagated.
70+
assertNotNull(env.envVars());
71+
assertEquals("test_value", env.envVars().get("CUSTOM_VAR"));
72+
73+
// Verify inheritRunningJava() sets JAVA_HOME.
74+
String javaHome = System.getProperty("java.home");
75+
if (javaHome != null) {
76+
assertEquals(javaHome, env.envVars().get("JAVA_HOME"));
77+
// Verify Java bin directory is in binPaths.
78+
String javaBin = new File(javaHome, "bin").getAbsolutePath();
79+
assertTrue(env.binPaths().contains(javaBin),
80+
"Java bin directory should be in binPaths");
81+
}
82+
83+
// Verify that the custom environment can execute Python tasks.
84+
try (Service service = env.python()) {
85+
maybeDebug(service);
86+
Task task = service.task("2 + 2");
87+
task.waitFor();
88+
assertComplete(task);
89+
Number result = (Number) task.result();
90+
assertEquals(4, result.intValue());
91+
}
92+
93+
// Test custom environment with specific base directory.
94+
File customDir = new File("target/test-custom");
95+
customDir.mkdirs();
96+
try {
97+
Environment customEnv = Appose.custom()
98+
.base(customDir)
99+
.appendSystemPath()
100+
.build();
101+
102+
assertEquals(customDir.getAbsolutePath(), customEnv.base());
103+
assertNotNull(customEnv.binPaths());
104+
}
105+
finally {
106+
customDir.delete();
107+
}
108+
109+
// Test custom environment with specific binary paths.
110+
Environment pathEnv = Appose.custom()
111+
.binPaths("/usr/bin", "/usr/local/bin")
112+
.build();
113+
114+
List<String> binPaths = pathEnv.binPaths();
115+
assertTrue(binPaths.contains("/usr/bin"),
116+
"Custom binPaths should include /usr/bin");
117+
assertTrue(binPaths.contains("/usr/local/bin"),
118+
"Custom binPaths should include /usr/local/bin");
119+
}
120+
}

0 commit comments

Comments
 (0)