本文整理汇总了Scala中org.junit.After类的典型用法代码示例。如果您正苦于以下问题:Scala After类的具体用法?Scala After怎么用?Scala After使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了After类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SettingsTest
//设置package包名称以及导入依赖的类
package org.eck.entities
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
import com.google.appengine.tools.development.testing.LocalServiceTestHelper
import com.google.gson.JsonObject
import org.junit.{Assert, Test, After, Before}
class SettingsTest {
val helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig())
@Before def setUp(): Unit = helper.setUp
@After def tearDown() = helper.tearDown()
@Test
def testSetAndGetSetting = {
Settings.set("bla", "ble")
Assert.assertTrue(Settings.get("bla").isDefined)
Assert.assertEquals("ble", Settings.get("bla").get)
}
@Test
def testFromJson = {
val json = new JsonObject
json.addProperty("bla", "ble")
json.addProperty("ble", "bla")
Settings.fromJson(json)
Assert.assertTrue(Settings.get("bla").isDefined)
Assert.assertEquals("ble", Settings.get("bla").get)
Assert.assertTrue(Settings.get("ble").isDefined)
Assert.assertEquals("bla", Settings.get("ble").get)
}
@Test
def asJson = {
Settings.set("bla", "ble")
Settings.set("ble", "bla")
val json = Settings.asJson
Assert.assertEquals("ble", json.get("bla").getAsString)
Assert.assertEquals("bla", json.get("ble").getAsString)
}
}
示例2: TestProducer
//设置package包名称以及导入依赖的类
package com.rockiey.kafka
import java.util.{Date, Properties, Random}
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
import org.junit.{After, Before, Test}
class TestProducer {
val brokers = "localhost:9092"
val topic = "test"
val rnd = new Random()
val props = new Properties()
props.put("metadata.broker.list", brokers)
props.put("serializer.class", "kafka.serializer.StringEncoder")
//props.put("partitioner.class", "com.colobu.kafka.SimplePartitioner")
props.put("producer.type", "async")
//props.put("request.required.acks", "1")
var producer: Producer[String, String] = null
@Before
def before: Unit = {
val config = new ProducerConfig(props)
producer = new Producer[String, String](config)
}
@After
def after: Unit = {
producer.close()
}
def produce(events: Int): Unit = {
val t = System.currentTimeMillis()
for (nEvents <- Range(0, events)) {
val runtime = new Date().getTime()
val ip = "192.168.2." + rnd.nextInt(255)
val msg = runtime + "," + nEvents + ",www.example.com," + ip
val data = new KeyedMessage[String, String](topic, ip, msg)
producer.send(data)
}
System.out.println("sent per second: " + events * 1000 / (System.currentTimeMillis() - t))
}
@Test
def testProducer: Unit = {
produce(100)
}
@Test
def testConsumer {
}
}
示例3: MessageTest
//设置package包名称以及导入依赖的类
package org.eck.entities
import com.google.appengine.tools.development.testing.{LocalDatastoreServiceTestConfig, LocalServiceTestHelper}
import org.junit.{Assert, After, Before, Test}
class MessageTest {
val helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig().setDefaultHighRepJobPolicyUnappliedJobPercentage(100))
@Before def setUp(): Unit = helper.setUp
@After def tearDown() = helper.tearDown()
@Test
def testSaveAndFind = {
val id = new Message("messageTitle", "messageContent").save
val message = Message.findById(id)
Assert.assertEquals(id, message.id)
Assert.assertEquals("messageTitle", message.title)
Assert.assertEquals("messageContent", message.content)
}
}
示例4: ScheduleTest
//设置package包名称以及导入依赖的类
package com.gaiam.gcsis.util
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.Assert._
import org.joda.time.{Interval => JInterval}
import org.joda.time.Instant
import org.joda.time.DateTime
class ScheduleTest {
val i1 : JInterval = new JInterval(new DateTime("2010-01-01"), new DateTime("2010-02-01"))
val i2 : JInterval = new JInterval(new DateTime("2010-02-01"), new DateTime("2010-03-01"))
val i3 : JInterval = new JInterval(new DateTime("2010-03-01"), new DateTime("2010-04-01"))
val i4 : JInterval = new JInterval(new DateTime("2010-01-15"), new DateTime("2010-03-15"))
@Before
def setUp: Unit = {
}
@After
def tearDown: Unit = {
}
@Test
def testOneIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1))
val begin = new DateTime("2010-01-01")
val interval = schedule.continuousInterval(begin)
assertTrue(interval.isDefined)
assertEquals(begin, interval.get.getStart)
assertEquals(i1.getEnd, interval.get.getEnd)
}
@Test
def testTwoOverlappingIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1, i4))
val date = new DateTime("2010-01-20")
val interval = schedule.continuousInterval(date)
assertTrue(interval.isDefined)
assertTrue("interval '" + interval + "' doesn't contain date '" + date + "'", interval.get.contains(date))
assertEquals(i4.getEnd, interval.get.getEnd)
}
@Test
def testAbutsIntervalContinuousInterval = {
val schedule = new IntervalSchedule(Array(i1, i2, i3))
val date = new DateTime("2010-01-20")
val interval = schedule.continuousInterval(date)
assertTrue(interval.isDefined)
assertTrue(interval.get.contains(date))
assertEquals(i3.getEnd, interval.get.getEnd)
}
}
示例5: PluginTest
//设置package包名称以及导入依赖的类
package org.webant.plugin.test
import java.nio.charset.Charset
import org.apache.http.client.fluent.Response
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
class PluginTest extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
def testRegex(): Unit = {
val regex = "http://user.mahua.com/ajax/joke/checkJokesDynamic[\\w\\W]*"
val url = "http://user.mahua.com/ajax/joke/checkJokesDynamic?callback=jQuery17209865076656443552_1498566208473&joke_ids=1679937%2C1679936%2C1679935%2C1679934%2C1679933%2C1679932%2C1679928%2C1679927%2C1679929%2C1679931%2C1679930%2C1679926%2C1679923%2C1679921%2C1679919%2C1679918%2C1679925%2C1679924%2C1679922%2C1679920&_=1498566208688"
println(url.matches(regex))
}
@Test
def testGetVoteUpDown(): Unit = {
val url = "http://user.mahua.com/ajax/joke/checkJokesDynamic?callback=jQuery&joke_ids=1679937&_=1498571259447"
val resp: Response = org.apache.http.client.fluent.Request.Get(url)
.addHeader("Accept", "text/html,application/xhtml+xml,application/json;q=0.9,image/webp,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate, sdch")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36")
.addHeader("Upgrade-Insecure-Requests", "1")
.addHeader("Proxy-Connection", "keep-alive")
.addHeader("DNT", "1")
.execute
val result = resp.returnContent.asString(Charset.forName("UTF-8"))
println(result)
}
}
示例6: KuaidailiCrawlerTest
//设置package包名称以及导入依赖的类
package org.webant.plugin.test.kuaidaili
import java.io.IOException
import java.nio.charset.Charset
import org.jsoup.Jsoup
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
import scala.collection.JavaConverters._
class KuaidailiCrawlerTest extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
@throws[IOException]
def crawl() {
val regex = "http://www.kuaidaili.com/free/?\\w*/?\\d*/?"
val url = "http://www.kuaidaili.com/free/intr/1714/"
if (!url.matches(regex))
return
val resp = org.apache.http.client.fluent.Request.Get(url)
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8")
.addHeader("Cache-Control", "max-age=0")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "channelid=0; sid=1499250960617393; _ga=GA1.2.1752332708.1497859110; _gid=GA1.2.235526105.1499251241; Hm_lvt_7ed65b1cc4b810e9fd37959c9bb51b31=1497859110; Hm_lpvt_7ed65b1cc4b810e9fd37959c9bb51b31=1499252564")
.addHeader("Upgrade-Insecure-Requests", "1")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
.execute
val result = resp.returnContent.asString(Charset.forName("UTF-8"))
val doc = Jsoup.parse(result, url)
val tds = doc.select("#list tbody tr").asScala.map(tr => {
tr.select("td").asScala.map(td => {
td.text()
})
})
println(tds)
}
}
示例7: GuShiWenCrawlerTest
//设置package包名称以及导入依赖的类
package org.webant.plugin.test.gushiwen
import java.io.IOException
import java.nio.charset.Charset
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
import org.webant.plugin.zhihu.processor.{AnswersProcessor, ZhihuSeedProcessor}
class GuShiWenCrawlerTest extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
def testLoadIds(): Unit = {
val seed = new ZhihuSeedProcessor
val answer = new AnswersProcessor
val ids = seed.links()
val remainIds = ids.filter(answer.accept)
println(remainIds.size)
}
@Test
def testRegex(): Unit = {
val regex = "https://www.zhihu.com/api/v4/members/[0-9a-zA-Z-]*/answers?[\\w\\W]*"
val url = "https://www.zhihu.com/api/v4/members/ma-en-32/answers?include=data%5B*%5D.is_normal%2Cis_collapsed%2Ccollapse_reason%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%2Cupvoted_followees%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=20&limit=20&sort_by=created"
println(url.matches(regex))
}
@Test
@throws[IOException]
def crawl() {
val url = "http://www.gushiwen.org/default_3.aspx"
val body = ""
val resp = org.apache.http.client.fluent.Request.Get(url)
// .bodyString(body, ContentType.APPLICATION_FORM_URLENCODED)
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8")
.addHeader("Cache-Control", "max-age=0")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "ASP.NET_SessionId=53xs3mimhjnhuoprpehzws0i; Hm_lvt_04660099568f561a75456483228a9516=1498717319; Hm_lpvt_04660099568f561a75456483228a9516=1498720515")
// .addHeader("If-Modified-Since", "Wed, 28 Jun 2017 08:59:13 GMT")
.addHeader("Referer", "http://www.gushiwen.org/")
.addHeader("Upgrade-Insecure-Requests", "1")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
.execute
val result = resp.returnContent.asString(Charset.forName("UTF-8"))
println(result)
}
}
示例8: ZhihuCrawler
//设置package包名称以及导入依赖的类
package org.webant.plugin.test.zhihu
import java.io.IOException
import java.nio.charset.Charset
import org.apache.http.client.fluent.Response
import org.junit.{After, Before, Test}
import org.scalatest.junit.AssertionsForJUnit
import org.webant.plugin.zhihu.processor.{AnswersProcessor, ZhihuSeedProcessor}
class ZhihuCrawler extends AssertionsForJUnit {
@Before
def init(): Unit = {
}
@After
def exit() {
}
@Test
def testLoadIds(): Unit = {
val seed = new ZhihuSeedProcessor
val answer = new AnswersProcessor
val ids = seed.links()
val remainIds = ids.filter(answer.accept)
println(remainIds.size)
}
@Test
def testRegex(): Unit = {
val regex = "https://www.zhihu.com/api/v4/members/[0-9a-zA-Z-]*/answers?[\\w\\W]*"
val url = "https://www.zhihu.com/api/v4/members/ma-en-32/answers?include=data%5B*%5D.is_normal%2Cis_collapsed%2Ccollapse_reason%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Cmark_infos%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelationship.is_authorized%2Cvoting%2Cis_author%2Cis_thanked%2Cis_nothelp%2Cupvoted_followees%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=20&limit=20&sort_by=created"
println(url.matches(regex))
}
@Test
@throws[IOException]
def crawl() {
val url: String = "https://www.zhihu.com/api/v4/members/huang-jie-rui-23/answers?offset=0&limit=20&sort_by=created&include=data[*].is_normal,is_collapsed,collapse_reason,suggest_edit,comment_count,can_comment,content,voteup_count,reshipment_settings,comment_permission,mark_infos,created_time,updated_time,review_info,relationship.is_authorized,voting,is_author,is_thanked,is_nothelp,upvoted_followees;data[*].author.badge[?(type=best_answerer)].topics"
val body: String = "offset=20&limit=20&sort_by=created&include=data[*].is_normal,is_collapsed,collapse_reason,suggest_edit,comment_count,can_comment,content,voteup_count,reshipment_settings,comment_permission,mark_infos,created_time,updated_time,review_info,relationship.is_authorized,voting,is_author,is_thanked,is_nothelp,upvoted_followees;data[*].author.badge[?(type=best_answerer)].topics"
val referer: String = "https://www.zhihu.com/people/sgai/answers"
val resp: Response = org.apache.http.client.fluent.Request.Get(url)
// .bodyString(body, ContentType.APPLICATION_FORM_URLENCODED)
.addHeader("Accept", "application/json, text/plain, */*")
.addHeader("Accept-Encoding", "gzip, deflate, br")
.addHeader("Accept-Language", "zh-CN,zh;q=0.8")
.addHeader("authorization", "oauth c3cef7c66a1843f8b3a9e6a1e3160e20")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "q_c1=4e2c8fb281aa49f7a1a4c8f88297eb25|1497321957000|1497321957000; q_c1=ce4133c29ce34b8cb8a3d2f217706cee|1497321957000|1497321957000; aliyungf_tc=AQAAAOHxiwPxPQUAUb0Qt6/uDktO7KJF; capsion_ticket=\"2|1:0|10:1497930998|14:capsion_ticket|44:ZjRkNDVkNDEwYmY1NDZiNjk0ZjhlNjA1NGM3Mjk1ODk=|1f544f44ef3522b9bd1dede68727c906774eef7d8e1efc05e62b642bea3278ac\"; r_cap_id=\"MGQxNmI4MTViNDNkNDdkZDhiNDJjYmMxYjFlZTk2MTk=|1498653197|7a5cc12917ace5c66d6558b8d9639d3bdd9734f9\"; cap_id=\"Y2RjYzU4YjQ5MzRlNDEzOGE5NDlhMTgyYTU0Y2ZmNWM=|1498653197|5eb2b7e7932423a4f49322a0d7b0d4087b5536a0\"; d_c0=\"AIBCCu2_-wuPTv6gpIWSY62GJJWv1Q6X7vM=|1498653198\"; _zap=5da260eb-bc7d-4ee6-8563-ca7267dc83a7; __utma=51854390.1081252107.1498653231.1498653231.1498653231.1; __utmc=51854390; __utmz=51854390.1498653231.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=51854390.000--|3=entry_date=20170613=1; l_n_c=1; l_cap_id=\"NzFiNzIxZjM0YTZkNGRmYWJkMGU3NzliZjljYWRmZGQ=|1498653211|9028a58183ea376bf5dcc3be0014a071a6fb0a16\"; n_c=1; _xsrf=77f2b8a9-9707-4117-b1e6-2876f8f8405a")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36")
.addHeader("x-udid", "AIBCCu2_-wuPTv6gpIWSY62GJJWv1Q6X7vM=")
.execute
val result = resp.returnContent.asString(Charset.forName("GBK"))
println(result)
}
}
示例9: TempFileWebCrawlerTest
//设置package包名称以及导入依赖的类
package org.zella.web
import java.util.logging.Level
import com.gargoylesoftware.htmlunit.{BrowserVersion, WebClient}
import com.google.common.truth.Truth._
import org.junit.{After, Before, Test}
class TempFileWebCrawlerTest {
//TODO mp3spbcrawler
val VALID_DOWNLOAD_LINK = "http://musicmp3spb.org/download/nude_city_life/67940862cca1c77354504829f3bfcb6f1480066258"
var webClient: WebClient = _
@Before def setup() {
webClient = new WebClient(BrowserVersion.FIREFOX_45)
webClient.getOptions.setThrowExceptionOnScriptError(false)
webClient.getOptions.setThrowExceptionOnFailingStatusCode(false)
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF)
}
@Test
def clickButton() {
val webCrawler = new TempFileWebCrawler(webClient)
//TODO move webClient.getPage(VALID_DOWNLOAD_LINK) to TempFileWebCrawler
val page = webCrawler.clickButton(webClient.getPage(VALID_DOWNLOAD_LINK))
assertThat(page.getTitleText).isEqualTo("TempFile.ru - ????????? ???????? ?????? ?? 200 ??. ?????????? ??????? ????????.")
}
@Test
def clickDownLoadLink() {
val webCrawler = new TempFileWebCrawler(webClient)
val page = webCrawler.clickButton(webClient.getPage(VALID_DOWNLOAD_LINK))
val link = webCrawler.clickDownloadLink(page)
assertThat(link).startsWith("http://tempfile.ru/download/")
}
@After def clickDownloadLink() {
webClient.close()
}
}
示例10: getCacheManager
//设置package包名称以及导入依赖的类
package org.littlewings.tweetbot.test
import org.infinispan.configuration.global.GlobalConfigurationBuilder
import org.infinispan.manager.{DefaultCacheManager, EmbeddedCacheManager}
import org.junit.After
trait CacheTestSupport {
private var cacheManager: EmbeddedCacheManager = _
protected def getCacheManager: EmbeddedCacheManager = {
if (cacheManager == null) {
val configurationBuilder = new GlobalConfigurationBuilder
configurationBuilder
.globalJmxStatistics()
.allowDuplicateDomains(true)
val m = new DefaultCacheManager(configurationBuilder.build)
cacheManager = m
m
} else {
cacheManager
}
}
@After
def tearDownCacheManager(): Unit = {
cacheManager.stop()
cacheManager = null
}
}