View Javadoc
1   /*-
2    * #%L
3    * io.earcam.instrumental.agent.junit
4    * %%
5    * Copyright (C) 2018 earcam
6    * %%
7    * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8    * 
9    * You <b>must</b> choose to accept, in full - any individual or combination of 
10   * the following licenses:
11   * <ul>
12   * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13   * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14   * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15   * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16   * </ul>
17   * #L%
18   */
19  package io.earcam.instrumental.agent.junit;
20  
21  import static io.earcam.instrumental.archive.AsAgentJar.asAgentJar;
22  import static io.earcam.instrumental.archive.Archive.archive;
23  
24  import java.nio.file.Path;
25  import java.nio.file.Paths;
26  
27  import org.junit.AfterClass;
28  import org.junit.BeforeClass;
29  import org.junit.jupiter.api.AfterAll;
30  import org.junit.jupiter.api.BeforeAll;
31  
32  import com.acme.StubAgent;
33  import com.acme.StubAgentState;
34  
35  // FIXME this is dodgy - fails in parallel exec of surefire
36  public abstract class AbstractAgentJarTest {
37  
38  	// EARCAM_SNIPPET_BEGIN: setup
39  	protected static final String DIR = "target";
40  	protected static final String FILE = "AbstractAgentJarTest-stubagent.jar";
41  
42  	public static final String JAR_NAME = DIR + '/' + FILE;
43  	public static final Path JAR_PATH = Paths.get(DIR, FILE);
44  
45  	public static final String AGENT_ARGUMENTS = "-Awinter=socks";
46  	// EARCAM_SNIPPET_END: setup
47  
48  
49  	@BeforeClass
50  	@BeforeAll
51  	public static void begin()
52  	{
53  		archive()
54  				.configured(asAgentJar().withAgentClass(StubAgent.class))
55  				.to(JAR_PATH);
56  	}
57  
58  
59  	@AfterClass
60  	@AfterAll
61  	public static void reset()
62  	{
63  		StubAgentState.initialize();
64  	}
65  }