下面列出了怎么用org.junit.jupiter.api.BeforeAll的API类实例代码及写法,或者点击链接到github查看源代码。
@BeforeAll
public static void setUp() {
JUDGMENTS.addJudgment("1", 3);
JUDGMENTS.addJudgment("2", 2);
JUDGMENTS.addJudgment("3", 3);
JUDGMENTS.addJudgment("5", 1);
JUDGMENTS.addJudgment("6", 2);
JUDGMENTS.addJudgment("7", 3);
JUDGMENTS.addJudgment("8", 2);
List<String> ids = new ArrayList<>();
for (int i = 1; i <= 6; i++) {
ids.add(Integer.toString(i));
}
RESULT_SET = new SearchResultSet(1000, 10, 100, ids);
}
@BeforeAll
static void setUpOnce() throws IOException {
discoverAssets(
RdsClient.class,
AwsRdsScanner::new,
api ->
when(api.describeDBInstances())
.thenReturn(
DescribeDbInstancesResponse.builder()
.dbInstances(
DBInstance.builder()
.dbInstanceArn("arn:aws:rds:us-east-1:1234567890:db:mysqldb")
.storageEncrypted(true)
.publiclyAccessible(false)
.build())
.build()));
}
@BeforeAll
static void setUpOnce() throws IOException {
discoverAssets(
CloudTrailClient.class,
AwsCloudTrailScanner::new,
api ->
when(api.describeTrails())
.thenReturn(
DescribeTrailsResponse.builder()
.trailList(
Trail.builder()
.trailARN(ENCRYPTED_TRAIL)
.kmsKeyId("some-key-arn")
.build(),
Trail.builder().trailARN(UNENCRYPTED_TRAIL).build())
.build()));
}
@BeforeAll
static void setUpOnce() {
discoverAssets(
AzureSQLDatabaseScanner::new,
api -> {
var server = createSqlServer("id", new ServerInner());
when(server.name()).thenReturn("myServer");
when(api.azure.sqlServers().list()).thenReturn(MockedPagedList.of(server));
var db = createSqlDatabase("id", "name", new DatabaseInner());
when(db.name()).thenReturn("myDatabase");
when(server.databases().list()).thenReturn(MockedPagedList.of(db));
});
}
@BeforeAll
static void setUpOnce() {
discoverAssets(
AzureAadUserScanner::new,
api -> {
var user1 =
createWithId(
ActiveDirectoryUser.class,
"1",
new UserInner().withUserPrincipalName("#EXT#name"));
var user2 =
createWithId(
ActiveDirectoryUser.class, "2", new UserInner().withUserPrincipalName("name"));
when(api.azure.accessManagement().activeDirectoryUsers().list())
.thenReturn(MockedPagedList.of(user1, user2));
});
}
@BeforeAll
public static void setUpBase() {
Runtime.getRuntime()
.addShutdownHook(new Thread(DataPathFeatureFlagAcceptanceTest::tearDownBase));
final DockerClient docker = new DockerClientFactory().create();
final NodeConfiguration nodeConfig = new NodeConfigurationBuilder().build();
/*
* Dynamic port allocation for either the RPC or WS ports triggers use of the data path.
* use_data_path = (httpRpcPort == 0 || webSocketPort == 0)
* By defining a value for those ports, no data path is present when launching EthSigner.
*/
final SignerConfiguration signerConfig =
new SignerConfigurationBuilder().withHttpRpcPort(7009).withWebSocketPort(7010).build();
ethNode = new BesuNode(docker, nodeConfig);
ethNode.start();
ethNode.awaitStartupCompletion();
ethSigner = new Signer(signerConfig, nodeConfig, ethNode.ports());
ethSigner.start();
ethSigner.awaitStartupCompletion();
}
@BeforeAll
public static void setUpBase() {
Runtime.getRuntime()
.addShutdownHook(new Thread(ValueTransferWithAzureAcceptanceTest::tearDownBase));
Assumptions.assumeTrue(
System.getenv("ETHSIGNER_AZURE_CLIENT_ID") != null
&& System.getenv("ETHSIGNER_AZURE_CLIENT_SECRET") != null,
"Ensure Azure client id and client secret env variables are set");
final DockerClient docker = new DockerClientFactory().create();
final NodeConfiguration nodeConfig = new NodeConfigurationBuilder().build();
ethNode = new BesuNode(docker, nodeConfig);
ethNode.start();
ethNode.awaitStartupCompletion();
final SignerConfiguration signerConfig =
new SignerConfigurationBuilder().withAzureKeyVault("ethsignertestkey").build();
ethSigner = new Signer(signerConfig, nodeConfig, ethNode.ports());
ethSigner.start();
ethSigner.awaitStartupCompletion();
}
@BeforeAll
static void startServers(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
SelfSignedCertificate caSignedCert = SelfSignedCertificate.create("localhost");
caValidFingerprint = certificateHexFingerprint(Paths.get(caSignedCert.keyCertOptions().getCertPath()));
SecurityTestUtils.configureJDKTrustStore(tempDir, caSignedCert);
caValidServer = vertx
.createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(caSignedCert.keyCertOptions()))
.requestHandler(context -> context.response().end("OK"));
startServer(caValidServer);
SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
fooServer = vertx
.createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(fooCert.keyCertOptions()))
.requestHandler(context -> context.response().end("OK"));
startServer(fooServer);
SelfSignedCertificate barCert = SelfSignedCertificate.create("bar.com");
barFingerprint = certificateHexFingerprint(Paths.get(barCert.keyCertOptions().getCertPath()));
barServer = vertx
.createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(barCert.keyCertOptions()))
.requestHandler(context -> context.response().end("OK"));
startServer(barServer);
}
@BeforeAll
public static void setUp() throws Exception {
JSON = Files.createTempFile("quaerite-features", ".json");
EXPERIMENTS = Files.createTempFile("quaerite-experiments", ".json");
Files.copy(
TestGenerateSolrExperiments.class.getResourceAsStream(
"/test-documents/experiment_features_solr_1.json"),
JSON, StandardCopyOption.REPLACE_EXISTING);
}
@BeforeAll
public static void beforeClass() {
// 注意此处的编解码器
Codec codec = new JsonJacksonCodec();
Config configuration = new Config();
configuration.setCodec(codec);
configuration.useSingleServer().setAddress("redis://127.0.0.1:6379");
redisson = (Redisson) Redisson.create(configuration);
}
@BeforeAll
static void setUpOnce() {
discoverAssets(
LambdaClient.class,
AwsLambdaScanner::new,
api -> {
when(api.listFunctions())
.thenReturn(
ListFunctionsResponse.builder()
.functions(
FunctionConfiguration.builder()
.functionArn(
"arn:aws:lambda:eu-central-1:123456789:function:function-1")
.functionName("function-1")
.kmsKeyArn("some-key")
.build(),
FunctionConfiguration.builder()
.functionArn(
"arn:aws:lambda:eu-central-1:123456789:function:function-2")
.functionName("function-2")
.build())
.build());
when(api.getPolicy(GetPolicyRequest.builder().functionName("function-1").build()))
.thenReturn(GetPolicyResponse.builder().policy("*").build());
when(api.getPolicy(GetPolicyRequest.builder().functionName("function-2").build()))
.thenReturn(GetPolicyResponse.builder().policy("no-wildcard").build());
});
}
@BeforeAll
static void setUp() throws ClassHierarchyException, CallGraphBuilderCancelException, IOException {
var path = Paths.get(new File(Thread.currentThread().getContextClassLoader()
.getResource("SingleSourceToTarget.jar")
.getFile()).getAbsolutePath());
graph = WalaResultAnalyzer.wrap(CallGraphConstructor.generateCallGraph(path.toString()));
type = graph.getClassHierarchy()
.get(new FastenJavaURI("/name.space/SingleSourceToTarget"));
}
@BeforeAll
static void setUpOnce() {
discoverAssets(
AzureSQLServerScanner::new,
api -> {
var server = createSqlServer("id", new ServerInner());
when(server.name()).thenReturn("myServer");
when(api.azure.sqlServers().list()).thenReturn(MockedPagedList.of(server));
});
}
@BeforeAll
static void setUpOnce() {
discoverAssets(
AzureNetworkSecurityGroupScanner::new,
api -> {
var nsg = createWithId(NetworkSecurityGroup.class, "id", new NetworkSecurityGroupInner());
when(api.azure.networkSecurityGroups().list()).thenReturn(MockedPagedList.of(nsg));
});
}
@BeforeAll
static void setUpOnce() {
discoverAssets(
AzureSubscriptionScanner::new,
api -> {
var profile =
new LogProfileResourceInner()
.withRetentionPolicy(new RetentionPolicy().withDays(90).withEnabled(true));
when(api.monitor().inner().logProfiles().list()).thenReturn(MockedPagedList.of(profile));
});
}
@BeforeAll
static void createDatabase(@Autowired Driver driver) {
try (Session session = driver.session(SessionConfig.forDatabase("system"))) {
session.run("CREATE DATABASE movies");
session.run("CREATE DATABASE otherDb");
}
}
@BeforeAll
public static void before() {
model = Model.assembler()
.addImport(UnreferencedShapesTest.class.getResource("unreferenced-test.json"))
.assemble()
.unwrap();
}
@BeforeAll
public static void before() {
model = Model.assembler()
.addImport(ForwardNeighborSelectorTest.class.getResource("neighbor-test.smithy"))
.assemble()
.unwrap();
}
@BeforeAll
public static void before() {
modelJson = Model.assembler().addImport(SelectorTest.class.getResource("model.json"))
.disablePrelude()
.assemble()
.unwrap();
traitModel = Model.assembler()
.addImport(SelectorTest.class.getResource("nested-traits.smithy"))
.assemble()
.unwrap();
}
@BeforeAll
public static void setUp() throws CmdUtilException, IOException, SvnClientException {
LogUtil.entering();
final TempSvnRepository createAndFillTempSvnRepository = TempSvnRepositoryFactory
.createAndFillTempSvnRepository();
testRepoUrlString = createAndFillTempSvnRepository.testRepoUrlString;
client = new SvnClientJavaHl(() -> new String[0], new JUnitConfiguration());
}
@BeforeAll
public static void beforeAll() {
model = Model.assembler()
.addImport(EventStreamIndexTest.class.getResource("event-stream-index.json"))
.assemble()
.unwrap();
}
@BeforeAll
static void createConstraints(@Autowired Driver driver) {
Flux.using(driver::rxSession,
session -> session.run("CREATE CONSTRAINT ON (person:SimplePerson) ASSERT person.name IS UNIQUE").consume(),
RxSession::close
).then().as(StepVerifier::create).verifyComplete();
}
@BeforeAll
static void initBsonDocs() {
flatStructKey = new BsonDocument();
flatStructKey.put("_id", new BsonObjectId(ObjectId.get()));
flatStructKey.put("myBoolean", new BsonBoolean(true));
flatStructKey.put("myInt", new BsonInt32(42));
flatStructKey.put("myBytes", new BsonBinary(new byte[] {65, 66, 67}));
BsonArray ba1 = new BsonArray();
ba1.addAll(asList(new BsonInt32(1), new BsonInt32(2), new BsonInt32(3)));
flatStructKey.put("myArray", ba1);
flatStructValue = new BsonDocument();
flatStructValue.put("myLong", new BsonInt64(42L));
flatStructValue.put("myDouble", new BsonDouble(23.23d));
flatStructValue.put("myString", new BsonString("BSON"));
flatStructValue.put("myBytes", new BsonBinary(new byte[] {120, 121, 122}));
BsonArray ba2 = new BsonArray();
ba2.addAll(asList(new BsonInt32(9), new BsonInt32(8), new BsonInt32(7)));
flatStructValue.put("myArray", ba2);
nestedStructKey = new BsonDocument();
nestedStructKey.put("_id", new BsonDocument("myString", new BsonString("doc")));
nestedStructKey.put(
"mySubDoc", new BsonDocument("mySubSubDoc", new BsonDocument("myInt", new BsonInt32(23))));
nestedStructValue = new BsonDocument();
nestedStructValue.put("mySubDocA", new BsonDocument("myBoolean", new BsonBoolean(false)));
nestedStructValue.put(
"mySubDocB",
new BsonDocument(
"mySubSubDocC", new BsonDocument("myString", new BsonString("some text..."))));
}
@BeforeAll
private static void setup() {
testService = Model.assembler()
.addImport(OpenApiConverterTest.class.getResource("test-service.json"))
.discoverModels()
.assemble()
.unwrap();
}
@BeforeAll
public static void setupOnce() {
// create a client identity spring for this test suite
clientId = UUID.randomUUID().toString();
// create a Spring context for this test suite and obtain some beans
context = new AnnotationConfigApplicationContext(ServerConfig.class);
// Create an RSocket server for use in testing
RSocketMessageHandler messageHandler = context.getBean(RSocketMessageHandler.class);
server = RSocketServer.create(messageHandler.responder())
.payloadDecoder(PayloadDecoder.ZERO_COPY)
.bind(TcpServerTransport.create("localhost", 0))
.block();
}
@BeforeAll
public static void before() {
model = Model.assembler()
.addImport(RemoveUnusedComponentsTest.class.getResource("greedy-labels.smithy"))
.discoverModels()
.assemble()
.unwrap();
}
@BeforeAll
public static void setUp() {
triangle = new TriangleFunction("Triangle Function", N_SAMPLES, 0);
triangleWithNaN = new DoubleDataSet(triangle);
((DoubleDataSet) triangleWithNaN).set(N_SAMPLES / 4, N_SAMPLES / 4, Double.NaN);
((DoubleDataSet) triangleWithNaN).set(N_SAMPLES / 4 * 3, Double.NaN, Double.NaN);
emptyDataSet = new DefaultDataSet("EmptyDataSet");
testGauss = new GaussFunction("testGauss", N_SAMPLES);
}
@BeforeAll
public static void setupOnce(@Autowired RSocketRequester.Builder builder,
@LocalRSocketServerPort Integer port,
@Autowired RSocketStrategies strategies) {
mimeType = MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString());
reqbuilder = builder;
theport = port;
// ******* The user 'fake' is NOT in the user list! **********
credentials = new UsernamePasswordMetadata("fake", "pass");
}
@BeforeAll
public static void initSecurityManager() throws NoSuchAlgorithmException {
oldSecurityManager = System.getSecurityManager();
oldPolicy = Policy.getPolicy();
// permissive policy
Policy.setPolicy(new Policy() {
@Override
public boolean implies(ProtectionDomain domain, Permission permission) {
return true;
}
});
System.setSecurityManager(new SecurityManager());
}
@BeforeAll
static void createDatabase(@Autowired Driver driver) {
try (Session session = driver.session(SessionConfig.forDatabase("system"))) {
session.run("CREATE DATABASE movies");
}
}