下面列出了org.junit.Assume#assumeNotNull ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Note that this "test" method only exists as a convenient way to capture test resources to deploy into other environments.
* Set the "TEST_RESOURCES" env var in order to write these resources out.
*/
@Test
public void outputTestResources() throws Exception {
String outputPath = System.getenv("TEST_RESOURCES");
// Ignore this is not set.
Assume.assumeNotNull(outputPath);
// For both of these, capture the optimized JAR and ABI.
System.out.println("Outputing test resources to: \"" + outputPath + "\"");
outputResourcesForTestClass(outputPath, CallContract.class);
outputResourcesForTestClass(outputPath, CPUIntensiveOperations.class);
outputResourcesForTestClass(outputPath, MemoryUsage.class);
outputResourcesForTestClass(outputPath, SimpleContractWithABI.class);
outputResourcesForTestClass(outputPath, SimpleContractWithoutABI.class);
outputResourcesForTestClass(outputPath, SimpleStorageStatic.class);
outputResourcesForTestClass(outputPath, StorageLargeDataContract.class);
}
@Test
public void testSkipJDKClassLoaders() throws MalformedURLException, IOException {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
ClassLoader parent = classLoader.getParent();
// This test is only meaningful if parent classloader exists (most likely the extension classloader
// and is also a URLClassLoader
Assume.assumeNotNull(parent);
Assume.assumeTrue(parent instanceof URLClassLoader);
URL[] parentURLs = ((URLClassLoader) parent).getURLs();
Stream<Path> stream = AppBundleGenerator.toPathStream(classLoader);
assertFalse("Stream contains a jar from the parent classloader", stream.anyMatch(path -> {
try {
return Arrays.asList(parentURLs).contains(path.toUri().toURL());
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}));
}
@Test
public void deleteTest() throws Exception {
Assume.assumeNotNull(getFs());
Path testFile = new Path(getBaseURI() + "/testFile");
createFile(testFile, data);
Path input = new Path(getBaseURI() + "/a/b/c/m.data/_temporary/"
+ "0/_temporary/attempt_201603141928_0000_m_000099_102/part-00099");
Whitebox.setInternalState(mMockObjectStoreFileSystem, "hostNameScheme", getBaseURI());
String result = Whitebox.invokeMethod(mMockStocatorPath, "parseHadoopFOutputCommitterV1", input,
true, getBaseURI());
Path modifiedInput = new Path(getBaseURI() + result);
createFile(input, data);
Assert.assertTrue(getFs().exists(modifiedInput));
Assert.assertTrue(getFs().exists(testFile));
getFs().delete(testFile, false);
Assert.assertFalse(getFs().exists(testFile));
getFs().delete(modifiedInput, false);
Assert.assertFalse(getFs().exists(modifiedInput));
}
public void testJRuby() throws ScriptException, NoSuchMethodException {
// Simply adding jruby.jar to Solr's lib/ directory gets this test passing
ScriptEngine engine = manager.getEngineByName("jruby");
Assume.assumeNotNull(engine);
assertNotNull(engine);
engine.eval("def add(a,b); a + b; end");
Number result = (Number) ((Invocable)engine).invokeFunction("add", 1, 2);
assertNotNull(result);
assertEquals(3, result.intValue());
}
@Test
public void openCreateTest() throws Exception {
Assume.assumeNotNull(getFs());
Path testFile = new Path(getBaseURI() + "/testFile");
createFile(testFile, data);
FSDataInputStream inputStream = getFs().open(testFile);
String uri = (Whitebox.getInternalState(inputStream.getWrappedStream(), "uri"));
Path path = new Path(uri);
Assert.assertEquals(testFile.getName(), path.getName());
}
@Test
public void testUploadWithScriptUpdateProcessor() throws Exception {
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("JavaScript"));
// Authorization off
// unprotectConfigsHandler(); // TODO Enable this back when testUploadWithLibDirective() is re-enabled
final String untrustedSuffix = "-untrusted";
uploadConfigSetWithAssertions("with-script-processor", untrustedSuffix, null, null);
// try to create a collection with the uploaded configset
Throwable thrown = expectThrows(BaseHttpSolrClient.RemoteSolrException.class, () -> {
createCollection("newcollection2", "with-script-processor" + untrustedSuffix,
1, 1, solrCluster.getSolrClient());
});
assertThat(thrown.getMessage(), containsString("Underlying core creation failed"));
// Authorization on
final String trustedSuffix = "-trusted";
protectConfigsHandler();
uploadConfigSetWithAssertions("with-script-processor", trustedSuffix, "solr", "SolrRocks");
// try to create a collection with the uploaded configset
CollectionAdminResponse resp = createCollection("newcollection2", "with-script-processor" + trustedSuffix,
1, 1, solrCluster.getSolrClient());
scriptRequest("newcollection2");
}
@Test
public void testUploadContextPNGUpperCase() throws IOException {
Assume.assumeNotNull(smartlingTestConfig.projectId);
ClassPathResource classPathResource = new ClassPathResource("/com/box/l10n/mojito/img/1.png");
byte[] content = ByteStreams.toByteArray(classPathResource.getInputStream());
smartlingClient.uploadContext(smartlingTestConfig.projectId, "caseissuewithpng.PNG", content);
}
@Test
public void testAuthenticateOpenSSHKeyWithoutPassphrase() throws Exception {
Assume.assumeNotNull(System.getProperty("manta.url"), System.getProperty("manta.key_id"), System.getProperty("manta.key_path"));
final Credentials credentials = new Credentials(System.getProperty("manta.user"), "");
final Local key = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
credentials.setIdentity(key);
try {
new DefaultLocalTouchFeature().touch(key);
IOUtils.copy(
new FileReader(System.getProperty("manta.key_path")),
key.getOutputStream(false),
StandardCharsets.UTF_8
);
final String hostname = new URL(System.getProperty("manta.url")).getHost();
final Host host = new Host(new MantaProtocol(), hostname, credentials);
final MantaSession session = new MantaSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(Proxy.DIRECT,
new DisabledLoginCallback() {
@Override
public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
throw new LoginCanceledException();
}
},
new DisabledCancelCallback()
);
assertEquals(session.getClient().getContext().getMantaKeyId(), System.getProperty("manta.key_id"));
session.close();
}
finally {
key.delete();
}
}
@Test(expected = FileNotFoundException.class)
public void listLocatedStatusTestNotFound1() throws Exception {
Assume.assumeNotNull(getFs());
int count = 0;
RemoteIterator<LocatedFileStatus> stats = getFs().listLocatedStatus(new Path(fileName));
while (stats.hasNext()) {
LocatedFileStatus stat = stats.next();
Assert.assertTrue(stat.getPath().getName().startsWith("testFile"));
count++;
}
Assert.assertEquals(iterNum * 0, count);
}
@BeforeClass
public static void beforeClass() throws Exception {
assumeFalse("https://twitter.com/UweSays/status/260487231880433664 / SOLR-4233: OS X bogusly starts AWT!",
Constants.MAC_OS_X);
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByName("JavaScript"));
}
@Test
public void testServiceAccountCredentials() throws IOException, GeneralSecurityException {
Assume.assumeNotNull(credentials);
final GoogleCredentials serviceAccountCredentials;
final URI keyUri = URI.create("gs://styx-oss-test/styx-test-user.json");
try (InputStream is = Files.newInputStream(Paths.get(keyUri))) {
serviceAccountCredentials = GoogleCredentials.fromStream(is);
}
assertThat(canAcquireIdToken(serviceAccountCredentials), is(true));
}
@Before
public void init() {
Assume.assumeNotNull(smartlingClient);
}
public String getRetargetingRequestId() {
Assume.assumeNotNull(retargetingRequestId);
return retargetingRequestId;
}
protected String getTestShareGuestURL () {
String testGuestShare = getProperties().get(TestProperties.TEST_SHARE_GUEST);
Assume.assumeNotNull(testGuestShare);
return "smb://" + getTestServer() + "/" + testGuestShare + "/";
}
private String getCallPipeUrl () {
String testCallPipe = getProperties().get(TestProperties.TEST_CALL_PIPE);
Assume.assumeNotNull(testCallPipe);
return "smb://" + getTestServer() + "/IPC$/" + testCallPipe;
}
@BeforeClass
public static void beforeClass() throws Exception {
Assume.assumeNotNull((new ScriptEngineManager()).getEngineByExtension("js"));
initCore("solrconfig-script-updateprocessor.xml", "schema12.xml");
}
public String getUserId() {
Assume.assumeNotNull(userId);
return userId;
}
@Before
public void setUp() throws Exception {
Assume.assumeNotNull(sFileSystem);
}
protected String getRequiredProperty ( String prop ) {
String val = this.properties.get(prop);
Assume.assumeNotNull(val);
return val;
}
protected String getTestDomain () {
String testDomain = getProperties().get(TestProperties.TEST_DOMAIN);
Assume.assumeNotNull(testDomain);
return testDomain;
}